1
Fork 0

Auto merge of #55262 - oli-obk:dangling_alloc_id_ice, r=RalfJung

Change the ICE from #55223 to a hard error

cc @SimonSapin

r? @RalfJung

fixes https://github.com/rust-lang/rust/issues/55287
This commit is contained in:
bors 2018-11-06 23:36:13 +00:00
commit ddd4b194a0
5 changed files with 56 additions and 0 deletions

View file

@ -730,6 +730,11 @@ where
if self.alloc_map.contains_key(&alloc) {
// Not yet interned, so proceed recursively
self.intern_static(alloc, mutability)?;
} else if self.dead_alloc_map.contains_key(&alloc) {
// dangling pointer
return err!(ValidationFailure(
"encountered dangling pointer in final constant".into(),
))
}
}
Ok(())

View file

@ -0,0 +1,15 @@
// https://github.com/rust-lang/rust/issues/55223
#![feature(const_let)]
union Foo<'a> {
y: &'a (),
long_live_the_unit: &'static (),
}
const FOO: &() = { //~ ERROR any use of this value will cause an error
let y = ();
unsafe { Foo { y: &y }.long_live_the_unit }
};
fn main() {}

View file

@ -0,0 +1,13 @@
error: any use of this value will cause an error
--> $DIR/dangling-alloc-id-ice.rs:10:1
|
LL | / const FOO: &() = { //~ ERROR any use of this value will cause an error
LL | | let y = ();
LL | | unsafe { Foo { y: &y }.long_live_the_unit }
LL | | };
| |__^ type validation failed: encountered dangling pointer in final constant
|
= note: #[deny(const_err)] on by default
error: aborting due to previous error

View file

@ -0,0 +1,10 @@
#![feature(const_let)]
const FOO: *const u32 = { //~ ERROR any use of this value will cause an error
let x = 42;
&x
};
fn main() {
let x = FOO;
}

View file

@ -0,0 +1,13 @@
error: any use of this value will cause an error
--> $DIR/dangling_raw_ptr.rs:3:1
|
LL | / const FOO: *const u32 = { //~ ERROR any use of this value will cause an error
LL | | let x = 42;
LL | | &x
LL | | };
| |__^ type validation failed: encountered dangling pointer in final constant
|
= note: #[deny(const_err)] on by default
error: aborting due to previous error