Skip to content

Commit 5c87ca2

Browse files
committed
Add some weird test cases to the non_local_definitions lint tests
1 parent aa029ce commit 5c87ca2

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
@@ -245,6 +245,26 @@ fn bad() {
245245
//~^ WARN non-local `impl` definition
246246
}
247247

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

250270
fn fun() {

tests/ui/lint/non_local_definitions.stderr

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

444444
warning: non-local `impl` definition, they should be avoided as they go against expectation
445-
--> $DIR/non_local_definitions.rs:253:5
445+
--> $DIR/non_local_definitions.rs:252:9
446+
|
447+
LL | impl Uto9 for Test {}
448+
| ^^^^^^^^^^^^^^^^^^^^^
449+
|
450+
= help: move this `impl` block outside the of the current closure `<unnameable>` and up 2 bodies
451+
= 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
452+
= 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
453+
= 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>
454+
455+
warning: non-local `impl` definition, they should be avoided as they go against expectation
456+
--> $DIR/non_local_definitions.rs:259:9
457+
|
458+
LL | impl Uto10 for Test {}
459+
| ^^^^^^^^^^^^^^^^^^^^^^
460+
|
461+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
462+
= 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
463+
= 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
464+
= 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>
465+
466+
warning: non-local `impl` definition, they should be avoided as they go against expectation
467+
--> $DIR/non_local_definitions.rs:273:5
446468
|
447469
LL | / impl Default for UwU<OwO> {
448470
LL | |
@@ -458,7 +480,7 @@ LL | | }
458480
= 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>
459481

460482
warning: non-local `impl` definition, they should be avoided as they go against expectation
461-
--> $DIR/non_local_definitions.rs:264:5
483+
--> $DIR/non_local_definitions.rs:284:5
462484
|
463485
LL | / impl From<Cat> for () {
464486
LL | |
@@ -474,7 +496,7 @@ LL | | }
474496
= 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>
475497

476498
warning: non-local `impl` definition, they should be avoided as they go against expectation
477-
--> $DIR/non_local_definitions.rs:273:5
499+
--> $DIR/non_local_definitions.rs:293:5
478500
|
479501
LL | / impl AsRef<Cat> for () {
480502
LL | |
@@ -488,7 +510,7 @@ LL | | }
488510
= 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>
489511

490512
warning: non-local `impl` definition, they should be avoided as they go against expectation
491-
--> $DIR/non_local_definitions.rs:284:5
513+
--> $DIR/non_local_definitions.rs:304:5
492514
|
493515
LL | / impl PartialEq<B> for G {
494516
LL | |
@@ -504,7 +526,7 @@ LL | | }
504526
= 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>
505527

506528
warning: non-local `impl` definition, they should be avoided as they go against expectation
507-
--> $DIR/non_local_definitions.rs:301:5
529+
--> $DIR/non_local_definitions.rs:321:5
508530
|
509531
LL | / impl PartialEq<Dog> for &Dog {
510532
LL | |
@@ -520,7 +542,7 @@ LL | | }
520542
= 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>
521543

522544
warning: non-local `impl` definition, they should be avoided as they go against expectation
523-
--> $DIR/non_local_definitions.rs:308:5
545+
--> $DIR/non_local_definitions.rs:328:5
524546
|
525547
LL | / impl PartialEq<()> for Dog {
526548
LL | |
@@ -536,7 +558,7 @@ LL | | }
536558
= 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>
537559

538560
warning: non-local `impl` definition, they should be avoided as they go against expectation
539-
--> $DIR/non_local_definitions.rs:315:5
561+
--> $DIR/non_local_definitions.rs:335:5
540562
|
541563
LL | / impl PartialEq<()> for &Dog {
542564
LL | |
@@ -552,7 +574,7 @@ LL | | }
552574
= 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>
553575

554576
warning: non-local `impl` definition, they should be avoided as they go against expectation
555-
--> $DIR/non_local_definitions.rs:322:5
577+
--> $DIR/non_local_definitions.rs:342:5
556578
|
557579
LL | / impl PartialEq<Dog> for () {
558580
LL | |
@@ -568,7 +590,7 @@ LL | | }
568590
= 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>
569591

570592
warning: non-local `impl` definition, they should be avoided as they go against expectation
571-
--> $DIR/non_local_definitions.rs:344:5
593+
--> $DIR/non_local_definitions.rs:364:5
572594
|
573595
LL | / impl From<Wrap<Wrap<Lion>>> for () {
574596
LL | |
@@ -584,7 +606,7 @@ LL | | }
584606
= 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>
585607

586608
warning: non-local `impl` definition, they should be avoided as they go against expectation
587-
--> $DIR/non_local_definitions.rs:351:5
609+
--> $DIR/non_local_definitions.rs:371:5
588610
|
589611
LL | / impl From<()> for Wrap<Lion> {
590612
LL | |
@@ -600,7 +622,7 @@ LL | | }
600622
= 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>
601623

602624
warning: non-local `impl` definition, they should be avoided as they go against expectation
603-
--> $DIR/non_local_definitions.rs:364:13
625+
--> $DIR/non_local_definitions.rs:384:13
604626
|
605627
LL | impl MacroTrait for OutsideStruct {}
606628
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -615,7 +637,7 @@ LL | m!();
615637
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
616638

617639
warning: non-local `impl` definition, they should be avoided as they go against expectation
618-
--> $DIR/non_local_definitions.rs:374:1
640+
--> $DIR/non_local_definitions.rs:394:1
619641
|
620642
LL | non_local_macro::non_local_impl!(CargoUpdate);
621643
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -628,7 +650,7 @@ LL | non_local_macro::non_local_impl!(CargoUpdate);
628650
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
629651

630652
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
631-
--> $DIR/non_local_definitions.rs:377:1
653+
--> $DIR/non_local_definitions.rs:397:1
632654
|
633655
LL | non_local_macro::non_local_macro_rules!(my_macro);
634656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -640,5 +662,5 @@ LL | non_local_macro::non_local_macro_rules!(my_macro);
640662
= 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`
641663
= 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)
642664

643-
warning: 50 warnings emitted
665+
warning: 52 warnings emitted
644666

0 commit comments

Comments
 (0)