Rollup merge of #120817 - compiler-errors:more-mir-errors, r=oli-obk
Fix more `ty::Error` ICEs in MIR passes Fixes #120791 - Add a check for `ty::Error` in the `ByMove` coroutine pass Fixes #120816 - Add a check for `ty::Error` in the MIR validator Also a drive-by fix for a FIXME I had asked oli to add r? oli-obk
This commit is contained in:
commit
116efb5bb1
7 changed files with 73 additions and 12 deletions
|
@ -60,6 +60,8 @@ impl<'tcx> MirPass<'tcx> for Validator {
|
||||||
ty::Closure(..) => Abi::RustCall,
|
ty::Closure(..) => Abi::RustCall,
|
||||||
ty::CoroutineClosure(..) => Abi::RustCall,
|
ty::CoroutineClosure(..) => Abi::RustCall,
|
||||||
ty::Coroutine(..) => Abi::Rust,
|
ty::Coroutine(..) => Abi::Rust,
|
||||||
|
// No need to do MIR validation on error bodies
|
||||||
|
ty::Error(_) => return,
|
||||||
_ => {
|
_ => {
|
||||||
span_bug!(body.span, "unexpected body ty: {:?} phase {:?}", body_ty, mir_phase)
|
span_bug!(body.span, "unexpected body ty: {:?} phase {:?}", body_ty, mir_phase)
|
||||||
}
|
}
|
||||||
|
|
|
@ -675,16 +675,32 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
|
||||||
))),
|
))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ty::CoroutineClosure(did, _args) => {
|
ty::CoroutineClosure(did, args) => {
|
||||||
// FIXME(async_closures): Recover the proper error signature
|
let args = args.as_coroutine_closure();
|
||||||
let inputs = tcx
|
let sig = tcx.liberate_late_bound_regions(
|
||||||
.closure_user_provided_sig(did.expect_local())
|
def_id.to_def_id(),
|
||||||
.value
|
args.coroutine_closure_sig(),
|
||||||
.skip_binder()
|
);
|
||||||
.inputs();
|
let self_ty = match args.kind() {
|
||||||
|
ty::ClosureKind::Fn => {
|
||||||
let err = Ty::new_error(tcx, guar);
|
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
|
||||||
(inputs.iter().map(|_| err).collect(), err, None)
|
}
|
||||||
|
ty::ClosureKind::FnMut => {
|
||||||
|
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
|
||||||
|
}
|
||||||
|
ty::ClosureKind::FnOnce => closure_ty,
|
||||||
|
};
|
||||||
|
(
|
||||||
|
[self_ty].into_iter().chain(sig.tupled_inputs_ty.tuple_fields()).collect(),
|
||||||
|
sig.to_coroutine(
|
||||||
|
tcx,
|
||||||
|
args.parent_args(),
|
||||||
|
args.kind_ty(),
|
||||||
|
tcx.coroutine_for_closure(*did),
|
||||||
|
Ty::new_error(tcx, guar),
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ty::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
|
ty::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
|
||||||
kind => {
|
kind => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::mir::visit::MutVisitor;
|
use rustc_middle::mir::visit::MutVisitor;
|
||||||
use rustc_middle::mir::{self, dump_mir, MirPass};
|
use rustc_middle::mir::{self, dump_mir, MirPass};
|
||||||
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt};
|
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, TypeVisitableExt};
|
||||||
use rustc_target::abi::FieldIdx;
|
use rustc_target::abi::FieldIdx;
|
||||||
|
|
||||||
pub struct ByMoveBody;
|
pub struct ByMoveBody;
|
||||||
|
@ -23,7 +23,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
|
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
|
||||||
let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!() };
|
if coroutine_ty.references_error() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!("{body:#?}") };
|
||||||
|
|
||||||
let coroutine_kind = args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap();
|
let coroutine_kind = args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap();
|
||||||
if coroutine_kind == ty::ClosureKind::FnOnce {
|
if coroutine_kind == ty::ClosureKind::FnOnce {
|
||||||
|
|
13
tests/ui/async-await/async-closures/tainted-body.rs
Normal file
13
tests/ui/async-await/async-closures/tainted-body.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// edition:2021
|
||||||
|
|
||||||
|
#![feature(async_closure)]
|
||||||
|
|
||||||
|
// Don't ICE in ByMove shim builder when MIR body is tainted by writeback errors
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = async || {
|
||||||
|
used_fn();
|
||||||
|
//~^ ERROR cannot find function `used_fn` in this scope
|
||||||
|
0
|
||||||
|
};
|
||||||
|
}
|
9
tests/ui/async-await/async-closures/tainted-body.stderr
Normal file
9
tests/ui/async-await/async-closures/tainted-body.stderr
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0425]: cannot find function `used_fn` in this scope
|
||||||
|
--> $DIR/tainted-body.rs:9:9
|
||||||
|
|
|
||||||
|
LL | used_fn();
|
||||||
|
| ^^^^^^^ not found in this scope
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0425`.
|
9
tests/ui/mir/validate/error-body.rs
Normal file
9
tests/ui/mir/validate/error-body.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// compile-flags: -Zvalidate-mir
|
||||||
|
|
||||||
|
fn _test() {
|
||||||
|
let x = || 45;
|
||||||
|
missing();
|
||||||
|
//~^ ERROR cannot find function `missing` in this scope
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
9
tests/ui/mir/validate/error-body.stderr
Normal file
9
tests/ui/mir/validate/error-body.stderr
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0425]: cannot find function `missing` in this scope
|
||||||
|
--> $DIR/error-body.rs:5:5
|
||||||
|
|
|
||||||
|
LL | missing();
|
||||||
|
| ^^^^^^^ not found in this scope
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0425`.
|
Loading…
Add table
Add a link
Reference in a new issue