Skip to content
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

Bail out of drop elaboration when encountering error types #120802

Merged
merged 1 commit into from
Feb 13, 2024
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
5 changes: 4 additions & 1 deletion compiler/rustc_mir_dataflow/src/move_paths/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_index::IndexVec;
use rustc_middle::mir::tcx::{PlaceTy, RvalueInitializationState};
use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use smallvec::{smallvec, SmallVec};

use std::mem;
Expand Down Expand Up @@ -132,6 +132,9 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
let body = self.builder.body;
let tcx = self.builder.tcx;
let place_ty = place_ref.ty(body, tcx).ty;
if place_ty.references_error() {
return MovePathResult::Error;
}
match elem {
ProjectionElem::Deref => match place_ty.kind() {
ty::Ref(..) | ty::RawPtr(..) => {
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/drop/drop_elaboration_with_errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// can't use build-fail, because this also fails check-fail, but
// the ICE from #120787 only reproduces on build-fail.
// compile-flags: --emit=mir

#![feature(type_alias_impl_trait)]

struct Foo {
field: String,
}

type Tait = impl Sized;

fn ice_cold(beverage: Tait) {
let Foo { field } = beverage;
_ = field;
}

fn main() {
Ok(()) //~ ERROR mismatched types
}
14 changes: 14 additions & 0 deletions tests/ui/drop/drop_elaboration_with_errors.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/drop_elaboration_with_errors.rs:19:5
|
LL | fn main() {
| - expected `()` because of default return type
LL | Ok(())
| ^^^^^^ expected `()`, found `Result<(), _>`
|
= note: expected unit type `()`
found enum `Result<(), _>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading