Skip to content

Commit 094fd26

Browse files
committed
Invoke bounds (and type-inference) in non_local_defs
1 parent a48d5a2 commit 094fd26

12 files changed

+56
-0
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho
549549
*[other] `{$body_name}` and up {$depth} bodies
550550
}
551551
.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`
552+
.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
552553
.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
553554
.const_anon = use a const-anon item to suppress this lint
554555

compiler/rustc_lint/src/lints.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ pub enum NonLocalDefinitionsDiag {
13471347
body_name: String,
13481348
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13491349
const_anon: Option<Option<Span>>,
1350+
bounds: Option<()>,
13501351
},
13511352
MacroRules {
13521353
depth: u32,
@@ -1367,12 +1368,16 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13671368
body_name,
13681369
cargo_update,
13691370
const_anon,
1371+
bounds,
13701372
} => {
13711373
diag.arg("depth", depth);
13721374
diag.arg("body_kind_descr", body_kind_descr);
13731375
diag.arg("body_name", body_name);
13741376

13751377
diag.help(fluent::lint_help);
1378+
if let Some(()) = bounds {
1379+
diag.note(fluent::lint_bounds);
1380+
}
13761381
diag.note(fluent::lint_non_local);
13771382

13781383
if let Some(cargo_update) = cargo_update {

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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)