diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index f4c7234cd8f83..375f0de806e0a 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -20,21 +20,19 @@ use std::ops::{Bound, ControlFlow}; use rustc_abi::{ExternAbi, Size}; use rustc_ast::Recovered; -use rustc_data_structures::assert_matches; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; +use rustc_data_structures::{assert_matches, defer}; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, E0228, ErrorGuaranteed, StashKey}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::intravisit::{self, InferKind, Visitor, VisitorExt}; +use rustc_hir::intravisit::{self, InferKind, Visitor}; use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind, find_attr}; -use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; +use rustc_infer::infer::InferCtxt; use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; use rustc_middle::hir::nested_filter; use rustc_middle::query::Providers; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{ - self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, TypingMode, fold_regions, -}; +use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName; @@ -129,6 +127,7 @@ pub(crate) struct ItemCtxt<'tcx> { tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, tainted_by_errors: Cell>, + suppress_placeholder_errors: Cell, } /////////////////////////////////////////////////////////////////////////// @@ -239,7 +238,12 @@ fn bad_placeholder<'cx, 'tcx>( impl<'tcx> ItemCtxt<'tcx> { pub(crate) fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> { - ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) } + ItemCtxt { + tcx, + item_def_id, + tainted_by_errors: Cell::new(None), + suppress_placeholder_errors: Cell::new(false), + } } pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { @@ -265,7 +269,10 @@ impl<'tcx> ItemCtxt<'tcx> { &self, placeholder_types: Vec, infer_replacements: Vec<(Span, String)>, - ) -> ErrorGuaranteed { + ) { + if self.suppress_placeholder_errors.get() { + return; + } let node = self.tcx.hir_node_by_def_id(self.item_def_id); let generics = node.generics(); let kind_id = match node { @@ -296,7 +303,7 @@ impl<'tcx> ItemCtxt<'tcx> { ); } - diag.emit() + diag.emit(); } } @@ -524,6 +531,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { _generics: Option<&hir::Generics<'_>>, hir_id: rustc_hir::HirId, _hir_ty: Option<&hir::Ty<'_>>, + suppress_ret_ty_placeholder_errors: bool, ) -> (Vec>, Ty<'tcx>) { let tcx = self.tcx(); @@ -548,7 +556,15 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { let output_ty = match decl.output { hir::FnRetTy::Return(output) => { - if let hir::TyKind::Infer(()) = output.kind + let old_suppress_placeholder_errors = self.suppress_placeholder_errors.get(); + let _restore = + defer(|| self.suppress_placeholder_errors.set(old_suppress_placeholder_errors)); + + if suppress_ret_ty_placeholder_errors { + self.suppress_placeholder_errors.set(true); + } + if !suppress_ret_ty_placeholder_errors + && let hir::TyKind::Infer(()) = output.kind && let Some(suggested_ty) = self.lowerer().suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None) { @@ -950,55 +966,69 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { } } -#[instrument(level = "debug", skip(tcx), ret)] -fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFnSig<'_>> { +/// We'll emit an error about the suggestable infer ty in `typeck` query if this is true. +/// In that case we suppress errors about it in the `fn_sig` query. +pub fn suggest_ret_ty_in_typeck<'tcx>( + tcx: TyCtxt<'tcx>, + node: &Node<'tcx>, + hir_id: HirId, +) -> Option<&'tcx hir::Ty<'tcx>> { use rustc_hir::Node::*; use rustc_hir::*; - - let hir_id = tcx.local_def_id_to_hir_id(def_id); - - let icx = ItemCtxt::new(tcx, def_id); - - let output = match tcx.hir_node(hir_id) { + let sig = match node { TraitItem(hir::TraitItem { - kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)), - generics, - .. + kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)), .. }) - | Item(hir::Item { kind: ItemKind::Fn { sig, generics, .. }, .. }) => { - lower_fn_sig_recovering_infer_ret_ty(&icx, sig, generics, def_id) - } + | Item(hir::Item { kind: ItemKind::Fn { sig, .. }, .. }) => Some(sig), - ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => { + ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => { // 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, - ) + None } else { - lower_fn_sig_recovering_infer_ret_ty(&icx, sig, generics, def_id) + Some(sig) } } + _ => None, + }; + sig.and_then(|sig| sig.decl.output.is_suggestable_infer_ty()) +} + +#[instrument(level = "debug", skip(tcx), ret)] +fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFnSig<'_>> { + use rustc_hir::Node::*; + use rustc_hir::*; + + let hir_id = tcx.local_def_id_to_hir_id(def_id); + + let icx = ItemCtxt::new(tcx, def_id); + + let node = &tcx.hir_node(hir_id); + + let suggest_ret_ty_in_typeck = suggest_ret_ty_in_typeck(tcx, node, hir_id).is_some(); + + let output = match *node { TraitItem(hir::TraitItem { - kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _), + kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)), generics, .. - }) => icx.lowerer().lower_fn_ty( - hir_id, - header.safety(), - header.abi, - decl, - Some(generics), - None, - ), + }) + | 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, + suggest_ret_ty_in_typeck, + ) + } ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(sig, _, _), .. }) => { let abi = tcx.hir_get_foreign_abi(hir_id); @@ -1039,183 +1069,6 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn ty::EarlyBinder::bind(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.c_variadic, - fn_sig.safety, - fn_sig.abi, - ); - - 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>, @@ -1453,8 +1306,9 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( safety: hir::Safety, ) -> ty::PolyFnSig<'tcx> { let hir_id = tcx.local_def_id_to_hir_id(def_id); - let fty = - ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, safety, abi, decl, None, None); + let fty = ItemCtxt::new(tcx, def_id) + .lowerer() + .lower_fn_ty(hir_id, safety, abi, decl, None, None, false); // Feature gate SIMD types in FFI, since I am not sure that the // ABIs are handled at all correctly. -huonw diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 5cda2ac660fb1..cd665ef2c719f 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -799,7 +799,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/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 8021b02fa2964..5b66e0f427568 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -201,6 +201,7 @@ pub trait HirTyLowerer<'tcx> { generics: Option<&hir::Generics<'_>>, hir_id: HirId, hir_ty: Option<&hir::Ty<'_>>, + suppress_ret_ty_placeholder_errors: bool, ) -> (Vec>, Ty<'tcx>); /// Returns `AdtDef` if `ty` is an ADT. @@ -2924,7 +2925,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Ty::new_fn_ptr( tcx, - self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl, None, Some(hir_ty)), + self.lower_fn_ty( + hir_ty.hir_id, + bf.safety, + bf.abi, + bf.decl, + None, + Some(hir_ty), + false, + ), ) } hir::TyKind::UnsafeBinder(binder) => Ty::new_unsafe_binder( @@ -3315,12 +3324,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { decl: &hir::FnDecl<'tcx>, generics: Option<&hir::Generics<'_>>, hir_ty: Option<&hir::Ty<'_>>, + suppress_ret_ty_placeholder_errors: bool, ) -> ty::PolyFnSig<'tcx> { let tcx = self.tcx(); let bound_vars = tcx.late_bound_vars(hir_id); debug!(?bound_vars); - let (input_tys, output_ty) = self.lower_fn_sig(decl, generics, hir_id, hir_ty); + let (input_tys, output_ty) = + self.lower_fn_sig(decl, generics, hir_id, hir_ty, suppress_ret_ty_placeholder_errors); debug!(?output_ty); diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index a1c8b8421e7c1..e7575ad8f0c04 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -96,7 +96,7 @@ use rustc_session::parse::feature_err; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::traits; -pub use crate::collect::suggest_impl_trait; +pub use crate::collect::{suggest_impl_trait, suggest_ret_ty_in_typeck}; 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/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 873e95f13bb97..99dce50947b9f 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -446,6 +446,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { _generics: Option<&rustc_hir::Generics<'_>>, _hir_id: rustc_hir::HirId, _hir_ty: Option<&hir::Ty<'_>>, + _suppress_ret_ty_placeholder_errors: bool, ) -> (Vec>, Ty<'tcx>) { let input_tys = decl.inputs.iter().map(|a| self.lowerer().lower_ty(a)).collect(); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 15e94a27d559c..1affcf8c87668 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -44,15 +44,18 @@ use fn_ctxt::FnCtxt; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_err}; -use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{HirId, HirIdMap, Node}; +use rustc_hir::intravisit::VisitorExt; +use rustc_hir::{self as hir, HirId, HirIdMap, Node}; use rustc_hir_analysis::check::{check_abi, check_custom_abi}; +use rustc_hir_analysis::errors::PlaceholderNotAllowedItemSignatures; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; +use rustc_hir_analysis::suggest_ret_ty_in_typeck; +use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::config; use rustc_span::Span; @@ -142,7 +145,7 @@ fn typeck_with_inspect<'tcx>( // type that has an infer in it, lower the type directly so that it'll // be correctly filled with infer. We'll use this inference to provide // a suggestion later on. - fcx.lowerer().lower_fn_ty(id, header.safety(), header.abi, decl, None, None) + fcx.lowerer().lower_fn_ty(id, header.safety(), header.abi, decl, None, None, false) } else { tcx.fn_sig(def_id).instantiate_identity() }; @@ -267,6 +270,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 @@ -276,6 +281,78 @@ 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 Some(infer_ret_ty) = suggest_ret_ty_in_typeck(tcx, &node, hir_id) else { return }; + + struct PlaceholderSpanCollector<'a>(&'a mut 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.0.push(inf_span); + } + } + + // Collect all `_` placeholder spans from the return type. + let mut spans = Vec::new(); + let mut collector = PlaceholderSpanCollector(&mut spans); + collector.visit_ty_unambig(infer_ret_ty); + + let mut diag = tcx.dcx().create_err(PlaceholderNotAllowedItemSignatures { + 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) = rustc_hir_analysis::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 infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Option> { let tcx = fcx.tcx; let def_id = fcx.body_id; 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/const-generics/generic_arg_infer/in-signature.stderr b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr index d7a7ab52c83de..ecd83d6638224 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 | @@ -160,6 +122,44 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | const ARR: Bar<_, _>; | ^ not allowed in type signatures +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: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0121`. 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/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/ty-variance-issue-124423.stderr b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr index bf9ad85dfc5c6..5bd65c6f5beb1 100644 --- a/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr +++ b/tests/ui/parallel-rustc/ty-variance-issue-124423.stderr @@ -280,7 +280,6 @@ note: if you're trying to build a new `Box<_, _>` consider using one of the foll Box::::try_new --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -error: aborting due to 30 previous errors Some errors have detailed explanations: E0121, E0224, E0261, E0425, E0599. -For more information about an error, try `rustc --explain E0121`. +For more information about an error, try `rustc --explain E0121`. \ No newline at end of file diff --git a/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr b/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr index 55d52d35f4a8d..eb0ffdabb91d8 100644 --- a/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr +++ b/tests/ui/parallel-rustc/ty-variance-issue-127971.stderr @@ -106,7 +106,6 @@ note: if you're trying to build a new `Box<_, _>` consider using one of the foll Box::::try_new --> $SRC_DIR/alloc/src/boxed.rs:LL:COL -error: aborting due to 11 previous errors Some errors have detailed explanations: E0121, E0224, E0261, E0599. For more information about an error, try `rustc --explain E0121`. \ No newline at end of file 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/type-alias-impl-trait/issue-77179.stderr b/tests/ui/type-alias-impl-trait/issue-77179.stderr index 222edfb90a7b3..46ae1f61df9ee 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.stderr +++ b/tests/ui/type-alias-impl-trait/issue-77179.stderr @@ -1,3 +1,9 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-77179.rs:19:25 + | +LL | fn bar() -> Pointer<_>; + | ^ not allowed in type signatures + error[E0792]: expected generic type parameter, found `i32` --> $DIR/issue-77179.rs:8:14 | @@ -19,12 +25,6 @@ LL - fn test() -> Pointer<_> { LL + fn test() -> Pointer { | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-77179.rs:19:25 - | -LL | fn bar() -> Pointer<_>; - | ^ not allowed in type signatures - error: aborting due to 3 previous errors Some errors have detailed explanations: E0121, E0792. 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 48547c019d628..f7ff2b36b500f 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 { @@ -230,7 +233,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..1d6d76d2f37a8 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -1,35 +1,35 @@ 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:176: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:176: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:181:19 | LL | struct BadStruct2<_, T>(_, T); | ^ expected identifier, found reserved identifier error: associated constant in `impl` without body - --> $DIR/typeck_type_placeholder_item.rs:215:5 + --> $DIR/typeck_type_placeholder_item.rs:218:5 | LL | const C: _; | ^^^^^^^^^^- @@ -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:176: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 | @@ -139,85 +113,61 @@ 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 + --> $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:68:9 + --> $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:68:12 + --> $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:123:12 + --> $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:125:13 + --> $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:125:16 + --> $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:158:21 + --> $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:173:25 + --> $DIR/typeck_type_placeholder_item.rs:176: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 + --> $DIR/typeck_type_placeholder_item.rs:181: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 +179,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 +191,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 +209,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 +220,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 +233,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 +245,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 @@ -335,25 +259,25 @@ 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 + --> $DIR/typeck_type_placeholder_item.rs:96: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 + --> $DIR/typeck_type_placeholder_item.rs:99: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 + --> $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 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 +289,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,156 +300,128 @@ 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 - | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ cannot infer type - -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 functions + --> $DIR/typeck_type_placeholder_item.rs:131:21 | 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 - | -LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: replace with the correct return type - | -LL - fn fn_test12(x: i32) -> (_, _) { (x, x) } -LL + fn fn_test12(x: i32) -> (i32, i32) { (x, 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:137:33 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:139:21 | 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) } - | + | ^ 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:142:31 + --> $DIR/typeck_type_placeholder_item.rs:145:31 | 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 + --> $DIR/typeck_type_placeholder_item.rs:147:31 | 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 + --> $DIR/typeck_type_placeholder_item.rs:147:37 | 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 + --> $DIR/typeck_type_placeholder_item.rs:150:31 | 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 + --> $DIR/typeck_type_placeholder_item.rs:152:26 | 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 + --> $DIR/typeck_type_placeholder_item.rs:154:26 | 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:151:32 + --> $DIR/typeck_type_placeholder_item.rs:154: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 + --> $DIR/typeck_type_placeholder_item.rs:157:28 | 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 + --> $DIR/typeck_type_placeholder_item.rs:166:32 | 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 + --> $DIR/typeck_type_placeholder_item.rs:166:15 | 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 + --> $DIR/typeck_type_placeholder_item.rs:170:34 | 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 + --> $DIR/typeck_type_placeholder_item.rs:185: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:188:21 + --> $DIR/typeck_type_placeholder_item.rs:191:21 | LL | type Y = impl Trait<_>; | ^ 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 + --> $DIR/typeck_type_placeholder_item.rs:201:14 | LL | type B = _; | ^ 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 + --> $DIR/typeck_type_placeholder_item.rs:214:14 | 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 + --> $DIR/typeck_type_placeholder_item.rs:216:14 | 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 + --> $DIR/typeck_type_placeholder_item.rs:203:14 | LL | const C: _; | ^ 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:215:14 + --> $DIR/typeck_type_placeholder_item.rs:218:14 | LL | const C: _; | ^ 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 + --> $DIR/typeck_type_placeholder_item.rs:205:14 | LL | const D: _ = 42; | ^ not allowed in type signatures @@ -537,13 +433,13 @@ LL + const D: i32 = 42; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:218:14 + --> $DIR/typeck_type_placeholder_item.rs:221:14 | 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 + --> $DIR/typeck_type_placeholder_item.rs:212:1 | LL | type F: std::ops::Fn(_); | ----------------------- `F` from trait @@ -551,53 +447,91 @@ LL | type F: std::ops::Fn(_); 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 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:234:17 | -LL | fn value() -> Option<&'static _> { - | ^ not allowed in type signatures +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:242:10 | -help: replace with the correct return type +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^ not allowed in type signatures | -LL - fn value() -> Option<&'static _> { -LL + fn value() -> Option<&'static u8> { +note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:242:29}>, {closure@typeck_type_placeholder_item.rs:242:49}>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:242: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 constants - --> $DIR/typeck_type_placeholder_item.rs:231:17 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods + --> $DIR/typeck_type_placeholder_item.rs:43:27 | -LL | const _: Option<_> = map(value); - | ^ not allowed in type signatures +LL | fn test10(&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:111:34 | -help: replace this with a fully-specified type +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:208:26 + | +LL | type F: std::ops::Fn(_); + | ^ 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:208:26 | -LL - const _: Option<_> = map(value); -LL + const _: Option = map(value); +LL | type F: std::ops::Fn(_); + | ^ 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: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:191:21 + | +LL | type Y = impl Trait<_>; + | ^ 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 return types - --> $DIR/typeck_type_placeholder_item.rs:235:31 + --> $DIR/typeck_type_placeholder_item.rs:7:14 | -LL | fn evens_squared(n: usize) -> _ { - | ^ not allowed in type signatures +LL | fn test() -> _ { 5 } + | ^ not allowed in type signatures | -help: replace with an appropriate return type +help: replace with the correct return type | -LL - fn evens_squared(n: usize) -> _ { -LL + fn evens_squared(n: usize) -> impl Iterator { +LL - fn test() -> _ { 5 } +LL + fn test() -> i32 { 5 } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:240:10 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:10:16 | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^ not allowed in type signatures +LL | fn test2() -> (_, _) { (5, 5) } + | ^ ^ not allowed in type signatures + | | + | 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 +help: replace with the correct return type + | +LL - fn test2() -> (_, _) { (5, 5) } +LL + fn test2() -> (i32, i32) { (5, 5) } | -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:40:24 @@ -611,14 +545,58 @@ LL - fn test9(&self) -> _ { () } LL + fn test9(&self) -> () { () } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:43:27 +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 { | -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 + --> $DIR/typeck_type_placeholder_item.rs:53: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 return types + --> $DIR/typeck_type_placeholder_item.rs:81: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: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) } + | + +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 @@ -629,72 +607,109 @@ LL - fn fn_test9(&self) -> _ { () } LL + fn fn_test9(&self) -> () { () } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods - --> $DIR/typeck_type_placeholder_item.rs:110:34 +error[E0282]: type annotations needed + --> $DIR/typeck_type_placeholder_item.rs:131:21 | -LL | fn fn_test10(&self, _x : _) { } - | ^ 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 types - --> $DIR/typeck_type_placeholder_item.rs:205:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:131:28 | -LL | type F: std::ops::Fn(_); - | ^ 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 types - --> $DIR/typeck_type_placeholder_item.rs:205:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:136:30 | -LL | type F: std::ops::Fn(_); - | ^ 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 with the correct return type + | +LL - fn fn_test12(x: i32) -> (_, _) { (x, x) } +LL + fn fn_test12(x: i32) -> (i32, i32) { (x, x) } | - = 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:167:34 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:139:33 | -LL | fn impl_trait() -> impl BadTrait<_> { - | ^ not allowed in type signatures +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) } | - = 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 return types + --> $DIR/typeck_type_placeholder_item.rs:229:31 | -LL | type Y = impl Trait<_>; - | ^ not allowed in type signatures +LL | fn value() -> Option<&'static _> { + | ^ not allowed in type signatures + | +help: replace with the correct return type + | +LL - fn value() -> Option<&'static _> { +LL + fn value() -> Option<&u8> { | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -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 return types + --> $DIR/typeck_type_placeholder_item.rs:237:31 | -LL | const _: Option<_> = map(value); - | ^^^^^^^^^^ +LL | fn evens_squared(n: usize) -> _ { + | ^ not allowed in type signatures | -note: function `map` is not const - --> $DIR/typeck_type_placeholder_item.rs:222:1 +help: replace with an appropriate return type + | +LL - fn evens_squared(n: usize) -> _ { +LL + fn evens_squared(n: usize) -> impl Iterator { | -LL | fn map(_: fn() -> Option<&'static T>) -> Option { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: calls in constants are limited to constant functions, tuple structs and tuple variants -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[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:242:29: 242:32}>` in constants + --> $DIR/typeck_type_placeholder_item.rs:242:22 | 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[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[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:242:29: 242:32}> as Iterator>::map::` in constants + --> $DIR/typeck_type_placeholder_item.rs:242: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: aborting due to 83 previous errors - -Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. +error[E0597]: `x` does not live long enough + --> $DIR/typeck_type_placeholder_item.rs:49:5 + | +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: aborting due to 85 previous errors + +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..4cb0bc06ba583 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 | @@ -64,29 +52,18 @@ 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) } | - = note: expected type `f64` - found enum `Option` -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`.