Skip to content

Commit c9e8d0b

Browse files
committed
Invoke bounds (and type-inference) in non_local_defs
1 parent 0befac4 commit c9e8d0b

12 files changed

+56
-0
lines changed

compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho
447447
*[other] `{$body_name}` and up {$depth} bodies
448448
}
449449
.non_local = an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
450+
.bounds = `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
450451
.exception = anon-const (`const _: () = {"{"} ... {"}"}`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
451452
.const_anon = use a const-anon item to suppress this lint
452453

compiler/rustc_lint/src/lints.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ pub enum NonLocalDefinitionsDiag {
13401340
body_name: String,
13411341
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13421342
const_anon: Option<Option<Span>>,
1343+
bounds: Option<()>,
13431344
},
13441345
MacroRules {
13451346
depth: u32,
@@ -1360,12 +1361,16 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13601361
body_name,
13611362
cargo_update,
13621363
const_anon,
1364+
bounds,
13631365
} => {
13641366
diag.arg("depth", depth);
13651367
diag.arg("body_kind_descr", body_kind_descr);
13661368
diag.arg("body_name", body_name);
13671369

13681370
diag.help(fluent::lint_help);
1371+
if let Some(()) = bounds {
1372+
diag.note(fluent::lint_bounds);
1373+
}
13691374
diag.note(fluent::lint_non_local);
13701375

13711376
if let Some(cargo_update) = cargo_update {

compiler/rustc_lint/src/non_local_def.rs

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
228228
.unwrap_or_else(|| "<unnameable>".to_string()),
229229
cargo_update: cargo_update(),
230230
const_anon,
231+
bounds: impl_.of_trait.map(|_| ()),
231232
},
232233
)
233234
}

tests/ui/lint/non-local-defs/cargo-update.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: move this `impl` block outside the of the current constant `_IMPL_DEBUG`
8+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
89
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
910
= note: the macro `non_local_macro::non_local_impl` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
1011
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level

tests/ui/lint/non-local-defs/consts.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LL | impl Uto for &Test {}
88
| ^^^^^^^^^^^^^^^^^^^^^
99
|
1010
= help: move this `impl` block outside the of the current constant `Z`
11+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
1112
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1213
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
1314
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
@@ -20,6 +21,7 @@ LL | impl Uto2 for Test {}
2021
| ^^^^^^^^^^^^^^^^^^^^^
2122
|
2223
= help: move this `impl` block outside the of the current static `A`
24+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
2325
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
2426
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
2527
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
@@ -31,6 +33,7 @@ LL | impl Uto3 for Test {}
3133
| ^^^^^^^^^^^^^^^^^^^^^
3234
|
3335
= help: move this `impl` block outside the of the current constant `B`
36+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
3437
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
3538
= note: anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type are consider to be transparent regarding the nesting level
3639
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
@@ -82,6 +85,7 @@ LL | impl Uto9 for Test {}
8285
| ^^^^^^^^^^^^^^^^^^^^^
8386
|
8487
= help: move this `impl` block outside the of the current closure `<unnameable>` and up 2 bodies
88+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
8589
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
8690
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
8791

@@ -92,6 +96,7 @@ LL | impl Uto10 for Test {}
9296
| ^^^^^^^^^^^^^^^^^^^^^^
9397
|
9498
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
99+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
95100
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
96101
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
97102

tests/ui/lint/non-local-defs/exhaustive-trait.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LL | | }
1010
| |_____^
1111
|
1212
= help: move this `impl` block outside the of the current function `main`
13+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
1314
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1415
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
1516
= note: `#[warn(non_local_definitions)]` on by default
@@ -26,6 +27,7 @@ LL | | }
2627
| |_____^
2728
|
2829
= help: move this `impl` block outside the of the current function `main`
30+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
2931
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
3032
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
3133

@@ -41,6 +43,7 @@ LL | | }
4143
| |_____^
4244
|
4345
= help: move this `impl` block outside the of the current function `main`
46+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
4447
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
4548
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
4649

@@ -56,6 +59,7 @@ LL | | }
5659
| |_____^
5760
|
5861
= help: move this `impl` block outside the of the current function `main`
62+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
5963
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
6064
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
6165

@@ -71,6 +75,7 @@ LL | | }
7175
| |_____^
7276
|
7377
= help: move this `impl` block outside the of the current function `main`
78+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
7479
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
7580
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
7681

@@ -86,6 +91,7 @@ LL | | }
8691
| |_____^
8792
|
8893
= help: move this `impl` block outside the of the current function `main`
94+
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
8995
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
9096
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
9197

0 commit comments

Comments
 (0)