mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 17:33:07 +00:00
Turn ICE for dangling pointers into error
This commit is contained in:
parent
4e88b7363b
commit
e70b63458a
@ -737,6 +737,11 @@ where
|
|||||||
if self.alloc_map.contains_key(&alloc) {
|
if self.alloc_map.contains_key(&alloc) {
|
||||||
// Not yet interned, so proceed recursively
|
// Not yet interned, so proceed recursively
|
||||||
self.intern_static(alloc, mutability)?;
|
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(())
|
Ok(())
|
||||||
|
15
src/test/ui/consts/dangling-alloc-id-ice.rs
Normal file
15
src/test/ui/consts/dangling-alloc-id-ice.rs
Normal 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() {}
|
13
src/test/ui/consts/dangling-alloc-id-ice.stderr
Normal file
13
src/test/ui/consts/dangling-alloc-id-ice.stderr
Normal 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
|
||||||
|
|
10
src/test/ui/consts/dangling_raw_ptr.rs
Normal file
10
src/test/ui/consts/dangling_raw_ptr.rs
Normal 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;
|
||||||
|
}
|
13
src/test/ui/consts/dangling_raw_ptr.stderr
Normal file
13
src/test/ui/consts/dangling_raw_ptr.stderr
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user