Skip to content

Commit 4af32ca

Browse files
committed
Add test
1 parent ba2600e commit 4af32ca

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

tests/ui/resolve/use-self-in-inner-fn.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ impl A {
77
//~^ ERROR can't use `Self` from outer item
88
//~| NOTE use of `Self` from outer item
99
//~| NOTE `Self` used in this inner function
10-
//~| NOTE refer to the type directly here instead
10+
//~| HELP refer to the type directly here instead
1111
}
1212
}
1313
}
1414

15+
enum MyEnum {}
16+
17+
impl MyEnum {
18+
//~^ NOTE `Self` type implicitly declared here, by this `impl`
19+
fn do_something(result: impl FnOnce()) {
20+
result();
21+
}
22+
23+
fn do_something_extra() {
24+
fn inner() {
25+
//~^ NOTE `Self` used in this inner function
26+
Self::do_something(move || {});
27+
//~^ ERROR can't use `Self` from outer item
28+
//~| NOTE use of `Self` from outer item
29+
//~| HELP refer to the type directly here instead
30+
MyEnum::do_something(move || {});
31+
}
32+
inner();
33+
}
34+
}
35+
1536
fn main() {}

tests/ui/resolve/use-self-in-inner-fn.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ LL - fn peach(this: &Self) {
1515
LL + fn peach(this: &A) {
1616
|
1717

18-
error: aborting due to 1 previous error
18+
error[E0401]: can't use `Self` from outer item
19+
--> $DIR/use-self-in-inner-fn.rs:26:13
20+
|
21+
LL | impl MyEnum {
22+
| ---- `Self` type implicitly declared here, by this `impl`
23+
...
24+
LL | fn inner() {
25+
| ----- `Self` used in this inner function
26+
LL |
27+
LL | Self::do_something(move || {});
28+
| ^^^^^^^^^^^^^^^^^^ use of `Self` from outer item
29+
|
30+
help: refer to the type directly here instead
31+
|
32+
LL - Self::do_something(move || {});
33+
LL + MyEnum(move || {});
34+
|
35+
36+
error: aborting due to 2 previous errors
1937

2038
For more information about this error, try `rustc --explain E0401`.

0 commit comments

Comments
 (0)