forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// ICE: ImmTy { imm: Scalar(alloc1), ty: *const dyn Sync } input to a fat-to-thin cast (*const dyn Sync -> *const usize | ||
// or with -Zextra-const-ub-checks: expected wide pointer extra data (e.g. slice length or trait object vtable) | ||
// issue: rust-lang/rust#121413 | ||
//@ compile-flags: -Zextra-const-ub-checks | ||
// ignore-tidy-linelength | ||
#![feature(const_refs_to_static)] | ||
const REF_INTERIOR_MUT: &usize = { | ||
static FOO: Sync = AtomicUsize::new(0); | ||
//~^ ERROR failed to resolve: use of undeclared type `AtomicUsize` | ||
//~| WARN trait objects without an explicit `dyn` are deprecated | ||
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time | ||
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time | ||
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
unsafe { &*(&FOO as *const _ as *const usize) } | ||
}; | ||
pub fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
error[E0433]: failed to resolve: use of undeclared type `AtomicUsize` | ||
--> $DIR/const_refs_to_static-ice-121413.rs:8:24 | ||
| | ||
LL | static FOO: Sync = AtomicUsize::new(0); | ||
| ^^^^^^^^^^^ use of undeclared type `AtomicUsize` | ||
| | ||
help: consider importing this struct | ||
| | ||
LL + use std::sync::atomic::AtomicUsize; | ||
| | ||
|
||
warning: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/const_refs_to_static-ice-121413.rs:8:17 | ||
| | ||
LL | static FOO: Sync = AtomicUsize::new(0); | ||
| ^^^^ | ||
| | ||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> | ||
= note: `#[warn(bare_trait_objects)]` on by default | ||
help: if this is an object-safe trait, use `dyn` | ||
| | ||
LL | static FOO: dyn Sync = AtomicUsize::new(0); | ||
| +++ | ||
|
||
error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time | ||
--> $DIR/const_refs_to_static-ice-121413.rs:8:17 | ||
| | ||
LL | static FOO: Sync = AtomicUsize::new(0); | ||
| ^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)` | ||
|
||
error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time | ||
--> $DIR/const_refs_to_static-ice-121413.rs:8:24 | ||
| | ||
LL | static FOO: Sync = AtomicUsize::new(0); | ||
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)` | ||
= note: constant expressions must have a statically known size | ||
|
||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0277, E0433. | ||
For more information about an error, try `rustc --explain E0277`. |