Skip to content

Commit c115ad9

Browse files
authored
Rollup merge of #69154 - JohnTitor:fix-macro-ices, r=petrochenkov
Avoid calling `fn_sig` on closures Fixes #68060 r? @petrochenkov
2 parents 728be34 + 47aa2b5 commit c115ad9

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
22802280
} else if attr.check_name(sym::thread_local) {
22812281
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
22822282
} else if attr.check_name(sym::track_caller) {
2283-
if tcx.fn_sig(id).abi() != abi::Abi::Rust {
2283+
if tcx.is_closure(id) || tcx.fn_sig(id).abi() != abi::Abi::Rust {
22842284
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
22852285
.emit();
22862286
}
@@ -2301,7 +2301,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
23012301
codegen_fn_attrs.export_name = Some(s);
23022302
}
23032303
} else if attr.check_name(sym::target_feature) {
2304-
if tcx.fn_sig(id).unsafety() == Unsafety::Normal {
2304+
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == Unsafety::Normal {
23052305
let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
23062306
tcx.sess
23072307
.struct_span_err(attr.span, msg)

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build-fail
2+
3+
#![feature(track_caller)]
4+
5+
fn main() {
6+
(0..)
7+
.map(
8+
#[target_feature(enable = "")]
9+
//~^ ERROR: the feature named `` is not valid for this target
10+
//~| ERROR: `#[target_feature(..)]` can only be applied to `unsafe` functions
11+
#[track_caller]
12+
//~^ ERROR: `#[track_caller]` requires Rust ABI
13+
|_| (),
14+
)
15+
.next();
16+
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
2+
--> $DIR/issue-68060.rs:8:13
3+
|
4+
LL | #[target_feature(enable = "")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
6+
...
7+
LL | |_| (),
8+
| ------ not an `unsafe` function
9+
10+
error: the feature named `` is not valid for this target
11+
--> $DIR/issue-68060.rs:8:30
12+
|
13+
LL | #[target_feature(enable = "")]
14+
| ^^^^^^^^^^^ `` is not valid for this target
15+
16+
error[E0737]: `#[track_caller]` requires Rust ABI
17+
--> $DIR/issue-68060.rs:11:13
18+
|
19+
LL | #[track_caller]
20+
| ^^^^^^^^^^^^^^^
21+
22+
error: aborting due to 3 previous errors
23+
24+
For more information about this error, try `rustc --explain E0737`.

0 commit comments

Comments
 (0)