Skip to content

Commit

Permalink
Auto merge of #55262 - oli-obk:dangling_alloc_id_ice, r=RalfJung
Browse files Browse the repository at this point in the history
Change the ICE from #55223 to a hard error

cc @SimonSapin

r? @RalfJung

fixes #55287
  • Loading branch information
bors committed Nov 6, 2018
2 parents 15d7704 + e70b634 commit ddd4b19
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc_mir/interpret/memory.rs
Expand Up @@ -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(())
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/consts/dangling-alloc-id-ice.rs
@@ -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() {}
13 changes: 13 additions & 0 deletions src/test/ui/consts/dangling-alloc-id-ice.stderr
@@ -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

10 changes: 10 additions & 0 deletions src/test/ui/consts/dangling_raw_ptr.rs
@@ -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;
}
13 changes: 13 additions & 0 deletions src/test/ui/consts/dangling_raw_ptr.stderr
@@ -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

0 comments on commit ddd4b19

Please sign in to comment.