Skip to content

Commit d5471a7

Browse files
committed
Fix feature gate check
1 parent f387030 commit d5471a7

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

compiler/rustc_typeck/src/collect.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,15 +2600,20 @@ fn simd_ffi_check<'tcx>(
26002600

26012601
// The use of SIMD types in FFI is feature-gated:
26022602
if !tcx.features().simd_ffi {
2603+
let snip = tcx
2604+
.sess
2605+
.source_map()
2606+
.span_to_snippet(ast_ty.span)
2607+
.map_or_else(|_| String::new(), |s| format!("{}", s));
26032608
tcx.sess
26042609
.struct_span_err(
26052610
ast_ty.span,
26062611
&format!(
26072612
"use of SIMD type `{}` in FFI is unstable",
2608-
tcx.hir().node_to_string(ast_ty.hir_id)
2613+
snip
26092614
),
26102615
)
2611-
.help("add #![feature(simd_ffi)] to the crate attributes to enable")
2616+
.help("add `#![feature(simd_ffi)]` to the crate attributes to enable")
26122617
.emit();
26132618
return;
26142619
}
@@ -2642,7 +2647,11 @@ fn simd_ffi_check<'tcx>(
26422647

26432648
for f in features {
26442649
if let Err(v) = simd_ffi_feature_check(target, simd_len, simd_elem_width, f.to_ident_string()) {
2645-
let type_str = tcx.hir().node_to_string(ast_ty.hir_id);
2650+
let type_str = tcx
2651+
.sess
2652+
.source_map()
2653+
.span_to_snippet(ast_ty.span)
2654+
.map_or_else(|_| String::new(), |s| format!("{}", s));
26462655
let msg = if let Some(f) = v {
26472656
format!(
26482657
"use of SIMD type `{}` in FFI requires `#[target_feature(enable = \"{}\")]`",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// only-x86_64
2+
3+
#![feature(repr_simd)]
4+
#![feature(avx512_target_feature)]
5+
#![allow(non_camel_case_types)]
6+
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
7+
8+
#[repr(simd)]
9+
struct v128(i128);
10+
11+
extern {
12+
fn foo(x: v128); //~ ERROR use of SIMD type `v128` in FFI is unstable
13+
fn bar(x: i32, y: v128); //~ ERROR use of SIMD type `v128` in FFI is unstable
14+
fn baz(x: i32) -> v128; //~ ERROR use of SIMD type `v128` in FFI is unstable
15+
}
16+
17+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: use of SIMD type `v128` in FFI is unstable
2+
--> $DIR/simd-ffi-feature-gate.rs:12:15
3+
|
4+
LL | fn foo(x: v128);
5+
| ^^^^
6+
|
7+
= help: add `#![feature(simd_ffi)]` to the crate attributes to enable
8+
9+
error: use of SIMD type `v128` in FFI is unstable
10+
--> $DIR/simd-ffi-feature-gate.rs:13:23
11+
|
12+
LL | fn bar(x: i32, y: v128);
13+
| ^^^^
14+
|
15+
= help: add `#![feature(simd_ffi)]` to the crate attributes to enable
16+
17+
error: use of SIMD type `v128` in FFI is unstable
18+
--> $DIR/simd-ffi-feature-gate.rs:14:23
19+
|
20+
LL | fn baz(x: i32) -> v128;
21+
| ^^^^
22+
|
23+
= help: add `#![feature(simd_ffi)]` to the crate attributes to enable
24+
25+
error: aborting due to 3 previous errors
26+

src/test/ui/rfcs/rfc-2574-simd-ffi/target-feature-on-foreign-function.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)