Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_transmute/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ mod rustc {
.enumerate()
.find(|(_, field_def)| name == field_def.name)
.unwrap_or_else(|| panic!("There were no fields named `{name}`."));
fields[field_idx].to_leaf() == ScalarInt::TRUE
fields[field_idx].try_to_leaf().map(|leaf| leaf == ScalarInt::TRUE)
};

Some(Self {
alignment: get_field(sym::alignment),
lifetimes: get_field(sym::lifetimes),
safety: get_field(sym::safety),
validity: get_field(sym::validity),
alignment: get_field(sym::alignment)?,
lifetimes: get_field(sym::lifetimes)?,
safety: get_field(sym::safety)?,
validity: get_field(sym::validity)?,
})
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/ui/transmutability/non_scalar_alignment_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![feature(min_generic_const_args)]
//~^ WARN the feature `min_generic_const_args` is incomplete

#![feature(transmutability)]

mod assert {
use std::mem::{Assume, TransmuteFrom};
struct Dst {}
fn is_maybe_transmutable()
where
Dst: TransmuteFrom<
(),
{
Assume {
alignment: Assume {},
//~^ ERROR struct expression with missing field initialiser for `alignment`
//~| ERROR struct expression with missing field initialiser for `lifetimes`
//~| ERROR struct expression with missing field initialiser for `safety`
//~| ERROR struct expression with missing field initialiser for `validity`
lifetimes: const { true },
safety: const { true },
validity: const { true },
}
},
>,
{
}
}

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/transmutability/non_scalar_alignment_value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/non_scalar_alignment_value.rs:1:12
|
LL | #![feature(min_generic_const_args)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
= note: `#[warn(incomplete_features)]` on by default

error: struct expression with missing field initialiser for `alignment`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^

error: struct expression with missing field initialiser for `lifetimes`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^

error: struct expression with missing field initialiser for `safety`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^

error: struct expression with missing field initialiser for `validity`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^

error: aborting due to 4 previous errors; 1 warning emitted

Loading