Skip to content

Commit dba1503

Browse files
committed
Ensure codegen_fn_attrs during collection.
1 parent 928d14b commit dba1503

File tree

12 files changed

+103
-129
lines changed

12 files changed

+103
-129
lines changed

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
314314
if let hir::ExprKind::Closure { .. } = expr.kind {
315315
let def_id = self.tcx.hir().local_def_id(expr.hir_id);
316316
self.tcx.ensure().generics_of(def_id);
317+
self.tcx.ensure().codegen_fn_attrs(def_id);
317318
// We do not call `type_of` for closures here as that
318319
// depends on typecheck and would therefore hide
319320
// any further errors in case one typeck fails.
@@ -586,8 +587,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
586587
tcx.ensure().type_of(item.owner_id);
587588
tcx.ensure().predicates_of(item.owner_id);
588589
match item.kind {
589-
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.owner_id),
590+
hir::ForeignItemKind::Fn(..) => {
591+
tcx.ensure().codegen_fn_attrs(item.owner_id);
592+
tcx.ensure().fn_sig(item.owner_id)
593+
}
590594
hir::ForeignItemKind::Static(..) => {
595+
tcx.ensure().codegen_fn_attrs(item.owner_id);
591596
let mut visitor = HirPlaceholderCollector::default();
592597
visitor.visit_foreign_item(item);
593598
placeholder_type_error(
@@ -676,6 +681,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
676681
tcx.ensure().type_of(def_id);
677682
tcx.ensure().predicates_of(def_id);
678683
tcx.ensure().fn_sig(def_id);
684+
tcx.ensure().codegen_fn_attrs(def_id);
679685
}
680686
}
681687
}
@@ -687,6 +693,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
687693

688694
match trait_item.kind {
689695
hir::TraitItemKind::Fn(..) => {
696+
tcx.ensure().codegen_fn_attrs(def_id);
690697
tcx.ensure().type_of(def_id);
691698
tcx.ensure().fn_sig(def_id);
692699
}
@@ -736,6 +743,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
736743
let impl_item = tcx.hir().impl_item(impl_item_id);
737744
match impl_item.kind {
738745
hir::ImplItemKind::Fn(..) => {
746+
tcx.ensure().codegen_fn_attrs(def_id);
739747
tcx.ensure().fn_sig(def_id);
740748
}
741749
hir::ImplItemKind::Type(_) => {

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,6 @@ impl CheckAttrVisitor<'_> {
219219
return;
220220
}
221221

222-
// FIXME(@lcnr): this doesn't belong here.
223-
if matches!(
224-
target,
225-
Target::Closure
226-
| Target::Fn
227-
| Target::Method(_)
228-
| Target::ForeignFn
229-
| Target::ForeignStatic
230-
) {
231-
self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
232-
}
233-
234222
self.check_repr(attrs, span, target, item, hir_id);
235223
self.check_used(attrs, target);
236224
}

src/test/ui/lang-items/lang-item-generic-requirements.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ trait MyIndex<'a, T> {}
2222
#[lang = "phantom_data"]
2323
//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
2424
struct MyPhantomData<T, U>;
25-
//~^ ERROR parameter `T` is never used
26-
//~| ERROR parameter `U` is never used
2725

2826
#[lang = "owned_box"]
2927
//~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument

src/test/ui/lang-items/lang-item-generic-requirements.stderr

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LL | struct MyPhantomData<T, U>;
3333
| ------ this struct has 2 generic arguments
3434

3535
error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument
36-
--> $DIR/lang-item-generic-requirements.rs:28:1
36+
--> $DIR/lang-item-generic-requirements.rs:26:1
3737
|
3838
LL | #[lang = "owned_box"]
3939
| ^^^^^^^^^^^^^^^^^^^^^
@@ -42,33 +42,14 @@ LL | struct Foo;
4242
| - this struct has 0 generic arguments
4343

4444
error[E0718]: `start` language item must be applied to a function with 1 generic argument
45-
--> $DIR/lang-item-generic-requirements.rs:34:1
45+
--> $DIR/lang-item-generic-requirements.rs:32:1
4646
|
4747
LL | #[lang = "start"]
4848
| ^^^^^^^^^^^^^^^^^
4949
LL |
5050
LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
5151
| - this function has 0 generic arguments
5252

53-
error[E0392]: parameter `T` is never used
54-
--> $DIR/lang-item-generic-requirements.rs:24:22
55-
|
56-
LL | struct MyPhantomData<T, U>;
57-
| ^ unused parameter
58-
|
59-
= help: consider removing `T` or referring to it in a field
60-
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
61-
62-
error[E0392]: parameter `U` is never used
63-
--> $DIR/lang-item-generic-requirements.rs:24:25
64-
|
65-
LL | struct MyPhantomData<T, U>;
66-
| ^ unused parameter
67-
|
68-
= help: consider removing `U` or referring to it in a field
69-
= help: if you intended `U` to be a const parameter, use `const U: usize` instead
70-
71-
error: aborting due to 8 previous errors
53+
error: aborting due to 6 previous errors
7254

73-
Some errors have detailed explanations: E0392, E0718.
74-
For more information about an error, try `rustc --explain E0392`.
55+
For more information about this error, try `rustc --explain E0718`.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ fn main() {
33
.map(
44
#[target_feature(enable = "")]
55
//~^ ERROR: attribute should be applied to a function
6+
//~| ERROR: feature named `` is not valid
7+
//~| NOTE: `` is not valid for this target
68
#[track_caller]
9+
//~^ ERROR: `#[track_caller]` on closures is currently unstable
10+
//~| NOTE: see issue #87417
711
|_| (),
812
//~^ NOTE: not a function
913
)

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,21 @@ LL | #[target_feature(enable = "")]
77
LL | |_| (),
88
| ------ not a function definition
99

10-
error: aborting due to previous error
10+
error: the feature named `` is not valid for this target
11+
--> $DIR/issue-68060.rs:4:30
12+
|
13+
LL | #[target_feature(enable = "")]
14+
| ^^^^^^^^^^^ `` is not valid for this target
15+
16+
error[E0658]: `#[track_caller]` on closures is currently unstable
17+
--> $DIR/issue-68060.rs:8:13
18+
|
19+
LL | #[track_caller]
20+
| ^^^^^^^^^^^^^^^
21+
|
22+
= note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information
23+
= help: add `#![feature(closure_track_caller)]` to the crate attributes to enable
24+
25+
error: aborting due to 3 previous errors
1126

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

src/test/ui/panic-handler/panic-handler-std.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ LL | fn panic(info: PanicInfo) -> ! {
88
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
99
= note: second definition in the local crate (`panic_handler_std`)
1010

11-
error: argument should be `&PanicInfo`
12-
--> $DIR/panic-handler-std.rs:8:16
13-
|
14-
LL | fn panic(info: PanicInfo) -> ! {
15-
| ^^^^^^^^^
16-
17-
error: aborting due to 2 previous errors
11+
error: aborting due to previous error
1812

1913
For more information about this error, try `rustc --explain E0152`.

src/test/ui/range/issue-54505-no-std.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// error-pattern: `#[panic_handler]` function required, but not found
2-
31
// Regression test for #54505 - range borrowing suggestion had
42
// incorrect syntax (missing parentheses).
53

@@ -18,6 +16,10 @@ extern "C" fn eh_personality() {}
1816
#[lang = "eh_catch_typeinfo"]
1917
static EH_CATCH_TYPEINFO: u8 = 0;
2018

19+
#[panic_handler]
20+
fn panic_handler() {}
21+
//~^ ERROR return type should be `!`
22+
//~| ERROR function should have one argument
2123

2224
// take a reference to any built-in range
2325
fn take_range(_r: &impl RangeBounds<i8>) {}

src/test/ui/range/issue-54505-no-std.stderr

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
error: `#[panic_handler]` function required, but not found
1+
error: return type should be `!`
2+
--> $DIR/issue-54505-no-std.rs:20:20
3+
|
4+
LL | fn panic_handler() {}
5+
| ^
6+
7+
error: function should have one argument
8+
--> $DIR/issue-54505-no-std.rs:20:1
9+
|
10+
LL | fn panic_handler() {}
11+
| ^^^^^^^^^^^^^^^^^^
212

313
error[E0308]: mismatched types
4-
--> $DIR/issue-54505-no-std.rs:27:16
14+
--> $DIR/issue-54505-no-std.rs:29:16
515
|
616
LL | take_range(0..1);
717
| ---------- ^^^^
@@ -13,13 +23,13 @@ LL | take_range(0..1);
1323
= note: expected reference `&_`
1424
found struct `Range<{integer}>`
1525
note: function defined here
16-
--> $DIR/issue-54505-no-std.rs:23:4
26+
--> $DIR/issue-54505-no-std.rs:25:4
1727
|
1828
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
1929
| ^^^^^^^^^^ -------------------------
2030

2131
error[E0308]: mismatched types
22-
--> $DIR/issue-54505-no-std.rs:32:16
32+
--> $DIR/issue-54505-no-std.rs:34:16
2333
|
2434
LL | take_range(1..);
2535
| ---------- ^^^
@@ -31,13 +41,13 @@ LL | take_range(1..);
3141
= note: expected reference `&_`
3242
found struct `RangeFrom<{integer}>`
3343
note: function defined here
34-
--> $DIR/issue-54505-no-std.rs:23:4
44+
--> $DIR/issue-54505-no-std.rs:25:4
3545
|
3646
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
3747
| ^^^^^^^^^^ -------------------------
3848

3949
error[E0308]: mismatched types
40-
--> $DIR/issue-54505-no-std.rs:37:16
50+
--> $DIR/issue-54505-no-std.rs:39:16
4151
|
4252
LL | take_range(..);
4353
| ---------- ^^
@@ -49,13 +59,13 @@ LL | take_range(..);
4959
= note: expected reference `&_`
5060
found struct `RangeFull`
5161
note: function defined here
52-
--> $DIR/issue-54505-no-std.rs:23:4
62+
--> $DIR/issue-54505-no-std.rs:25:4
5363
|
5464
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
5565
| ^^^^^^^^^^ -------------------------
5666

5767
error[E0308]: mismatched types
58-
--> $DIR/issue-54505-no-std.rs:42:16
68+
--> $DIR/issue-54505-no-std.rs:44:16
5969
|
6070
LL | take_range(0..=1);
6171
| ---------- ^^^^^
@@ -67,13 +77,13 @@ LL | take_range(0..=1);
6777
= note: expected reference `&_`
6878
found struct `RangeInclusive<{integer}>`
6979
note: function defined here
70-
--> $DIR/issue-54505-no-std.rs:23:4
80+
--> $DIR/issue-54505-no-std.rs:25:4
7181
|
7282
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
7383
| ^^^^^^^^^^ -------------------------
7484

7585
error[E0308]: mismatched types
76-
--> $DIR/issue-54505-no-std.rs:47:16
86+
--> $DIR/issue-54505-no-std.rs:49:16
7787
|
7888
LL | take_range(..5);
7989
| ---------- ^^^
@@ -85,13 +95,13 @@ LL | take_range(..5);
8595
= note: expected reference `&_`
8696
found struct `RangeTo<{integer}>`
8797
note: function defined here
88-
--> $DIR/issue-54505-no-std.rs:23:4
98+
--> $DIR/issue-54505-no-std.rs:25:4
8999
|
90100
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
91101
| ^^^^^^^^^^ -------------------------
92102

93103
error[E0308]: mismatched types
94-
--> $DIR/issue-54505-no-std.rs:52:16
104+
--> $DIR/issue-54505-no-std.rs:54:16
95105
|
96106
LL | take_range(..=42);
97107
| ---------- ^^^^^
@@ -103,11 +113,11 @@ LL | take_range(..=42);
103113
= note: expected reference `&_`
104114
found struct `RangeToInclusive<{integer}>`
105115
note: function defined here
106-
--> $DIR/issue-54505-no-std.rs:23:4
116+
--> $DIR/issue-54505-no-std.rs:25:4
107117
|
108118
LL | fn take_range(_r: &impl RangeBounds<i8>) {}
109119
| ^^^^^^^^^^ -------------------------
110120

111-
error: aborting due to 7 previous errors
121+
error: aborting due to 8 previous errors
112122

113123
For more information about this error, try `rustc --explain E0308`.

src/test/ui/target-feature/invalid-attribute.stderr

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,6 @@ error: malformed `target_feature` attribute input
44
LL | #[target_feature = "+sse2"]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]`
66

7-
error: the feature named `foo` is not valid for this target
8-
--> $DIR/invalid-attribute.rs:19:18
9-
|
10-
LL | #[target_feature(enable = "foo")]
11-
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
12-
13-
error: malformed `target_feature` attribute input
14-
--> $DIR/invalid-attribute.rs:22:18
15-
|
16-
LL | #[target_feature(bar)]
17-
| ^^^ help: must be of the form: `enable = ".."`
18-
19-
error: malformed `target_feature` attribute input
20-
--> $DIR/invalid-attribute.rs:24:18
21-
|
22-
LL | #[target_feature(disable = "baz")]
23-
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
24-
25-
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
26-
--> $DIR/invalid-attribute.rs:28:1
27-
|
28-
LL | #[target_feature(enable = "sse2")]
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30-
...
31-
LL | fn bar() {}
32-
| -------- not an `unsafe` function
33-
|
34-
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
35-
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
36-
377
error: attribute should be applied to a function definition
388
--> $DIR/invalid-attribute.rs:34:1
399
|
@@ -92,12 +62,6 @@ LL |
9262
LL | trait Baz {}
9363
| ------------ not a function definition
9464

95-
error: cannot use `#[inline(always)]` with `#[target_feature]`
96-
--> $DIR/invalid-attribute.rs:67:1
97-
|
98-
LL | #[inline(always)]
99-
| ^^^^^^^^^^^^^^^^^
100-
10165
error: attribute should be applied to a function definition
10266
--> $DIR/invalid-attribute.rs:85:5
10367
|
@@ -119,6 +83,42 @@ LL |
11983
LL | || {};
12084
| ----- not a function definition
12185

86+
error: the feature named `foo` is not valid for this target
87+
--> $DIR/invalid-attribute.rs:19:18
88+
|
89+
LL | #[target_feature(enable = "foo")]
90+
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
91+
92+
error: malformed `target_feature` attribute input
93+
--> $DIR/invalid-attribute.rs:22:18
94+
|
95+
LL | #[target_feature(bar)]
96+
| ^^^ help: must be of the form: `enable = ".."`
97+
98+
error: malformed `target_feature` attribute input
99+
--> $DIR/invalid-attribute.rs:24:18
100+
|
101+
LL | #[target_feature(disable = "baz")]
102+
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
103+
104+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
105+
--> $DIR/invalid-attribute.rs:28:1
106+
|
107+
LL | #[target_feature(enable = "sse2")]
108+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109+
...
110+
LL | fn bar() {}
111+
| -------- not an `unsafe` function
112+
|
113+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
114+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
115+
116+
error: cannot use `#[inline(always)]` with `#[target_feature]`
117+
--> $DIR/invalid-attribute.rs:67:1
118+
|
119+
LL | #[inline(always)]
120+
| ^^^^^^^^^^^^^^^^^
121+
122122
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
123123
--> $DIR/invalid-attribute.rs:77:5
124124
|

0 commit comments

Comments
 (0)