Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a48cebc
Coroutine variant fields can be uninitialized
tmiasko Dec 12, 2023
fb32eb3
Clean up CodeBlocks::next code
GuillaumeGomez Dec 12, 2023
e9b16cc
rustc_passes: Enforce `rustc::potential_query_instability` lint
Enselic Dec 12, 2023
d3cb25f
Add `rustX` check to codeblock attributes lint
GuillaumeGomez Dec 12, 2023
98aa20b
Add test for `rustX` codeblock attribute
GuillaumeGomez Dec 12, 2023
bb0fd66
Follow guidelines for lint suggestions
GuillaumeGomez Dec 12, 2023
6892fcd
simplify merging of two vecs
matthiaskrgr Dec 12, 2023
d707461
clippy::complexity fixes
matthiaskrgr Dec 12, 2023
f1342f3
Clean up variables in `search.js`
GuillaumeGomez Dec 12, 2023
58327c1
Add a test for a codeblock with multiple invalid attributes
GuillaumeGomez Dec 12, 2023
046f2de
Typo
smoelius Dec 12, 2023
2a1acc2
Update compiler/rustc_pattern_analysis/src/constructor.rs
matthiaskrgr Dec 12, 2023
5ae76ae
Rollup merge of #118870 - Enselic:rustc_passes-query-stability, r=com…
GuillaumeGomez Dec 12, 2023
a5bd88b
Rollup merge of #118871 - tmiasko:coroutine-maybe-uninit-fields, r=co…
GuillaumeGomez Dec 12, 2023
57d8f24
Rollup merge of #118872 - GuillaumeGomez:codeblock-attr-lint, r=notri…
GuillaumeGomez Dec 12, 2023
a0c6c64
Rollup merge of #118884 - matthiaskrgr:auszweimacheins, r=Nadrieril
GuillaumeGomez Dec 12, 2023
244429d
Rollup merge of #118885 - matthiaskrgr:compl_2023, r=compiler-errors
GuillaumeGomez Dec 12, 2023
c8755d8
Rollup merge of #118886 - GuillaumeGomez:clean-up-search-vars, r=notr…
GuillaumeGomez Dec 12, 2023
ee9b563
Rollup merge of #118887 - smoelius:patch-1, r=Nilstrieb
GuillaumeGomez Dec 12, 2023
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
Next Next commit
Coroutine variant fields can be uninitialized
Wrap coroutine variant fields in MaybeUninit to indicate that they
might be uninitialized. Otherwise an uninhabited field will make
the entire variant uninhabited and introduce undefined behaviour.

The analogous issue in the prefix of coroutine layout was addressed by
6fae7f8.
  • Loading branch information
tmiasko committed Dec 12, 2023
commit a48cebc4b833bc0df9242ae9845a79299b4cf079
5 changes: 4 additions & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,10 @@ fn coroutine_layout<'tcx>(
Assigned(_) => bug!("assignment does not match variant"),
Ineligible(_) => false,
})
.map(|local| subst_field(info.field_tys[*local].ty));
.map(|local| {
let field_ty = subst_field(info.field_tys[*local].ty);
Ty::new_maybe_uninit(tcx, field_ty)
});

let mut variant = univariant_uninterned(
cx,
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/async-await/future-sizes/async-awaiting-fut.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ print-type-size variant `Panicked`: 1024 bytes
print-type-size upvar `.arg`: 1024 bytes
print-type-size type: `std::mem::ManuallyDrop<bool>`: 1 bytes, alignment: 1 bytes
print-type-size field `.value`: 1 bytes
print-type-size type: `std::mem::ManuallyDrop<{async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19}>`: 1 bytes, alignment: 1 bytes
print-type-size field `.value`: 1 bytes
print-type-size type: `std::mem::MaybeUninit<bool>`: 1 bytes, alignment: 1 bytes
print-type-size variant `MaybeUninit`: 1 bytes
print-type-size field `.uninit`: 0 bytes
print-type-size field `.value`: 1 bytes
print-type-size type: `std::mem::MaybeUninit<{async fn body@$DIR/async-awaiting-fut.rs:6:17: 6:19}>`: 1 bytes, alignment: 1 bytes
print-type-size variant `MaybeUninit`: 1 bytes
print-type-size field `.uninit`: 0 bytes
print-type-size field `.value`: 1 bytes
print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `Ready`: 0 bytes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
error[E0391]: cycle detected when computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}`
error[E0391]: cycle detected when computing layout of `core::mem::maybe_uninit::MaybeUninit<{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}>`
|
= note: ...which requires computing layout of `<<A as First>::Second as Second>::{opaque#0}`...
= note: ...which again requires computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}`, completing the cycle
= note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}>`...
= note: ...which requires computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}`...
= note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<<<A as First>::Second as Second>::{opaque#0}>`...
= note: ...which again requires computing layout of `core::mem::maybe_uninit::MaybeUninit<{async fn body@$DIR/indirect-recursion-issue-112047.rs:33:27: 35:6}>`, completing the cycle
= note: cycle used when computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:6:13: 8:6}`
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

Expand Down
37 changes: 37 additions & 0 deletions tests/ui/coroutine/uninhabited-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Test that uninhabited saved local doesn't make the entire variant uninhabited.
// run-pass
#![allow(unused)]
#![feature(assert_matches)]
#![feature(coroutine_trait)]
#![feature(coroutines)]
#![feature(never_type)]
use std::assert_matches::assert_matches;
use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::Pin;

fn conjure<T>() -> T { loop {} }

fn run<T>(x: bool, y: bool) {
let mut c = || {
if x {
let a : T;
if y {
a = conjure::<T>();
}
yield ();
} else {
let a : T;
if y {
a = conjure::<T>();
}
yield ();
}
};
assert_matches!(Pin::new(&mut c).resume(()), CoroutineState::Yielded(()));
assert_matches!(Pin::new(&mut c).resume(()), CoroutineState::Complete(()));
}

fn main() {
run::<!>(false, false);
}
6 changes: 6 additions & 0 deletions tests/ui/print_type_sizes/coroutine_discr_placement.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ print-type-size padding: 3 bytes
print-type-size local `.z`: 4 bytes, alignment: 4 bytes
print-type-size variant `Returned`: 0 bytes
print-type-size variant `Panicked`: 0 bytes
print-type-size type: `std::mem::ManuallyDrop<i32>`: 4 bytes, alignment: 4 bytes
print-type-size field `.value`: 4 bytes
print-type-size type: `std::mem::MaybeUninit<i32>`: 4 bytes, alignment: 4 bytes
print-type-size variant `MaybeUninit`: 4 bytes
print-type-size field `.uninit`: 0 bytes
print-type-size field `.value`: 4 bytes