Skip to content

Commit

Permalink
Rollup merge of rust-lang#69154 - JohnTitor:fix-macro-ices, r=petroch…
Browse files Browse the repository at this point in the history
…enkov

Avoid calling `fn_sig` on closures

Fixes rust-lang#68060

r? @petrochenkov
  • Loading branch information
Dylan-DPC committed Feb 15, 2020
2 parents 728be34 + 47aa2b5 commit c115ad9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Expand Up @@ -2280,7 +2280,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
} else if attr.check_name(sym::thread_local) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
} else if attr.check_name(sym::track_caller) {
if tcx.fn_sig(id).abi() != abi::Abi::Rust {
if tcx.is_closure(id) || tcx.fn_sig(id).abi() != abi::Abi::Rust {
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
.emit();
}
Expand All @@ -2301,7 +2301,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
codegen_fn_attrs.export_name = Some(s);
}
} else if attr.check_name(sym::target_feature) {
if tcx.fn_sig(id).unsafety() == Unsafety::Normal {
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == Unsafety::Normal {
let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
tcx.sess
.struct_span_err(attr.span, msg)
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/macros/issue-68060.rs
@@ -0,0 +1,16 @@
// build-fail

#![feature(track_caller)]

fn main() {
(0..)
.map(
#[target_feature(enable = "")]
//~^ ERROR: the feature named `` is not valid for this target
//~| ERROR: `#[target_feature(..)]` can only be applied to `unsafe` functions
#[track_caller]
//~^ ERROR: `#[track_caller]` requires Rust ABI
|_| (),
)
.next();
}
24 changes: 24 additions & 0 deletions src/test/ui/macros/issue-68060.stderr
@@ -0,0 +1,24 @@
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/issue-68060.rs:8:13
|
LL | #[target_feature(enable = "")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
...
LL | |_| (),
| ------ not an `unsafe` function

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

error[E0737]: `#[track_caller]` requires Rust ABI
--> $DIR/issue-68060.rs:11:13
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

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

0 comments on commit c115ad9

Please sign in to comment.