From f6938709c8aef58ade5577ae8ff77fbcb99d0845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 1 Nov 2025 18:29:46 +0000 Subject: [PATCH] Point at inner item when using outer item type param ``` error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:4:39 | LL | fn foo(x: T) { | - type parameter from outer item LL | fn bfnr, W: Fn()>(y: T) { | ---- ^ use of generic parameter from outer item | | | generic parameter used in this inner function | help: try introducing a local generic parameter here | LL | fn bfnr, W: Fn()>(y: T) { | ++ ``` --- compiler/rustc_resolve/messages.ftl | 5 ++++ compiler/rustc_resolve/src/diagnostics.rs | 7 ++++++ compiler/rustc_resolve/src/errors.rs | 10 ++++++++ compiler/rustc_resolve/src/ident.rs | 25 ++++++++++++++++++- compiler/rustc_resolve/src/late.rs | 15 +++++++---- compiler/rustc_resolve/src/lib.rs | 2 +- tests/ui/delegation/target-expr.stderr | 4 ++- tests/ui/error-codes/E0401.stderr | 16 ++++++++---- ...n-with-outer-generic-parameter-5997.stderr | 4 ++- ...eneric-params-nested-fn-scope-error.stderr | 8 ++++-- tests/ui/generics/issue-98432.stderr | 4 ++- tests/ui/resolve/bad-type-env-capture.stderr | 4 ++- ...om-outer-item-in-const-item.default.stderr | 12 ++++++--- ...m-in-const-item.generic_const_items.stderr | 12 ++++++--- tests/ui/resolve/issue-12796.stderr | 9 ++++--- tests/ui/resolve/issue-3021-c.stderr | 8 ++++-- tests/ui/resolve/issue-3214.stderr | 1 + ...65025-extern-static-parent-generics.stderr | 13 ++++++---- ...e-65035-static-with-parent-generics.stderr | 17 ++++++++----- ...resolve-type-param-in-item-in-trait.stderr | 16 +++++++++--- tests/ui/resolve/use-self-in-inner-fn.rs | 1 + tests/ui/resolve/use-self-in-inner-fn.stderr | 9 ++++--- .../static-generic-param-soundness.stderr | 4 ++- tests/ui/type/type-arg-out-of-scope.stderr | 8 ++++-- 24 files changed, 162 insertions(+), 52 deletions(-) diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index 5bf90d2637df..d462ff589f0d 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -180,6 +180,11 @@ resolve_generic_params_from_outer_item_const = a `const` is a separate item from resolve_generic_params_from_outer_item_const_param = const parameter from outer item +resolve_generic_params_from_outer_item_inner_item = {$is_self -> + [true] `Self` + *[false] generic parameter + } used in this inner {$descr} + resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl` resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 236ab1f09d35..f302da356e1e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -557,6 +557,7 @@ pub(crate) fn into_struct_error( outer_res, has_generic_params, def_kind, + item, ) => { use errs::GenericParamsFromOuterItemLabel as Label; let static_or_const = match def_kind { @@ -575,6 +576,10 @@ pub(crate) fn into_struct_error( sugg: None, static_or_const, is_self, + item: item.map(|(span, descr)| errs::GenericParamsFromOuterItemInnerItem { + span, + descr, + }), }; let sm = self.tcx.sess.source_map(); @@ -2506,6 +2511,7 @@ pub(crate) fn report_path_resolution_error( None, &ribs[ns_to_try], ignore_binding, + None, ) { // we found a locally-imported or available item/module Some(LexicalScopeBinding::Item(binding)) => Some(binding), @@ -2556,6 +2562,7 @@ pub(crate) fn report_path_resolution_error( None, &ribs[ValueNS], ignore_binding, + None, ) } else { None diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 3465c7fb1647..5c5938a3260e 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -24,6 +24,16 @@ pub(crate) struct GenericParamsFromOuterItem { #[subdiagnostic] pub(crate) static_or_const: Option, pub(crate) is_self: bool, + #[subdiagnostic] + pub(crate) item: Option, +} + +#[derive(Subdiagnostic)] +#[label(resolve_generic_params_from_outer_item_inner_item)] +pub(crate) struct GenericParamsFromOuterItemInnerItem { + #[primary_span] + pub(crate) span: Span, + pub(crate) descr: String, } #[derive(Subdiagnostic)] diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 2a195c8068da..4856b1e7cf97 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -12,7 +12,9 @@ use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst}; use crate::imports::{Import, NameResolution}; -use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind}; +use crate::late::{ + ConstantHasGenerics, DiagMetadata, NoConstantGenericsReason, PathSource, Rib, RibKind, +}; use crate::macros::{MacroRulesScope, sub_namespace_match}; use crate::{ AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingKey, CmResolver, Determinacy, @@ -295,6 +297,7 @@ pub(crate) fn resolve_ident_in_lexical_scope( finalize: Option, ribs: &[Rib<'ra>], ignore_binding: Option>, + diag_metadata: Option<&DiagMetadata<'_>>, ) -> Option> { assert!(ns == TypeNS || ns == ValueNS); let orig_ident = ident; @@ -326,6 +329,7 @@ pub(crate) fn resolve_ident_in_lexical_scope( finalize.map(|finalize| finalize.path_span), *original_rib_ident_def, ribs, + diag_metadata, ))); } else if let RibKind::Block(Some(module)) = rib.kind && let Ok(binding) = self.cm().resolve_ident_in_module_unadjusted( @@ -1193,6 +1197,7 @@ fn validate_res_from_ribs( finalize: Option, original_rib_ident_def: Ident, all_ribs: &[Rib<'ra>], + diag_metadata: Option<&DiagMetadata<'_>>, ) -> Res { debug!("validate_res_from_ribs({:?})", res); let ribs = &all_ribs[rib_index + 1..]; @@ -1391,12 +1396,25 @@ fn validate_res_from_ribs( }; if let Some(span) = finalize { + let item = if let Some(diag_metadata) = diag_metadata + && let Some(current_item) = diag_metadata.current_item + { + let span = current_item + .kind + .ident() + .map(|i| i.span) + .unwrap_or(current_item.span); + Some((span, current_item.kind.descr().to_string())) + } else { + None + }; self.report_error( span, ResolutionError::GenericParamsFromOuterItem( res, has_generic_params, def_kind, + item, ), ); } @@ -1472,6 +1490,7 @@ fn validate_res_from_ribs( res, has_generic_params, def_kind, + None, ), ); } @@ -1501,6 +1520,7 @@ pub(crate) fn maybe_resolve_path<'r>( None, None, ignore_import, + None, ) } #[instrument(level = "debug", skip(self))] @@ -1522,6 +1542,7 @@ pub(crate) fn resolve_path<'r>( None, ignore_binding, ignore_import, + None, ) } @@ -1535,6 +1556,7 @@ pub(crate) fn resolve_path_with_ribs<'r>( ribs: Option<&PerNS>>>, ignore_binding: Option>, ignore_import: Option>, + diag_metadata: Option<&DiagMetadata<'_>>, ) -> PathResult<'ra> { let mut module = None; let mut module_had_parse_errors = false; @@ -1675,6 +1697,7 @@ fn record_segment_res<'r, 'ra, 'tcx>( finalize, &ribs[ns], ignore_binding, + diag_metadata, ) { // we found a locally-imported or available item/module Some(LexicalScopeBinding::Item(binding)) => Ok(binding), diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index e3051dc38eca..198fef0cd630 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -667,7 +667,7 @@ pub(crate) struct UnnecessaryQualification<'ra> { } #[derive(Default, Debug)] -struct DiagMetadata<'ast> { +pub(crate) struct DiagMetadata<'ast> { /// The current trait's associated items' ident, used for diagnostic suggestions. current_trait_assoc_items: Option<&'ast [Box]>, @@ -678,7 +678,7 @@ struct DiagMetadata<'ast> { current_self_item: Option, /// The current trait (used to suggest). - current_item: Option<&'ast Item>, + pub(crate) current_item: Option<&'ast Item>, /// When processing generic arguments and encountering an unresolved ident not found, /// suggest introducing a type or const param depending on the context. @@ -885,6 +885,7 @@ fn visit_ty(&mut self, ty: &'ast Ty) { TypeNS, Some(Finalize::new(ty.id, ty.span)), None, + None, ) .map_or(Res::Err, |d| d.res()); self.r.record_partial_res(ty.id, PartialRes::new(res)); @@ -1457,6 +1458,7 @@ fn maybe_resolve_ident_in_lexical_scope( None, &self.ribs[ns], None, + None, ) } @@ -1466,6 +1468,7 @@ fn resolve_ident_in_lexical_scope( ns: Namespace, finalize: Option, ignore_binding: Option>, + diag_metadata: Option<&crate::late::DiagMetadata<'_>>, ) -> Option> { self.r.resolve_ident_in_lexical_scope( ident, @@ -1474,6 +1477,7 @@ fn resolve_ident_in_lexical_scope( finalize, &self.ribs[ns], ignore_binding, + diag_metadata, ) } @@ -1493,6 +1497,7 @@ fn resolve_path( Some(&self.ribs), None, None, + Some(&self.diag_metadata), ) } @@ -2551,8 +2556,8 @@ fn future_proof_import(&mut self, use_tree: &UseTree) { report_error(self, ns); } Some(LexicalScopeBinding::Item(binding)) => { - if let Some(LexicalScopeBinding::Res(..)) = - self.resolve_ident_in_lexical_scope(ident, ns, None, Some(binding)) + if let Some(LexicalScopeBinding::Res(..)) = self + .resolve_ident_in_lexical_scope(ident, ns, None, Some(binding), None) { report_error(self, ns); } @@ -5105,7 +5110,7 @@ fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finali // use the type namespace let ns = if i + 1 == path.len() { ns } else { TypeNS }; let res = self.r.partial_res_map.get(&seg.id?)?.full_res()?; - let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None)?; + let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None, None)?; (res == binding.res()).then_some((seg, binding)) }); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index f6a4f59cb339..c7f5ec76c075 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -241,7 +241,7 @@ struct BindingError { #[derive(Debug)] enum ResolutionError<'ra> { /// Error E0401: can't use type or const parameters from outer item. - GenericParamsFromOuterItem(Res, HasGenericParams, DefKind), + GenericParamsFromOuterItem(Res, HasGenericParams, DefKind, Option<(Span, String)>), /// Error E0403: the name is already used for a type or const parameter in this generic /// parameter list. NameAlreadyUsedInParameterList(Ident, Span), diff --git a/tests/ui/delegation/target-expr.stderr b/tests/ui/delegation/target-expr.stderr index 8bb25ad9e96e..f2e6c331193f 100644 --- a/tests/ui/delegation/target-expr.stderr +++ b/tests/ui/delegation/target-expr.stderr @@ -3,7 +3,9 @@ error[E0401]: can't use generic parameters from outer item | LL | fn bar(_: T) { | - type parameter from outer item -... +LL | reuse Trait::static_method { + | ------------- generic parameter used in this inner delegated function +LL | LL | let _ = T::Default(); | ^^^^^^^^^^ use of generic parameter from outer item | diff --git a/tests/ui/error-codes/E0401.stderr b/tests/ui/error-codes/E0401.stderr index fedb064c6bea..8daaf09df159 100644 --- a/tests/ui/error-codes/E0401.stderr +++ b/tests/ui/error-codes/E0401.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(x: T) { | - type parameter from outer item LL | fn bfnr, W: Fn()>(y: T) { - | ^ use of generic parameter from outer item + | ---- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | @@ -17,6 +19,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(x: T) { | - type parameter from outer item ... +LL | fn baz Iterator for A { | ---- `Self` type implicitly declared here, by this `impl` ... LL | fn helper(sel: &Self) -> u8 { - | ^^^^ - | | - | use of `Self` from outer item - | refer to the type directly here instead + | ------ ^^^^ + | | | + | | use of `Self` from outer item + | | refer to the type directly here instead + | `Self` used in this inner function error: aborting due to 3 previous errors diff --git a/tests/ui/generics/enum-definition-with-outer-generic-parameter-5997.stderr b/tests/ui/generics/enum-definition-with-outer-generic-parameter-5997.stderr index cded8ce31961..fb2d2f247b65 100644 --- a/tests/ui/generics/enum-definition-with-outer-generic-parameter-5997.stderr +++ b/tests/ui/generics/enum-definition-with-outer-generic-parameter-5997.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn f() -> bool { | - type parameter from outer item LL | enum E { V(Z) } - | ^ use of generic parameter from outer item + | - ^ use of generic parameter from outer item + | | + | generic parameter used in this inner enum | help: try introducing a local generic parameter here | diff --git a/tests/ui/generics/generic-params-nested-fn-scope-error.stderr b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr index 8c3b65d1edea..f809740ed381 100644 --- a/tests/ui/generics/generic-params-nested-fn-scope-error.stderr +++ b/tests/ui/generics/generic-params-nested-fn-scope-error.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(v: Vec) -> U { | - type parameter from outer item LL | fn bar(w: [U]) -> U { - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | @@ -17,7 +19,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(v: Vec) -> U { | - type parameter from outer item LL | fn bar(w: [U]) -> U { - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | diff --git a/tests/ui/generics/issue-98432.stderr b/tests/ui/generics/issue-98432.stderr index f20f779d884c..a1efee78cb7d 100644 --- a/tests/ui/generics/issue-98432.stderr +++ b/tests/ui/generics/issue-98432.stderr @@ -5,7 +5,9 @@ LL | impl Struct { | - type parameter from outer item LL | const CONST: fn() = || { LL | struct _Obligation where T:; - | ^ use of generic parameter from outer item + | ----------- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner struct | help: try introducing a local generic parameter here | diff --git a/tests/ui/resolve/bad-type-env-capture.stderr b/tests/ui/resolve/bad-type-env-capture.stderr index 272672beb4fb..c565997ca2a2 100644 --- a/tests/ui/resolve/bad-type-env-capture.stderr +++ b/tests/ui/resolve/bad-type-env-capture.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo() { | - type parameter from outer item LL | fn bar(b: T) { } - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr index fbb9ede8aa17..bc67e9dce4e3 100644 --- a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn outer() { // outer function | - type parameter from outer item LL | const K: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it @@ -15,7 +17,9 @@ LL | impl Tr for T { // outer impl block | - type parameter from outer item LL | const C: u32 = { LL | const I: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it @@ -25,7 +29,9 @@ error[E0401]: can't use generic parameters from outer item LL | struct S(U32<{ // outer struct | - type parameter from outer item LL | const _: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr index 3852b84fee2e..3959d117c7c9 100644 --- a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn outer() { // outer function | - type parameter from outer item LL | const K: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it help: try introducing a local generic parameter here @@ -19,7 +21,9 @@ LL | impl Tr for T { // outer impl block | - type parameter from outer item LL | const C: u32 = { LL | const I: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it help: try introducing a local generic parameter here @@ -33,7 +37,9 @@ error[E0401]: can't use generic parameters from outer item LL | struct S(U32<{ // outer struct | - type parameter from outer item LL | const _: u32 = T::C; - | ^^^^ use of generic parameter from outer item + | - ^^^^ use of generic parameter from outer item + | | + | generic parameter used in this inner constant item | = note: a `const` is a separate item from the item that contains it help: try introducing a local generic parameter here diff --git a/tests/ui/resolve/issue-12796.stderr b/tests/ui/resolve/issue-12796.stderr index 2305971303a7..b5828c6f5fc8 100644 --- a/tests/ui/resolve/issue-12796.stderr +++ b/tests/ui/resolve/issue-12796.stderr @@ -2,10 +2,11 @@ error[E0401]: can't use `Self` from outer item --> $DIR/issue-12796.rs:3:22 | LL | fn inner(_: &Self) { - | ^^^^ - | | - | use of `Self` from outer item - | can't use `Self` here + | ----- ^^^^ + | | | + | | use of `Self` from outer item + | | can't use `Self` here + | `Self` used in this inner function error: aborting due to 1 previous error diff --git a/tests/ui/resolve/issue-3021-c.stderr b/tests/ui/resolve/issue-3021-c.stderr index dcbaf2afd10c..8c554fd1b97d 100644 --- a/tests/ui/resolve/issue-3021-c.stderr +++ b/tests/ui/resolve/issue-3021-c.stderr @@ -3,7 +3,9 @@ error[E0401]: can't use generic parameters from outer item | LL | fn siphash() { | - type parameter from outer item -... +LL | +LL | trait U { + | - generic parameter used in this inner trait LL | fn g(&self, x: T) -> T; | ^ use of generic parameter from outer item | @@ -17,7 +19,9 @@ error[E0401]: can't use generic parameters from outer item | LL | fn siphash() { | - type parameter from outer item -... +LL | +LL | trait U { + | - generic parameter used in this inner trait LL | fn g(&self, x: T) -> T; | ^ use of generic parameter from outer item | diff --git a/tests/ui/resolve/issue-3214.stderr b/tests/ui/resolve/issue-3214.stderr index 5e5872f2a5fb..ab12676bdd80 100644 --- a/tests/ui/resolve/issue-3214.stderr +++ b/tests/ui/resolve/issue-3214.stderr @@ -4,6 +4,7 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo() { | - type parameter from outer item LL | struct Foo { + | --- generic parameter used in this inner struct LL | x: T, | ^ use of generic parameter from outer item | diff --git a/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr b/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr index ca32147d1976..2d21ed0155a7 100644 --- a/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr +++ b/tests/ui/resolve/issue-65025-extern-static-parent-generics.stderr @@ -1,11 +1,14 @@ error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65025-extern-static-parent-generics.rs:3:28 | -LL | unsafe fn foo() { - | - type parameter from outer item -LL | extern "C" { -LL | static baz: *const A; - | ^ use of generic parameter from outer item +LL | unsafe fn foo() { + | - type parameter from outer item +LL | / extern "C" { +LL | | static baz: *const A; + | | ^ use of generic parameter from outer item +LL | | +LL | | } + | |_____- generic parameter used in this inner extern block | = note: a `static` is a separate item from the item that contains it diff --git a/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr b/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr index 98ffb4567f16..869e1729cb85 100644 --- a/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr +++ b/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr @@ -1,11 +1,14 @@ error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:3:26 | -LL | fn f() { - | - type parameter from outer item -LL | extern "C" { -LL | static a: *const T; - | ^ use of generic parameter from outer item +LL | fn f() { + | - type parameter from outer item +LL | / extern "C" { +LL | | static a: *const T; + | | ^ use of generic parameter from outer item +LL | | +LL | | } + | |_____- generic parameter used in this inner extern block | = note: a `static` is a separate item from the item that contains it @@ -15,7 +18,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn g() { | - type parameter from outer item LL | static a: *const T = Default::default(); - | ^ use of generic parameter from outer item + | - ^ use of generic parameter from outer item + | | + | generic parameter used in this inner static item | = note: a `static` is a separate item from the item that contains it diff --git a/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr b/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr index 086418df7a25..00aa645688e7 100644 --- a/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr +++ b/tests/ui/resolve/resolve-type-param-in-item-in-trait.stderr @@ -3,7 +3,9 @@ error[E0401]: can't use generic parameters from outer item | LL | trait TraitA { | - type parameter from outer item -... +LL | fn outer(&self) { +LL | enum Foo { + | --- generic parameter used in this inner enum LL | Variance(A) | ^ use of generic parameter from outer item | @@ -19,7 +21,9 @@ LL | trait TraitB { | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo(A); - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner struct | help: try introducing a local generic parameter here | @@ -33,7 +37,9 @@ LL | trait TraitC { | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo { a: A } - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner struct | help: try introducing a local generic parameter here | @@ -47,7 +53,9 @@ LL | trait TraitD { | - type parameter from outer item LL | fn outer(&self) { LL | fn foo(a: A) { } - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | diff --git a/tests/ui/resolve/use-self-in-inner-fn.rs b/tests/ui/resolve/use-self-in-inner-fn.rs index 62f9dc5664ff..ed64ee885271 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.rs +++ b/tests/ui/resolve/use-self-in-inner-fn.rs @@ -6,6 +6,7 @@ fn banana(&mut self) { fn peach(this: &Self) { //~^ ERROR can't use `Self` from outer item //~| NOTE use of `Self` from outer item + //~| NOTE `Self` used in this inner function //~| NOTE refer to the type directly here instead } } diff --git a/tests/ui/resolve/use-self-in-inner-fn.stderr b/tests/ui/resolve/use-self-in-inner-fn.stderr index 9c388df8bc20..645875f6e726 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.stderr +++ b/tests/ui/resolve/use-self-in-inner-fn.stderr @@ -5,10 +5,11 @@ LL | impl A { | ---- `Self` type implicitly declared here, by this `impl` ... LL | fn peach(this: &Self) { - | ^^^^ - | | - | use of `Self` from outer item - | refer to the type directly here instead + | ----- ^^^^ + | | | + | | use of `Self` from outer item + | | refer to the type directly here instead + | `Self` used in this inner function error: aborting due to 1 previous error diff --git a/tests/ui/statics/static-generic-param-soundness.stderr b/tests/ui/statics/static-generic-param-soundness.stderr index 47554c7fcb0f..72f65e2bac7c 100644 --- a/tests/ui/statics/static-generic-param-soundness.stderr +++ b/tests/ui/statics/static-generic-param-soundness.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo() { | - type parameter from outer item LL | static a: Bar = Bar::What; - | ^ use of generic parameter from outer item + | - ^ use of generic parameter from outer item + | | + | generic parameter used in this inner static item | = note: a `static` is a separate item from the item that contains it diff --git a/tests/ui/type/type-arg-out-of-scope.stderr b/tests/ui/type/type-arg-out-of-scope.stderr index f4fbcdac53b6..3d8850ebccea 100644 --- a/tests/ui/type/type-arg-out-of-scope.stderr +++ b/tests/ui/type/type-arg-out-of-scope.stderr @@ -4,7 +4,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(x: T) { | - type parameter from outer item LL | fn bar(f: Box T>) { } - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here | @@ -17,7 +19,9 @@ error[E0401]: can't use generic parameters from outer item LL | fn foo(x: T) { | - type parameter from outer item LL | fn bar(f: Box T>) { } - | ^ use of generic parameter from outer item + | --- ^ use of generic parameter from outer item + | | + | generic parameter used in this inner function | help: try introducing a local generic parameter here |