Skip to content

Commit 28f60ff

Browse files
committed
add test for #121413
Fixes #121413
1 parent f22a0c2 commit 28f60ff

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ICE: ImmTy { imm: Scalar(alloc1), ty: *const dyn Sync } input to a fat-to-thin cast (*const dyn Sync -> *const usize
2+
// or with -Zextra-const-ub-checks: expected wide pointer extra data (e.g. slice length or trait object vtable)
3+
// issue: rust-lang/rust#121413
4+
//@ compile-flags: -Zextra-const-ub-checks
5+
// ignore-tidy-linelength
6+
#![feature(const_refs_to_static)]
7+
const REF_INTERIOR_MUT: &usize = {
8+
static FOO: Sync = AtomicUsize::new(0);
9+
//~^ ERROR failed to resolve: use of undeclared type `AtomicUsize`
10+
//~| WARN trait objects without an explicit `dyn` are deprecated
11+
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
12+
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
13+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
14+
unsafe { &*(&FOO as *const _ as *const usize) }
15+
};
16+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error[E0433]: failed to resolve: use of undeclared type `AtomicUsize`
2+
--> $DIR/const_refs_to_static-ice-121413.rs:8:24
3+
|
4+
LL | static FOO: Sync = AtomicUsize::new(0);
5+
| ^^^^^^^^^^^ use of undeclared type `AtomicUsize`
6+
|
7+
help: consider importing this struct
8+
|
9+
LL + use std::sync::atomic::AtomicUsize;
10+
|
11+
12+
warning: trait objects without an explicit `dyn` are deprecated
13+
--> $DIR/const_refs_to_static-ice-121413.rs:8:17
14+
|
15+
LL | static FOO: Sync = AtomicUsize::new(0);
16+
| ^^^^
17+
|
18+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
19+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
20+
= note: `#[warn(bare_trait_objects)]` on by default
21+
help: if this is an object-safe trait, use `dyn`
22+
|
23+
LL | static FOO: dyn Sync = AtomicUsize::new(0);
24+
| +++
25+
26+
error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
27+
--> $DIR/const_refs_to_static-ice-121413.rs:8:17
28+
|
29+
LL | static FOO: Sync = AtomicUsize::new(0);
30+
| ^^^^ doesn't have a size known at compile-time
31+
|
32+
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)`
33+
34+
error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
35+
--> $DIR/const_refs_to_static-ice-121413.rs:8:24
36+
|
37+
LL | static FOO: Sync = AtomicUsize::new(0);
38+
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
39+
|
40+
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)`
41+
= note: constant expressions must have a statically known size
42+
43+
error: aborting due to 3 previous errors; 1 warning emitted
44+
45+
Some errors have detailed explanations: E0277, E0433.
46+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)