From b00e408e613700124463b72f0a449a28c44a8178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 10 Sep 2023 23:06:14 +0200 Subject: [PATCH 1/3] Generalize E0401 --- .../src/error_codes/E0401.md | 6 ++-- compiler/rustc_resolve/src/diagnostics.rs | 22 +++++-------- compiler/rustc_resolve/src/ident.rs | 10 ++---- compiler/rustc_resolve/src/lib.rs | 4 +-- .../early/const-param-from-outer-fn.rs | 2 +- .../early/const-param-from-outer-fn.stderr | 8 ++--- tests/ui/error-codes/E0401.stderr | 22 ++++++------- tests/ui/generics/issue-94432-garbage-ice.rs | 2 +- tests/ui/generics/issue-98432.rs | 2 +- tests/ui/generics/issue-98432.stderr | 8 ++--- tests/ui/inner-static-type-parameter.rs | 2 +- tests/ui/inner-static-type-parameter.stderr | 6 ++-- tests/ui/issues/issue-3214.rs | 2 +- tests/ui/issues/issue-3214.stderr | 8 ++--- tests/ui/issues/issue-5997-enum.rs | 2 +- tests/ui/issues/issue-5997-enum.stderr | 8 ++--- tests/ui/issues/issue-5997-struct.rs | 2 +- tests/ui/issues/issue-5997-struct.stderr | 8 ++--- tests/ui/nested-ty-params.rs | 2 +- tests/ui/nested-ty-params.stderr | 16 +++++----- tests/ui/resolve/bad-type-env-capture.stderr | 8 ++--- tests/ui/resolve/issue-12796.rs | 2 +- tests/ui/resolve/issue-12796.stderr | 4 +-- tests/ui/resolve/issue-3021-c.rs | 4 +-- tests/ui/resolve/issue-3021-c.stderr | 16 +++++----- ...sue-65025-extern-static-parent-generics.rs | 2 +- ...65025-extern-static-parent-generics.stderr | 6 ++-- ...issue-65035-static-with-parent-generics.rs | 10 +++--- ...e-65035-static-with-parent-generics.stderr | 30 ++++++++--------- .../resolve-type-param-in-item-in-trait.rs | 8 ++--- ...resolve-type-param-in-item-in-trait.stderr | 32 +++++++++---------- tests/ui/resolve/use-self-in-inner-fn.rs | 6 ++-- tests/ui/resolve/use-self-in-inner-fn.stderr | 6 ++-- tests/ui/type/type-arg-out-of-scope.rs | 2 +- tests/ui/type/type-arg-out-of-scope.stderr | 16 +++++----- 35 files changed, 141 insertions(+), 153 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0401.md b/compiler/rustc_error_codes/src/error_codes/E0401.md index 4c93053d5f8b6..45d083681e574 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0401.md +++ b/compiler/rustc_error_codes/src/error_codes/E0401.md @@ -1,4 +1,4 @@ -Inner items do not inherit type or const parameters from the functions +Inner items do not inherit the generic parameters from the items they are embedded in. Erroneous code example: @@ -32,8 +32,8 @@ fn foo(x: T) { } ``` -Items inside functions are basically just like top-level items, except -that they can only be used from the function they are in. +Items nested inside other items are basically just like top-level items, except +that they can only be used from the item they are in. There are a couple of solutions for this. diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index d99fc07a7cd28..a99b610ed36af 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -553,14 +553,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { resolution_error: ResolutionError<'a>, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { match resolution_error { - ResolutionError::GenericParamsFromOuterFunction(outer_res, has_generic_params) => { + ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params) => { let mut err = struct_span_err!( self.tcx.sess, span, E0401, - "can't use generic parameters from outer function", + "can't use generic parameters from outer item", ); - err.span_label(span, "use of generic parameter from outer function"); + err.span_label(span, "use of generic parameter from outer item"); let sm = self.tcx.sess.source_map(); let def_id = match outer_res { @@ -573,23 +573,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { reduce_impl_span_to_impl_keyword(sm, self.def_span(def_id)), "`Self` type implicitly declared here, by this `impl`", ); - err.span_label(span, "use a type here instead"); + err.span_label(span, "refer to the type directly here instead"); return err; } Res::Def(DefKind::TyParam, def_id) => { - err.span_label(self.def_span(def_id), "type parameter from outer function"); + err.span_label(self.def_span(def_id), "type parameter from outer item"); def_id } Res::Def(DefKind::ConstParam, def_id) => { - err.span_label( - self.def_span(def_id), - "const parameter from outer function", - ); + err.span_label(self.def_span(def_id), "const parameter from outer item"); def_id } _ => { bug!( - "GenericParamsFromOuterFunction should only be used with \ + "GenericParamsFromOuterItem should only be used with \ Res::SelfTyParam, Res::SelfTyAlias, DefKind::TyParam or \ DefKind::ConstParam" ); @@ -597,9 +594,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }; if let HasGenericParams::Yes(span) = has_generic_params { - // Try to retrieve the span of the function signature and generate a new - // message with a local type or const parameter. - let sugg_msg = "try using a local generic parameter instead"; + let sugg_msg = "try introducing a local generic parameter here"; let name = self.tcx.item_name(def_id); let (span, snippet) = if span.is_empty() { let snippet = format!("<{name}>"); @@ -609,7 +604,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let snippet = format!("{name}, "); (span, snippet) }; - // Suggest the modification to the user err.span_suggestion(span, sugg_msg, snippet, Applicability::MaybeIncorrect); } diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 61e05b65f90f5..4817484f56435 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1229,10 +1229,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(span) = finalize { self.report_error( span, - ResolutionError::GenericParamsFromOuterFunction( - res, - has_generic_params, - ), + ResolutionError::GenericParamsFromOuterItem(res, has_generic_params), ); } return Res::Err; @@ -1296,10 +1293,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(span) = finalize { self.report_error( span, - ResolutionError::GenericParamsFromOuterFunction( - res, - has_generic_params, - ), + ResolutionError::GenericParamsFromOuterItem(res, has_generic_params), ); } return Res::Err; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index b757f42eaa026..5bb8a21513849 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -186,8 +186,8 @@ struct BindingError { #[derive(Debug)] enum ResolutionError<'a> { - /// Error E0401: can't use type or const parameters from outer function. - GenericParamsFromOuterFunction(Res, HasGenericParams), + /// Error E0401: can't use type or const parameters from outer item. + GenericParamsFromOuterItem(Res, HasGenericParams), /// Error E0403: the name is already used for a type or const parameter in this generic /// parameter list. NameAlreadyUsedInParameterList(Symbol, Span), diff --git a/tests/ui/const-generics/early/const-param-from-outer-fn.rs b/tests/ui/const-generics/early/const-param-from-outer-fn.rs index c3b418ee3f8ad..ee57f3c4fc32c 100644 --- a/tests/ui/const-generics/early/const-param-from-outer-fn.rs +++ b/tests/ui/const-generics/early/const-param-from-outer-fn.rs @@ -1,6 +1,6 @@ fn foo() { fn bar() -> u32 { - X //~ ERROR can't use generic parameters from outer function + X //~ ERROR can't use generic parameters from outer item } } diff --git a/tests/ui/const-generics/early/const-param-from-outer-fn.stderr b/tests/ui/const-generics/early/const-param-from-outer-fn.stderr index e3bf38b702e75..826f2657905d3 100644 --- a/tests/ui/const-generics/early/const-param-from-outer-fn.stderr +++ b/tests/ui/const-generics/early/const-param-from-outer-fn.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/const-param-from-outer-fn.rs:3:9 | LL | fn foo() { - | - const parameter from outer function + | - const parameter from outer item LL | fn bar() -> u32 { - | - help: try using a local generic parameter instead: `` + | - help: try introducing a local generic parameter here: `` LL | X - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to previous error diff --git a/tests/ui/error-codes/E0401.stderr b/tests/ui/error-codes/E0401.stderr index fa4b91cacef72..928c8d11d2030 100644 --- a/tests/ui/error-codes/E0401.stderr +++ b/tests/ui/error-codes/E0401.stderr @@ -1,26 +1,26 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:4:39 | LL | fn foo(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bfnr, W: Fn()>(y: T) { - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `T,` + | help: try introducing a local generic parameter here: `T,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/E0401.rs:9:16 | LL | fn foo(x: T) { - | - type parameter from outer function + | - type parameter from outer item ... LL | fn baz $DIR/E0401.rs:24:25 | LL | impl Iterator for A { @@ -29,8 +29,8 @@ LL | impl Iterator for A { LL | fn helper(sel: &Self) -> u8 { | ^^^^ | | - | use of generic parameter from outer function - | use a type here instead + | use of generic parameter from outer item + | refer to the type directly here instead error[E0282]: type annotations needed --> $DIR/E0401.rs:11:5 diff --git a/tests/ui/generics/issue-94432-garbage-ice.rs b/tests/ui/generics/issue-94432-garbage-ice.rs index d0709e2d2a46c..4ddb3a7e9f86b 100644 --- a/tests/ui/generics/issue-94432-garbage-ice.rs +++ b/tests/ui/generics/issue-94432-garbage-ice.rs @@ -4,7 +4,7 @@ fn�a(){fn�p(){e}} //~ ERROR unknown start of token: \u{fffd} //~^ ERROR unknown start of token: \u{fffd} -//~^^ ERROR can't use generic parameters from outer function [E0401] +//~^^ ERROR can't use generic parameters from outer item [E0401] //~^^^ WARN type parameter `e` should have an upper camel case name fn main(){} diff --git a/tests/ui/generics/issue-98432.rs b/tests/ui/generics/issue-98432.rs index 780c50d6ffa19..c31dea76c090c 100644 --- a/tests/ui/generics/issue-98432.rs +++ b/tests/ui/generics/issue-98432.rs @@ -2,7 +2,7 @@ struct Struct(T); impl Struct { const CONST: fn() = || { - struct _Obligation where T:; //~ ERROR can't use generic parameters from outer function + struct _Obligation where T:; //~ ERROR can't use generic parameters from outer item }; } diff --git a/tests/ui/generics/issue-98432.stderr b/tests/ui/generics/issue-98432.stderr index c7b5c33618d5f..0736d94106e7d 100644 --- a/tests/ui/generics/issue-98432.stderr +++ b/tests/ui/generics/issue-98432.stderr @@ -1,13 +1,13 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-98432.rs:5:34 | LL | impl Struct { - | - type parameter from outer function + | - type parameter from outer item LL | const CONST: fn() = || { LL | struct _Obligation where T:; - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to previous error diff --git a/tests/ui/inner-static-type-parameter.rs b/tests/ui/inner-static-type-parameter.rs index c08ccd29d8011..a1994e7529cb7 100644 --- a/tests/ui/inner-static-type-parameter.rs +++ b/tests/ui/inner-static-type-parameter.rs @@ -4,7 +4,7 @@ enum Bar { What } //~ ERROR parameter `T` is never used fn foo() { static a: Bar = Bar::What; -//~^ ERROR can't use generic parameters from outer function +//~^ ERROR can't use generic parameters from outer item } fn main() { diff --git a/tests/ui/inner-static-type-parameter.stderr b/tests/ui/inner-static-type-parameter.stderr index e4e449e4159b6..ff6558e494b11 100644 --- a/tests/ui/inner-static-type-parameter.stderr +++ b/tests/ui/inner-static-type-parameter.stderr @@ -1,10 +1,10 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/inner-static-type-parameter.rs:6:19 | LL | fn foo() { - | - type parameter from outer function + | - type parameter from outer item LL | static a: Bar = Bar::What; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error[E0392]: parameter `T` is never used --> $DIR/inner-static-type-parameter.rs:3:10 diff --git a/tests/ui/issues/issue-3214.rs b/tests/ui/issues/issue-3214.rs index e3c07bb3f724f..b2c27f5be957c 100644 --- a/tests/ui/issues/issue-3214.rs +++ b/tests/ui/issues/issue-3214.rs @@ -1,6 +1,6 @@ fn foo() { struct Foo { - x: T, //~ ERROR can't use generic parameters from outer function + x: T, //~ ERROR can't use generic parameters from outer item } impl Drop for Foo { diff --git a/tests/ui/issues/issue-3214.stderr b/tests/ui/issues/issue-3214.stderr index 7a2d772f0a1b5..5b57c1baf90ba 100644 --- a/tests/ui/issues/issue-3214.stderr +++ b/tests/ui/issues/issue-3214.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3214.rs:3:12 | LL | fn foo() { - | - type parameter from outer function + | - type parameter from outer item LL | struct Foo { - | - help: try using a local generic parameter instead: `` + | - help: try introducing a local generic parameter here: `` LL | x: T, - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-3214.rs:6:22 diff --git a/tests/ui/issues/issue-5997-enum.rs b/tests/ui/issues/issue-5997-enum.rs index 3ff4e036c60be..0b1857ae3df30 100644 --- a/tests/ui/issues/issue-5997-enum.rs +++ b/tests/ui/issues/issue-5997-enum.rs @@ -1,6 +1,6 @@ fn f() -> bool { enum E { V(Z) } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item true } diff --git a/tests/ui/issues/issue-5997-enum.stderr b/tests/ui/issues/issue-5997-enum.stderr index 3a79215d3ae9c..d07258ea7a2f9 100644 --- a/tests/ui/issues/issue-5997-enum.stderr +++ b/tests/ui/issues/issue-5997-enum.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-5997-enum.rs:2:16 | LL | fn f() -> bool { - | - type parameter from outer function + | - type parameter from outer item LL | enum E { V(Z) } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to previous error diff --git a/tests/ui/issues/issue-5997-struct.rs b/tests/ui/issues/issue-5997-struct.rs index 6cf510b0a9d75..19d994b0dfb7a 100644 --- a/tests/ui/issues/issue-5997-struct.rs +++ b/tests/ui/issues/issue-5997-struct.rs @@ -1,5 +1,5 @@ fn f() -> bool { - struct S(T); //~ ERROR can't use generic parameters from outer function + struct S(T); //~ ERROR can't use generic parameters from outer item true } diff --git a/tests/ui/issues/issue-5997-struct.stderr b/tests/ui/issues/issue-5997-struct.stderr index d2e97f767719f..83229e02c6ca0 100644 --- a/tests/ui/issues/issue-5997-struct.stderr +++ b/tests/ui/issues/issue-5997-struct.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-5997-struct.rs:2:14 | LL | fn f() -> bool { - | - type parameter from outer function + | - type parameter from outer item LL | struct S(T); - | -^ use of generic parameter from outer function + | -^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to previous error diff --git a/tests/ui/nested-ty-params.rs b/tests/ui/nested-ty-params.rs index 85413acdb1491..25bac1ba24bd1 100644 --- a/tests/ui/nested-ty-params.rs +++ b/tests/ui/nested-ty-params.rs @@ -1,4 +1,4 @@ -// error-pattern:can't use generic parameters from outer function +// error-pattern:can't use generic parameters from outer item fn hd(v: Vec ) -> U { fn hd1(w: [U]) -> U { return w[0]; } diff --git a/tests/ui/nested-ty-params.stderr b/tests/ui/nested-ty-params.stderr index 8f4746f5ec3bd..a9cdec667199a 100644 --- a/tests/ui/nested-ty-params.stderr +++ b/tests/ui/nested-ty-params.stderr @@ -1,22 +1,22 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/nested-ty-params.rs:3:16 | LL | fn hd(v: Vec ) -> U { - | - type parameter from outer function + | - type parameter from outer item LL | fn hd1(w: [U]) -> U { return w[0]; } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/nested-ty-params.rs:3:23 | LL | fn hd(v: Vec ) -> U { - | - type parameter from outer function + | - type parameter from outer item LL | fn hd1(w: [U]) -> U { return w[0]; } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to 2 previous errors diff --git a/tests/ui/resolve/bad-type-env-capture.stderr b/tests/ui/resolve/bad-type-env-capture.stderr index b6282c2d0703b..941b6b7a68c35 100644 --- a/tests/ui/resolve/bad-type-env-capture.stderr +++ b/tests/ui/resolve/bad-type-env-capture.stderr @@ -1,12 +1,12 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/bad-type-env-capture.rs:2:15 | LL | fn foo() { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(b: T) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to previous error diff --git a/tests/ui/resolve/issue-12796.rs b/tests/ui/resolve/issue-12796.rs index 942d6b9a5686e..de3e73437f080 100644 --- a/tests/ui/resolve/issue-12796.rs +++ b/tests/ui/resolve/issue-12796.rs @@ -1,7 +1,7 @@ trait Trait { fn outer(&self) { fn inner(_: &Self) { - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } } diff --git a/tests/ui/resolve/issue-12796.stderr b/tests/ui/resolve/issue-12796.stderr index a01fd2d65420b..ef59d00360b88 100644 --- a/tests/ui/resolve/issue-12796.stderr +++ b/tests/ui/resolve/issue-12796.stderr @@ -1,10 +1,10 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-12796.rs:3:22 | LL | fn inner(_: &Self) { | ^^^^ | | - | use of generic parameter from outer function + | use of generic parameter from outer item | can't use `Self` here error: aborting due to previous error diff --git a/tests/ui/resolve/issue-3021-c.rs b/tests/ui/resolve/issue-3021-c.rs index 94ed1fdf78191..bd21d1244235d 100644 --- a/tests/ui/resolve/issue-3021-c.rs +++ b/tests/ui/resolve/issue-3021-c.rs @@ -1,8 +1,8 @@ fn siphash() { trait U { - fn g(&self, x: T) -> T; //~ ERROR can't use generic parameters from outer function - //~^ ERROR can't use generic parameters from outer function + fn g(&self, x: T) -> T; //~ ERROR can't use generic parameters from outer item + //~^ ERROR can't use generic parameters from outer item } } diff --git a/tests/ui/resolve/issue-3021-c.stderr b/tests/ui/resolve/issue-3021-c.stderr index 5176efc3a6be7..537bbaf7b6a56 100644 --- a/tests/ui/resolve/issue-3021-c.stderr +++ b/tests/ui/resolve/issue-3021-c.stderr @@ -1,24 +1,24 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3021-c.rs:4:24 | LL | fn siphash() { - | - type parameter from outer function + | - type parameter from outer item LL | LL | trait U { - | - help: try using a local generic parameter instead: `` + | - help: try introducing a local generic parameter here: `` LL | fn g(&self, x: T) -> T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-3021-c.rs:4:30 | LL | fn siphash() { - | - type parameter from outer function + | - type parameter from outer item LL | LL | trait U { - | - help: try using a local generic parameter instead: `` + | - help: try introducing a local generic parameter here: `` LL | fn g(&self, x: T) -> T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to 2 previous errors diff --git a/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs b/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs index ce45f630e48a5..4fa3f12d024d5 100644 --- a/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs +++ b/tests/ui/resolve/issue-65025-extern-static-parent-generics.rs @@ -1,7 +1,7 @@ unsafe fn foo() { extern "C" { static baz: *const A; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } let bar: *const u64 = core::mem::transmute(&baz); 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 6bbf76dd1fbb2..3e9c3fd11b74d 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,11 @@ -error[E0401]: can't use generic parameters from outer function +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 function + | - type parameter from outer item LL | extern "C" { LL | static baz: *const A; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to previous error diff --git a/tests/ui/resolve/issue-65035-static-with-parent-generics.rs b/tests/ui/resolve/issue-65035-static-with-parent-generics.rs index f96c04841dd28..bc99584a8d26a 100644 --- a/tests/ui/resolve/issue-65035-static-with-parent-generics.rs +++ b/tests/ui/resolve/issue-65035-static-with-parent-generics.rs @@ -1,26 +1,26 @@ fn f() { extern "C" { static a: *const T; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } fn g() { static a: *const T = Default::default(); - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } fn h() { extern "C" { static a: [u8; N]; - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } fn i() { static a: [u8; N] = [0; N]; - //~^ ERROR can't use generic parameters from outer function - //~| ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item + //~| ERROR can't use generic parameters from outer item } fn main() {} 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 7ed572f80b896..f1fe1a6002c93 100644 --- a/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr +++ b/tests/ui/resolve/issue-65035-static-with-parent-generics.stderr @@ -1,44 +1,44 @@ -error[E0401]: can't use generic parameters from outer function +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 function + | - type parameter from outer item LL | extern "C" { LL | static a: *const T; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:9:22 | LL | fn g() { - | - type parameter from outer function + | - type parameter from outer item LL | static a: *const T = Default::default(); - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:15:24 | LL | fn h() { - | - const parameter from outer function + | - const parameter from outer item LL | extern "C" { LL | static a: [u8; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:21:20 | LL | fn i() { - | - const parameter from outer function + | - const parameter from outer item LL | static a: [u8; N] = [0; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/issue-65035-static-with-parent-generics.rs:21:29 | LL | fn i() { - | - const parameter from outer function + | - const parameter from outer item LL | static a: [u8; N] = [0; N]; - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item error: aborting due to 5 previous errors diff --git a/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs b/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs index c77a66524f73f..2d5f34c62a6f9 100644 --- a/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs +++ b/tests/ui/resolve/resolve-type-param-in-item-in-trait.rs @@ -6,7 +6,7 @@ trait TraitA { fn outer(&self) { enum Foo { Variance(A) - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } } @@ -14,21 +14,21 @@ trait TraitA { trait TraitB { fn outer(&self) { struct Foo(A); - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } trait TraitC { fn outer(&self) { struct Foo { a: A } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } trait TraitD { fn outer(&self) { fn foo(a: A) { } - //~^ ERROR can't use generic parameters from outer function + //~^ ERROR can't use generic parameters from outer item } } 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 0a6d1cc3bcd45..1ab56fdc50441 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 @@ -1,46 +1,46 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:8:22 | LL | trait TraitA { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | enum Foo { - | - help: try using a local generic parameter instead: `A,` + | - help: try introducing a local generic parameter here: `A,` LL | Variance(A) - | ^ use of generic parameter from outer function + | ^ use of generic parameter from outer item -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:16:23 | LL | trait TraitB { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo(A); - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:23:28 | LL | trait TraitC { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | struct Foo { a: A } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/resolve-type-param-in-item-in-trait.rs:30:22 | LL | trait TraitD { - | - type parameter from outer function + | - type parameter from outer item LL | fn outer(&self) { LL | fn foo(a: A) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `A,` + | help: try introducing a local generic parameter here: `A,` error: aborting due to 4 previous errors diff --git a/tests/ui/resolve/use-self-in-inner-fn.rs b/tests/ui/resolve/use-self-in-inner-fn.rs index eccb315feb1e2..f4dfa4c40ab24 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.rs +++ b/tests/ui/resolve/use-self-in-inner-fn.rs @@ -4,9 +4,9 @@ impl A { //~^ NOTE `Self` type implicitly declared here, by this `impl` fn banana(&mut self) { fn peach(this: &Self) { - //~^ ERROR can't use generic parameters from outer function - //~| NOTE use of generic parameter from outer function - //~| NOTE use a type here instead + //~^ ERROR can't use generic parameters from outer item + //~| NOTE use of generic parameter from outer item + //~| 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 966093499241d..832aaacaf49c8 100644 --- a/tests/ui/resolve/use-self-in-inner-fn.stderr +++ b/tests/ui/resolve/use-self-in-inner-fn.stderr @@ -1,4 +1,4 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/use-self-in-inner-fn.rs:6:25 | LL | impl A { @@ -7,8 +7,8 @@ LL | impl A { LL | fn peach(this: &Self) { | ^^^^ | | - | use of generic parameter from outer function - | use a type here instead + | use of generic parameter from outer item + | refer to the type directly here instead error: aborting due to previous error diff --git a/tests/ui/type/type-arg-out-of-scope.rs b/tests/ui/type/type-arg-out-of-scope.rs index 02aad00770793..c36f9904e5dc1 100644 --- a/tests/ui/type/type-arg-out-of-scope.rs +++ b/tests/ui/type/type-arg-out-of-scope.rs @@ -1,4 +1,4 @@ -// error-pattern:can't use generic parameters from outer function +// error-pattern:can't use generic parameters from outer item fn foo(x: T) { fn bar(f: Box T>) { } } diff --git a/tests/ui/type/type-arg-out-of-scope.stderr b/tests/ui/type/type-arg-out-of-scope.stderr index 7f18b4510f4b2..8665001e24319 100644 --- a/tests/ui/type/type-arg-out-of-scope.stderr +++ b/tests/ui/type/type-arg-out-of-scope.stderr @@ -1,22 +1,22 @@ -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/type-arg-out-of-scope.rs:3:29 | LL | fn foo(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(f: Box T>) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` -error[E0401]: can't use generic parameters from outer function +error[E0401]: can't use generic parameters from outer item --> $DIR/type-arg-out-of-scope.rs:3:35 | LL | fn foo(x: T) { - | - type parameter from outer function + | - type parameter from outer item LL | fn bar(f: Box T>) { } - | - ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer item | | - | help: try using a local generic parameter instead: `` + | help: try introducing a local generic parameter here: `` error: aborting due to 2 previous errors From 9b3625247782650d57efa141ee4378eafe0d8dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 10 Sep 2023 23:06:28 +0200 Subject: [PATCH 2/3] Make E0401 translatable --- compiler/rustc_resolve/messages.ftl | 29 ++++++++---------- compiler/rustc_resolve/src/diagnostics.rs | 37 +++++++++++------------ compiler/rustc_resolve/src/errors.rs | 34 +++++++++++++++++++++ 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index f98918cba8800..619c30ac54a33 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -64,9 +64,6 @@ resolve_cannot_find_ident_in_this_scope = resolve_cannot_glob_import_possible_crates = cannot glob-import all possible crates -resolve_cannot_use_self_type_here = - can't use `Self` here - resolve_change_import_binding = you can use `as` to change the binding name of the import @@ -86,9 +83,6 @@ resolve_const_not_member_of_trait = const `{$const_}` is not a member of trait `{$trait_}` .label = not a member of trait `{$trait_}` -resolve_const_param_from_outer_fn = - const parameter from outer function - resolve_const_param_in_enum_discriminant = const parameters may not be used in enum discriminant values @@ -115,10 +109,19 @@ resolve_forward_declared_generic_param = generic parameters with a default cannot use forward declared identifiers .label = defaulted generic parameters cannot be forward declared -resolve_generic_params_from_outer_function = - can't use generic parameters from outer function - .label = use of generic parameter from outer function - .suggestion = try using a local generic parameter instead +resolve_generic_params_from_outer_item = + can't use generic parameters from outer item + .label = use of generic parameter from outer item + .refer_to_type_directly = refer to the type directly here instead + .suggestion = try introducing a local generic parameter here + +resolve_generic_params_from_outer_item_const_param = const parameter from outer item + +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 + +resolve_generic_params_from_outer_item_ty_param = type parameter from outer item resolve_glob_import_doesnt_reexport = glob import doesn't reexport anything because no candidate is public enough @@ -273,9 +276,6 @@ resolve_type_not_member_of_trait = type `{$type_}` is not a member of trait `{$trait_}` .label = not a member of trait `{$trait_}` -resolve_type_param_from_outer_fn = - type parameter from outer function - resolve_type_param_in_enum_discriminant = type parameters may not be used in enum discriminant values @@ -311,9 +311,6 @@ resolve_unreachable_label_suggestion_use_similarly_named = resolve_unreachable_label_with_similar_name_exists = a label with a similar name exists but is unreachable -resolve_use_a_type_here_instead = - use a type here instead - resolve_variable_bound_with_different_mode = variable `{$variable_name}` is bound inconsistently across alternatives separated by `|` .label = bound in different ways diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a99b610ed36af..bcf62d8a2f290 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -554,34 +554,34 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { match resolution_error { ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params) => { - let mut err = struct_span_err!( - self.tcx.sess, + use errs::GenericParamsFromOuterItemLabel as Label; + let mut err = errs::GenericParamsFromOuterItem { span, - E0401, - "can't use generic parameters from outer item", - ); - err.span_label(span, "use of generic parameter from outer item"); + label: None, + refer_to_type_directly: None, + sugg: None, + }; let sm = self.tcx.sess.source_map(); let def_id = match outer_res { Res::SelfTyParam { .. } => { - err.span_label(span, "can't use `Self` here"); - return err; + err.label = Some(Label::SelfTyParam(span)); + return self.tcx.sess.create_err(err); } Res::SelfTyAlias { alias_to: def_id, .. } => { - err.span_label( - reduce_impl_span_to_impl_keyword(sm, self.def_span(def_id)), - "`Self` type implicitly declared here, by this `impl`", - ); - err.span_label(span, "refer to the type directly here instead"); - return err; + err.label = Some(Label::SelfTyAlias(reduce_impl_span_to_impl_keyword( + sm, + self.def_span(def_id), + ))); + err.refer_to_type_directly = Some(span); + return self.tcx.sess.create_err(err); } Res::Def(DefKind::TyParam, def_id) => { - err.span_label(self.def_span(def_id), "type parameter from outer item"); + err.label = Some(Label::TyParam(self.def_span(def_id))); def_id } Res::Def(DefKind::ConstParam, def_id) => { - err.span_label(self.def_span(def_id), "const parameter from outer item"); + err.label = Some(Label::ConstParam(self.def_span(def_id))); def_id } _ => { @@ -594,7 +594,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }; if let HasGenericParams::Yes(span) = has_generic_params { - let sugg_msg = "try introducing a local generic parameter here"; let name = self.tcx.item_name(def_id); let (span, snippet) = if span.is_empty() { let snippet = format!("<{name}>"); @@ -604,10 +603,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let snippet = format!("{name}, "); (span, snippet) }; - err.span_suggestion(span, sugg_msg, snippet, Applicability::MaybeIncorrect); + err.sugg = Some(errs::GenericParamsFromOuterItemSugg { span, snippet }); } - err + self.tcx.sess.create_err(err) } ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self .tcx diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index e4b89c65853d0..4f91f6aa90f79 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -32,6 +32,40 @@ pub(crate) struct CrateRootNamesMustBeNamedExplicitly(#[primary_span] pub(crate) #[diag(resolve_crate_root_imports_must_be_named_explicitly)] pub(crate) struct ResolutionError(#[primary_span] pub(crate) Span); +#[derive(Diagnostic)] +#[diag(resolve_generic_params_from_outer_item, code = "E0401")] +pub(crate) struct GenericParamsFromOuterItem { + #[primary_span] + #[label] + pub(crate) span: Span, + #[subdiagnostic] + pub(crate) label: Option, + #[label(resolve_refer_to_type_directly)] + pub(crate) refer_to_type_directly: Option, + #[subdiagnostic] + pub(crate) sugg: Option, +} + +#[derive(Subdiagnostic)] +pub(crate) enum GenericParamsFromOuterItemLabel { + #[label(resolve_generic_params_from_outer_item_self_ty_param)] + SelfTyParam(#[primary_span] Span), + #[label(resolve_generic_params_from_outer_item_self_ty_alias)] + SelfTyAlias(#[primary_span] Span), + #[label(resolve_generic_params_from_outer_item_ty_param)] + TyParam(#[primary_span] Span), + #[label(resolve_generic_params_from_outer_item_const_param)] + ConstParam(#[primary_span] Span), +} + +#[derive(Subdiagnostic)] +#[suggestion(resolve_suggestion, code = "{snippet}", applicability = "maybe-incorrect")] +pub(crate) struct GenericParamsFromOuterItemSugg { + #[primary_span] + pub(crate) span: Span, + pub(crate) snippet: String, +} + #[derive(Diagnostic)] #[diag(resolve_name_is_already_used_as_generic_parameter, code = "E0403")] pub(crate) struct NameAlreadyUsedInParameterList { From daf3c45531815e8015e8a508f2650fcfa166cf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 10 Sep 2023 22:29:37 +0200 Subject: [PATCH 3/3] Do not suggest generic const items unless enabled --- compiler/rustc_resolve/src/late.rs | 6 ++- ...om-outer-item-in-const-item.default.stderr | 28 +++++++++++++ ...m-in-const-item.generic_const_items.stderr | 34 ++++++++++++++++ ...ic-params-from-outer-item-in-const-item.rs | 39 +++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr create mode 100644 tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr create mode 100644 tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 486d60eab2101..d40b1b2e3a900 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2450,7 +2450,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { ItemKind::Const(box ast::ConstItem { ref generics, ref ty, ref expr, .. }) => { self.with_generic_param_rib( &generics.params, - RibKind::Item(HasGenericParams::Yes(generics.span)), + RibKind::Item(if self.r.tcx.features().generic_const_items { + HasGenericParams::Yes(generics.span) + } else { + HasGenericParams::No + }), LifetimeRibKind::Generics { binder: item.id, kind: LifetimeBinderKind::ConstItem, 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 new file mode 100644 index 0000000000000..4f8538292792c --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.default.stderr @@ -0,0 +1,28 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:12:20 + | +LL | fn outer() { // outer function + | - type parameter from outer item +LL | const K: u32 = T::C; + | ^^^^ use of generic parameter from outer item + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:19:24 + | +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 + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:27:20 + | +LL | struct S(U32<{ // outer struct + | - type parameter from outer item +LL | const _: u32 = T::C; + | ^^^^ use of generic parameter from outer item + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0401`. 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 new file mode 100644 index 0000000000000..1cb55842bc665 --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.generic_const_items.stderr @@ -0,0 +1,34 @@ +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:12:20 + | +LL | fn outer() { // outer function + | - type parameter from outer item +LL | const K: u32 = T::C; + | - ^^^^ use of generic parameter from outer item + | | + | help: try introducing a local generic parameter here: `` + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:19:24 + | +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 + | | + | help: try introducing a local generic parameter here: `` + +error[E0401]: can't use generic parameters from outer item + --> $DIR/generic-params-from-outer-item-in-const-item.rs:27:20 + | +LL | struct S(U32<{ // outer struct + | - type parameter from outer item +LL | const _: u32 = T::C; + | - ^^^^ use of generic parameter from outer item + | | + | help: try introducing a local generic parameter here: `` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0401`. diff --git a/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs new file mode 100644 index 0000000000000..e5647d72cba35 --- /dev/null +++ b/tests/ui/resolve/generic-params-from-outer-item-in-const-item.rs @@ -0,0 +1,39 @@ +// Regression test for issue #115720. +// If a const item contains generic params from an outer items, only suggest +// turning the const item generic if the feature `generic_const_items` is enabled. + +// revisions: default generic_const_items + +#![cfg_attr(generic_const_items, feature(generic_const_items))] +#![feature(generic_const_exprs)] // only used for the test case "outer struct" +#![allow(incomplete_features)] + +fn outer() { // outer function + const K: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here +} + +impl Tr for T { // outer impl block + const C: u32 = { + const I: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here + I + }; +} + +struct S(U32<{ // outer struct + const _: u32 = T::C; + //~^ ERROR can't use generic parameters from outer item + //[generic_const_items]~| HELP try introducing a local generic parameter here + 0 +}>); + +trait Tr { + const C: u32; +} + +struct U32; + +fn main() {}