Skip to content

Commit 2d6bf87

Browse files
committed
Add some weird test cases to the non_local_definitions lint tests
1 parent b0d3e04 commit 2d6bf87

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

tests/ui/lint/non_local_definitions.rs

+20
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ fn bad() {
244244
//~^ WARN non-local `impl` definition
245245
}
246246

247+
trait Uto9 {}
248+
trait Uto10 {}
249+
const _: u32 = {
250+
let _a = || {
251+
impl Uto9 for Test {}
252+
//~^ WARN non-local `impl` definition
253+
254+
1
255+
};
256+
257+
type A = [u32; {
258+
impl Uto10 for Test {}
259+
//~^ WARN non-local `impl` definition
260+
261+
1
262+
}];
263+
264+
1
265+
};
266+
247267
struct UwU<T>(T);
248268

249269
fn fun() {

tests/ui/lint/non_local_definitions.stderr

+36-14
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,29 @@ LL | impl<T> Uto8 for T {}
438438
= 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>
439439

440440
warning: non-local `impl` definition, they should be avoided as they go against expectation
441-
--> $DIR/non_local_definitions.rs:252:5
441+
--> $DIR/non_local_definitions.rs:251:9
442+
|
443+
LL | impl Uto9 for Test {}
444+
| ^^^^^^^^^^^^^^^^^^^^^
445+
|
446+
= help: move this `impl` block outside the of the current closure `<unnameable>` and up 2 bodies
447+
= note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block
448+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
449+
= 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>
450+
451+
warning: non-local `impl` definition, they should be avoided as they go against expectation
452+
--> $DIR/non_local_definitions.rs:258:9
453+
|
454+
LL | impl Uto10 for Test {}
455+
| ^^^^^^^^^^^^^^^^^^^^^^
456+
|
457+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
458+
= note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block
459+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
460+
= 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>
461+
462+
warning: non-local `impl` definition, they should be avoided as they go against expectation
463+
--> $DIR/non_local_definitions.rs:272:5
442464
|
443465
LL | / impl Default for UwU<OwO> {
444466
LL | |
@@ -454,7 +476,7 @@ LL | | }
454476
= 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>
455477

456478
warning: non-local `impl` definition, they should be avoided as they go against expectation
457-
--> $DIR/non_local_definitions.rs:263:5
479+
--> $DIR/non_local_definitions.rs:283:5
458480
|
459481
LL | / impl From<Cat> for () {
460482
LL | |
@@ -470,7 +492,7 @@ LL | | }
470492
= 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>
471493

472494
warning: non-local `impl` definition, they should be avoided as they go against expectation
473-
--> $DIR/non_local_definitions.rs:272:5
495+
--> $DIR/non_local_definitions.rs:292:5
474496
|
475497
LL | / impl AsRef<Cat> for () {
476498
LL | |
@@ -484,7 +506,7 @@ LL | | }
484506
= 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>
485507

486508
warning: non-local `impl` definition, they should be avoided as they go against expectation
487-
--> $DIR/non_local_definitions.rs:283:5
509+
--> $DIR/non_local_definitions.rs:303:5
488510
|
489511
LL | / impl PartialEq<B> for G {
490512
LL | |
@@ -500,7 +522,7 @@ LL | | }
500522
= 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>
501523

502524
warning: non-local `impl` definition, they should be avoided as they go against expectation
503-
--> $DIR/non_local_definitions.rs:300:5
525+
--> $DIR/non_local_definitions.rs:320:5
504526
|
505527
LL | / impl PartialEq<Dog> for &Dog {
506528
LL | |
@@ -516,7 +538,7 @@ LL | | }
516538
= 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>
517539

518540
warning: non-local `impl` definition, they should be avoided as they go against expectation
519-
--> $DIR/non_local_definitions.rs:307:5
541+
--> $DIR/non_local_definitions.rs:327:5
520542
|
521543
LL | / impl PartialEq<()> for Dog {
522544
LL | |
@@ -532,7 +554,7 @@ LL | | }
532554
= 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>
533555

534556
warning: non-local `impl` definition, they should be avoided as they go against expectation
535-
--> $DIR/non_local_definitions.rs:314:5
557+
--> $DIR/non_local_definitions.rs:334:5
536558
|
537559
LL | / impl PartialEq<()> for &Dog {
538560
LL | |
@@ -548,7 +570,7 @@ LL | | }
548570
= 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>
549571

550572
warning: non-local `impl` definition, they should be avoided as they go against expectation
551-
--> $DIR/non_local_definitions.rs:321:5
573+
--> $DIR/non_local_definitions.rs:341:5
552574
|
553575
LL | / impl PartialEq<Dog> for () {
554576
LL | |
@@ -564,7 +586,7 @@ LL | | }
564586
= 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>
565587

566588
warning: non-local `impl` definition, they should be avoided as they go against expectation
567-
--> $DIR/non_local_definitions.rs:343:5
589+
--> $DIR/non_local_definitions.rs:363:5
568590
|
569591
LL | / impl From<Wrap<Wrap<Lion>>> for () {
570592
LL | |
@@ -580,7 +602,7 @@ LL | | }
580602
= 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>
581603

582604
warning: non-local `impl` definition, they should be avoided as they go against expectation
583-
--> $DIR/non_local_definitions.rs:350:5
605+
--> $DIR/non_local_definitions.rs:370:5
584606
|
585607
LL | / impl From<()> for Wrap<Lion> {
586608
LL | |
@@ -596,7 +618,7 @@ LL | | }
596618
= 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>
597619

598620
warning: non-local `impl` definition, they should be avoided as they go against expectation
599-
--> $DIR/non_local_definitions.rs:363:13
621+
--> $DIR/non_local_definitions.rs:383:13
600622
|
601623
LL | impl MacroTrait for OutsideStruct {}
602624
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -611,7 +633,7 @@ LL | m!();
611633
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
612634

613635
warning: non-local `impl` definition, they should be avoided as they go against expectation
614-
--> $DIR/non_local_definitions.rs:373:1
636+
--> $DIR/non_local_definitions.rs:393:1
615637
|
616638
LL | non_local_macro::non_local_impl!(CargoUpdate);
617639
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -624,7 +646,7 @@ LL | non_local_macro::non_local_impl!(CargoUpdate);
624646
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
625647

626648
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
627-
--> $DIR/non_local_definitions.rs:376:1
649+
--> $DIR/non_local_definitions.rs:396:1
628650
|
629651
LL | non_local_macro::non_local_macro_rules!(my_macro);
630652
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -636,5 +658,5 @@ LL | non_local_macro::non_local_macro_rules!(my_macro);
636658
= note: the macro `non_local_macro::non_local_macro_rules` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
637659
= note: this warning originates in the macro `non_local_macro::non_local_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info)
638660

639-
warning: 50 warnings emitted
661+
warning: 52 warnings emitted
640662

0 commit comments

Comments
 (0)