diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 98a5b32e5d902..ea105e26f050d 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -378,6 +378,8 @@ struct DiagCtxtInner { #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum StashKey { ItemNoType, + /// Placeholder type or const `_` in item signature. + BadPlaceholder, UnderscoreForArrayLengths, EarlySyntaxWarning, CallIntoMethod, @@ -579,22 +581,22 @@ impl<'a> DiagCtxtHandle<'a> { /// Stashes a diagnostic for possible later improvement in a different, /// later stage of the compiler. Possible actions depend on the diagnostic /// level: - /// - Level::Bug, Level:Fatal: not allowed, will trigger a panic. - /// - Level::Error: immediately counted as an error that has occurred, because it + /// - `Level::Bug`, `Level:Fatal`: not allowed, will trigger a panic. + /// - `Level::Error`: immediately counted as an error that has occurred, because it /// is guaranteed to be emitted eventually. Can be later accessed with the /// provided `span` and `key` through /// [`DiagCtxtHandle::try_steal_modify_and_emit_err`] or /// [`DiagCtxtHandle::try_steal_replace_and_emit_err`]. These do not allow /// cancellation or downgrading of the error. Returns /// `Some(ErrorGuaranteed)`. - /// - Level::DelayedBug: this does happen occasionally with errors that are + /// - `Level::DelayedBug`: this does happen occasionally with errors that are /// downgraded to delayed bugs. It is not stashed, but immediately /// emitted as a delayed bug. This is because stashing it would cause it /// to be counted by `err_count` which we don't want. It doesn't matter /// that we cannot steal and improve it later, because it's not a /// user-facing error. Returns `Some(ErrorGuaranteed)` as is normal for /// delayed bugs. - /// - Level::Warning and lower (i.e. !is_error()): can be accessed with the + /// - `Level::Warning` and lower (i.e. !is_error()): can be accessed with the /// provided `span` and `key` through [`DiagCtxtHandle::steal_non_err()`]. This /// allows cancelling and downgrading of the diagnostic. Returns `None`. pub fn stash_diagnostic( @@ -672,7 +674,7 @@ impl<'a> DiagCtxtHandle<'a> { assert!(guar.is_some()); let mut err = Diag::::new_diagnostic(self, err); modify_err(&mut err); - assert_eq!(err.level, Error); + assert_matches!(err.level, Error | DelayedBug); err.emit() }) } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 75c0ae86f7592..5d26ab39a06c6 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -28,21 +28,17 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{InferKind, Visitor}; use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind, find_attr}; -use rustc_infer::infer::{InferCtxt, SolverRegionConstraint, TyCtxtInferExt}; -use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; +use rustc_infer::infer::{InferCtxt, SolverRegionConstraint}; +use rustc_infer::traits::DynCompatibilityViolation; use rustc_lint_defs::builtin::REPR_C_ENUMS_LARGER_THAN_INT; use rustc_middle::query::Providers; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{ - self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized, - fold_regions, -}; +use rustc_middle::ty::{self, AdtKind, Const, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; -use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_span::{Ident, Span, Symbol, kw}; use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName; -use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{ - FulfillmentError, ObligationCtxt, hir_ty_lowering_dyn_compatibility_violations, + FulfillmentError, hir_ty_lowering_dyn_compatibility_violations, }; use tracing::{debug, instrument}; use ty::region_constraint::LeafRegionConstraint; @@ -160,20 +156,19 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector { fn placeholder_type_error_diag<'cx, 'tcx>( cx: &'cx dyn HirTyLowerer<'tcx>, generics: Option<&hir::Generics<'_>>, - placeholder_types: Vec, + placeholder_type: Option, additional_spans: Vec, suggest: bool, hir_ty: Option<&hir::Ty<'_>>, kind: &'static str, ) -> Diag<'cx> { - if placeholder_types.is_empty() { + let Some(placeholder_type) = placeholder_type else { return bad_placeholder(cx, additional_spans, kind); - } + }; let params = generics.map(|g| g.params).unwrap_or_default(); let type_name = params.next_type_param_name(None); - let mut sugg: Vec<_> = - placeholder_types.iter().map(|sp| (*sp, (*type_name).to_string())).collect(); + let mut sugg = vec![(placeholder_type, type_name.clone())]; if let Some(generics) = generics { if let Some(span) = params.iter().find_map(|arg| match arg.name { @@ -182,7 +177,7 @@ fn placeholder_type_error_diag<'cx, 'tcx>( }) { // Account for `_` already present in cases like `struct S<_>(_);` and suggest // `struct S(T);` instead of `struct S<_, T>(T);`. - sugg.push((span, (*type_name).to_string())); + sugg.push((span, type_name)); } else if let Some(span) = generics.span_for_param_suggestion() { // Account for bounds, we want `fn foo(_: K)` not `fn foo(_: K)`. sugg.push((span, format!(", {type_name}"))); @@ -191,8 +186,11 @@ fn placeholder_type_error_diag<'cx, 'tcx>( } } - let mut err = - bad_placeholder(cx, placeholder_types.into_iter().chain(additional_spans).collect(), kind); + let mut err = bad_placeholder( + cx, + std::iter::once(placeholder_type).chain(additional_spans).collect(), + kind, + ); // Suggest, but only if it is not a function in const or static if suggest { @@ -286,9 +284,18 @@ impl<'tcx> ItemCtxt<'tcx> { fn report_placeholder_type_error( &self, - placeholder_types: Vec, + placeholder_type: Option, infer_replacements: Vec<(Span, String)>, ) -> ErrorGuaranteed { + let dcx = self.dcx(); + + // Don't emit another diagnostic for synthetic placeholders. + if let Some(span) = placeholder_type + && dcx.has_stashed_diagnostic(span, StashKey::ItemNoType) + { + return dcx.span_delayed_bug(span, "stashed error for typeless item not emitted"); + } + let node = self.tcx.hir_node_by_def_id(self.item_def_id); let generics = node.generics(); let kind_id = match node { @@ -301,7 +308,7 @@ impl<'tcx> ItemCtxt<'tcx> { let mut diag = placeholder_type_error_diag( self, generics, - placeholder_types, + placeholder_type, infer_replacements.iter().map(|&(span, _)| span).collect(), false, None, @@ -311,15 +318,18 @@ impl<'tcx> ItemCtxt<'tcx> { diag.multipart_suggestion( format!( "try replacing `_` with the type{} in the corresponding trait method \ - signature", + signature", rustc_errors::pluralize!(infer_replacements.len()), ), infer_replacements, Applicability::MachineApplicable, ); } - - diag.emit() + if let Some(span) = placeholder_type { + diag.stash(span, StashKey::BadPlaceholder).unwrap() + } else { + diag.emit() + } } #[instrument(level = "debug", skip(self), ret)] @@ -531,15 +541,11 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { } fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> { - if !self.tcx.dcx().has_stashed_diagnostic(span, StashKey::ItemNoType) { - self.report_placeholder_type_error(vec![span], vec![]); - } - Ty::new_error_with_message(self.tcx(), span, "bad placeholder type") + Ty::new_error(self.tcx(), self.report_placeholder_type_error(Some(span), vec![])) } fn ct_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> { - self.report_placeholder_type_error(vec![span], vec![]); - ty::Const::new_error_with_message(self.tcx(), span, "bad placeholder constant") + ty::Const::new_error(self.tcx(), self.report_placeholder_type_error(Some(span), vec![])) } fn register_trait_ascription_bounds( @@ -727,16 +733,16 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { .inputs .iter() .enumerate() - .map(|(i, a)| { - if let hir::TyKind::Infer(()) = a.kind + .map(|(idx, ty)| { + if let hir::TyKind::Infer(()) = ty.kind && let Some(suggested_ty) = - self.lowerer().suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i)) + self.lowerer().suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(idx)) { - infer_replacements.push((a.span, suggested_ty.to_string())); - return Ty::new_error_with_message(tcx, a.span, suggested_ty.to_string()); + infer_replacements.push((ty.span, suggested_ty.to_string())); + return Ty::new_error_with_message(tcx, ty.span, suggested_ty.to_string()); } - self.lowerer().lower_ty(a) + self.lowerer().lower_ty(ty) }) .collect(); @@ -756,7 +762,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { }; if !infer_replacements.is_empty() { - self.report_placeholder_type_error(vec![], infer_replacements); + self.report_placeholder_type_error(None, infer_replacements); } (input_tys, output_ty) } @@ -1177,47 +1183,27 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn let icx = ItemCtxt::new(tcx, def_id); - let output = match tcx.hir_node(hir_id) { + let node = &tcx.hir_node(hir_id); + + let output = match *node { TraitItem(hir::TraitItem { kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)), generics, .. }) - | Item(hir::Item { kind: ItemKind::Fn { sig, generics, .. }, .. }) => { - lower_fn_sig_recovering_infer_ret_ty(&icx, sig, generics, def_id) - } - - ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => { - // Do not try to infer the return type for a impl method coming from a trait - if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id) - && i.of_trait.is_some() - { - icx.lowerer().lower_fn_ty( - hir_id, - sig.header.safety(), - sig.header.abi, - sig.decl, - Some(generics), - None, - ) - } else { - lower_fn_sig_recovering_infer_ret_ty(&icx, sig, generics, def_id) - } + | Item(hir::Item { kind: ItemKind::Fn { sig, generics, .. }, .. }) + | ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) + | TraitItem(hir::TraitItem { kind: TraitItemKind::Fn(sig, _), generics, .. }) => { + icx.lowerer().lower_fn_ty( + hir_id, + sig.header.safety(), + sig.header.abi, + sig.decl, + Some(generics), + None, + ) } - TraitItem(hir::TraitItem { - kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _), - generics, - .. - }) => icx.lowerer().lower_fn_ty( - hir_id, - header.safety(), - header.abi, - decl, - Some(generics), - None, - ), - ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(sig, _, _), .. }) => { let abi = tcx.hir_get_foreign_abi(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id, sig.decl, abi, sig.header.safety()) @@ -1255,313 +1241,6 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn ty::EarlyBinder::bind(tcx, output) } -fn lower_fn_sig_recovering_infer_ret_ty<'tcx>( - icx: &ItemCtxt<'tcx>, - sig: &'tcx hir::FnSig<'tcx>, - generics: &'tcx hir::Generics<'tcx>, - def_id: LocalDefId, -) -> ty::PolyFnSig<'tcx> { - if let Some(infer_ret_ty) = sig.decl.output.is_suggestable_infer_ty() { - return recover_infer_ret_ty(icx, infer_ret_ty, generics, def_id); - } - - icx.lowerer().lower_fn_ty( - icx.tcx().local_def_id_to_hir_id(def_id), - sig.header.safety(), - sig.header.abi, - sig.decl, - Some(generics), - None, - ) -} - -/// Convert `ReLateParam`s in `value` back into `ReBound`s and bind it with `bound_vars`. -fn late_param_regions_to_bound<'tcx, T>( - tcx: TyCtxt<'tcx>, - scope: DefId, - bound_vars: &'tcx ty::List>, - value: T, -) -> ty::Binder<'tcx, T> -where - T: ty::TypeFoldable>, -{ - let value = fold_regions(tcx, value, |r, debruijn| match r.kind() { - ty::ReLateParam(lp) => { - // Should be in scope, otherwise inconsistency happens somewhere. - assert_eq!(lp.scope, scope); - - let br = match lp.kind { - // These variants preserve the bound var index. - kind @ (ty::LateParamRegionKind::Anon(idx) - | ty::LateParamRegionKind::NamedAnon(idx, _)) => { - let idx = idx as usize; - let var = ty::BoundVar::from_usize(idx); - - let Some(ty::BoundVariableKind::Region(kind)) = bound_vars.get(idx).copied() - else { - bug!("unexpected late-bound region {kind:?} for bound vars {bound_vars:?}"); - }; - - ty::BoundRegion { var, kind } - } - - // For named regions, look up the corresponding bound var. - ty::LateParamRegionKind::Named(def_id) => bound_vars - .iter() - .enumerate() - .find_map(|(idx, bv)| match bv { - ty::BoundVariableKind::Region(kind @ ty::BoundRegionKind::Named(did)) - if did == def_id => - { - Some(ty::BoundRegion { var: ty::BoundVar::from_usize(idx), kind }) - } - _ => None, - }) - .unwrap(), - - ty::LateParamRegionKind::ClosureEnv => bound_vars - .iter() - .enumerate() - .find_map(|(idx, bv)| match bv { - ty::BoundVariableKind::Region(kind @ ty::BoundRegionKind::ClosureEnv) => { - Some(ty::BoundRegion { var: ty::BoundVar::from_usize(idx), kind }) - } - _ => None, - }) - .unwrap(), - }; - - ty::Region::new_bound(tcx, debruijn, br) - } - _ => r, - }); - - ty::Binder::bind_with_vars(value, bound_vars) -} - -fn recover_infer_ret_ty<'tcx>( - icx: &ItemCtxt<'tcx>, - infer_ret_ty: &'tcx hir::Ty<'tcx>, - generics: &'tcx hir::Generics<'tcx>, - def_id: LocalDefId, -) -> ty::PolyFnSig<'tcx> { - let tcx = icx.tcx; - let hir_id = tcx.local_def_id_to_hir_id(def_id); - - let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id]; - - // Typeck doesn't expect erased regions to be returned from `type_of`. - // This is a heuristic approach. If the scope has region parameters, - // we should change fn_sig's lifetime from `ReErased` to `ReError`, - // otherwise to `ReStatic`. - let has_region_params = generics.params.iter().any(|param| match param.kind { - GenericParamKind::Lifetime { .. } => true, - _ => false, - }); - let fn_sig = fold_regions(tcx, fn_sig, |r, _| match r.kind() { - ty::ReErased => { - if has_region_params { - ty::Region::new_error_with_message( - tcx, - DUMMY_SP, - "erased region is not allowed here in return type", - ) - } else { - tcx.lifetimes.re_static - } - } - _ => r, - }); - - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_ty_unambig(infer_ret_ty); - - let mut diag = bad_placeholder(icx.lowerer(), visitor.spans, "return type"); - let ret_ty = fn_sig.output(); - - // Don't leak types into signatures unless they're nameable! - // For example, if a function returns itself, we don't want that - // recursive function definition to leak out into the fn sig. - let mut recovered_ret_ty = None; - if let Some(suggestable_ret_ty) = ret_ty.make_suggestable(tcx, false, None) { - diag.span_suggestion_verbose( - infer_ret_ty.span, - "replace with the correct return type", - suggestable_ret_ty, - Applicability::MachineApplicable, - ); - recovered_ret_ty = Some(suggestable_ret_ty); - } else if let Some(sugg) = suggest_impl_trait( - &tcx.infer_ctxt().build(TypingMode::non_body_analysis()), - tcx.param_env(def_id), - ret_ty, - ) { - diag.span_suggestion_verbose( - infer_ret_ty.span, - "replace with an appropriate return type", - sugg, - Applicability::MachineApplicable, - ); - } else if ret_ty.is_closure() { - diag.help("consider using an `Fn`, `FnMut`, or `FnOnce` trait bound"); - } - - // Also note how `Fn` traits work just in case! - if ret_ty.is_closure() { - diag.note( - "for more information on `Fn` traits and closure types, see \ - https://doc.rust-lang.org/book/ch13-01-closures.html", - ); - } - let guar = diag.emit(); - - // If we return a dummy binder here, we can ICE later in borrowck when it encounters - // `ReLateParam` regions (e.g. in a local type annotation) which weren't registered via the - // signature binder. See #135845. - let bound_vars = tcx.late_bound_vars(hir_id); - let scope = def_id.to_def_id(); - - let fn_sig = tcx.mk_fn_sig( - fn_sig.inputs().iter().copied(), - recovered_ret_ty.unwrap_or_else(|| Ty::new_error(tcx, guar)), - fn_sig.fn_sig_kind, - ); - - late_param_regions_to_bound(tcx, scope, bound_vars, fn_sig) -} - -pub fn suggest_impl_trait<'tcx>( - infcx: &InferCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, - ret_ty: Ty<'tcx>, -) -> Option { - let format_as_assoc: fn(_, _, _, _, _) -> _ = - |tcx: TyCtxt<'tcx>, - _: ty::GenericArgsRef<'tcx>, - trait_def_id: DefId, - assoc_item_def_id: DefId, - item_ty: Ty<'tcx>| { - let trait_name = tcx.item_name(trait_def_id); - let assoc_name = tcx.item_name(assoc_item_def_id); - Some(format!("impl {trait_name}<{assoc_name} = {item_ty}>")) - }; - let format_as_parenthesized: fn(_, _, _, _, _) -> _ = - |tcx: TyCtxt<'tcx>, - args: ty::GenericArgsRef<'tcx>, - trait_def_id: DefId, - _: DefId, - item_ty: Ty<'tcx>| { - let trait_name = tcx.item_name(trait_def_id); - let args_tuple = args.type_at(1); - let ty::Tuple(types) = *args_tuple.kind() else { - return None; - }; - let types = types.make_suggestable(tcx, false, None)?; - let maybe_ret = - if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") }; - Some(format!( - "impl {trait_name}({}){maybe_ret}", - types.iter().map(|ty| ty.to_string()).collect::>().join(", ") - )) - }; - - for (trait_def_id, assoc_item_def_id, formatter) in [ - ( - infcx.tcx.get_diagnostic_item(sym::Iterator), - infcx.tcx.get_diagnostic_item(sym::IteratorItem), - format_as_assoc, - ), - ( - infcx.tcx.lang_items().future_trait(), - infcx.tcx.lang_items().future_output(), - format_as_assoc, - ), - ( - infcx.tcx.lang_items().async_fn_trait(), - infcx.tcx.lang_items().async_fn_once_output(), - format_as_parenthesized, - ), - ( - infcx.tcx.lang_items().async_fn_mut_trait(), - infcx.tcx.lang_items().async_fn_once_output(), - format_as_parenthesized, - ), - ( - infcx.tcx.lang_items().async_fn_once_trait(), - infcx.tcx.lang_items().async_fn_once_output(), - format_as_parenthesized, - ), - ( - infcx.tcx.lang_items().fn_trait(), - infcx.tcx.lang_items().fn_once_output(), - format_as_parenthesized, - ), - ( - infcx.tcx.lang_items().fn_mut_trait(), - infcx.tcx.lang_items().fn_once_output(), - format_as_parenthesized, - ), - ( - infcx.tcx.lang_items().fn_once_trait(), - infcx.tcx.lang_items().fn_once_output(), - format_as_parenthesized, - ), - ] { - let Some(trait_def_id) = trait_def_id else { - continue; - }; - let Some(assoc_item_def_id) = assoc_item_def_id else { - continue; - }; - if infcx.tcx.def_kind(assoc_item_def_id) != DefKind::AssocTy { - continue; - } - let sugg = infcx.probe(|_| { - let args = ty::GenericArgs::for_item(infcx.tcx, trait_def_id, |param, _| { - if param.index == 0 { ret_ty.into() } else { infcx.var_for_def(DUMMY_SP, param) } - }); - if !infcx - .type_implements_trait(trait_def_id, args, param_env) - .must_apply_modulo_regions() - { - return None; - } - let ocx = ObligationCtxt::new(&infcx); - let item_ty = ocx.normalize( - &ObligationCause::dummy(), - param_env, - Unnormalized::new(Ty::new_projection_from_args( - infcx.tcx, - ty::IsRigid::No, - assoc_item_def_id, - args, - )), - ); - // FIXME(compiler-errors): We may benefit from resolving regions here. - if ocx.try_evaluate_obligations().no_errors() - && let item_ty = infcx.resolve_vars_if_possible(item_ty) - && let Some(item_ty) = item_ty.make_suggestable(infcx.tcx, false, None) - && let Some(sugg) = formatter( - infcx.tcx, - infcx.resolve_vars_if_possible(args), - trait_def_id, - assoc_item_def_id, - item_ty, - ) - { - return Some(sugg); - } - - None - }); - - if sugg.is_some() { - return sugg; - } - } - None -} - fn impl_is_fully_generic_for_reflection(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { tcx.impl_trait_header(def_id).is_fully_generic_for_reflection() && tcx.explicit_clauses_of(def_id).is_fully_generic_for_reflection() diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 9ad26f7975858..19cdeb9a87de3 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -483,29 +483,31 @@ fn infer_placeholder_type<'tcx>( if ty_span.from_expansion() { return; } - if !ty.references_error() { - // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic). - let colon = if ty_span == item_ident.span.shrink_to_hi() { ":" } else { "" }; - - // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type. - // We are typeck and have the real type, so remove that and suggest the actual type. - if let Suggestions::Enabled(suggestions) = &mut err.suggestions { - suggestions.clear(); - } + if ty.references_error() { + return; + } - if let Some(ty) = ty.make_suggestable(tcx, false, None) { - err.span_suggestion( - ty_span, - format!("provide a type for the {kind}"), - with_types_for_suggestion!(format!("{colon} {ty}")), - Applicability::MachineApplicable, - ); - } else { - with_forced_trimmed_paths!(err.span_note( - body_span, - format!("however, the inferred type `{ty}` cannot be named"), - )); - } + // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic). + let colon = if ty_span == item_ident.span.shrink_to_hi() { ":" } else { "" }; + + // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type. + // We are typeck and have the real type, so remove that and suggest the actual type. + if let Suggestions::Enabled(suggestions) = &mut err.suggestions { + suggestions.clear(); + } + + if let Some(ty) = ty.make_suggestable(tcx, false, None) { + err.span_suggestion( + ty_span, + format!("provide a type for the {kind}"), + with_types_for_suggestion!(format!("{colon} {ty}")), + Applicability::MachineApplicable, + ); + } else { + with_forced_trimmed_paths!(err.span_note( + body_span, + format!("however, the inferred type `{ty}` cannot be named"), + )); } }) .unwrap_or_else(|| { diff --git a/compiler/rustc_hir_analysis/src/diagnostics.rs b/compiler/rustc_hir_analysis/src/diagnostics.rs index a50aefd016059..75988616aca33 100644 --- a/compiler/rustc_hir_analysis/src/diagnostics.rs +++ b/compiler/rustc_hir_analysis/src/diagnostics.rs @@ -818,7 +818,7 @@ pub(crate) struct ReturnTypeNotationEqualityBound { #[derive(Diagnostic)] #[diag("the placeholder `_` is not allowed within types on item signatures for {$kind}", code = E0121)] -pub(crate) struct PlaceholderNotAllowedItemSignatures { +pub struct PlaceholderNotAllowedItemSignatures { #[primary_span] #[label("not allowed in type signatures")] pub spans: Vec, diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 20ef75244bb4e..495de32d27d27 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -92,7 +92,6 @@ use rustc_session::diagnostics::feature_err; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::traits; -pub use crate::collect::suggest_impl_trait; use crate::hir_ty_lowering::HirTyLowerer; fn check_c_variadic_abi(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: ExternAbi, span: Span) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 3e2c2e8cc3944..eee6d9c00dcb4 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -16,7 +16,6 @@ use rustc_hir::{ TyKind, WherePredicateKind, expr_needs_parens, is_range_literal, }; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; -use rustc_hir_analysis::suggest_impl_trait; use rustc_middle::middle::stability::EvalResult; use rustc_middle::span_bug; use rustc_middle::ty::print::{with_no_trimmed_paths, with_types_for_suggestion}; @@ -1006,7 +1005,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span, found: found.to_string(), }); - } else if let Some(sugg) = suggest_impl_trait(self, self.param_env, found) { + } else if let Some(sugg) = crate::suggest_impl_trait(self, self.param_env, found) { err.subdiagnostic(diagnostics::AddReturnTypeSuggestion::Add { span, found: sugg, diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 0f977710fbe09..60ddd06c7fe57 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -46,17 +46,25 @@ use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::Visitor; use rustc_hir::{HirId, HirIdMap, Node}; use rustc_hir_analysis::check::check_abi; +use rustc_hir_analysis::diagnostics::PlaceholderNotAllowedItemSignatures; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; -use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, TraitEngine, WellFormedLoc}; +use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, FnSigKind, Ty, TyCtxt, Unnormalized}; +use rustc_middle::ty::{self, FnSigKind, IsSuggestable, Ty, TyCtxt, Unnormalized}; use rustc_middle::{bug, span_bug}; use rustc_session::config; -use rustc_span::Span; use rustc_span::def_id::LocalDefId; +use rustc_span::{DUMMY_SP, Span, sym}; +use rustc_trait_selection::infer::InferCtxtExt; +use rustc_trait_selection::traits::{ + ObligationCause, ObligationCauseCode, ObligationCtxt, ObligationInspector, TraitEngine, + WellFormedLoc, +}; use tracing::{debug, instrument}; use typeck_root_ctxt::TypeckRootCtxt; @@ -270,6 +278,8 @@ fn typeck_with_inspect<'tcx>( let typeck_results = fcx.resolve_type_vars_in_body(body); + check_placeholder_infer_ret_ty(tcx, typeck_results, id, def_id, node); + fcx.detect_opaque_types_added_during_writeback(); // Consistency check our TypeckResults instance can hold all ItemLocalIds @@ -279,6 +289,241 @@ fn typeck_with_inspect<'tcx>( typeck_results } +/// After typeck has inferred the return type for a function with `-> _`, +/// emit the error diagnostic with suggestions for the correct return type. +fn check_placeholder_infer_ret_ty<'tcx>( + tcx: TyCtxt<'tcx>, + typeck_results: &ty::TypeckResults<'tcx>, + hir_id: HirId, + def_id: LocalDefId, + node: Node<'tcx>, +) { + let sig = match node { + Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(_)), + .. + }) + | Node::Item(hir::Item { kind: hir::ItemKind::Fn { sig, .. }, .. }) => sig, + + Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(sig, _), .. }) => { + // Do not try to infer the return type for a impl method coming from a trait + if let Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) = + tcx.parent_hir_node(hir_id) + && i.of_trait.is_some() + { + return; + } else { + sig + } + } + + _ => return, + }; + let Some(infer_ret_ty) = sig.decl.output.is_suggestable_infer_ty() else { return }; + + struct PlaceholderSpanCollector { + spans: Vec, + } + + impl<'v> hir::intravisit::Visitor<'v> for PlaceholderSpanCollector { + fn visit_infer( + &mut self, + _inf_id: HirId, + inf_span: Span, + _kind: hir::intravisit::InferKind<'v>, + ) -> Self::Result { + self.spans.push(inf_span); + } + } + + // Collect all `_` placeholder spans from the return type. + let mut collector = PlaceholderSpanCollector { spans: Vec::new() }; + collector.visit_ty_unambig(infer_ret_ty); + + // Suppress the errors that HIR ty lowering has emitted for each placeholder since we want to + // emit a single diagnostic for all of them with a good structured suggestion if possible. + for &span in &collector.spans { + tcx.dcx().try_steal_modify_and_emit_err( + span, + rustc_errors::StashKey::BadPlaceholder, + |diag| diag.downgrade_to_delayed_bug(), + ); + } + let mut diag = tcx.dcx().create_err(PlaceholderNotAllowedItemSignatures { + spans: collector.spans, + kind: "return types".to_string(), + }); + + let ret_ty = typeck_results.liberated_fn_sigs()[hir_id].output(); + + // Don't leak types into signatures unless they're nameable! + // For example, if a function returns itself, we don't want that + // recursive function definition to leak out into the fn sig. + if let Some(suggestable_ret_ty) = ret_ty.make_suggestable(tcx, false, None) { + diag.span_suggestion_verbose( + infer_ret_ty.span, + "replace with the correct return type", + suggestable_ret_ty, + Applicability::MachineApplicable, + ); + } else if let Some(sugg) = suggest_impl_trait( + &tcx.infer_ctxt().build(ty::TypingMode::non_body_analysis()), + tcx.param_env(def_id), + ret_ty, + ) { + diag.span_suggestion_verbose( + infer_ret_ty.span, + "replace with an appropriate return type", + sugg, + Applicability::MachineApplicable, + ); + } else if ret_ty.is_closure() { + diag.help("consider using an `Fn`, `FnMut`, or `FnOnce` trait bound"); + } + + // Also note how `Fn` traits work just in case! + if ret_ty.is_closure() { + diag.note( + "for more information on `Fn` traits and closure types, see \ + https://doc.rust-lang.org/book/ch13-01-closures.html", + ); + } + + diag.emit(); +} + +fn suggest_impl_trait<'tcx>( + infcx: &InferCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ret_ty: Ty<'tcx>, +) -> Option { + let format_as_assoc: fn(_, _, _, _, _) -> _ = + |tcx: TyCtxt<'tcx>, + _: ty::GenericArgsRef<'tcx>, + trait_def_id: DefId, + assoc_item_def_id: DefId, + item_ty: Ty<'tcx>| { + let trait_name = tcx.item_name(trait_def_id); + let assoc_name = tcx.item_name(assoc_item_def_id); + Some(format!("impl {trait_name}<{assoc_name} = {item_ty}>")) + }; + let format_as_parenthesized: fn(_, _, _, _, _) -> _ = + |tcx: TyCtxt<'tcx>, + args: ty::GenericArgsRef<'tcx>, + trait_def_id: DefId, + _: DefId, + item_ty: Ty<'tcx>| { + let trait_name = tcx.item_name(trait_def_id); + let args_tuple = args.type_at(1); + let ty::Tuple(types) = *args_tuple.kind() else { + return None; + }; + let types = types.make_suggestable(tcx, false, None)?; + let maybe_ret = + if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") }; + Some(format!( + "impl {trait_name}({}){maybe_ret}", + types.iter().map(|ty| ty.to_string()).collect::>().join(", ") + )) + }; + + for (trait_def_id, assoc_item_def_id, formatter) in [ + ( + infcx.tcx.get_diagnostic_item(sym::Iterator), + infcx.tcx.get_diagnostic_item(sym::IteratorItem), + format_as_assoc, + ), + ( + infcx.tcx.lang_items().future_trait(), + infcx.tcx.lang_items().future_output(), + format_as_assoc, + ), + ( + infcx.tcx.lang_items().async_fn_trait(), + infcx.tcx.lang_items().async_fn_once_output(), + format_as_parenthesized, + ), + ( + infcx.tcx.lang_items().async_fn_mut_trait(), + infcx.tcx.lang_items().async_fn_once_output(), + format_as_parenthesized, + ), + ( + infcx.tcx.lang_items().async_fn_once_trait(), + infcx.tcx.lang_items().async_fn_once_output(), + format_as_parenthesized, + ), + ( + infcx.tcx.lang_items().fn_trait(), + infcx.tcx.lang_items().fn_once_output(), + format_as_parenthesized, + ), + ( + infcx.tcx.lang_items().fn_mut_trait(), + infcx.tcx.lang_items().fn_once_output(), + format_as_parenthesized, + ), + ( + infcx.tcx.lang_items().fn_once_trait(), + infcx.tcx.lang_items().fn_once_output(), + format_as_parenthesized, + ), + ] { + let Some(trait_def_id) = trait_def_id else { + continue; + }; + let Some(assoc_item_def_id) = assoc_item_def_id else { + continue; + }; + if infcx.tcx.def_kind(assoc_item_def_id) != DefKind::AssocTy { + continue; + } + let sugg = infcx.probe(|_| { + let args = ty::GenericArgs::for_item(infcx.tcx, trait_def_id, |param, _| { + if param.index == 0 { ret_ty.into() } else { infcx.var_for_def(DUMMY_SP, param) } + }); + if !infcx + .type_implements_trait(trait_def_id, args, param_env) + .must_apply_modulo_regions() + { + return None; + } + let ocx = ObligationCtxt::new(&infcx); + let item_ty = ocx.normalize( + &ObligationCause::dummy(), + param_env, + Unnormalized::new(Ty::new_projection_from_args( + infcx.tcx, + ty::IsRigid::No, + assoc_item_def_id, + args, + )), + ); + // FIXME(compiler-errors): We may benefit from resolving regions here. + if ocx.try_evaluate_obligations().no_errors() + && let item_ty = infcx.resolve_vars_if_possible(item_ty) + && let Some(item_ty) = item_ty.make_suggestable(infcx.tcx, false, None) + && let Some(sugg) = formatter( + infcx.tcx, + infcx.resolve_vars_if_possible(args), + trait_def_id, + assoc_item_def_id, + item_ty, + ) + { + return Some(sugg); + } + + None + }); + + if sugg.is_some() { + return sugg; + } + } + None +} + fn extend_err_with_const_context( err: &mut Diag<'_>, tcx: TyCtxt<'_>, diff --git a/tests/ui/async-await/async-closures/ice-async-closure-variance-issue-148488.stderr b/tests/ui/async-await/async-closures/ice-async-closure-variance-issue-148488.stderr index 507b1e895898d..6cb68da292809 100644 --- a/tests/ui/async-await/async-closures/ice-async-closure-variance-issue-148488.stderr +++ b/tests/ui/async-await/async-closures/ice-async-closure-variance-issue-148488.stderr @@ -6,6 +6,14 @@ LL | fn ord() -> _ { | = note: `#[warn(non_camel_case_types)]` (part of `#[warn(nonstandard_style)]`) on by default +error[E0392]: lifetime parameter `'g` is never used + --> $DIR/ice-async-closure-variance-issue-148488.rs:3:10 + | +LL | struct T<'g>(); + | ^^ unused lifetime parameter + | + = help: consider removing `'g`, referring to it in a field, or using a marker such as `PhantomData` + error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/ice-async-closure-variance-issue-148488.rs:6:16 | @@ -18,14 +26,6 @@ LL - fn ord() -> _ { LL + fn ord() -> impl AsyncFn() { | -error[E0392]: lifetime parameter `'g` is never used - --> $DIR/ice-async-closure-variance-issue-148488.rs:3:10 - | -LL | struct T<'g>(); - | ^^ unused lifetime parameter - | - = help: consider removing `'g`, referring to it in a field, or using a marker such as `PhantomData` - error: aborting due to 2 previous errors; 1 warning emitted Some errors have detailed explanations: E0121, E0392. diff --git a/tests/ui/async-await/issues/issue-95307.rs b/tests/ui/async-await/issues/issue-95307.rs index 40905c239c348..aae20fbd62dba 100644 --- a/tests/ui/async-await/issues/issue-95307.rs +++ b/tests/ui/async-await/issues/issue-95307.rs @@ -6,9 +6,6 @@ pub trait C { async fn new() -> [u8; _]; //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types - //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types - //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types - //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types } fn main() {} diff --git a/tests/ui/async-await/issues/issue-95307.stderr b/tests/ui/async-await/issues/issue-95307.stderr index 0aae7a215cda0..573bb046f9649 100644 --- a/tests/ui/async-await/issues/issue-95307.stderr +++ b/tests/ui/async-await/issues/issue-95307.stderr @@ -4,30 +4,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | async fn new() -> [u8; _]; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/issue-95307.rs:7:28 - | -LL | async fn new() -> [u8; _]; - | ^ not allowed in type signatures - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/issue-95307.rs:7:28 - | -LL | async fn new() -> [u8; _]; - | ^ not allowed in type signatures - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/issue-95307.rs:7:28 - | -LL | async fn new() -> [u8; _]; - | ^ not allowed in type signatures - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 4 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/closures/missing-body.stderr b/tests/ui/closures/missing-body.stderr index 33580fc2fbd2a..ffe40892de9cf 100644 --- a/tests/ui/closures/missing-body.stderr +++ b/tests/ui/closures/missing-body.stderr @@ -1,9 +1,3 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for closures - --> $DIR/missing-body.rs:5:23 - | -LL | fn main() { |b: [str; _]| {}; } - | ^ not allowed in type signatures - error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/missing-body.rs:5:17 | @@ -13,6 +7,12 @@ LL | fn main() { |b: [str; _]| {}; } = help: the trait `Sized` is not implemented for `str` = note: slice and array elements must have `Sized` type +error[E0121]: the placeholder `_` is not allowed within types on item signatures for closures + --> $DIR/missing-body.rs:5:23 + | +LL | fn main() { |b: [str; _]| {}; } + | ^ not allowed in type signatures + error: aborting due to 2 previous errors Some errors have detailed explanations: E0121, E0277. diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr index d7a7ab52c83de..89fc94e9ae5ef 100644 --- a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr +++ b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr @@ -1,41 +1,3 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/in-signature.rs:6:21 - | -LL | fn arr_fn() -> [u8; _] { - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn arr_fn() -> [u8; _] { -LL + fn arr_fn() -> [u8; 3] { - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/in-signature.rs:11:24 - | -LL | fn ty_fn() -> Bar { - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn ty_fn() -> Bar { -LL + fn ty_fn() -> Bar { - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/in-signature.rs:16:25 - | -LL | fn ty_fn_mixed() -> Bar<_, _> { - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn ty_fn_mixed() -> Bar<_, _> { -LL + fn ty_fn_mixed() -> Bar { - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/in-signature.rs:21:20 | @@ -112,6 +74,68 @@ LL - static TY_STATIC_MIXED: Bar<_, _> = Bar::(0); LL + static TY_STATIC_MIXED: Bar = Bar::(0); | +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/in-signature.rs:6:21 + | +LL | fn arr_fn() -> [u8; _] { + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn arr_fn() -> [u8; _] { +LL + fn arr_fn() -> [u8; 3] { + | + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/in-signature.rs:11:24 + | +LL | fn ty_fn() -> Bar { + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn ty_fn() -> Bar { +LL + fn ty_fn() -> Bar { + | + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/in-signature.rs:16:25 + | +LL | fn ty_fn_mixed() -> Bar<_, _> { + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn ty_fn_mixed() -> Bar<_, _> { +LL + fn ty_fn_mixed() -> Bar { + | + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/in-signature.rs:42:23 + | +LL | const ARR: Bar<_, _>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/in-signature.rs:42:20 + | +LL | const ARR: Bar<_, _>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/in-signature.rs:38:25 + | +LL | const ARR: Bar; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/in-signature.rs:34:21 + | +LL | const ARR: [u8; _]; + | ^ not allowed in type signatures + error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types --> $DIR/in-signature.rs:51:23 | @@ -136,30 +160,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | type Assoc = Bar<_, _>; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/in-signature.rs:34:21 - | -LL | const ARR: [u8; _]; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/in-signature.rs:38:25 - | -LL | const ARR: Bar; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/in-signature.rs:42:20 - | -LL | const ARR: Bar<_, _>; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/in-signature.rs:42:23 - | -LL | const ARR: Bar<_, _>; - | ^ not allowed in type signatures - error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr index bd738ad505705..c0b8164a99b16 100644 --- a/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr +++ b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr @@ -1,15 +1,15 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/pointee-type-with-error-issue-159560.rs:4:8 - | -LL | f: _, - | ^ not allowed in type signatures - error[E0080]: encountered static that tried to access itself during initialization --> $DIR/pointee-type-with-error-issue-159560.rs:8:16 | LL | static B: &A = B; | ^ evaluation of `B` failed here +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/pointee-type-with-error-issue-159560.rs:4:8 + | +LL | f: _, + | ^ not allowed in type signatures + error: aborting due to 2 previous errors Some errors have detailed explanations: E0080, E0121. diff --git a/tests/ui/delegation/generics/generics-gen-args-errors.stderr b/tests/ui/delegation/generics/generics-gen-args-errors.stderr index 600b30f19ba6f..08f1e39f9c9bb 100644 --- a/tests/ui/delegation/generics/generics-gen-args-errors.stderr +++ b/tests/ui/delegation/generics/generics-gen-args-errors.stderr @@ -458,12 +458,6 @@ error: inferred lifetimes are not allowed in delegations as we need to inherit s LL | reuse Trait::<'static, 'static>::foo as bar2; | ^^^^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/generics-gen-args-errors.rs:103:11 - | -LL | reuse Trait::<'static, 'static>::foo as bar2; - | ^^^^^ not allowed in type signatures - error[E0107]: trait takes 3 lifetime arguments but 0 lifetime arguments were supplied --> $DIR/generics-gen-args-errors.rs:107:11 | @@ -560,12 +554,6 @@ error: inferred lifetimes are not allowed in delegations as we need to inherit s LL | reuse Trait::<'static>::foo as bar5; | ^^^^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/generics-gen-args-errors.rs:117:11 - | -LL | reuse Trait::<'static>::foo as bar5; - | ^^^^^ not allowed in type signatures - error[E0107]: trait takes 3 lifetime arguments but 1 lifetime argument was supplied --> $DIR/generics-gen-args-errors.rs:122:11 | @@ -790,6 +778,18 @@ error[E0747]: constant provided when a type was expected LL | reuse foo::<{}, {}, {}> as bar8; | ^^ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/generics-gen-args-errors.rs:103:11 + | +LL | reuse Trait::<'static, 'static>::foo as bar2; + | ^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/generics-gen-args-errors.rs:117:11 + | +LL | reuse Trait::<'static>::foo as bar5; + | ^^^^^ not allowed in type signatures + error: aborting due to 74 previous errors Some errors have detailed explanations: E0107, E0121, E0261, E0401, E0423, E0425, E0747. diff --git a/tests/ui/delegation/generics/infers.stderr b/tests/ui/delegation/generics/infers.stderr index 1ab3ef232832e..a7b424aea660a 100644 --- a/tests/ui/delegation/generics/infers.stderr +++ b/tests/ui/delegation/generics/infers.stderr @@ -446,12 +446,6 @@ error[E0224]: at least one trait is required for an object type LL | reuse foo::('_, _, _, _) as bar; | ^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:54:25 - | -LL | reuse foo::('_, _, _, _) as bar; - | ^ not allowed in type signatures - error[E0107]: function takes 3 generic arguments but 5 generic arguments were supplied --> $DIR/infers.rs:86:11 | @@ -601,18 +595,6 @@ error: inferred lifetimes are not allowed in delegations as we need to inherit s LL | reuse foo::, _, _, ()> as foo11; | ^^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:117:21 - | -LL | reuse foo::, _, _, ()> as foo11; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:128:25 - | -LL | reuse foo::<'_, Vec<_>, Vec>, _> as foo13; - | ^ not allowed in type signatures - error[E0747]: type provided when a constant was expected --> $DIR/infers.rs:128:29 | @@ -804,18 +786,6 @@ error: inferred lifetimes are not allowed in delegations as we need to inherit s LL | reuse Trait::foo::, _, _, ()> as foo11; | ^^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:189:32 - | -LL | reuse Trait::foo::, _, _, ()> as foo11; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:200:36 - | -LL | reuse Trait::foo::<'_, Vec<_>, Vec>, _> as foo13; - | ^ not allowed in type signatures - error[E0747]: type provided when a constant was expected --> $DIR/infers.rs:200:40 | @@ -900,24 +870,6 @@ help: add missing generic arguments LL | reuse Trait::<_, _>::foo, X, C, Y as foo5; | +++++++++ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:231:15 - | -LL | reuse Trait::<'_, '_>::foo as foo6; - | ^^^^^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:234:35 - | -LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo as foo7; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:234:52 - | -LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo as foo7; - | ^ not allowed in type signatures - error[E0107]: trait takes 3 generic arguments but 7 generic arguments were supplied --> $DIR/infers.rs:241:15 | @@ -1030,12 +982,6 @@ note: method defined here, with 3 generic parameters: `XX`, `M`, `YY` LL | fn foo<'aa, 'bb: 'bb, 'cc, XX, const M: usize, YY>(&self, _: &'aa &'b &'cc ()) {} | ^^^ -- -------------- -- -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:276:15 - | -LL | reuse Trait::<'_, '_>::foo::<_, _, _, '_, '_, '_, _, _, _,> as foo6; - | ^^^^^ not allowed in type signatures - error[E0107]: method takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/infers.rs:276:32 | @@ -1064,18 +1010,6 @@ note: method defined here, with 3 generic parameters: `XX`, `M`, `YY` LL | fn foo<'aa, 'bb: 'bb, 'cc, XX, const M: usize, YY>(&self, _: &'aa &'b &'cc ()) {} | ^^^ -- -------------- -- -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:283:35 - | -LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo::<_, '_, _, _> as foo7; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:283:52 - | -LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo::<_, '_, _, _> as foo7; - | ^ not allowed in type signatures - error[E0107]: method takes 3 generic arguments but 0 generic arguments were supplied --> $DIR/infers.rs:294:51 | @@ -1209,12 +1143,6 @@ error: inferred lifetimes are not allowed in delegations as we need to inherit s LL | reuse Trait::<'static, 'static, '_,'_, '_, '_, '_, '_>::foo::, _, _, ()> as foo11; | ^^^ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/infers.rs:306:75 - | -LL | reuse Trait::<'static, 'static, '_,'_, '_, '_, '_, '_>::foo::, _, _, ()> as foo11; - | ^ not allowed in type signatures - error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied --> $DIR/infers.rs:316:15 | @@ -1290,6 +1218,78 @@ note: function defined here LL | pub fn foo(_: ()) {} | ^^^ ----- +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:54:25 + | +LL | reuse foo::('_, _, _, _) as bar; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:117:21 + | +LL | reuse foo::, _, _, ()> as foo11; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:128:25 + | +LL | reuse foo::<'_, Vec<_>, Vec>, _> as foo13; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:189:32 + | +LL | reuse Trait::foo::, _, _, ()> as foo11; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:200:36 + | +LL | reuse Trait::foo::<'_, Vec<_>, Vec>, _> as foo13; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:231:15 + | +LL | reuse Trait::<'_, '_>::foo as foo6; + | ^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:234:35 + | +LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo as foo7; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:234:52 + | +LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo as foo7; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:276:15 + | +LL | reuse Trait::<'_, '_>::foo::<_, _, _, '_, '_, '_, _, _, _,> as foo6; + | ^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:283:35 + | +LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo::<_, '_, _, _> as foo7; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:283:52 + | +LL | reuse Trait::<'_, '_, Vec<_>, 123, Vec>>::foo::<_, '_, _, _> as foo7; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/infers.rs:306:75 + | +LL | reuse Trait::<'static, 'static, '_,'_, '_, '_, '_, '_>::foo::, _, _, ()> as foo11; + | ^ not allowed in type signatures + error: aborting due to 138 previous errors Some errors have detailed explanations: E0107, E0121, E0207, E0214, E0224, E0261, E0308, E0425, E0747. diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr index a7966f87ad379..a77b465394cc4 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr @@ -149,12 +149,6 @@ LL - type D = (u8, u8)::AssocTy; LL + type D = <(u8, u8) as Example>::AssocTy; | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/bad-assoc-ty.rs:21:10 - | -LL | type E = _::AssocTy; - | ^ not allowed in type signatures - error[E0223]: ambiguous associated type --> $DIR/bad-assoc-ty.rs:25:19 | @@ -232,6 +226,24 @@ LL - type I = ty!()::AssocTy; LL + type I = ::AssocTy; | +error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union + --> $DIR/bad-assoc-ty.rs:79:5 + | +LL | foo: F, + | ^^^^^^ + | + = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` +help: wrap the field type in `ManuallyDrop<...>` + | +LL | foo: std::mem::ManuallyDrop, + | +++++++++++++++++++++++ + + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases + --> $DIR/bad-assoc-ty.rs:21:10 + | +LL | type E = _::AssocTy; + | ^ not allowed in type signatures + error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/bad-assoc-ty.rs:56:13 | @@ -280,18 +292,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | union O where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/bad-assoc-ty.rs:79:5 - | -LL | foo: F, - | ^^^^^^ - | - = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` -help: wrap the field type in `ManuallyDrop<...>` - | -LL | foo: std::mem::ManuallyDrop, - | +++++++++++++++++++++++ + - error[E0121]: the placeholder `_` is not allowed within types on item signatures for traits --> $DIR/bad-assoc-ty.rs:83:29 | diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr index 2ee8ab2760a92..760d1f2f93eba 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr @@ -149,12 +149,6 @@ LL - type D = (u8, u8)::AssocTy; LL + type D = <(u8, u8) as Example>::AssocTy; | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/bad-assoc-ty.rs:21:10 - | -LL | type E = _::AssocTy; - | ^ not allowed in type signatures - error[E0223]: ambiguous associated type --> $DIR/bad-assoc-ty.rs:25:19 | @@ -218,6 +212,24 @@ LL - type I = ty!()::AssocTy; LL + type I = ::AssocTy; | +error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union + --> $DIR/bad-assoc-ty.rs:79:5 + | +LL | foo: F, + | ^^^^^^ + | + = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` +help: wrap the field type in `ManuallyDrop<...>` + | +LL | foo: std::mem::ManuallyDrop, + | +++++++++++++++++++++++ + + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases + --> $DIR/bad-assoc-ty.rs:21:10 + | +LL | type E = _::AssocTy; + | ^ not allowed in type signatures + error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/bad-assoc-ty.rs:56:13 | @@ -266,18 +278,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | union O where F: Fn() -> _ { | ^ not allowed in type signatures -error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/bad-assoc-ty.rs:79:5 - | -LL | foo: F, - | ^^^^^^ - | - = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` -help: wrap the field type in `ManuallyDrop<...>` - | -LL | foo: std::mem::ManuallyDrop, - | +++++++++++++++++++++++ + - error[E0121]: the placeholder `_` is not allowed within types on item signatures for traits --> $DIR/bad-assoc-ty.rs:83:29 | diff --git a/tests/ui/error-codes/E0121.stderr b/tests/ui/error-codes/E0121.stderr index 074929c4e74f9..6440e9e68f2fa 100644 --- a/tests/ui/error-codes/E0121.stderr +++ b/tests/ui/error-codes/E0121.stderr @@ -1,15 +1,3 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/E0121.rs:1:13 - | -LL | fn foo() -> _ { 5 } - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn foo() -> _ { 5 } -LL + fn foo() -> i32 { 5 } - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables --> $DIR/E0121.rs:3:13 | @@ -22,6 +10,18 @@ LL - static BAR: _ = "test"; LL + static BAR: &str = "test"; | +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/E0121.rs:1:13 + | +LL | fn foo() -> _ { 5 } + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn foo() -> _ { 5 } +LL + fn foo() -> i32 { 5 } + | + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/macros/issue-118048.rs b/tests/ui/macros/issue-118048.rs index 3b3ab3b4fc936..15a834fa2df48 100644 --- a/tests/ui/macros/issue-118048.rs +++ b/tests/ui/macros/issue-118048.rs @@ -6,6 +6,5 @@ macro_rules! foo { foo!(_); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions -//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions fn main() {} diff --git a/tests/ui/macros/issue-118048.stderr b/tests/ui/macros/issue-118048.stderr index f5468b341bce6..86481f0cf80ca 100644 --- a/tests/ui/macros/issue-118048.stderr +++ b/tests/ui/macros/issue-118048.stderr @@ -4,14 +4,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | foo!(_); | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-118048.rs:7:6 - | -LL | foo!(_); - | ^ not allowed in type signatures - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr index 8ed4530e85e3c..e462546fc5bf1 100644 --- a/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr +++ b/tests/ui/mismatched_types/mismatch-args-crash-issue-130400.stderr @@ -2,7 +2,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/mismatch-args-crash-issue-130400.rs:4:9 | LL | Self::foo() - | ^^^^^^^^^-- argument #1 is missing + | ^^^^^^^^^-- argument #1 of type `&mut Self` is missing | note: method defined here --> $DIR/mismatch-args-crash-issue-130400.rs:2:8 @@ -11,8 +11,8 @@ LL | fn foo(&mut self) -> _ { | ^^^ --------- help: provide the argument | -LL | Self::foo(/* value */) - | +++++++++++ +LL | Self::foo(/* &mut Self */) + | +++++++++++++++ error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/mismatch-args-crash-issue-130400.rs:2:26 diff --git a/tests/ui/parallel-rustc/dyn-trait-ice-153366.rs b/tests/ui/parallel-rustc/dyn-trait-ice-153366.rs index 9fd53f31a9f61..a3cafdc11018b 100644 --- a/tests/ui/parallel-rustc/dyn-trait-ice-153366.rs +++ b/tests/ui/parallel-rustc/dyn-trait-ice-153366.rs @@ -4,9 +4,12 @@ fn iso(a: Fn) -> Option<_> //~^ ERROR missing generics for trait `Fn` +//~| ERROR missing generics for trait `Fn` //~| ERROR the placeholder `_` is not allowed within types on item signatures for return types //~| WARN trait objects without an explicit `dyn` are deprecated //~| WARN this is accepted in the current edition +//~| WARN trait objects without an explicit `dyn` are deprecated +//~| WARN this is accepted in the current edition where dyn Fn(A) -> (): Sized, { diff --git a/tests/ui/parallel-rustc/dyn-trait-ice-153366.stderr b/tests/ui/parallel-rustc/dyn-trait-ice-153366.stderr index a9ca104c00d36..eea38cb53bda4 100644 --- a/tests/ui/parallel-rustc/dyn-trait-ice-153366.stderr +++ b/tests/ui/parallel-rustc/dyn-trait-ice-153366.stderr @@ -23,30 +23,34 @@ help: add missing generic argument LL | fn iso(a: Fn) -> Option<_> | ++++++ -error[E0277]: the size for values of type `(dyn Fn(_) + 'static)` cannot be known at compilation time - --> $DIR/dyn-trait-ice-153366.rs:18:5 +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-trait-ice-153366.rs:5:14 | -LL | iso(()) - | ^^^^^^^ doesn't have a size known at compile-time +LL | fn iso(a: Fn) -> Option<_> + | ^^ | - = help: the trait `Sized` is not implemented for `(dyn Fn(_) + 'static)` -note: required by a bound in `iso` - --> $DIR/dyn-trait-ice-153366.rs:11:22 + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: if this is a dyn-compatible trait, use `dyn` | -LL | fn iso(a: Fn) -> Option<_> - | --- required by a bound in this function -... -LL | dyn Fn(A) -> (): Sized, - | ^^^^^ required by this bound in `iso` +LL | fn iso(a: dyn Fn) -> Option<_> + | +++ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/dyn-trait-ice-153366.rs:16:30 +error[E0107]: missing generics for trait `Fn` + --> $DIR/dyn-trait-ice-153366.rs:5:14 | -LL | fn iso_un_option() -> Box<_> { - | ^ not allowed in type signatures +LL | fn iso(a: Fn) -> Option<_> + | ^^ expected 1 generic argument + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | fn iso(a: Fn) -> Option<_> + | ++++++ error[E0308]: mismatched types - --> $DIR/dyn-trait-ice-153366.rs:13:5 + --> $DIR/dyn-trait-ice-153366.rs:16:5 | LL | fn iso(a: Fn) -> Option<_> | --------- expected `Option<_>` because of return type @@ -55,11 +59,7 @@ LL | Box::new(iso_un_option) | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<_>`, found `Box _ {iso_un_option::<_>}>` | = note: expected enum `Option<_>` - found struct `Box {type error} {iso_un_option::<_>}>` -help: use parentheses to call this function - | -LL | Box::new(iso_un_option)() - | ++ + found struct `Box Box<{type error}, {type error}> {iso_un_option::<_>}>` help: try wrapping the expression in `Some` | LL | Some(Box::new(iso_un_option)) @@ -72,14 +72,36 @@ LL | fn iso(a: Fn) -> Option<_> | ^ not allowed in type signatures error[E0277]: the size for values of type `(dyn Fn(_) + 'static)` cannot be known at compilation time - --> $DIR/dyn-trait-ice-153366.rs:23:5 + --> $DIR/dyn-trait-ice-153366.rs:21:5 + | +LL | iso(()) + | ^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Fn(_) + 'static)` +note: required by a bound in `iso` + --> $DIR/dyn-trait-ice-153366.rs:14:22 + | +LL | fn iso(a: Fn) -> Option<_> + | --- required by a bound in this function +... +LL | dyn Fn(A) -> (): Sized, + | ^^^^^ required by this bound in `iso` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/dyn-trait-ice-153366.rs:19:30 + | +LL | fn iso_un_option() -> Box<_> { + | ^ not allowed in type signatures + +error[E0277]: the size for values of type `(dyn Fn(_) + 'static)` cannot be known at compilation time + --> $DIR/dyn-trait-ice-153366.rs:26:5 | LL | iso(()) | ^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Fn(_) + 'static)` note: required by a bound in `iso` - --> $DIR/dyn-trait-ice-153366.rs:11:22 + --> $DIR/dyn-trait-ice-153366.rs:14:22 | LL | fn iso(a: Fn) -> Option<_> | --- required by a bound in this function @@ -87,7 +109,7 @@ LL | fn iso(a: Fn) -> Option<_> LL | dyn Fn(A) -> (): Sized, | ^^^^^ required by this bound in `iso` -error: aborting due to 6 previous errors; 1 warning emitted +error: aborting due to 7 previous errors; 2 warnings emitted Some errors have detailed explanations: E0107, E0121, E0277, E0308. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.rs b/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.rs index 1c1ab67a4f67b..ee04a0b62f83e 100644 --- a/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.rs +++ b/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.rs @@ -14,13 +14,11 @@ fn tuple() -> impl Sized { (tuple(),) } -fn array() -> _ { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types +fn array() -> _ { //~ ERROR the placeholder `_` is not allowed [array()] } -fn ptr() -> _ { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types +fn ptr() -> _ { //~ ERROR the placeholder `_` is not allowed &ptr() as *const impl Sized //~^ ERROR `impl Trait` is not allowed in cast expression types } @@ -43,8 +41,7 @@ fn closure_ref_capture() -> impl Sized { } } -fn closure_sig() -> _ { - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types +fn closure_sig() -> _ { //~ ERROR the placeholder `_` is not allowed || closure_sig() } diff --git a/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.stderr b/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.stderr index aadefd9007a20..783fc72eddf1d 100644 --- a/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.stderr +++ b/tests/ui/parallel-rustc/recursive-impl-trait-deadlock-issue-129912.stderr @@ -1,5 +1,5 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found reserved keyword `virtual` - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:80:11 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:77:11 | LL | x virtual ; | ^^^^^^^ expected one of 8 possible tokens @@ -22,19 +22,19 @@ LL | if generator_sig() < 0 { None } else { Sized((option(i - Sized), i)) } = note: a trait named `Sized` exists in another namespace error[E0425]: cannot find value `i` in this scope - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:52:8 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:49:8 | LL | || i | ^ not found in this scope error[E0404]: expected trait, found builtin type `i32` - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:56:32 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:53:32 | LL | fn generator_capture() -> impl i32 { | ^^^ not a trait error[E0404]: cannot find trait `generator_capture` in this scope - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:72:29 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:69:29 | LL | fn generator_hold() -> impl generator_capture { | ^^^^^^^^^^^^^^^^^ not found in this scope @@ -42,7 +42,7 @@ LL | fn generator_hold() -> impl generator_capture { = note: a function named `generator_capture` exists in another namespace error[E0658]: yield syntax is experimental - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:60:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:57:9 | LL | yield; | ^^^^^ @@ -52,7 +52,7 @@ LL | yield; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: yield syntax is experimental - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:76:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:73:9 | LL | yield; | ^^^^^ @@ -62,7 +62,7 @@ LL | yield; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in cast expression types - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:24:22 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:22:22 | LL | &ptr() as *const impl Sized | ^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | &ptr() as *const impl Sized = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0658]: yield syntax is experimental - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:60:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:57:9 | LL | yield; | ^^^^^ @@ -80,7 +80,7 @@ LL | yield; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:60:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:57:9 | LL | yield; | ^^^^^ @@ -91,7 +91,7 @@ LL | #[coroutine] move || { | ++++++++++++ error[E0658]: yield syntax is experimental - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:76:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:73:9 | LL | yield; | ^^^^^ @@ -101,7 +101,7 @@ LL | yield; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:76:9 + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:73:9 | LL | yield; | ^^^^^ @@ -111,32 +111,32 @@ help: use `#[coroutine]` to make this closure a coroutine LL | #[coroutine] move || { | ++++++++++++ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types +error[E0423]: cannot find function, tuple struct or tuple variant `Sized` in this scope + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:8:44 + | +LL | if generator_sig() < 0 { None } else { Sized((option(i - Sized), i)) } + | ^^^^^ not found in this scope + | + = note: a trait named `Sized` exists in another namespace + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:17:15 | LL | fn array() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:22:13 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:21:13 | LL | fn ptr() -> _ { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:46:21 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:44:21 | LL | fn closure_sig() -> _ { | ^ not allowed in type signatures -error[E0423]: cannot find function, tuple struct or tuple variant `Sized` in this scope - --> $DIR/recursive-impl-trait-deadlock-issue-129912.rs:8:44 - | -LL | if generator_sig() < 0 { None } else { Sized((option(i - Sized), i)) } - | ^^^^^ not found in this scope - | - = note: a trait named `Sized` exists in another namespace - error: aborting due to 17 previous errors Some errors have detailed explanations: E0121, E0404, E0423, E0425, E0557, E0562, E0658. diff --git a/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr index 83764f9e22312..17474d0c5d7ee 100644 --- a/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr +++ b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr @@ -243,6 +243,12 @@ error[E0425]: cannot find type `new` in this scope LL | fn elided4(_: &impl Copy + 'a) -> new { x(x) } | ^^^ not found in this scope +error[E0224]: at least one trait is required for an object type + --> $DIR/ty-variance-issue-124423.rs:32:39 + | +LL | fn elided3(_: &impl Copy + 'a) -> Box { Box::new(x) } + | ^^^^^^ + error[E0224]: at least one trait is required for an object type --> $DIR/ty-variance-issue-124423.rs:38:40 | @@ -250,10 +256,10 @@ LL | fn x<'b>(_: &'a impl Copy + 'a) -> Box { Box::u32(x) } | ^^^^^^ error[E0224]: at least one trait is required for an object type - --> $DIR/ty-variance-issue-124423.rs:32:39 + --> $DIR/ty-variance-issue-124423.rs:52:40 | -LL | fn elided3(_: &impl Copy + 'a) -> Box { Box::new(x) } - | ^^^^^^ +LL | impl<'a> LifetimeTrait<'a> for &'a Box {} + | ^^^^^^ error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/ty-variance-issue-124423.rs:5:34 @@ -261,12 +267,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | fn elided(_: &impl Copy + 'a) -> _ { x } | ^ not allowed in type signatures -error[E0224]: at least one trait is required for an object type - --> $DIR/ty-variance-issue-124423.rs:52:40 - | -LL | impl<'a> LifetimeTrait<'a> for &'a Box {} - | ^^^^^^ - error[E0599]: no associated function or constant named `u32` found for struct `Box<_, _>` in the current scope --> $DIR/ty-variance-issue-124423.rs:38:55 | diff --git a/tests/ui/parallel-rustc/variances-cycle-ice-154560.rs b/tests/ui/parallel-rustc/variances-cycle-ice-154560.rs index 2f0690ab43736..27b0b59f8fb76 100644 --- a/tests/ui/parallel-rustc/variances-cycle-ice-154560.rs +++ b/tests/ui/parallel-rustc/variances-cycle-ice-154560.rs @@ -1,15 +1,12 @@ // Regression test for ICE from issue #154560. -//~^ ERROR cycle detected when computing the variances for items in this crate - -//@ ignore-parallel-frontend query cycle + ICE pub struct T<'a>(&'a str); -pub fn f() -> _ { +pub fn f() -> _ { //~ ERROR placeholder `_` is not allowed T } -pub fn g<'a>(val: T<'a>) -> _ { +pub fn g<'a>(val: T<'a>) -> _ { //~ ERROR placeholder `_` is not allowed T } diff --git a/tests/ui/parallel-rustc/variances-cycle-ice-154560.stderr b/tests/ui/parallel-rustc/variances-cycle-ice-154560.stderr index 6cfdadf5c5d5c..62928d294e7e3 100644 --- a/tests/ui/parallel-rustc/variances-cycle-ice-154560.stderr +++ b/tests/ui/parallel-rustc/variances-cycle-ice-154560.stderr @@ -1,24 +1,27 @@ -error[E0391]: cycle detected when computing the variances for items in this crate - | -note: ...which requires computing function signature of `f`... - --> $DIR/variances-cycle-ice-154560.rs:8:1 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/variances-cycle-ice-154560.rs:5:18 | LL | pub fn f() -> _ { - | ^^^^^^^^^^^^^^^^^^ - = note: ...which requires type-checking `f`... -note: ...which requires computing the variances of `T`... - --> $DIR/variances-cycle-ice-154560.rs:6:1 - | -LL | pub struct T<'a>(&'a str); - | ^^^^^^^^^^^^^^^^ - = note: ...which again requires computing the variances for items in this crate, completing the cycle -note: cycle used when computing the variances of `T` - --> $DIR/variances-cycle-ice-154560.rs:6:1 - | -LL | pub struct T<'a>(&'a str); - | ^^^^^^^^^^^^^^^^ - = note: for more information, see and + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - pub fn f() -> _ { +LL + pub fn f() -> fn(&str) -> T<'_> { + | + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/variances-cycle-ice-154560.rs:9:29 + | +LL | pub fn g<'a>(val: T<'a>) -> _ { + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - pub fn g<'a>(val: T<'a>) -> _ { +LL + pub fn g<'a>(val: T<'a>) -> fn(&str) -> T<'_> { + | -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr index 5aa46545943cb..55ea45ab9d325 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr @@ -1,9 +1,3 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions - --> $DIR/bad-infer-in-trait-impl.rs:6:15 - | -LL | fn bar(s: _) {} - | ^ not allowed in type signatures - error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 0 --> $DIR/bad-infer-in-trait-impl.rs:6:15 | @@ -13,6 +7,12 @@ LL | fn bar(); LL | fn bar(s: _) {} | ^ expected 0 parameters, found 1 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions + --> $DIR/bad-infer-in-trait-impl.rs:6:15 + | +LL | fn bar(s: _) {} + | ^ not allowed in type signatures + error: aborting due to 2 previous errors Some errors have detailed explanations: E0050, E0121. diff --git a/tests/ui/suggestions/return-cycle-2.stderr b/tests/ui/suggestions/return-cycle-2.stderr index e852cd34a72a3..f756dd065b7c5 100644 --- a/tests/ui/suggestions/return-cycle-2.stderr +++ b/tests/ui/suggestions/return-cycle-2.stderr @@ -7,7 +7,7 @@ LL | fn as_ref(_: i32, _: i32) -> _ { help: replace with the correct return type | LL - fn as_ref(_: i32, _: i32) -> _ { -LL + fn as_ref(_: i32, _: i32) -> Token<&'static T> { +LL + fn as_ref(_: i32, _: i32) -> Token<&T> { | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/issue-75883.rs b/tests/ui/typeck/issue-75883.rs index c50ea0a086b14..4a9ecb8adfaaa 100644 --- a/tests/ui/typeck/issue-75883.rs +++ b/tests/ui/typeck/issue-75883.rs @@ -5,6 +5,7 @@ pub struct UI {} impl UI { pub fn run() -> Result<_> { //~^ ERROR: enum takes 2 generic arguments but 1 generic argument was supplied + //~| ERROR: enum takes 2 generic arguments but 1 generic argument was supplied //~| ERROR: the placeholder `_` is not allowed within types on item signatures for return types let mut ui = UI {}; ui.interact(); @@ -14,6 +15,7 @@ impl UI { pub fn interact(&mut self) -> Result<_> { //~^ ERROR: enum takes 2 generic arguments but 1 generic argument was supplied + //~| ERROR: enum takes 2 generic arguments but 1 generic argument was supplied //~| ERROR: the placeholder `_` is not allowed within types on item signatures for return types unimplemented!(); } diff --git a/tests/ui/typeck/issue-75883.stderr b/tests/ui/typeck/issue-75883.stderr index a1ed0840675f5..f81f32acb6eff 100644 --- a/tests/ui/typeck/issue-75883.stderr +++ b/tests/ui/typeck/issue-75883.stderr @@ -12,7 +12,7 @@ LL | pub fn run() -> Result<_, E> { | +++ error[E0107]: enum takes 2 generic arguments but 1 generic argument was supplied - --> $DIR/issue-75883.rs:15:35 + --> $DIR/issue-75883.rs:16:35 | LL | pub fn interact(&mut self) -> Result<_> { | ^^^^^^ - supplied 1 generic argument @@ -24,11 +24,19 @@ help: add missing generic argument LL | pub fn interact(&mut self) -> Result<_, E> { | +++ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/issue-75883.rs:15:42 +error[E0107]: enum takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-75883.rs:6:21 | -LL | pub fn interact(&mut self) -> Result<_> { - | ^ not allowed in type signatures +LL | pub fn run() -> Result<_> { + | ^^^^^^ - supplied 1 generic argument + | | + | expected 2 generic arguments + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | pub fn run() -> Result<_, E> { + | +++ error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/issue-75883.rs:6:28 @@ -36,7 +44,27 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | pub fn run() -> Result<_> { | ^ not allowed in type signatures -error: aborting due to 4 previous errors +error[E0107]: enum takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-75883.rs:16:35 + | +LL | pub fn interact(&mut self) -> Result<_> { + | ^^^^^^ - supplied 1 generic argument + | | + | expected 2 generic arguments + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: add missing generic argument + | +LL | pub fn interact(&mut self) -> Result<_, E> { + | +++ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-75883.rs:16:42 + | +LL | pub fn interact(&mut self) -> Result<_> { + | ^ not allowed in type signatures + +error: aborting due to 6 previous errors Some errors have detailed explanations: E0107, E0121. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/typeck/issue-80779.stderr b/tests/ui/typeck/issue-80779.stderr index 90c80fa2ea6fd..ab4611f9b7a8a 100644 --- a/tests/ui/typeck/issue-80779.stderr +++ b/tests/ui/typeck/issue-80779.stderr @@ -1,3 +1,9 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-80779.rs:5:29 + | +LL | pub fn f<'a>(val: T<'a>) -> _ { + | ^ not allowed in type signatures + error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/issue-80779.rs:10:28 | @@ -10,18 +16,6 @@ LL - pub fn g(_: T<'static>) -> _ {} LL + pub fn g(_: T<'static>) -> () {} | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/issue-80779.rs:5:29 - | -LL | pub fn f<'a>(val: T<'a>) -> _ { - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - pub fn f<'a>(val: T<'a>) -> _ { -LL + pub fn f<'a>(val: T<'a>) -> () { - | - error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index 7616e391a35a9..0c3e8e290d849 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -47,6 +47,7 @@ impl Test9 { fn test11(x: &usize) -> &_ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types &x + //~^ ERROR: `x` does not live long enough } unsafe fn test12(x: *const usize) -> *const *const _ { @@ -129,6 +130,7 @@ pub fn main() { fn fn_test11(_: _) -> (_, _) { panic!() } //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions //~| ERROR type annotations needed fn fn_test12(x: i32) -> (_, _) { (x, x) } @@ -136,6 +138,7 @@ pub fn main() { fn fn_test13(x: _) -> (i32, _) { (x, x) } //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions } trait T { @@ -166,7 +169,6 @@ impl BadTrait<_> for BadStruct<_> {} fn impl_trait() -> impl BadTrait<_> { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types -//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types unimplemented!() } @@ -187,7 +189,6 @@ trait Trait {} impl Trait for Struct {} type Y = impl Trait<_>; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types -//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types #[define_opaque(Y)] fn foo() -> Y { Struct @@ -204,7 +205,6 @@ trait Qux { // type E: _; // FIXME: make the parser propagate the existence of `B` type F: std::ops::Fn(_); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types - //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated types } impl Qux for Struct { //~^ ERROR not all trait items implemented, missing: `F` @@ -230,7 +230,6 @@ fn value() -> Option<&'static _> { const _: Option<_> = map(value); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants -//~| ERROR cannot call non-const function `map::` in constants fn evens_squared(n: usize) -> _ { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 2772d55f953a8..80ab11f4778ee 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -1,29 +1,29 @@ error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:158:18 + --> $DIR/typeck_type_placeholder_item.rs:161:18 | LL | struct BadStruct<_>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:161:16 + --> $DIR/typeck_type_placeholder_item.rs:164:16 | LL | trait BadTrait<_> {} | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:173:19 + --> $DIR/typeck_type_placeholder_item.rs:175:19 | LL | struct BadStruct1<_, _>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:173:22 + --> $DIR/typeck_type_placeholder_item.rs:175:22 | LL | struct BadStruct1<_, _>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:178:19 + --> $DIR/typeck_type_placeholder_item.rs:180:19 | LL | struct BadStruct2<_, T>(_, T); | ^ expected identifier, found reserved identifier @@ -37,39 +37,13 @@ LL | const C: _; | help: provide a definition for the constant: `= ;` error[E0403]: the name `_` is already used for a generic parameter in this item's generic parameters - --> $DIR/typeck_type_placeholder_item.rs:173:22 + --> $DIR/typeck_type_placeholder_item.rs:175:22 | LL | struct BadStruct1<_, _>(_); | - ^ already used | | | first use of `_` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:7:14 - | -LL | fn test() -> _ { 5 } - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn test() -> _ { 5 } -LL + fn test() -> i32 { 5 } - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:10:16 - | -LL | fn test2() -> (_, _) { (5, 5) } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn test2() -> (_, _) { (5, 5) } -LL + fn test2() -> (i32, i32) { (5, 5) } - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables --> $DIR/typeck_type_placeholder_item.rs:13:15 | @@ -108,116 +82,8 @@ LL - static TEST5: (_, _) = (1, 2); LL + static TEST5: (i32, i32) = (1, 2); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:22:13 - | -LL | fn test6(_: _) { } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:25:18 - | -LL | fn test6_b(_: _, _: T) { } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:28:30 - | -LL | fn test6_c(_: _, _: (T, K, L, A, B)) { } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:31:13 - | -LL | fn test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:34:22 - | -LL | fn test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:66:8 - | -LL | a: _, - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:68:9 - | -LL | b: (_, _), - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:68:12 - | -LL | b: (_, _), - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:123:12 - | -LL | a: _, - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:125:13 - | -LL | b: (_, _), - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:125:16 - | -LL | b: (_, _), - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:158:21 - | -LL | struct BadStruct<_>(_); - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:173:25 - | -LL | struct BadStruct1<_, _>(_); - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:178:25 - | -LL | struct BadStruct2<_, T>(_, T); - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:47:26 - | -LL | fn test11(x: &usize) -> &_ { - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn test11(x: &usize) -> &_ { -LL + fn test11(x: &usize) -> &&usize { - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:52:52 - | -LL | unsafe fn test12(x: *const usize) -> *const *const _ { - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - unsafe fn test12(x: *const usize) -> *const *const _ { -LL + unsafe fn test12(x: *const usize) -> *const *const usize { - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:58:24 + --> $DIR/typeck_type_placeholder_item.rs:59:24 | LL | fn clone(&self) -> _ { Test9 } | ^ not allowed in type signatures @@ -229,7 +95,7 @@ LL + fn clone(&self) -> Test9 { Test9 } | error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:61:37 + --> $DIR/typeck_type_placeholder_item.rs:62:37 | LL | fn clone_from(&mut self, other: _) { *self = Test9; } | ^ not allowed in type signatures @@ -241,13 +107,13 @@ LL + fn clone_from(&mut self, other: &Test9) { *self = Test9; } | error: missing type for `static` item - --> $DIR/typeck_type_placeholder_item.rs:74:13 + --> $DIR/typeck_type_placeholder_item.rs:75:13 | LL | static A = 42; | ^ help: provide a type for the static variable: `: i32` error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:76:15 + --> $DIR/typeck_type_placeholder_item.rs:77:15 | LL | static B: _ = 42; | ^ not allowed in type signatures @@ -259,7 +125,7 @@ LL + static B: i32 = 42; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:78:22 + --> $DIR/typeck_type_placeholder_item.rs:79:22 | LL | static C: Option<_> = Some(42); | ^ not allowed in type signatures @@ -270,34 +136,8 @@ LL - static C: Option<_> = Some(42); LL + static C: Option = Some(42); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:80:21 - | -LL | fn fn_test() -> _ { 5 } - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn fn_test() -> _ { 5 } -LL + fn fn_test() -> i32 { 5 } - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:83:23 - | -LL | fn fn_test2() -> (_, _) { (5, 5) } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn fn_test2() -> (_, _) { (5, 5) } -LL + fn fn_test2() -> (i32, i32) { (5, 5) } - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:86:22 + --> $DIR/typeck_type_placeholder_item.rs:87:22 | LL | static FN_TEST3: _ = "test"; | ^ not allowed in type signatures @@ -309,7 +149,7 @@ LL + static FN_TEST3: &str = "test"; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:89:22 + --> $DIR/typeck_type_placeholder_item.rs:90:22 | LL | static FN_TEST4: _ = 145; | ^ not allowed in type signatures @@ -321,7 +161,7 @@ LL + static FN_TEST4: i32 = 145; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:92:23 + --> $DIR/typeck_type_placeholder_item.rs:93:23 | LL | static FN_TEST5: (_, _) = (1, 2); | ^ ^ not allowed in type signatures @@ -334,26 +174,8 @@ LL - static FN_TEST5: (_, _) = (1, 2); LL + static FN_TEST5: (i32, i32) = (1, 2); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:95:20 - | -LL | fn fn_test6(_: _) { } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:98:20 - | -LL | fn fn_test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:101:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:115:28 + --> $DIR/typeck_type_placeholder_item.rs:116:28 | LL | fn clone(&self) -> _ { FnTest9 } | ^ not allowed in type signatures @@ -365,7 +187,7 @@ LL + fn clone(&self) -> FnTest9 { FnTest9 } | error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:118:41 + --> $DIR/typeck_type_placeholder_item.rs:119:41 | LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } | ^ not allowed in type signatures @@ -376,180 +198,196 @@ LL - fn clone_from(&mut self, other: _) { *self = FnTest9; } LL + fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; } | -error[E0282]: type annotations needed - --> $DIR/typeck_type_placeholder_item.rs:130:21 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/typeck_type_placeholder_item.rs:215:14 | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ cannot infer type +LL | const C: _; + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:130:28 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/typeck_type_placeholder_item.rs:203:14 + | +LL | const D: _ = 42; + | ^ not allowed in type signatures + | +help: replace this with a fully-specified type + | +LL - const D: _ = 42; +LL + const D: i32 = 42; | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:134:30 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/typeck_type_placeholder_item.rs:218:14 | -LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures +LL | const D: _ = 42; + | ^ not allowed in type signatures + +error[E0046]: not all trait items implemented, missing: `F` + --> $DIR/typeck_type_placeholder_item.rs:209:1 | -help: replace with the correct return type +LL | type F: std::ops::Fn(_); + | ----------------------- `F` from trait +... +LL | impl Qux for Struct { + | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:231:17 | -LL - fn fn_test12(x: i32) -> (_, _) { (x, x) } -LL + fn fn_test12(x: i32) -> (i32, i32) { (x, x) } +LL | const _: Option<_> = map(value); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:239:10 + | +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^ not allowed in type signatures | +note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:239:29}>, {closure@typeck_type_placeholder_item.rs:239:49}>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:239:14 + | +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:137:33 + --> $DIR/typeck_type_placeholder_item.rs:7:14 | -LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } - | ^ not allowed in type signatures +LL | fn test() -> _ { 5 } + | ^ not allowed in type signatures | help: replace with the correct return type | -LL - fn fn_test13(x: _) -> (i32, _) { (x, x) } -LL + fn fn_test13(x: _) -> (i32, i32) { (x, x) } +LL - fn test() -> _ { 5 } +LL + fn test() -> i32 { 5 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:142:31 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:10:16 | -LL | fn method_test1(&self, x: _); - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:144:31 +LL | fn test2() -> (_, _) { (5, 5) } + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures | -LL | fn method_test2(&self, x: _) -> _; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:144:37 +help: replace with the correct return type | -LL | fn method_test2(&self, x: _) -> _; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:147:31 +LL - fn test2() -> (_, _) { (5, 5) } +LL + fn test2() -> (i32, i32) { (5, 5) } | -LL | fn method_test3(&self) -> _; - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions - --> $DIR/typeck_type_placeholder_item.rs:149:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:40:24 + | +LL | fn test9(&self) -> _ { () } + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn test9(&self) -> _ { () } +LL + fn test9(&self) -> () { () } | -LL | fn assoc_fn_test1(x: _); - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions - --> $DIR/typeck_type_placeholder_item.rs:151:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:47:26 | -LL | fn assoc_fn_test2(x: _) -> _; +LL | fn test11(x: &usize) -> &_ { | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions - --> $DIR/typeck_type_placeholder_item.rs:151:32 | -LL | fn assoc_fn_test2(x: _) -> _; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions - --> $DIR/typeck_type_placeholder_item.rs:154:28 +help: replace with the correct return type | -LL | fn assoc_fn_test3() -> _; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations - --> $DIR/typeck_type_placeholder_item.rs:163:32 +LL - fn test11(x: &usize) -> &_ { +LL + fn test11(x: &usize) -> &&usize { | -LL | impl BadTrait<_> for BadStruct<_> {} - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations - --> $DIR/typeck_type_placeholder_item.rs:163:15 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:53:52 | -LL | impl BadTrait<_> for BadStruct<_> {} - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:167:34 +LL | unsafe fn test12(x: *const usize) -> *const *const _ { + | ^ not allowed in type signatures | -LL | fn impl_trait() -> impl BadTrait<_> { - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:182:14 +help: replace with the correct return type + | +LL - unsafe fn test12(x: *const usize) -> *const *const _ { +LL + unsafe fn test12(x: *const usize) -> *const *const usize { | -LL | type X = Box<_>; - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:188:21 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:81:21 | -LL | type Y = impl Trait<_>; +LL | fn fn_test() -> _ { 5 } | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:198:14 | -LL | type B = _; - | ^ not allowed in type signatures +help: replace with the correct return type + | +LL - fn fn_test() -> _ { 5 } +LL + fn fn_test() -> i32 { 5 } + | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:211:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:84:23 + | +LL | fn fn_test2() -> (_, _) { (5, 5) } + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn fn_test2() -> (_, _) { (5, 5) } +LL + fn fn_test2() -> (i32, i32) { (5, 5) } | -LL | type A = _; - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:213:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:108:31 + | +LL | fn fn_test9(&self) -> _ { () } + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn fn_test9(&self) -> _ { () } +LL + fn fn_test9(&self) -> () { () } | -LL | type B = _; - | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:200:14 +error[E0282]: type annotations needed + --> $DIR/typeck_type_placeholder_item.rs:131:21 | -LL | const C: _; - | ^ not allowed in type signatures +LL | fn fn_test11(_: _) -> (_, _) { panic!() } + | ^ cannot infer type -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:215:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:131:28 | -LL | const C: _; - | ^ not allowed in type signatures +LL | fn fn_test11(_: _) -> (_, _) { panic!() } + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:202:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:136:30 | -LL | const D: _ = 42; - | ^ not allowed in type signatures +LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures | -help: replace this with a fully-specified type +help: replace with the correct return type | -LL - const D: _ = 42; -LL + const D: i32 = 42; +LL - fn fn_test12(x: i32) -> (_, _) { (x, x) } +LL + fn fn_test12(x: i32) -> (i32, i32) { (x, x) } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:218:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:139:33 | -LL | const D: _ = 42; - | ^ not allowed in type signatures - -error[E0046]: not all trait items implemented, missing: `F` - --> $DIR/typeck_type_placeholder_item.rs:209:1 +LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn fn_test13(x: _) -> (i32, _) { (x, x) } +LL + fn fn_test13(x: _) -> (i32, i32) { (x, x) } | -LL | type F: std::ops::Fn(_); - | ----------------------- `F` from trait -... -LL | impl Qux for Struct { - | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/typeck_type_placeholder_item.rs:226:31 @@ -560,23 +398,11 @@ LL | fn value() -> Option<&'static _> { help: replace with the correct return type | LL - fn value() -> Option<&'static _> { -LL + fn value() -> Option<&'static u8> { - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:231:17 - | -LL | const _: Option<_> = map(value); - | ^ not allowed in type signatures - | -help: replace this with a fully-specified type - | -LL - const _: Option<_> = map(value); -LL + const _: Option = map(value); +LL + fn value() -> Option<&u8> { | error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:235:31 + --> $DIR/typeck_type_placeholder_item.rs:234:31 | LL | fn evens_squared(n: usize) -> _ { | ^ not allowed in type signatures @@ -587,29 +413,145 @@ LL - fn evens_squared(n: usize) -> _ { LL + fn evens_squared(n: usize) -> impl Iterator { | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:240:10 +error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:239:29: 239:32}>` in constants + --> $DIR/typeck_type_placeholder_item.rs:239:22 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^ not allowed in type signatures + | ^^^^^^^^^^^^^^^^^^^^^^ | -note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:240:29}>, {closure@typeck_type_placeholder_item.rs:240:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:240:14 + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + +error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:239:29: 239:32}> as Iterator>::map::` in constants + --> $DIR/typeck_type_placeholder_item.rs:239:45 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:40:24 +error[E0597]: `x` does not live long enough + --> $DIR/typeck_type_placeholder_item.rs:49:5 | -LL | fn test9(&self) -> _ { () } - | ^ not allowed in type signatures +LL | fn test11(x: &usize) -> &_ { + | ------ -- has type `&'0 {type error}` + | | + | has type `&'0 usize` +LL | +LL | &x + | ^^ `x` would have to be valid for `'0`... +LL | +LL | } + | - + | | + | ...but `x` will be dropped here, when the function `test11` returns + | borrow later used here + | + = note: argument and return type have the same lifetime due to lifetime elision rules + = note: to learn more, visit + = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments + = note: to learn more, visit + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:206:26 | -help: replace with the correct return type +LL | type F: std::ops::Fn(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:111:34 | -LL - fn test9(&self) -> _ { () } -LL + fn test9(&self) -> () { () } +LL | fn fn_test10(&self, _x : _) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:211:14 | +LL | type A = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:22:13 + | +LL | fn test6(_: _) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:25:18 + | +LL | fn test6_b(_: _, _: T) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:28:30 + | +LL | fn test6_c(_: _, _: (T, K, L, A, B)) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:31:13 + | +LL | fn test7(x: _) { let _x: usize = x; } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:34:22 + | +LL | fn test8(_f: fn() -> _) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:67:8 + | +LL | a: _, + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:69:9 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:69:12 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:124:12 + | +LL | a: _, + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:126:13 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:126:16 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:161:21 + | +LL | struct BadStruct<_>(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:175:25 + | +LL | struct BadStruct1<_, _>(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:180:25 + | +LL | struct BadStruct2<_, T>(_, T); + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods --> $DIR/typeck_type_placeholder_item.rs:43:27 @@ -617,84 +559,133 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | fn test10(&self, _x : _) { } | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:107:31 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions + --> $DIR/typeck_type_placeholder_item.rs:157:28 | -LL | fn fn_test9(&self) -> _ { () } - | ^ not allowed in type signatures +LL | fn assoc_fn_test3() -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations + --> $DIR/typeck_type_placeholder_item.rs:166:32 | -help: replace with the correct return type +LL | impl BadTrait<_> for BadStruct<_> {} + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/typeck_type_placeholder_item.rs:201:14 | -LL - fn fn_test9(&self) -> _ { () } -LL + fn fn_test9(&self) -> () { () } +LL | const C: _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:213:14 | +LL | type B = _; + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:110:34 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:96:20 | -LL | fn fn_test10(&self, _x : _) { } - | ^ not allowed in type signatures +LL | fn fn_test6(_: _) { } + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:205:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:99:20 | -LL | type F: std::ops::Fn(_); - | ^ not allowed in type signatures +LL | fn fn_test7(x: _) { let _x: usize = x; } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:102:29 + | +LL | fn fn_test8(_f: fn() -> _) { } + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:131:21 + | +LL | fn fn_test11(_: _) -> (_, _) { panic!() } + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:205:26 + --> $DIR/typeck_type_placeholder_item.rs:199:14 | -LL | type F: std::ops::Fn(_); - | ^ not allowed in type signatures +LL | type B = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:190:21 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | type Y = impl Trait<_>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases + --> $DIR/typeck_type_placeholder_item.rs:184:14 + | +LL | type X = Box<_>; + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:167:34 + --> $DIR/typeck_type_placeholder_item.rs:170:34 | LL | fn impl_trait() -> impl BadTrait<_> { | ^ not allowed in type signatures - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:188:21 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:139:21 | -LL | type Y = impl Trait<_>; +LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations + --> $DIR/typeck_type_placeholder_item.rs:166:15 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | impl BadTrait<_> for BadStruct<_> {} + | ^ not allowed in type signatures -error[E0015]: cannot call non-const function `map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:231:22 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:145:31 | -LL | const _: Option<_> = map(value); - | ^^^^^^^^^^ +LL | fn method_test1(&self, x: _); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:147:31 | -note: function `map` is not const - --> $DIR/typeck_type_placeholder_item.rs:222:1 +LL | fn method_test2(&self, x: _) -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:147:37 | -LL | fn map(_: fn() -> Option<&'static T>) -> Option { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | fn method_test2(&self, x: _) -> _; + | ^ not allowed in type signatures -error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>` in constants - --> $DIR/typeck_type_placeholder_item.rs:240:22 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:150:31 | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | fn method_test3(&self) -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions + --> $DIR/typeck_type_placeholder_item.rs:152:26 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | fn assoc_fn_test1(x: _); + | ^ not allowed in type signatures -error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:240:45 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions + --> $DIR/typeck_type_placeholder_item.rs:154:26 | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^ +LL | fn assoc_fn_test2(x: _) -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions + --> $DIR/typeck_type_placeholder_item.rs:154:32 | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | fn assoc_fn_test2(x: _) -> _; + | ^ not allowed in type signatures -error: aborting due to 83 previous errors +error: aborting due to 82 previous errors -Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. +Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403, E0597. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.rs b/tests/ui/typeck/typeck_type_placeholder_item_help.rs index 758b94f985411..8d3ead480fc23 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.rs @@ -26,7 +26,7 @@ impl Test6 { } pub fn main() { - let _: Option = test1(); //~ ERROR mismatched types - let _: f64 = test1(); //~ ERROR mismatched types + let _: Option = test1(); + let _: f64 = test1(); let _: Option = test1(); } diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr index 3f21ff6d4ec9f..2d2015791ce31 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -1,15 +1,3 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item_help.rs:4:15 - | -LL | fn test1() -> _ { Some(42) } - | ^ not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn test1() -> _ { Some(42) } -LL + fn test1() -> Option { Some(42) } - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants --> $DIR/typeck_type_placeholder_item_help.rs:7:14 | @@ -34,12 +22,6 @@ LL - const TEST3: _ = Some(42); LL + const TEST3: Option = Some(42); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item_help.rs:13:22 - | -LL | const TEST4: fn() -> _ = 42; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants --> $DIR/typeck_type_placeholder_item_help.rs:24:18 | @@ -64,29 +46,24 @@ LL - const TEST5: _ = 42; LL + const TEST5: i32 = 42; | -error[E0308]: mismatched types - --> $DIR/typeck_type_placeholder_item_help.rs:29:28 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item_help.rs:4:15 | -LL | let _: Option = test1(); - | ------------- ^^^^^^^ expected `Option`, found `Option` - | | - | expected due to this +LL | fn test1() -> _ { Some(42) } + | ^ not allowed in type signatures | - = note: expected enum `Option` - found enum `Option` - -error[E0308]: mismatched types - --> $DIR/typeck_type_placeholder_item_help.rs:30:18 +help: replace with the correct return type | -LL | let _: f64 = test1(); - | --- ^^^^^^^ expected `f64`, found `Option` - | | - | expected due to this +LL - fn test1() -> _ { Some(42) } +LL + fn test1() -> Option { Some(42) } + | + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item_help.rs:13:22 | - = note: expected type `f64` - found enum `Option` +LL | const TEST4: fn() -> _ = 42; + | ^ not allowed in type signatures -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0121, E0308. -For more information about an error, try `rustc --explain E0121`. +For more information about this error, try `rustc --explain E0121`.