Skip to content

Commit 9a2bca6

Browse files
committed
rustc: fix check_attr() for methods, closures and foreign functions
UI tests are updated with additional error messages that were missing before.
1 parent df768c5 commit 9a2bca6

9 files changed

+75
-20
lines changed

src/librustc_passes/check_attr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl CheckAttrVisitor<'tcx> {
7676
return;
7777
}
7878

79-
if target == Target::Fn {
79+
if matches!(target, Target::Fn | Target::Method(_) | Target::ForeignFn) {
8080
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
8181
}
8282

@@ -391,6 +391,9 @@ impl CheckAttrVisitor<'tcx> {
391391
);
392392
}
393393
}
394+
if target == Target::Closure {
395+
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id));
396+
}
394397
}
395398

396399
fn check_used(&self, attrs: &'hir [Attribute], target: Target) {

src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,28 @@
88
struct Foo;
99
impl Fn<()> for Foo {
1010
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
11+
//~| ERROR manual implementations of `Fn` are experimental
1112
extern "rust-call" fn call(self, args: ()) -> () {}
1213
//~^ ERROR rust-call ABI is subject to change
1314
}
1415
struct Foo1;
1516
impl FnOnce() for Foo1 {
1617
//~^ ERROR associated type bindings are not allowed here
18+
//~| ERROR manual implementations of `FnOnce` are experimental
1719
extern "rust-call" fn call_once(self, args: ()) -> () {}
1820
//~^ ERROR rust-call ABI is subject to change
1921
}
2022
struct Bar;
2123
impl FnMut<()> for Bar {
2224
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
25+
//~| ERROR manual implementations of `FnMut` are experimental
2326
extern "rust-call" fn call_mut(&self, args: ()) -> () {}
2427
//~^ ERROR rust-call ABI is subject to change
2528
}
2629
struct Baz;
2730
impl FnOnce<()> for Baz {
2831
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
32+
//~| ERROR manual implementations of `FnOnce` are experimental
2933
extern "rust-call" fn call_once(&self, args: ()) -> () {}
3034
//~^ ERROR rust-call ABI is subject to change
3135
}

src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: rust-call ABI is subject to change
2-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:11:12
2+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:12:12
33
|
44
LL | extern "rust-call" fn call(self, args: ()) -> () {}
55
| ^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | extern "rust-call" fn call(self, args: ()) -> () {}
88
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
99

1010
error[E0658]: rust-call ABI is subject to change
11-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:17:12
11+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:19:12
1212
|
1313
LL | extern "rust-call" fn call_once(self, args: ()) -> () {}
1414
| ^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | extern "rust-call" fn call_once(self, args: ()) -> () {}
1717
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
1818

1919
error[E0658]: rust-call ABI is subject to change
20-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:23:12
20+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:26:12
2121
|
2222
LL | extern "rust-call" fn call_mut(&self, args: ()) -> () {}
2323
| ^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | extern "rust-call" fn call_mut(&self, args: ()) -> () {}
2626
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
2727

2828
error[E0658]: rust-call ABI is subject to change
29-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:29:12
29+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:33:12
3030
|
3131
LL | extern "rust-call" fn call_once(&self, args: ()) -> () {}
3232
| ^^^^^^^^^^^
@@ -44,13 +44,13 @@ LL | impl Fn<()> for Foo {
4444
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
4545

4646
error[E0229]: associated type bindings are not allowed here
47-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:15:6
47+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:16:6
4848
|
4949
LL | impl FnOnce() for Foo1 {
5050
| ^^^^^^^^ associated type not allowed here
5151

5252
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
53-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:21:6
53+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:23:6
5454
|
5555
LL | impl FnMut<()> for Bar {
5656
| ^^^^^^^^^ help: use parenthetical notation instead: `FnMut() -> ()`
@@ -59,15 +59,47 @@ LL | impl FnMut<()> for Bar {
5959
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
6060

6161
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
62-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:27:6
62+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:30:6
6363
|
6464
LL | impl FnOnce<()> for Baz {
6565
| ^^^^^^^^^^ help: use parenthetical notation instead: `FnOnce() -> ()`
6666
|
6767
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
6868
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
6969

70-
error: aborting due to 8 previous errors
70+
error[E0183]: manual implementations of `Fn` are experimental
71+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:9:1
72+
|
73+
LL | impl Fn<()> for Foo {
74+
| ^^^^^^^^^^^^^^^^^^^ manual implementations of `Fn` are experimental
75+
|
76+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
77+
78+
error[E0183]: manual implementations of `FnMut` are experimental
79+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:23:1
80+
|
81+
LL | impl FnMut<()> for Bar {
82+
| ^^^^^^^^^^^^^^^^^^^^^^ manual implementations of `FnMut` are experimental
83+
|
84+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
85+
86+
error[E0183]: manual implementations of `FnOnce` are experimental
87+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:16:1
88+
|
89+
LL | impl FnOnce() for Foo1 {
90+
| ^^^^^^^^^^^^^^^^^^^^^^ manual implementations of `FnOnce` are experimental
91+
|
92+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
93+
94+
error[E0183]: manual implementations of `FnOnce` are experimental
95+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:30:1
96+
|
97+
LL | impl FnOnce<()> for Baz {
98+
| ^^^^^^^^^^^^^^^^^^^^^^^ manual implementations of `FnOnce` are experimental
99+
|
100+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
101+
102+
error: aborting due to 12 previous errors
71103

72104
Some errors have detailed explanations: E0229, E0658.
73105
For more information about an error, try `rustc --explain E0229`.

src/test/ui/feature-gates/feature-gate-unboxed-closures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ struct Test;
44

55
impl FnOnce<(u32, u32)> for Test {
66
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change
7+
//~| ERROR manual implementations of `FnOnce` are experimental
78
type Output = u32;
89

910
extern "rust-call" fn call_once(self, (a, b): (u32, u32)) -> u32 {

src/test/ui/feature-gates/feature-gate-unboxed-closures.stderr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: rust-call ABI is subject to change
2-
--> $DIR/feature-gate-unboxed-closures.rs:9:12
2+
--> $DIR/feature-gate-unboxed-closures.rs:10:12
33
|
44
LL | extern "rust-call" fn call_once(self, (a, b): (u32, u32)) -> u32 {
55
| ^^^^^^^^^^^
@@ -16,6 +16,14 @@ LL | impl FnOnce<(u32, u32)> for Test {
1616
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
1717
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
1818

19-
error: aborting due to 2 previous errors
19+
error[E0183]: manual implementations of `FnOnce` are experimental
20+
--> $DIR/feature-gate-unboxed-closures.rs:5:1
21+
|
22+
LL | impl FnOnce<(u32, u32)> for Test {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ manual implementations of `FnOnce` are experimental
24+
|
25+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
26+
27+
error: aborting due to 3 previous errors
2028

2129
For more information about this error, try `rustc --explain E0658`.

src/test/ui/issues/issue-3214.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
// ignore-tidy-linelength
2+
13
fn foo<T>() {
24
struct Foo {
35
x: T, //~ ERROR can't use generic parameters from outer function
46
}
57

68
impl<T> Drop for Foo<T> {
79
//~^ ERROR wrong number of type arguments
10+
//~| ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
811
fn drop(&mut self) {}
912
}
1013
}

src/test/ui/issues/issue-3214.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0401]: can't use generic parameters from outer function
2-
--> $DIR/issue-3214.rs:3:12
2+
--> $DIR/issue-3214.rs:5:12
33
|
44
LL | fn foo<T>() {
55
| --- - type parameter from outer function
@@ -10,12 +10,18 @@ LL | x: T,
1010
| ^ use of generic parameter from outer function
1111

1212
error[E0107]: wrong number of type arguments: expected 0, found 1
13-
--> $DIR/issue-3214.rs:6:26
13+
--> $DIR/issue-3214.rs:8:26
1414
|
1515
LL | impl<T> Drop for Foo<T> {
1616
| ^ unexpected type argument
1717

18-
error: aborting due to 2 previous errors
18+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
19+
--> $DIR/issue-3214.rs:8:10
20+
|
21+
LL | impl<T> Drop for Foo<T> {
22+
| ^ unconstrained type parameter
23+
24+
error: aborting due to 3 previous errors
1925

20-
Some errors have detailed explanations: E0107, E0401.
26+
Some errors have detailed explanations: E0107, E0207, E0401.
2127
For more information about an error, try `rustc --explain E0107`.

src/test/ui/macros/issue-68060.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// build-fail
2-
31
#![feature(track_caller)]
42

53
fn main() {

src/test/ui/macros/issue-68060.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
2-
--> $DIR/issue-68060.rs:8:13
2+
--> $DIR/issue-68060.rs:6:13
33
|
44
LL | #[target_feature(enable = "")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
@@ -8,13 +8,13 @@ LL | |_| (),
88
| ------ not an `unsafe` function
99

1010
error: the feature named `` is not valid for this target
11-
--> $DIR/issue-68060.rs:8:30
11+
--> $DIR/issue-68060.rs:6:30
1212
|
1313
LL | #[target_feature(enable = "")]
1414
| ^^^^^^^^^^^ `` is not valid for this target
1515

1616
error[E0737]: `#[track_caller]` requires Rust ABI
17-
--> $DIR/issue-68060.rs:11:13
17+
--> $DIR/issue-68060.rs:9:13
1818
|
1919
LL | #[track_caller]
2020
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)