summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-15 09:45:46 +0100
committerGitHub <noreply@github.com>2020-02-15 09:45:46 +0100
commitc115ad927a2dc24400de60dc280a9e7029b9bd44 (patch)
tree7242a3a9f9348931ad5268afa6d240e9881e0464
parentRollup merge of #69106 - RReverser:wasi-fs-copy, r=KodrAus (diff)
parentAvoid calling `fn_sig` on closures (diff)
downloadrust-c115ad927a2dc24400de60dc280a9e7029b9bd44.tar.gz
rust-c115ad927a2dc24400de60dc280a9e7029b9bd44.tar.bz2
rust-c115ad927a2dc24400de60dc280a9e7029b9bd44.tar.xz
Rollup merge of #69154 - JohnTitor:fix-macro-ices, r=petrochenkov
Avoid calling `fn_sig` on closures Fixes #68060 r? @petrochenkov
-rw-r--r--src/librustc_typeck/collect.rs4
-rw-r--r--src/test/ui/macros/issue-68060.rs16
-rw-r--r--src/test/ui/macros/issue-68060.stderr24
3 files changed, 42 insertions, 2 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 1a505a3..80d914d 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -2280,7 +2280,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2280 } else if attr.check_name(sym::thread_local) { 2280 } else if attr.check_name(sym::thread_local) {
2281 codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL; 2281 codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
2282 } else if attr.check_name(sym::track_caller) { 2282 } 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 {
2284 struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI") 2284 struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
2285 .emit(); 2285 .emit();
2286 } 2286 }
@@ -2301,7 +2301,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2301 codegen_fn_attrs.export_name = Some(s); 2301 codegen_fn_attrs.export_name = Some(s);
2302 } 2302 }
2303 } else if attr.check_name(sym::target_feature) { 2303 } 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 {
2305 let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions"; 2305 let msg = "`#[target_feature(..)]` can only be applied to `unsafe` functions";
2306 tcx.sess 2306 tcx.sess
2307 .struct_span_err(attr.span, msg) 2307 .struct_span_err(attr.span, msg)
diff --git a/src/test/ui/macros/issue-68060.rs b/src/test/ui/macros/issue-68060.rs
new file mode 100644
index 0000000..85ebd66
--- /dev/null
+++ b/src/test/ui/macros/issue-68060.rs
@@ -0,0 +1,16 @@
1// build-fail
2
3#![feature(track_caller)]
4
5fn 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}
diff --git a/src/test/ui/macros/issue-68060.stderr b/src/test/ui/macros/issue-68060.stderr
new file mode 100644
index 0000000..2308674
--- /dev/null
+++ b/src/test/ui/macros/issue-68060.stderr
@@ -0,0 +1,24 @@
1error: `#[target_feature(..)]` can only be applied to `unsafe` functions
2 --> $DIR/issue-68060.rs:8:13
3 |
4LL | #[target_feature(enable = "")]
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
6...
7LL | |_| (),
8 | ------ not an `unsafe` function
9
10error: the feature named `` is not valid for this target
11 --> $DIR/issue-68060.rs:8:30
12 |
13LL | #[target_feature(enable = "")]
14 | ^^^^^^^^^^^ `` is not valid for this target
15
16error[E0737]: `#[track_caller]` requires Rust ABI
17 --> $DIR/issue-68060.rs:11:13
18 |
19LL | #[track_caller]
20 | ^^^^^^^^^^^^^^^
21
22error: aborting due to 3 previous errors
23
24For more information about this error, try `rustc --explain E0737`.