Skip to content

Rollup of 6 pull requests #98910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
369555c
Implement `FusedIterator` for `std::net::[Into]Incoming`
ChayimFriedman2 May 23, 2022
c36572c
add AllocRange Debug impl; remove redundant AllocId Display impl
RalfJung Jul 2, 2022
d31cbb5
make AllocRef APIs more consistent
RalfJung Jul 2, 2022
0832d1d
more use of format! variable capture
RalfJung Jul 2, 2022
76c0429
Bump std::net::Incoming FusedIterator impl to Rust 1.64
dtolnay Jul 2, 2022
46ccde4
clean up the borrowing in rustc_hir_pretty
kadiwa4 Jul 3, 2022
7fc7780
fix interpreter validity check on Box
RalfJung Jul 3, 2022
d7edf66
move Box mess handling into general visitor
RalfJung Jul 4, 2022
eb80407
suggest `#[derive(Default)]` to enums with `#[default]`
TaKO8Ki Jul 4, 2022
c2ed087
remove unused function argument
lcnr Jul 1, 2022
f1836c4
update infer cost computation for types
lcnr Jul 1, 2022
eef34a6
stop suggesting things inside of macros
lcnr Jul 1, 2022
7952d2e
resolve vars in node substs
lcnr Jul 1, 2022
f475e88
`InferSource::GenericArg`, check for contains
lcnr Jul 1, 2022
d26ccf7
Rollup merge of #97300 - ChayimFriedman2:patch-1, r=dtolnay
Dylan-DPC Jul 5, 2022
6a9db39
Rollup merge of #98761 - lcnr:need_type_info-cont, r=estebank
Dylan-DPC Jul 5, 2022
522d52c
Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obk
Dylan-DPC Jul 5, 2022
7702c50
Rollup merge of #98847 - RalfJung:box-is-special, r=oli-obk
Dylan-DPC Jul 5, 2022
6e5f1d4
Rollup merge of #98854 - kadiwa4:rustc_hir_pretty_clean_up_borrowing,…
Dylan-DPC Jul 5, 2022
9a2274c
Rollup merge of #98873 - TaKO8Ki:suggest-default-derive-to-enum-with-…
Dylan-DPC Jul 5, 2022
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
Prev Previous commit
Next Next commit
fix interpreter validity check on Box
  • Loading branch information
RalfJung committed Jul 4, 2022
commit 7fc77806d4f66819cf9d7ebd53a3338686c08b7d
34 changes: 28 additions & 6 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,35 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
Ok(true)
}
ty::Adt(def, ..) if def.is_box() => {
let unique = self.ecx.operand_field(value, 0)?;
let nonnull = self.ecx.operand_field(&unique, 0)?;
let ptr = self.ecx.operand_field(&nonnull, 0)?;
self.check_safe_pointer(&ptr, "box")?;
// Box is special, very special. We carefully assert all the assumptions we make
// here; if this needs to be adjusted, remember to also adjust all the other
// visitors -- in particular the Stacked Borrows retagging visitor in Miri.
// Did I mention that this is a gross hack? Anyway...

// Check other fields of Box
self.walk_value(value)?;
// `Box` has two fields: the pointer we care about, and the allocator.
assert_eq!(value.layout.fields.count(), 2, "`Box` must have exactly 2 fields");
let (unique_ptr, alloc) =
(self.ecx.operand_field(value, 0)?, self.ecx.operand_field(value, 1)?);
// Unfortunately there is some type junk in the way here: `unique_ptr` is a `Unique`...
// (which means another 2 fields, the second of which is a `PhantomData`)
assert_eq!(unique_ptr.layout.fields.count(), 2);
let (nonnull_ptr, phantom) = (
self.ecx.operand_field(&unique_ptr, 0)?,
self.ecx.operand_field(&unique_ptr, 1)?,
);
assert!(
phantom.layout.ty.ty_adt_def().is_some_and(|adt| adt.is_phantom_data()),
"2nd field of `Unique` should be PhantomData but is {:?}",
phantom.layout.ty,
);
// ... that contains a `NonNull`... (gladly, only a single field here)
assert_eq!(nonnull_ptr.layout.fields.count(), 1);
let raw_ptr = self.ecx.operand_field(&nonnull_ptr, 0)?; // the actual raw ptr
// ... whose only field finally is a raw ptr we can dereference.
self.check_safe_pointer(&raw_ptr, "box")?;
// The second `Box` field is the allocator, which we recursively check for validity
// like in regular structs.
self.walk_value(&alloc)?;
Ok(true)
}
ty::FnPtr(_sig) => {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Rust MIR: a lowered representation of Rust.
#![feature(trusted_step)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![feature(is_some_with)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]

Expand Down