Skip to content

Commit f9cf0c4

Browse files
committed
add Tainted for NonAsmTypeReason
1 parent 112d833 commit f9cf0c4

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

compiler/rustc_hir_typeck/src/inline_asm.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::bug;
77
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
88
use rustc_session::lint;
99
use rustc_span::def_id::LocalDefId;
10-
use rustc_span::{Span, Symbol, sym};
10+
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1111
use rustc_target::asm::{
1212
InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType, ModifierInfo,
1313
};
@@ -27,6 +27,7 @@ enum NonAsmTypeReason<'tcx> {
2727
InvalidElement(DefId, Ty<'tcx>),
2828
NotSizedPtr(Ty<'tcx>),
2929
EmptySIMDArray(Ty<'tcx>),
30+
Tainted(ErrorGuaranteed),
3031
}
3132

3233
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@@ -94,11 +95,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
9495
}
9596
ty::Adt(adt, args) if adt.repr().simd() => {
9697
if !adt.is_struct() {
97-
self.fcx.dcx().span_delayed_bug(
98+
let guar = self.fcx.dcx().span_delayed_bug(
9899
span,
99100
format!("repr(simd) should only be used on structs, got {}", adt.descr()),
100101
);
101-
return Err(NonAsmTypeReason::Invalid(ty));
102+
return Err(NonAsmTypeReason::Tainted(guar));
102103
}
103104

104105
let fields = &adt.non_enum_variant().fields;
@@ -242,6 +243,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
242243
let msg = format!("use of empty SIMD vector `{ty}`");
243244
self.fcx.dcx().struct_span_err(expr.span, msg).emit();
244245
}
246+
NonAsmTypeReason::Tainted(_error_guard) => {
247+
// An error has already been reported.
248+
}
245249
}
246250
return None;
247251
}

tests/ui/asm/invalid-repr-simd-on-enum-148634.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ ignore-x86_64-unknown-linux-gnu
12
#![feature(repr_simd)]
23

34
use std::arch::asm;
@@ -11,6 +12,5 @@ fn main() {
1112
unsafe {
1213
let mut x: Es;
1314
asm!("{}", out(reg) x);
14-
//~^ ERROR cannot use value of type `Es` for inline assembly
1515
}
1616
}
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0517]: attribute should be applied to a struct
2-
--> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8
2+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8
33
|
44
LL | #[repr(simd)]
55
| ^^^^
@@ -8,23 +8,15 @@ LL | enum Es {}
88
| ---------- not a struct
99

1010
error[E0084]: unsupported representation for zero-variant enum
11-
--> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8
11+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8
1212
|
1313
LL | #[repr(simd)]
1414
| ^^^^
1515
...
1616
LL | enum Es {}
1717
| ------- zero-variant enum
1818

19-
error: cannot use value of type `Es` for inline assembly
20-
--> $DIR/invalid-repr-simd-on-enum-148634.rs:13:29
21-
|
22-
LL | asm!("{}", out(reg) x);
23-
| ^
24-
|
25-
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
26-
27-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
2820

2921
Some errors have detailed explanations: E0084, E0517.
3022
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)