Skip to content

Commit 774fbc7

Browse files
committed
fix ICE when asm_const and const_refs_to_static are combined
1 parent 494e5b7 commit 774fbc7

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc_macros::extension;
2929
use rustc_middle::ty::fold::TypeFoldable;
3030
use rustc_middle::ty::print::with_no_trimmed_paths;
3131
use rustc_middle::ty::{
32-
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt,
32+
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
33+
TyCtxt, TypeVisitableExt,
3334
};
3435
use rustc_middle::{bug, span_bug};
3536
use rustc_span::symbol::{kw, sym};
@@ -798,6 +799,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
798799
// "output" (the type of the constant).
799800
assert_eq!(self.mir_def.to_def_id(), def_id);
800801
let ty = tcx.type_of(self.mir_def).instantiate_identity();
802+
803+
// FIXME(#129952): We probably want a more principled approach here.
804+
if let Err(terr) = ty.error_reported() {
805+
self.infcx.set_tainted_by_errors(terr);
806+
}
807+
801808
let ty = indices.fold_to_region_vids(tcx, ty);
802809
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
803810
}

tests/ui/asm/const-refs-to-static.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ needs-asm-support
2+
//@ ignore-nvptx64
3+
//@ ignore-spirv
4+
5+
#![feature(const_refs_to_static)]
6+
7+
use std::arch::{asm, global_asm};
8+
use std::ptr::addr_of;
9+
10+
static FOO: u8 = 42;
11+
12+
global_asm!("{}", const addr_of!(FOO));
13+
//~^ ERROR invalid type for `const` operand
14+
15+
#[no_mangle]
16+
fn inline() {
17+
unsafe { asm!("{}", const addr_of!(FOO)) };
18+
//~^ ERROR invalid type for `const` operand
19+
}
20+
21+
fn main() {}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: invalid type for `const` operand
2+
--> $DIR/const-refs-to-static.rs:12:19
3+
|
4+
LL | global_asm!("{}", const addr_of!(FOO));
5+
| ^^^^^^-------------
6+
| |
7+
| is a `*const u8`
8+
|
9+
= help: `const` operands must be of an integer type
10+
11+
error: invalid type for `const` operand
12+
--> $DIR/const-refs-to-static.rs:17:25
13+
|
14+
LL | unsafe { asm!("{}", const addr_of!(FOO)) };
15+
| ^^^^^^-------------
16+
| |
17+
| is a `*const u8`
18+
|
19+
= help: `const` operands must be of an integer type
20+
21+
error: aborting due to 2 previous errors
22+

0 commit comments

Comments
 (0)