borrow_interior_mutable_const ICE into FN (#13877)

This PR just makes sure that we exit the function before getting an ICE
and adds a regression test. Related to #12979. We would need to keep
researching the issue, but as the ICEing code isn't that complicated,
getting a hotfix into nightly is urgent.

changelog:[`borrow_interior_mutable_const`] Fix ICE #12979
This commit is contained in:
Fridtjof Stoldt 2024-12-29 15:52:35 +00:00 committed by GitHub
commit f5f1abd8fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 19 deletions

View file

@ -47,6 +47,17 @@ impl<T> std::ops::Deref for StaticRef<T> {
}
}
// ICE regression test
mod issue12979 {
use std::cell::UnsafeCell;
const ATOMIC_TUPLE: (Vec<UnsafeCell<u8>>, ()) = (Vec::new(), ());
fn main() {
let _x = &ATOMIC_TUPLE.0;
}
}
// use a tuple to make sure referencing a field behind a pointer isn't linted.
const CELL_REF: StaticRef<(UnsafeCell<u32>,)> = unsafe { StaticRef::new(std::ptr::null()) };

View file

@ -1,5 +1,5 @@
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:54:5
--> tests/ui/borrow_interior_mutable_const/others.rs:65:5
|
LL | ATOMIC.store(1, Ordering::SeqCst);
| ^^^^^^
@ -12,7 +12,7 @@ LL | #![deny(clippy::borrow_interior_mutable_const)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:55:16
--> tests/ui/borrow_interior_mutable_const/others.rs:66:16
|
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5);
| ^^^^^^
@ -20,7 +20,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5);
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:58:22
--> tests/ui/borrow_interior_mutable_const/others.rs:69:22
|
LL | let _once_ref = &ONCE_INIT;
| ^^^^^^^^^
@ -28,7 +28,7 @@ LL | let _once_ref = &ONCE_INIT;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:59:25
--> tests/ui/borrow_interior_mutable_const/others.rs:70:25
|
LL | let _once_ref_2 = &&ONCE_INIT;
| ^^^^^^^^^
@ -36,7 +36,7 @@ LL | let _once_ref_2 = &&ONCE_INIT;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:60:27
--> tests/ui/borrow_interior_mutable_const/others.rs:71:27
|
LL | let _once_ref_4 = &&&&ONCE_INIT;
| ^^^^^^^^^
@ -44,7 +44,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:61:26
--> tests/ui/borrow_interior_mutable_const/others.rs:72:26
|
LL | let _once_mut = &mut ONCE_INIT;
| ^^^^^^^^^
@ -52,7 +52,7 @@ LL | let _once_mut = &mut ONCE_INIT;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:72:14
--> tests/ui/borrow_interior_mutable_const/others.rs:83:14
|
LL | let _ = &ATOMIC_TUPLE;
| ^^^^^^^^^^^^
@ -60,7 +60,7 @@ LL | let _ = &ATOMIC_TUPLE;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:73:14
--> tests/ui/borrow_interior_mutable_const/others.rs:84:14
|
LL | let _ = &ATOMIC_TUPLE.0;
| ^^^^^^^^^^^^
@ -68,7 +68,7 @@ LL | let _ = &ATOMIC_TUPLE.0;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:74:19
--> tests/ui/borrow_interior_mutable_const/others.rs:85:19
|
LL | let _ = &(&&&&ATOMIC_TUPLE).0;
| ^^^^^^^^^^^^
@ -76,7 +76,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0;
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:75:14
--> tests/ui/borrow_interior_mutable_const/others.rs:86:14
|
LL | let _ = &ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
@ -84,7 +84,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0];
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:76:13
--> tests/ui/borrow_interior_mutable_const/others.rs:87:13
|
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst);
| ^^^^^^^^^^^^
@ -92,7 +92,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst);
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:81:13
--> tests/ui/borrow_interior_mutable_const/others.rs:92:13
|
LL | let _ = ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
@ -100,7 +100,7 @@ LL | let _ = ATOMIC_TUPLE.0[0];
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:86:5
--> tests/ui/borrow_interior_mutable_const/others.rs:97:5
|
LL | CELL.set(2);
| ^^^^
@ -108,7 +108,7 @@ LL | CELL.set(2);
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> tests/ui/borrow_interior_mutable_const/others.rs:87:16
--> tests/ui/borrow_interior_mutable_const/others.rs:98:16
|
LL | assert_eq!(CELL.get(), 6);
| ^^^^