mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
fix ICE when asm_const
and const_refs_to_static
are combined
This commit is contained in:
parent
f7679d0507
commit
49e3b9a2d2
@ -29,7 +29,8 @@ use rustc_macros::extension;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt,
|
||||
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
|
||||
TyCtxt, TypeVisitableExt,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
@ -688,7 +689,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
defining_ty: DefiningTy<'tcx>,
|
||||
) -> ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>> {
|
||||
let tcx = self.infcx.tcx;
|
||||
match defining_ty {
|
||||
|
||||
let inputs_and_output = match defining_ty {
|
||||
DefiningTy::Closure(def_id, args) => {
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let closure_sig = args.as_closure().sig();
|
||||
@ -798,6 +800,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
// "output" (the type of the constant).
|
||||
assert_eq!(self.mir_def.to_def_id(), def_id);
|
||||
let ty = tcx.type_of(self.mir_def).instantiate_identity();
|
||||
|
||||
let ty = indices.fold_to_region_vids(tcx, ty);
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
@ -807,7 +810,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
let ty = args.as_inline_const().ty();
|
||||
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME(#129952): We probably want a more principled approach here.
|
||||
if let Err(terr) = inputs_and_output.skip_binder().error_reported() {
|
||||
self.infcx.set_tainted_by_errors(terr);
|
||||
}
|
||||
|
||||
inputs_and_output
|
||||
}
|
||||
}
|
||||
|
||||
|
21
tests/ui/asm/const-refs-to-static.rs
Normal file
21
tests/ui/asm/const-refs-to-static.rs
Normal file
@ -0,0 +1,21 @@
|
||||
//@ needs-asm-support
|
||||
//@ ignore-nvptx64
|
||||
//@ ignore-spirv
|
||||
|
||||
#![feature(const_refs_to_static)]
|
||||
|
||||
use std::arch::{asm, global_asm};
|
||||
use std::ptr::addr_of;
|
||||
|
||||
static FOO: u8 = 42;
|
||||
|
||||
global_asm!("{}", const addr_of!(FOO));
|
||||
//~^ ERROR invalid type for `const` operand
|
||||
|
||||
#[no_mangle]
|
||||
fn inline() {
|
||||
unsafe { asm!("{}", const addr_of!(FOO)) };
|
||||
//~^ ERROR invalid type for `const` operand
|
||||
}
|
||||
|
||||
fn main() {}
|
22
tests/ui/asm/const-refs-to-static.stderr
Normal file
22
tests/ui/asm/const-refs-to-static.stderr
Normal file
@ -0,0 +1,22 @@
|
||||
error: invalid type for `const` operand
|
||||
--> $DIR/const-refs-to-static.rs:12:19
|
||||
|
|
||||
LL | global_asm!("{}", const addr_of!(FOO));
|
||||
| ^^^^^^-------------
|
||||
| |
|
||||
| is a `*const u8`
|
||||
|
|
||||
= help: `const` operands must be of an integer type
|
||||
|
||||
error: invalid type for `const` operand
|
||||
--> $DIR/const-refs-to-static.rs:17:25
|
||||
|
|
||||
LL | unsafe { asm!("{}", const addr_of!(FOO)) };
|
||||
| ^^^^^^-------------
|
||||
| |
|
||||
| is a `*const u8`
|
||||
|
|
||||
= help: `const` operands must be of an integer type
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user