Skip to content

Commit 47aa2b5

Browse files
committed
Avoid calling fn_sig on closures
1 parent 1010408 commit 47aa2b5

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
@@ -2877,7 +2877,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
28772877
} else if attr.check_name(sym::thread_local) {
28782878
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
28792879
} else if attr.check_name(sym::track_caller) {
2880-
if tcx.fn_sig(id).abi() != abi::Abi::Rust {
2880+
if tcx.is_closure(id) || tcx.fn_sig(id).abi() != abi::Abi::Rust {
28812881
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
28822882
.emit();
28832883
}
@@ -2898,7 +2898,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
28982898
codegen_fn_attrs.export_name = Some(s);
28992899
}
29002900
} else if attr.check_name(sym::target_feature) {
2901-
if tcx.fn_sig(id).unsafety() == Unsafety::Normal {
2901+
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == Unsafety::Normal {
29022902
let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
29032903
tcx.sess
29042904
.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)