Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7236f18

Browse files
committedMay 22, 2024·
Point the parent item and items that needs to be moved when appropriate
1 parent 10fcf87 commit 7236f18

13 files changed

+311
-462
lines changed
 

‎compiler/rustc_lint/messages.ftl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,19 @@ lint_non_local_definitions_cargo_update = the {$macro_kind} `{$macro_name}` may
543543
lint_non_local_definitions_deprecation = 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>
544544
545545
lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks should be written at the same level as their item
546-
.move_help =
547-
move this `impl` block outside of the current {$body_kind_descr} {$depth ->
548-
[one] `{$body_name}`
549-
*[other] `{$body_name}` and up {$depth} bodies
550-
}
551546
.remove_help = remove `{$may_remove_part}` to make the `impl` local
552547
.without_trait = methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
553548
.with_trait = an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
554549
.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
555550
.exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration
556551
.const_anon = use a const-anon item to suppress this lint
557552
553+
lint_non_local_definitions_impl_move_help =
554+
move this `impl` block outside of the current {$body_kind_descr} {$depth ->
555+
[one] `{$body_name}`
556+
*[other] `{$body_name}` and up {$depth} bodies
557+
}
558+
558559
lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
559560
.help =
560561
remove the `#[macro_export]` or move this `macro_rules!` outside the of the current {$body_kind_descr} {$depth ->

‎compiler/rustc_lint/src/lints.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,7 @@ pub enum NonLocalDefinitionsDiag {
13471347
body_name: String,
13481348
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13491349
const_anon: Option<Option<Span>>,
1350-
move_help: Span,
1351-
may_move: Vec<Span>,
1350+
move_to: Option<(Span, Vec<Span>)>,
13521351
may_remove: Option<(Span, String)>,
13531352
has_trait: bool,
13541353
self_ty_str: String,
@@ -1373,8 +1372,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13731372
body_name,
13741373
cargo_update,
13751374
const_anon,
1376-
move_help,
1377-
may_move,
1375+
move_to,
13781376
may_remove,
13791377
has_trait,
13801378
self_ty_str,
@@ -1395,11 +1393,13 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13951393
diag.note(fluent::lint_without_trait);
13961394
}
13971395

1398-
let mut ms = MultiSpan::from_span(move_help);
1399-
for sp in may_move {
1400-
ms.push_span_label(sp, fluent::lint_non_local_definitions_may_move);
1396+
if let Some((move_help, may_move)) = move_to {
1397+
let mut ms = MultiSpan::from_span(move_help);
1398+
for sp in may_move {
1399+
ms.push_span_label(sp, fluent::lint_non_local_definitions_may_move);
1400+
}
1401+
diag.span_help(ms, fluent::lint_non_local_definitions_impl_move_help);
14011402
}
1402-
diag.span_help(ms, fluent::lint_move_help);
14031403

14041404
if let Some((span, part)) = may_remove {
14051405
diag.arg("may_remove_part", part);

‎compiler/rustc_lint/src/non_local_def.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
198198
}
199199
collector.visit_generics(&impl_.generics);
200200

201-
let may_move: Vec<Span> = collector
201+
let mut may_move: Vec<Span> = collector
202202
.paths
203203
.into_iter()
204204
.filter_map(|path| {
205-
if path_has_local_parent(&path, cx, parent, parent_parent) {
206-
Some(path_span_without_args(&path))
205+
if let Some(did) = path.res.opt_def_id()
206+
&& did_has_local_parent(did, cx.tcx, parent, parent_parent)
207+
{
208+
Some(cx.tcx.def_span(did))
207209
} else {
208210
None
209211
}
210212
})
211213
.collect();
214+
may_move.sort();
215+
may_move.dedup();
212216

213217
let const_anon = matches!(parent_def_kind, DefKind::Const | DefKind::Static { .. })
214218
.then_some(span_for_const_anon_suggestion);
@@ -244,13 +248,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
244248
} else {
245249
None
246250
};
251+
let move_to = if may_move.is_empty() {
252+
ms.push_span_label(
253+
cx.tcx.def_span(parent),
254+
fluent::lint_non_local_definitions_impl_move_help,
255+
);
256+
None
257+
} else {
258+
Some((cx.tcx.def_span(parent), may_move))
259+
};
247260

248261
cx.emit_span_lint(
249262
NON_LOCAL_DEFINITIONS,
250263
ms,
251264
NonLocalDefinitionsDiag::Impl {
252265
depth: self.body_depth,
253-
move_help: item.span,
254266
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
255267
body_name: parent_opt_item_name
256268
.map(|s| s.to_ident_string())
@@ -259,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
259271
const_anon,
260272
self_ty_str,
261273
of_trait_str,
262-
may_move,
274+
move_to,
263275
may_remove,
264276
has_trait: impl_.of_trait.is_some(),
265277
},

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
66
| |
77
| `LocalStruct` is not local
88
| `Debug` is not local
9+
| move this `impl` block outside of the current constant `_IMPL_DEBUG`
910
|
1011
= 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` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12-
help: move this `impl` block outside of the current constant `_IMPL_DEBUG`
13-
--> $DIR/cargo-update.rs:17:1
14-
|
15-
LL | non_local_macro::non_local_impl!(LocalStruct);
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1713
= 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`
1814
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
1915
= 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>

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

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ warning: non-local `impl` definition, `impl` blocks should be written at the sam
22
--> $DIR/consts.rs:13:5
33
|
44
LL | const Z: () = {
5-
| - help: use a const-anon item to suppress this lint: `_`
5+
| -----------
6+
| | |
7+
| | help: use a const-anon item to suppress this lint: `_`
8+
| move this `impl` block outside of the current constant `Z`
69
...
710
LL | impl Uto for &Test {}
811
| ^^^^^---^^^^^-----
@@ -12,18 +15,15 @@ LL | impl Uto for &Test {}
1215
|
1316
= 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
1417
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
15-
help: move this `impl` block outside of the current constant `Z`
16-
--> $DIR/consts.rs:13:5
17-
|
18-
LL | impl Uto for &Test {}
19-
| ^^^^^^^^^^^^^^^^^^^^^
2018
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
2119
= 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>
2220
= note: `#[warn(non_local_definitions)]` on by default
2321

2422
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2523
--> $DIR/consts.rs:24:5
2624
|
25+
LL | static A: u32 = {
26+
| ------------- move this `impl` block outside of the current static `A`
2727
LL | impl Uto2 for Test {}
2828
| ^^^^^----^^^^^----
2929
| | |
@@ -32,17 +32,14 @@ LL | impl Uto2 for Test {}
3232
|
3333
= 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
3434
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
35-
help: move this `impl` block outside of the current static `A`
36-
--> $DIR/consts.rs:24:5
37-
|
38-
LL | impl Uto2 for Test {}
39-
| ^^^^^^^^^^^^^^^^^^^^^
4035
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
4136
= 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>
4237

4338
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
4439
--> $DIR/consts.rs:32:5
4540
|
41+
LL | const B: u32 = {
42+
| ------------ move this `impl` block outside of the current constant `B`
4643
LL | impl Uto3 for Test {}
4744
| ^^^^^----^^^^^----
4845
| | |
@@ -51,75 +48,60 @@ LL | impl Uto3 for Test {}
5148
|
5249
= 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
5350
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
54-
help: move this `impl` block outside of the current constant `B`
55-
--> $DIR/consts.rs:32:5
56-
|
57-
LL | impl Uto3 for Test {}
58-
| ^^^^^^^^^^^^^^^^^^^^^
5951
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
6052
= 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>
6153

6254
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
6355
--> $DIR/consts.rs:43:5
6456
|
57+
LL | fn main() {
58+
| --------- move this `impl` block outside of the current function `main`
6559
LL | impl Test {
6660
| ^^^^^----
6761
| |
6862
| `Test` is not local
6963
|
7064
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
71-
help: move this `impl` block outside of the current function `main`
72-
--> $DIR/consts.rs:43:5
73-
|
74-
LL | / impl Test {
75-
LL | |
76-
LL | | fn foo() {}
77-
LL | | }
78-
| |_____^
7965
= 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>
8066

8167
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
8268
--> $DIR/consts.rs:50:9
8369
|
84-
LL | impl Test {
85-
| ^^^^^----
86-
| |
87-
| `Test` is not local
88-
|
89-
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
90-
help: move this `impl` block outside of the current inline constant `<unnameable>` and up 2 bodies
91-
--> $DIR/consts.rs:50:9
92-
|
93-
LL | / impl Test {
70+
LL | const {
71+
| ___________-
72+
LL | | impl Test {
73+
| | ^^^^^----
74+
| | |
75+
| | `Test` is not local
9476
LL | |
9577
LL | | fn hoo() {}
96-
LL | | }
97-
| |_________^
78+
... |
79+
LL | | 1
80+
LL | | };
81+
| |_____- move this `impl` block outside of the current inline constant `<unnameable>` and up 2 bodies
82+
|
83+
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
9884
= 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>
9985

10086
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
10187
--> $DIR/consts.rs:59:9
10288
|
89+
LL | const _: u32 = {
90+
| ------------ move this `impl` block outside of the current constant `_` and up 2 bodies
10391
LL | impl Test {
10492
| ^^^^^----
10593
| |
10694
| `Test` is not local
10795
|
10896
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
109-
help: move this `impl` block outside of the current constant `_` and up 2 bodies
110-
--> $DIR/consts.rs:59:9
111-
|
112-
LL | / impl Test {
113-
LL | |
114-
LL | | fn foo2() {}
115-
LL | | }
116-
| |_________^
11797
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
11898
= 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>
11999

120100
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
121101
--> $DIR/consts.rs:72:9
122102
|
103+
LL | let _a = || {
104+
| -- move this `impl` block outside of the current closure `<unnameable>` and up 2 bodies
123105
LL | impl Uto9 for Test {}
124106
| ^^^^^----^^^^^----
125107
| | |
@@ -128,29 +110,25 @@ LL | impl Uto9 for Test {}
128110
|
129111
= 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
130112
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
131-
help: move this `impl` block outside of the current closure `<unnameable>` and up 2 bodies
132-
--> $DIR/consts.rs:72:9
133-
|
134-
LL | impl Uto9 for Test {}
135-
| ^^^^^^^^^^^^^^^^^^^^^
136113
= 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>
137114

138115
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
139116
--> $DIR/consts.rs:79:9
140117
|
141-
LL | impl Uto10 for Test {}
142-
| ^^^^^-----^^^^^----
143-
| | |
144-
| | `Test` is not local
145-
| `Uto10` is not local
118+
LL | type A = [u32; {
119+
| ____________________-
120+
LL | | impl Uto10 for Test {}
121+
| | ^^^^^-----^^^^^----
122+
| | | |
123+
| | | `Test` is not local
124+
| | `Uto10` is not local
125+
LL | |
126+
... |
127+
LL | | }];
128+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
146129
|
147130
= 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
148131
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
149-
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
150-
--> $DIR/consts.rs:79:9
151-
|
152-
LL | impl Uto10 for Test {}
153-
| ^^^^^^^^^^^^^^^^^^^^^^
154132
= 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>
155133

156134
warning: 8 warnings emitted

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

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
22
--> $DIR/exhaustive-trait.rs:7:5
33
|
4+
LL | fn main() {
5+
| --------- move this `impl` block outside of the current function `main`
46
LL | impl PartialEq<()> for Dog {
57
| ^^^^^---------^^^^^^^^^---
68
| | |
@@ -9,22 +11,15 @@ LL | impl PartialEq<()> for Dog {
911
|
1012
= 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
1113
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12-
help: move this `impl` block outside of the current function `main`
13-
--> $DIR/exhaustive-trait.rs:7:5
14-
|
15-
LL | / impl PartialEq<()> for Dog {
16-
LL | |
17-
LL | | fn eq(&self, _: &()) -> bool {
18-
LL | | todo!()
19-
LL | | }
20-
LL | | }
21-
| |_____^
2214
= 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>
2315
= note: `#[warn(non_local_definitions)]` on by default
2416

2517
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2618
--> $DIR/exhaustive-trait.rs:14:5
2719
|
20+
LL | fn main() {
21+
| --------- move this `impl` block outside of the current function `main`
22+
...
2823
LL | impl PartialEq<()> for &Dog {
2924
| ^^^^^---------^^^^^^^^^----
3025
| | |
@@ -33,21 +28,14 @@ LL | impl PartialEq<()> for &Dog {
3328
|
3429
= 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
3530
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
36-
help: move this `impl` block outside of the current function `main`
37-
--> $DIR/exhaustive-trait.rs:14:5
38-
|
39-
LL | / impl PartialEq<()> for &Dog {
40-
LL | |
41-
LL | | fn eq(&self, _: &()) -> bool {
42-
LL | | todo!()
43-
LL | | }
44-
LL | | }
45-
| |_____^
4631
= 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>
4732

4833
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
4934
--> $DIR/exhaustive-trait.rs:21:5
5035
|
36+
LL | fn main() {
37+
| --------- move this `impl` block outside of the current function `main`
38+
...
5139
LL | impl PartialEq<Dog> for () {
5240
| ^^^^^---------^^^^^^^^^^--
5341
| | |
@@ -56,21 +44,14 @@ LL | impl PartialEq<Dog> for () {
5644
|
5745
= 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
5846
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
59-
help: move this `impl` block outside of the current function `main`
60-
--> $DIR/exhaustive-trait.rs:21:5
61-
|
62-
LL | / impl PartialEq<Dog> for () {
63-
LL | |
64-
LL | | fn eq(&self, _: &Dog) -> bool {
65-
LL | | todo!()
66-
LL | | }
67-
LL | | }
68-
| |_____^
6947
= 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>
7048

7149
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
7250
--> $DIR/exhaustive-trait.rs:28:5
7351
|
52+
LL | fn main() {
53+
| --------- move this `impl` block outside of the current function `main`
54+
...
7455
LL | impl PartialEq<&Dog> for () {
7556
| ^^^^^---------^^^^^^^^^^^--
7657
| | |
@@ -79,21 +60,14 @@ LL | impl PartialEq<&Dog> for () {
7960
|
8061
= 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
8162
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
82-
help: move this `impl` block outside of the current function `main`
83-
--> $DIR/exhaustive-trait.rs:28:5
84-
|
85-
LL | / impl PartialEq<&Dog> for () {
86-
LL | |
87-
LL | | fn eq(&self, _: &&Dog) -> bool {
88-
LL | | todo!()
89-
LL | | }
90-
LL | | }
91-
| |_____^
9263
= 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>
9364

9465
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
9566
--> $DIR/exhaustive-trait.rs:35:5
9667
|
68+
LL | fn main() {
69+
| --------- move this `impl` block outside of the current function `main`
70+
...
9771
LL | impl PartialEq<Dog> for &Dog {
9872
| ^^^^^---------^^^^^^^^^^----
9973
| | |
@@ -102,21 +76,14 @@ LL | impl PartialEq<Dog> for &Dog {
10276
|
10377
= 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
10478
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
105-
help: move this `impl` block outside of the current function `main`
106-
--> $DIR/exhaustive-trait.rs:35:5
107-
|
108-
LL | / impl PartialEq<Dog> for &Dog {
109-
LL | |
110-
LL | | fn eq(&self, _: &Dog) -> bool {
111-
LL | | todo!()
112-
LL | | }
113-
LL | | }
114-
| |_____^
11579
= 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>
11680

11781
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
11882
--> $DIR/exhaustive-trait.rs:42:5
11983
|
84+
LL | fn main() {
85+
| --------- move this `impl` block outside of the current function `main`
86+
...
12087
LL | impl PartialEq<&Dog> for &Dog {
12188
| ^^^^^---------^^^^^^^^^^^----
12289
| | |
@@ -125,16 +92,6 @@ LL | impl PartialEq<&Dog> for &Dog {
12592
|
12693
= 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
12794
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
128-
help: move this `impl` block outside of the current function `main`
129-
--> $DIR/exhaustive-trait.rs:42:5
130-
|
131-
LL | / impl PartialEq<&Dog> for &Dog {
132-
LL | |
133-
LL | | fn eq(&self, _: &&Dog) -> bool {
134-
LL | | todo!()
135-
LL | | }
136-
LL | | }
137-
| |_____^
13895
= 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>
13996

14097
warning: 6 warnings emitted

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

Lines changed: 75 additions & 116 deletions
Large diffs are not rendered by default.

‎tests/ui/lint/non-local-defs/from-local-for-global.stderr

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
22
--> $DIR/from-local-for-global.rs:8:5
33
|
4+
LL | fn main() {
5+
| --------- move this `impl` block outside of the current function `main`
46
LL | impl From<Cat> for () {
57
| ^^^^^----^^^^^^^^^^--
68
| | |
@@ -9,16 +11,6 @@ LL | impl From<Cat> for () {
911
|
1012
= 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
1113
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12-
help: move this `impl` block outside of the current function `main`
13-
--> $DIR/from-local-for-global.rs:8:5
14-
|
15-
LL | / impl From<Cat> for () {
16-
LL | |
17-
LL | | fn from(_: Cat) -> () {
18-
LL | | todo!()
19-
LL | | }
20-
LL | | }
21-
| |_____^
2214
= 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>
2315
= note: `#[warn(non_local_definitions)]` on by default
2416

@@ -33,18 +25,13 @@ LL | impl From<Wrap<Wrap<Elephant>>> for () {
3325
= 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
3426
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
3527
help: move this `impl` block outside of the current function `main`
36-
--> $DIR/from-local-for-global.rs:18:5
28+
--> $DIR/from-local-for-global.rs:7:1
3729
|
38-
LL | impl From<Wrap<Wrap<Elephant>>> for () {
39-
| ^ -------- may need to be moved as well
40-
| _____|
41-
| |
42-
LL | |
43-
LL | | fn from(_: Wrap<Wrap<Elephant>>) -> Self {
44-
LL | | todo!()
45-
LL | | }
46-
LL | | }
47-
| |_____^
30+
LL | fn main() {
31+
| ^^^^^^^^^
32+
...
33+
LL | struct Elephant;
34+
| --------------- may need to be moved as well
4835
= 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>
4936

5037
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -60,12 +47,12 @@ LL | impl StillNonLocal for &Foo {}
6047
= 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
6148
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
6249
help: move this `impl` block outside of the current function `only_global`
63-
--> $DIR/from-local-for-global.rs:32:5
50+
--> $DIR/from-local-for-global.rs:30:1
6451
|
65-
LL | impl StillNonLocal for &Foo {}
66-
| ^^^^^^^^^^^^^^^^^^^^^^^^---^^^
67-
| |
68-
| may need to be moved as well
52+
LL | fn only_global() {
53+
| ^^^^^^^^^^^^^^^^
54+
LL | struct Foo;
55+
| ---------- may need to be moved as well
6956
= 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>
7057

7158
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -80,18 +67,12 @@ LL | impl From<Local1> for GlobalSameFunction {
8067
= 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
8168
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
8269
help: move this `impl` block outside of the current function `same_function`
83-
--> $DIR/from-local-for-global.rs:40:5
70+
--> $DIR/from-local-for-global.rs:38:1
8471
|
85-
LL | impl From<Local1> for GlobalSameFunction {
86-
| ^ ------ may need to be moved as well
87-
| _____|
88-
| |
89-
LL | |
90-
LL | | fn from(x: Local1) -> GlobalSameFunction {
91-
LL | | x.0
92-
LL | | }
93-
LL | | }
94-
| |_____^
72+
LL | fn same_function() {
73+
| ^^^^^^^^^^^^^^^^^^
74+
LL | struct Local1(GlobalSameFunction);
75+
| ------------- may need to be moved as well
9576
= 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>
9677

9778
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -106,18 +87,13 @@ LL | impl From<Local2> for GlobalSameFunction {
10687
= 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
10788
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
10889
help: move this `impl` block outside of the current function `same_function`
109-
--> $DIR/from-local-for-global.rs:48:5
90+
--> $DIR/from-local-for-global.rs:38:1
11091
|
111-
LL | impl From<Local2> for GlobalSameFunction {
112-
| ^ ------ may need to be moved as well
113-
| _____|
114-
| |
115-
LL | |
116-
LL | | fn from(x: Local2) -> GlobalSameFunction {
117-
LL | | x.0
118-
LL | | }
119-
LL | | }
120-
| |_____^
92+
LL | fn same_function() {
93+
| ^^^^^^^^^^^^^^^^^^
94+
...
95+
LL | struct Local2(GlobalSameFunction);
96+
| ------------- may need to be moved as well
12197
= 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>
12298

12399
warning: 5 warnings emitted

‎tests/ui/lint/non-local-defs/generics.stderr

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ LL | impl<T: Local> Global for Vec<T> { }
1010
= 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
1111
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1212
help: move this `impl` block outside of the current function `main`
13-
--> $DIR/generics.rs:9:5
13+
--> $DIR/generics.rs:6:1
1414
|
15-
LL | impl<T: Local> Global for Vec<T> { }
16-
| ^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^
17-
| |
18-
| may need to be moved as well
15+
LL | fn main() {
16+
| ^^^^^^^^^
17+
LL | trait Local {};
18+
| ----------- may need to be moved as well
1919
= 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>
2020
= note: `#[warn(non_local_definitions)]` on by default
2121

@@ -31,17 +31,20 @@ LL | impl Uto7 for Test where Local: std::any::Any {}
3131
= 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
3232
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
3333
help: move this `impl` block outside of the current function `bad`
34-
--> $DIR/generics.rs:20:5
34+
--> $DIR/generics.rs:18:1
3535
|
36-
LL | impl Uto7 for Test where Local: std::any::Any {}
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
38-
| |
39-
| may need to be moved as well
36+
LL | fn bad() {
37+
| ^^^^^^^^
38+
LL | struct Local;
39+
| ------------ may need to be moved as well
4040
= 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>
4141

4242
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
4343
--> $DIR/generics.rs:23:5
4444
|
45+
LL | fn bad() {
46+
| -------- move this `impl` block outside of the current function `bad`
47+
...
4548
LL | impl<T> Uto8 for T {}
4649
| ^^^^^^^^----^^^^^-
4750
| | |
@@ -50,11 +53,6 @@ LL | impl<T> Uto8 for T {}
5053
|
5154
= 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
5255
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
53-
help: move this `impl` block outside of the current function `bad`
54-
--> $DIR/generics.rs:23:5
55-
|
56-
LL | impl<T> Uto8 for T {}
57-
| ^^^^^^^^^^^^^^^^^^^^^
5856
= 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>
5957

6058
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -69,18 +67,13 @@ LL | impl Default for UwU<OwO> {
6967
= 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
7068
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
7169
help: move this `impl` block outside of the current function `fun`
72-
--> $DIR/generics.rs:32:5
70+
--> $DIR/generics.rs:29:1
7371
|
74-
LL | impl Default for UwU<OwO> {
75-
| ^ --- may need to be moved as well
76-
| _____|
77-
| |
78-
LL | |
79-
LL | | fn default() -> Self {
80-
LL | | UwU(OwO)
81-
LL | | }
82-
LL | | }
83-
| |_____^
72+
LL | fn fun() {
73+
| ^^^^^^^^
74+
LL | #[derive(Debug)]
75+
LL | struct OwO;
76+
| ---------- may need to be moved as well
8477
= 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>
8578

8679
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -95,16 +88,13 @@ LL | impl AsRef<Cat> for () {
9588
= 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
9689
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
9790
help: move this `impl` block outside of the current function `meow`
98-
--> $DIR/generics.rs:43:5
91+
--> $DIR/generics.rs:40:1
9992
|
100-
LL | impl AsRef<Cat> for () {
101-
| ^ --- may need to be moved as well
102-
| _____|
103-
| |
104-
LL | |
105-
LL | | fn as_ref(&self) -> &Cat { &Cat }
106-
LL | | }
107-
| |_____^
93+
LL | fn meow() {
94+
| ^^^^^^^^^
95+
LL | #[derive(Debug)]
96+
LL | struct Cat;
97+
| ---------- may need to be moved as well
10898
= 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>
10999

110100
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -119,18 +109,13 @@ LL | impl PartialEq<B> for G {
119109
= 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
120110
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
121111
help: move this `impl` block outside of the current function `fun2`
122-
--> $DIR/generics.rs:54:5
112+
--> $DIR/generics.rs:51:1
123113
|
124-
LL | impl PartialEq<B> for G {
125-
| ^ - may need to be moved as well
126-
| _____|
127-
| |
128-
LL | |
129-
LL | | fn eq(&self, _: &B) -> bool {
130-
LL | | true
131-
LL | | }
132-
LL | | }
133-
| |_____^
114+
LL | fn fun2() {
115+
| ^^^^^^^^^
116+
LL | #[derive(Debug, Default)]
117+
LL | struct B;
118+
| -------- may need to be moved as well
134119
= 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>
135120

136121
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -144,18 +129,12 @@ LL | impl From<Wrap<Wrap<Lion>>> for () {
144129
= 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
145130
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
146131
help: move this `impl` block outside of the current function `rawr`
147-
--> $DIR/generics.rs:69:5
132+
--> $DIR/generics.rs:66:1
148133
|
149-
LL | impl From<Wrap<Wrap<Lion>>> for () {
150-
| ^ ---- may need to be moved as well
151-
| _____|
152-
| |
153-
LL | |
154-
LL | | fn from(_: Wrap<Wrap<Lion>>) -> Self {
155-
LL | | todo!()
156-
LL | | }
157-
LL | | }
158-
| |_____^
134+
LL | fn rawr() {
135+
| ^^^^^^^^^
136+
LL | struct Lion;
137+
| ----------- may need to be moved as well
159138
= 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>
160139

161140
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
@@ -170,18 +149,12 @@ LL | impl From<()> for Wrap<Lion> {
170149
= 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
171150
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
172151
help: move this `impl` block outside of the current function `rawr`
173-
--> $DIR/generics.rs:76:5
152+
--> $DIR/generics.rs:66:1
174153
|
175-
LL | impl From<()> for Wrap<Lion> {
176-
| ^ ---- may need to be moved as well
177-
| _____|
178-
| |
179-
LL | |
180-
LL | | fn from(_: ()) -> Self {
181-
LL | | todo!()
182-
LL | | }
183-
LL | | }
184-
| |_____^
154+
LL | fn rawr() {
155+
| ^^^^^^^^^
156+
LL | struct Lion;
157+
| ----------- may need to be moved as well
185158
= 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>
186159

187160
warning: 8 warnings emitted

‎tests/ui/lint/non-local-defs/inside-macro_rules.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
22
--> $DIR/inside-macro_rules.rs:9:13
33
|
4+
LL | fn my_func() {
5+
| ------------ move this `impl` block outside of the current function `my_func`
46
LL | impl MacroTrait for OutsideStruct {}
57
| ^^^^^----------^^^^^-------------
68
| | |
@@ -12,14 +14,6 @@ LL | m!();
1214
|
1315
= 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
1416
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
15-
help: move this `impl` block outside of the current function `my_func`
16-
--> $DIR/inside-macro_rules.rs:9:13
17-
|
18-
LL | impl MacroTrait for OutsideStruct {}
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20-
...
21-
LL | m!();
22-
| ---- in this macro invocation
2317
= 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>
2418
= note: `#[warn(non_local_definitions)]` on by default
2519
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

‎tests/ui/lint/non-local-defs/suggest-moving-inner.stderr

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ LL | impl<T> Trait<InsideMain> for &Vec<below::Type<(InsideMain, T)>>
1010
= 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
1111
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1212
help: move this `impl` block outside of the current function `main`
13-
--> $DIR/suggest-moving-inner.rs:12:5
13+
--> $DIR/suggest-moving-inner.rs:5:1
1414
|
15-
LL | impl<T> Trait<InsideMain> for &Vec<below::Type<(InsideMain, T)>>
16-
| ^ ---------- ----------- ---------- may need to be moved as well
17-
| | | |
18-
| | | may need to be moved as well
19-
| _____| may need to be moved as well
20-
| |
21-
LL | |
22-
LL | | where
23-
LL | | T: HasFoo
24-
| | ------ may need to be moved as well
25-
LL | | {}
26-
| |______^
15+
LL | fn main() {
16+
| ^^^^^^^^^
17+
LL | mod below {
18+
LL | pub struct Type<T>(T);
19+
| ------------------ may need to be moved as well
20+
LL | }
21+
LL | struct InsideMain;
22+
| ----------------- may need to be moved as well
23+
LL | trait HasFoo {}
24+
| ------------ may need to be moved as well
2725
= 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>
2826
= note: `#[warn(non_local_definitions)]` on by default
2927

‎tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ LL | impl Test for &Local {}
1111
= 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
1212
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1313
help: move this `impl` block outside of the current function `main`
14-
--> $DIR/trait-solver-overflow-123573.rs:12:5
14+
--> $DIR/trait-solver-overflow-123573.rs:10:1
1515
|
16-
LL | impl Test for &Local {}
17-
| ^^^^^^^^^^^^^^^-----^^^
18-
| |
19-
| may need to be moved as well
16+
LL | fn main() {
17+
| ^^^^^^^^^
18+
LL | struct Local {}
19+
| ------------ may need to be moved as well
2020
= 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>
2121
= note: `#[warn(non_local_definitions)]` on by default
2222

‎tests/ui/lint/non-local-defs/weird-exprs.stderr

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,116 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
22
--> $DIR/weird-exprs.rs:8:5
33
|
4-
LL | impl Uto for *mut Test {}
5-
| ^^^^^---^^^^^---------
6-
| | |
7-
| | `*mut Test` is not local
8-
| `Uto` is not local
4+
LL | type A = [u32; {
5+
| ________________-
6+
LL | | impl Uto for *mut Test {}
7+
| | ^^^^^---^^^^^---------
8+
| | | |
9+
| | | `*mut Test` is not local
10+
| | `Uto` is not local
11+
LL | |
12+
... |
13+
LL | | }];
14+
| |_- move this `impl` block outside of the current constant expression `<unnameable>`
915
|
1016
= 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
1117
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12-
help: move this `impl` block outside of the current constant expression `<unnameable>`
13-
--> $DIR/weird-exprs.rs:8:5
14-
|
15-
LL | impl Uto for *mut Test {}
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1718
= 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>
1819
= note: `#[warn(non_local_definitions)]` on by default
1920

2021
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2122
--> $DIR/weird-exprs.rs:16:9
2223
|
23-
LL | impl Uto for Test {}
24-
| ^^^^^---^^^^^----
25-
| | |
26-
| | `Test` is not local
27-
| `Uto` is not local
24+
LL | Discr = {
25+
| _____________-
26+
LL | | impl Uto for Test {}
27+
| | ^^^^^---^^^^^----
28+
| | | |
29+
| | | `Test` is not local
30+
| | `Uto` is not local
31+
LL | |
32+
... |
33+
LL | | }
34+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>`
2835
|
2936
= 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
3037
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
31-
help: move this `impl` block outside of the current constant expression `<unnameable>`
32-
--> $DIR/weird-exprs.rs:16:9
33-
|
34-
LL | impl Uto for Test {}
35-
| ^^^^^^^^^^^^^^^^^^^^
3638
= 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>
3739

3840
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
3941
--> $DIR/weird-exprs.rs:25:9
4042
|
41-
LL | impl Test {
42-
| ^^^^^----
43-
| |
44-
| `Test` is not local
45-
|
46-
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
47-
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
48-
--> $DIR/weird-exprs.rs:25:9
49-
|
50-
LL | / impl Test {
43+
LL | let _array = [0i32; {
44+
| _________________________-
45+
LL | | impl Test {
46+
| | ^^^^^----
47+
| | |
48+
| | `Test` is not local
5149
LL | |
5250
LL | | fn bar() {}
53-
LL | | }
54-
| |_________^
51+
... |
52+
LL | | 1
53+
LL | | }];
54+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
55+
|
56+
= note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl`
5557
= 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>
5658

5759
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
5860
--> $DIR/weird-exprs.rs:34:9
5961
|
60-
LL | impl Uto for &Test {}
61-
| ^^^^^---^^^^^-----
62-
| | |
63-
| | `&'_ Test` is not local
64-
| `Uto` is not local
62+
LL | type A = [u32; {
63+
| ____________________-
64+
LL | | impl Uto for &Test {}
65+
| | ^^^^^---^^^^^-----
66+
| | | |
67+
| | | `&'_ Test` is not local
68+
| | `Uto` is not local
69+
LL | |
70+
... |
71+
LL | | }];
72+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
6573
|
6674
= 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
6775
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
68-
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
69-
--> $DIR/weird-exprs.rs:34:9
70-
|
71-
LL | impl Uto for &Test {}
72-
| ^^^^^^^^^^^^^^^^^^^^^
7376
= 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>
7477

7578
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
7679
--> $DIR/weird-exprs.rs:41:9
7780
|
78-
LL | impl Uto for &(Test,) {}
79-
| ^^^^^---^^^^^--------
80-
| | |
81-
| | `&'_ (Test,)` is not local
82-
| `Uto` is not local
81+
LL | fn a(_: [u32; {
82+
| ___________________-
83+
LL | | impl Uto for &(Test,) {}
84+
| | ^^^^^---^^^^^--------
85+
| | | |
86+
| | | `&'_ (Test,)` is not local
87+
| | `Uto` is not local
88+
LL | |
89+
... |
90+
LL | | }]) {}
91+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
8392
|
8493
= 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
8594
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
86-
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
87-
--> $DIR/weird-exprs.rs:41:9
88-
|
89-
LL | impl Uto for &(Test,) {}
90-
| ^^^^^^^^^^^^^^^^^^^^^^^^
9195
= 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>
9296

9397
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
9498
--> $DIR/weird-exprs.rs:48:9
9599
|
96-
LL | impl Uto for &(Test,Test) {}
97-
| ^^^^^---^^^^^------------
98-
| | |
99-
| | `&'_ (Test, Test)` is not local
100-
| `Uto` is not local
100+
LL | fn b() -> [u32; {
101+
| _____________________-
102+
LL | | impl Uto for &(Test,Test) {}
103+
| | ^^^^^---^^^^^------------
104+
| | | |
105+
| | | `&'_ (Test, Test)` is not local
106+
| | `Uto` is not local
107+
LL | |
108+
... |
109+
LL | | }] { todo!() }
110+
| |_____- move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
101111
|
102112
= 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
103113
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
104-
help: move this `impl` block outside of the current constant expression `<unnameable>` and up 2 bodies
105-
--> $DIR/weird-exprs.rs:48:9
106-
|
107-
LL | impl Uto for &(Test,Test) {}
108-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109114
= 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>
110115

111116
warning: 6 warnings emitted

0 commit comments

Comments
 (0)
Please sign in to comment.