Skip to content

Commit ad10322

Browse files
committed
Fix cycle error
1 parent 4702a9a commit ad10322

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

compiler/rustc_typeck/src/collect.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,30 +2588,22 @@ fn simd_ffi_feature_check(
25882588
}
25892589
}
25902590

2591-
fn simd_ffi_check<'tcx>(
2592-
tcx: TyCtxt<'tcx>,
2593-
def_id: DefId,
2594-
ast_ty: &hir::Ty<'_>,
2595-
ty: Ty<'tcx>,
2596-
) {
2591+
fn simd_ffi_check<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ast_ty: &hir::Ty<'_>, ty: Ty<'tcx>) {
25972592
if !ty.is_simd() {
25982593
return;
25992594
}
26002595

26012596
// The use of SIMD types in FFI is feature-gated:
26022597
if !tcx.features().simd_ffi {
26032598
let snip = tcx
2604-
.sess
2605-
.source_map()
2606-
.span_to_snippet(ast_ty.span)
2607-
.map_or_else(|_| String::new(), |s| format!("{}", s));
2599+
.sess
2600+
.source_map()
2601+
.span_to_snippet(ast_ty.span)
2602+
.map_or_else(|_| String::new(), |s| format!("{}", s));
26082603
tcx.sess
26092604
.struct_span_err(
26102605
ast_ty.span,
2611-
&format!(
2612-
"use of SIMD type `{}` in FFI is unstable",
2613-
snip
2614-
),
2606+
&format!("use of SIMD type `{}` in FFI is unstable", snip),
26152607
)
26162608
.help("add `#![feature(simd_ffi)]` to the crate attributes to enable")
26172609
.emit();
@@ -2646,12 +2638,14 @@ fn simd_ffi_check<'tcx>(
26462638
let target: &str = &tcx.sess.target.arch;
26472639

26482640
for f in features {
2649-
if let Err(v) = simd_ffi_feature_check(target, simd_len, simd_elem_width, f.to_ident_string()) {
2641+
if let Err(v) =
2642+
simd_ffi_feature_check(target, simd_len, simd_elem_width, f.to_ident_string())
2643+
{
26502644
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));
2645+
.sess
2646+
.source_map()
2647+
.span_to_snippet(ast_ty.span)
2648+
.map_or_else(|_| String::new(), |s| format!("{}", s));
26552649
let msg = if let Some(f) = v {
26562650
format!(
26572651
"use of SIMD type `{}` in FFI requires `#[target_feature(enable = \"{}\")]`",
@@ -2952,7 +2946,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29522946
codegen_fn_attrs.export_name = Some(s);
29532947
}
29542948
} else if tcx.sess.check_name(attr, sym::target_feature) {
2955-
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
2949+
if !tcx.is_closure(id)
2950+
&& !tcx.is_foreign_item(id)
2951+
&& tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal
2952+
{
29562953
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
29572954
// The `#[target_feature]` attribute is allowed on
29582955
// WebAssembly targets on all functions, including safe

src/test/ui/rfcs/rfc-2574-simd-ffi/simd-ffi-x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(repr_simd)]
44
#![feature(simd_ffi)]
55
#![feature(avx512_target_feature)]
6-
#![allow(non_camel_case_types)]
6+
#![allow(non_camel_case_types, improper_ctypes)]
77
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
88

99
#[repr(simd)]
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
error[E0391]: cycle detected when computing codegen attributes of `qux`
2-
--> $DIR/simd-ffi-x86.rs:19:5
1+
error: use of SIMD type `v256` in FFI requires `#[target_feature(enable = "avx")]`
2+
--> $DIR/simd-ffi-x86.rs:33:22
33
|
4-
LL | fn qux(x: v128);
5-
| ^^^^^^^^^^^^^^^^
6-
|
7-
note: ...which requires computing function signature of `qux`...
8-
--> $DIR/simd-ffi-x86.rs:19:5
4+
LL | fn quux_fail2(x: v256);
5+
| ^^^^
6+
7+
error: use of SIMD type `v512` in FFI requires `#[target_feature(enable = "acx512")]`
8+
--> $DIR/simd-ffi-x86.rs:43:23
99
|
10-
LL | fn qux(x: v128);
11-
| ^^^^^^^^^^^^^^^^
12-
= note: ...which again requires computing codegen attributes of `qux`, completing the cycle
13-
note: cycle used when checking attributes in top-level module
14-
--> $DIR/simd-ffi-x86.rs:3:1
10+
LL | fn quuux_fail2(x: v512);
11+
| ^^^^
12+
13+
error: use of SIMD type `v512` in FFI requires `#[target_feature(enable = "acx512")]`
14+
--> $DIR/simd-ffi-x86.rs:45:23
1515
|
16-
LL | / #![feature(repr_simd)]
17-
LL | | #![feature(simd_ffi)]
18-
LL | | #![feature(avx512_target_feature)]
19-
LL | | #![allow(non_camel_case_types)]
20-
... |
21-
LL | | #[repr(simd)]
22-
LL | | struct v512(i128, i128, i128, i128);
23-
| |____________________________________^
16+
LL | fn quuux_fail3(x: v512);
17+
| ^^^^
2418

25-
error: aborting due to previous error
19+
error: aborting due to 3 previous errors
2620

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

0 commit comments

Comments
 (0)