Skip to content

Commit b3da04a

Browse files
Check both align and size in PointerSized
1 parent da3c539 commit b3da04a

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10691069
let usize_layout =
10701070
self.tcx().layout_of(ty::ParamEnv::empty().and(self.tcx().types.usize)).unwrap().layout;
10711071
if let Ok(layout) = self.tcx().layout_of(obligation.param_env.and(self_ty))
1072-
&& layout.layout.size().bytes() == usize_layout.size().bytes()
1072+
&& layout.layout.size() == usize_layout.size()
1073+
&& layout.layout.align() == usize_layout.align()
10731074
{
10741075
candidates.vec.push(BuiltinCandidate { has_nested: false });
10751076
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/align.rs:4:12
3+
|
4+
LL | #![feature(dyn_star)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/align.rs:4:12
3+
|
4+
LL | #![feature(dyn_star)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: `AlignedUsize` needs to be a pointer-sized type
11+
--> $DIR/align.rs:15:13
12+
|
13+
LL | let x = AlignedUsize(12) as dyn* Debug;
14+
| ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-sized type
15+
|
16+
= help: the trait `PointerSized` is not implemented for `AlignedUsize`
17+
18+
error: aborting due to previous error; 1 warning emitted
19+
20+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/dyn-star/align.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// revisions: normal over_aligned
2+
//[normal] check-pass
3+
4+
#![feature(dyn_star)]
5+
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
6+
7+
use std::fmt::Debug;
8+
9+
#[cfg_attr(over_aligned, repr(C, align(1024)))]
10+
#[cfg_attr(not(over_aligned), repr(C))]
11+
#[derive(Debug)]
12+
struct AlignedUsize(usize);
13+
14+
fn main() {
15+
let x = AlignedUsize(12) as dyn* Debug;
16+
//[over_aligned]~^ ERROR `AlignedUsize` needs to be a pointer-sized type
17+
}

0 commit comments

Comments
 (0)