Skip to content

Commit 8b49731

Browse files
authoredSep 11, 2023
Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errors
Improve diagnostic for generic params from outer items (E0401) Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples). Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled. Lastly, make E0401 translatable while we're at it. Fixes #115720.
·
1.89.01.74.0
2 parents f279afb + daf3c45 commit 8b49731

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+306
-183
lines changed
 

‎compiler/rustc_error_codes/src/error_codes/E0401.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Inner items do not inherit type or const parameters from the functions
1+
Inner items do not inherit the generic parameters from the items
22
they are embedded in.
33

44
Erroneous code example:
@@ -32,8 +32,8 @@ fn foo<T>(x: T) {
3232
}
3333
```
3434

35-
Items inside functions are basically just like top-level items, except
36-
that they can only be used from the function they are in.
35+
Items nested inside other items are basically just like top-level items, except
36+
that they can only be used from the item they are in.
3737

3838
There are a couple of solutions for this.
3939

‎compiler/rustc_resolve/messages.ftl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ resolve_cannot_find_ident_in_this_scope =
6868
resolve_cannot_glob_import_possible_crates =
6969
cannot glob-import all possible crates
7070
71-
resolve_cannot_use_self_type_here =
72-
can't use `Self` here
73-
7471
resolve_change_import_binding =
7572
you can use `as` to change the binding name of the import
7673
@@ -90,9 +87,6 @@ resolve_const_not_member_of_trait =
9087
const `{$const_}` is not a member of trait `{$trait_}`
9188
.label = not a member of trait `{$trait_}`
9289
93-
resolve_const_param_from_outer_fn =
94-
const parameter from outer function
95-
9690
resolve_const_param_in_enum_discriminant =
9791
const parameters may not be used in enum discriminant values
9892
@@ -119,10 +113,19 @@ resolve_forward_declared_generic_param =
119113
generic parameters with a default cannot use forward declared identifiers
120114
.label = defaulted generic parameters cannot be forward declared
121115
122-
resolve_generic_params_from_outer_function =
123-
can't use generic parameters from outer function
124-
.label = use of generic parameter from outer function
125-
.suggestion = try using a local generic parameter instead
116+
resolve_generic_params_from_outer_item =
117+
can't use generic parameters from outer item
118+
.label = use of generic parameter from outer item
119+
.refer_to_type_directly = refer to the type directly here instead
120+
.suggestion = try introducing a local generic parameter here
121+
122+
resolve_generic_params_from_outer_item_const_param = const parameter from outer item
123+
124+
resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl`
125+
126+
resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here
127+
128+
resolve_generic_params_from_outer_item_ty_param = type parameter from outer item
126129
127130
resolve_glob_import_doesnt_reexport =
128131
glob import doesn't reexport anything because no candidate is public enough
@@ -277,9 +280,6 @@ resolve_type_not_member_of_trait =
277280
type `{$type_}` is not a member of trait `{$trait_}`
278281
.label = not a member of trait `{$trait_}`
279282
280-
resolve_type_param_from_outer_fn =
281-
type parameter from outer function
282-
283283
resolve_type_param_in_enum_discriminant =
284284
type parameters may not be used in enum discriminant values
285285
@@ -315,9 +315,6 @@ resolve_unreachable_label_suggestion_use_similarly_named =
315315
resolve_unreachable_label_with_similar_name_exists =
316316
a label with a similar name exists but is unreachable
317317
318-
resolve_use_a_type_here_instead =
319-
use a type here instead
320-
321318
resolve_variable_bound_with_different_mode =
322319
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
323320
.label = bound in different ways

0 commit comments

Comments
 (0)
Please sign in to comment.