Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d21aa86
unicode-table-generator: match bin name with tool name
jieyouxu Oct 13, 2024
3748c5e
bootstrap: register `src/tools/unicode-table-generator` as a runnable…
jieyouxu Oct 13, 2024
75a9c86
unicode-table-generator: sync comments
jieyouxu Oct 13, 2024
be89da5
triagebot: add reminder for `library/core/src/unicode/unicode_data.rs…
jieyouxu Oct 13, 2024
f5577a8
fix missing rustfmt and clippy for msi
heiseish Oct 7, 2024
2316749
fix missing rustfmt for apple darwin
heiseish Oct 7, 2024
e78d788
Allow `#[deny(..)]` inside `#[forbid(..)]` as a no-op with a warning
Noratrieb Oct 17, 2024
1af9d11
Expand test coverage for deny-inside-forbid interactions
jieyouxu Oct 18, 2024
28fce83
Align boolean option descriptions in `configure.py`
clubby789 Oct 19, 2024
3310419
Make `llvm::set_section` take a `&CStr`
Zalathar Oct 18, 2024
e32a5be
compiletest: disambiguate between `tidy` and `tidy` (html version)
jieyouxu Oct 20, 2024
eca5359
add latest crash tests
matthiaskrgr Oct 20, 2024
ef5a56f
Remove outdated comment
ChrisDenton Oct 20, 2024
68d1fd9
compiler: pre-move code for fixing enum layout ICEs
workingjubilee Oct 17, 2024
9f4c915
compiler: Reject impossible reprs during enum layout
workingjubilee Oct 20, 2024
7b714d4
Rollup merge of #121560 - Noratrieb:stop-lint-macro-nonsense, r=jieyouxu
matthiaskrgr Oct 20, 2024
17ac4c8
Rollup merge of #131365 - heiseish:fix-issue-101993, r=Mark-Simulacrum
matthiaskrgr Oct 20, 2024
fb42a45
Rollup merge of #131647 - jieyouxu:unicode-table-generator, r=Mark-Si…
matthiaskrgr Oct 20, 2024
6d43de6
Rollup merge of #131843 - workingjubilee:thaw-impossible-reprs, r=luk…
matthiaskrgr Oct 20, 2024
2f77343
Rollup merge of #131926 - clubby789:configure-enable, r=Kobzol
matthiaskrgr Oct 20, 2024
0d4cf05
Rollup merge of #131961 - jieyouxu:dirty, r=Zalathar
matthiaskrgr Oct 20, 2024
da8a115
Rollup merge of #131962 - Zalathar:llvm-set-section, r=Swatinem,worki…
matthiaskrgr Oct 20, 2024
5533c96
Rollup merge of #131964 - matthiaskrgr:crashes2010, r=jieyouxu
matthiaskrgr Oct 20, 2024
a860657
Rollup merge of #131965 - ChrisDenton:outdated-comment, r=jieyouxu
matthiaskrgr Oct 20, 2024
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
9 changes: 9 additions & 0 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub enum LayoutCalculatorError<F> {

/// A union had no fields.
EmptyUnion,

/// The fields or variants have irreconcilable reprs
ReprConflict,
}

impl<F> LayoutCalculatorError<F> {
Expand All @@ -64,6 +67,7 @@ impl<F> LayoutCalculatorError<F> {
}
LayoutCalculatorError::SizeOverflow => LayoutCalculatorError::SizeOverflow,
LayoutCalculatorError::EmptyUnion => LayoutCalculatorError::EmptyUnion,
LayoutCalculatorError::ReprConflict => LayoutCalculatorError::ReprConflict,
}
}

Expand All @@ -77,6 +81,7 @@ impl<F> LayoutCalculatorError<F> {
}
LayoutCalculatorError::SizeOverflow => "size overflow",
LayoutCalculatorError::EmptyUnion => "type is a union with no fields",
LayoutCalculatorError::ReprConflict => "type has an invalid repr",
})
}
}
Expand Down Expand Up @@ -514,6 +519,10 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
}

let dl = self.cx.data_layout();
// bail if the enum has an incoherent repr that cannot be computed
if repr.packed() {
return Err(LayoutCalculatorError::ReprConflict);
}

let calculate_niche_filling_layout = || -> Option<TmpLayout<FieldIdx, VariantIdx>> {
if dont_niche_optimize_enum {
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use {rustc_abi as abi, rustc_hir as hir};
use crate::errors::{
MultipleArrayFieldsSimdType, NonPrimitiveSimdType, OversizedSimdType, ZeroLengthSimdType,
};
use crate::layout_sanity_check::sanity_check_layout;

mod invariant;

pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { layout_of, ..*providers };
Expand Down Expand Up @@ -79,7 +80,7 @@ fn layout_of<'tcx>(
record_layout_for_printing(&cx, layout);
}

sanity_check_layout(&cx, &layout);
invariant::partially_check_layout(&cx, &layout);

Ok(layout)
}
Expand Down Expand Up @@ -115,6 +116,11 @@ fn map_error<'tcx>(
cx.tcx().dcx().delayed_bug(format!("computed layout of empty union: {ty:?}"));
LayoutError::Unknown(ty)
}
LayoutCalculatorError::ReprConflict => {
// packed enums are the only known trigger of this, but others might arise
cx.tcx().dcx().delayed_bug(format!("computed impossible repr (packed enum?): {ty:?}"));
LayoutError::Unknown(ty)
}
};
error(cx, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
use rustc_target::abi::*;

/// Enforce some basic invariants on layouts.
pub(super) fn sanity_check_layout<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
pub(super) fn partially_check_layout<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
let tcx = cx.tcx();

// Type-level uninhabitedness should always imply ABI uninhabitedness.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ty_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ mod errors;
mod implied_bounds;
mod instance;
mod layout;
mod layout_sanity_check;
mod needs_drop;
mod opaque_types;
mod representability;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//@ known-bug: rust-lang/rust#126966
#![crate_type = "lib"]

mod assert {
use std::mem::{Assume, TransmuteFrom};
//~^ ERROR: use of unstable library feature 'transmutability'
//~| ERROR: use of unstable library feature 'transmutability'

pub fn is_transmutable<Src, Dst>()
where
Dst: TransmuteFrom<Src>,
//~^ ERROR: use of unstable library feature 'transmutability'
{
}
}
Expand All @@ -15,15 +19,18 @@ enum Ox00 {
}

#[repr(C, packed(2))]
//~^ ERROR: attribute should be applied to a struct
enum OxFF {
V = 0xFF,
}

fn test() {
union Superset {
a: Ox00,
//~^ ERROR: field must implement `Copy`
b: OxFF,
}

assert::is_transmutable::<Superset, Subset>();
//~^ ERROR: cannot find type `Subset`
}
68 changes: 68 additions & 0 deletions tests/ui/layout/thaw-transmute-invalid-enum.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
error[E0412]: cannot find type `Subset` in this scope
--> $DIR/thaw-transmute-invalid-enum.rs:34:41
|
LL | assert::is_transmutable::<Superset, Subset>();
| ^^^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn test<Subset>() {
| ++++++++

error[E0517]: attribute should be applied to a struct or union
--> $DIR/thaw-transmute-invalid-enum.rs:21:11
|
LL | #[repr(C, packed(2))]
| ^^^^^^^^^
LL |
LL | / enum OxFF {
LL | | V = 0xFF,
LL | | }
| |_- not a struct or union

error[E0658]: use of unstable library feature 'transmutability'
--> $DIR/thaw-transmute-invalid-enum.rs:4:20
|
LL | use std::mem::{Assume, TransmuteFrom};
| ^^^^^^
|
= note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
= help: add `#![feature(transmutability)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature 'transmutability'
--> $DIR/thaw-transmute-invalid-enum.rs:4:28
|
LL | use std::mem::{Assume, TransmuteFrom};
| ^^^^^^^^^^^^^
|
= note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
= help: add `#![feature(transmutability)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature 'transmutability'
--> $DIR/thaw-transmute-invalid-enum.rs:10:14
|
LL | Dst: TransmuteFrom<Src>,
| ^^^^^^^^^^^^^^^^^^
|
= note: see issue #99571 <https://github.com/rust-lang/rust/issues/99571> for more information
= help: add `#![feature(transmutability)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/thaw-transmute-invalid-enum.rs:29:9
|
LL | a: Ox00,
| ^^^^^^^
|
= note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
help: wrap the field type in `ManuallyDrop<...>`
|
LL | a: std::mem::ManuallyDrop<Ox00>,
| +++++++++++++++++++++++ +

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0412, E0517, E0658, E0740.
For more information about an error, try `rustc --explain E0412`.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ known-bug: rust-lang/rust#128870
//@ compile-flags: -Zvalidate-mir

#[repr(packed)]
#[repr(packed)] //~ ERROR: attribute should be applied to a struct
#[repr(u32)]
enum E {
A,
Expand All @@ -12,7 +11,7 @@ enum E {
fn main() {
union InvalidTag {
int: u32,
e: E,
e: E, //~ ERROR: field must implement `Copy`
}
let _invalid_tag = InvalidTag { int: 4 };
}
29 changes: 29 additions & 0 deletions tests/ui/layout/thaw-validate-invalid-enum.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0517]: attribute should be applied to a struct or union
--> $DIR/thaw-validate-invalid-enum.rs:3:8
|
LL | #[repr(packed)]
| ^^^^^^
LL | #[repr(u32)]
LL | / enum E {
LL | | A,
LL | | B,
LL | | C,
LL | | }
| |_- not a struct or union

error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
--> $DIR/thaw-validate-invalid-enum.rs:14:9
|
LL | e: E,
| ^^^^
|
= note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
help: wrap the field type in `ManuallyDrop<...>`
|
LL | e: std::mem::ManuallyDrop<E>,
| +++++++++++++++++++++++ +

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0517, E0740.
For more information about an error, try `rustc --explain E0517`.