Skip to content

Commit

Permalink
Rollup merge of #73969 - davidtwco:issue-73914-checkedadd-temp-genera…
Browse files Browse the repository at this point in the history
…tor-interior, r=matthewjasper

mir: mark mir construction temporaries as internal

Fixes #73914.

This PR marks temporaries from MIR construction as internal such that they are skipped in `sanitize_witness` (where each MIR local is checked to have been contained within the generator interior computed during typeck). This resolves an ICE whereby the construction of checked addition introduced a `(u64, bool)` temporary which was not in the HIR and thus not in the generator interior.

r? @matthewjasper
  • Loading branch information
Manishearth authored Jul 7, 2020
2 parents ca5b64d + 1b747a0 commit 62ba1bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_mir_build/build/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// N.B., **No cleanup is scheduled for this temporary.** You should
/// call `schedule_drop` once the temporary is initialized.
crate fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
let temp = self.local_decls.push(LocalDecl::new(ty, span));
// Mark this local as internal to avoid temporaries with types not present in the
// user's code resulting in ICEs from the generator transform.
let temp = self.local_decls.push(LocalDecl::new(ty, span).internal());
let place = Place::from(temp);
debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
place
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/issue-73914.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// build-pass
// compile-flags:-Copt-level=0
// edition:2018

struct S<T>(std::marker::PhantomData<T>);

impl<T> std::ops::Deref for S<T> {
type Target = T;

fn deref(&self) -> &Self::Target {
todo!()
}
}
impl<T> std::ops::DerefMut for S<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
todo!()
}
}

async fn new() -> S<u64> {
todo!()
}

async fn crash() {
*new().await = 1 + 1;
}

fn main() {
let _ = crash();
}

0 comments on commit 62ba1bf

Please sign in to comment.