Skip to content

Commit 929e983

Browse files
authored
Unrolled build for rust-lang#120817
Rollup merge of rust-lang#120817 - compiler-errors:more-mir-errors, r=oli-obk Fix more `ty::Error` ICEs in MIR passes Fixes rust-lang#120791 - Add a check for `ty::Error` in the `ByMove` coroutine pass Fixes rust-lang#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
2 parents 8fb67fb + e32c1dd commit 929e983

File tree

7 files changed

+73
-12
lines changed

7 files changed

+73
-12
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl<'tcx> MirPass<'tcx> for Validator {
6060
ty::Closure(..) => Abi::RustCall,
6161
ty::CoroutineClosure(..) => Abi::RustCall,
6262
ty::Coroutine(..) => Abi::Rust,
63+
// No need to do MIR validation on error bodies
64+
ty::Error(_) => return,
6365
_ => {
6466
span_bug!(body.span, "unexpected body ty: {:?} phase {:?}", body_ty, mir_phase)
6567
}

compiler/rustc_mir_build/src/build/mod.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -675,16 +675,32 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
675675
))),
676676
)
677677
}
678-
ty::CoroutineClosure(did, _args) => {
679-
// FIXME(async_closures): Recover the proper error signature
680-
let inputs = tcx
681-
.closure_user_provided_sig(did.expect_local())
682-
.value
683-
.skip_binder()
684-
.inputs();
685-
686-
let err = Ty::new_error(tcx, guar);
687-
(inputs.iter().map(|_| err).collect(), err, None)
678+
ty::CoroutineClosure(did, args) => {
679+
let args = args.as_coroutine_closure();
680+
let sig = tcx.liberate_late_bound_regions(
681+
def_id.to_def_id(),
682+
args.coroutine_closure_sig(),
683+
);
684+
let self_ty = match args.kind() {
685+
ty::ClosureKind::Fn => {
686+
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
687+
}
688+
ty::ClosureKind::FnMut => {
689+
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, closure_ty)
690+
}
691+
ty::ClosureKind::FnOnce => closure_ty,
692+
};
693+
(
694+
[self_ty].into_iter().chain(sig.tupled_inputs_ty.tuple_fields()).collect(),
695+
sig.to_coroutine(
696+
tcx,
697+
args.parent_args(),
698+
args.kind_ty(),
699+
tcx.coroutine_for_closure(*did),
700+
Ty::new_error(tcx, guar),
701+
),
702+
None,
703+
)
688704
}
689705
ty::Error(_) => (vec![closure_ty, closure_ty], closure_ty, None),
690706
kind => {

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxIndexSet;
77
use rustc_hir as hir;
88
use rustc_middle::mir::visit::MutVisitor;
99
use rustc_middle::mir::{self, dump_mir, MirPass};
10-
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt};
10+
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, TypeVisitableExt};
1111
use rustc_target::abi::FieldIdx;
1212

1313
pub struct ByMoveBody;
@@ -23,7 +23,10 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
2323
return;
2424
};
2525
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
26-
let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!() };
26+
if coroutine_ty.references_error() {
27+
return;
28+
}
29+
let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!("{body:#?}") };
2730

2831
let coroutine_kind = args.as_coroutine().kind_ty().to_opt_closure_kind().unwrap();
2932
if coroutine_kind == ty::ClosureKind::FnOnce {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2021
2+
3+
#![feature(async_closure)]
4+
5+
// Don't ICE in ByMove shim builder when MIR body is tainted by writeback errors
6+
7+
fn main() {
8+
let _ = async || {
9+
used_fn();
10+
//~^ ERROR cannot find function `used_fn` in this scope
11+
0
12+
};
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `used_fn` in this scope
2+
--> $DIR/tainted-body.rs:9:9
3+
|
4+
LL | used_fn();
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

tests/ui/mir/validate/error-body.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: -Zvalidate-mir
2+
3+
fn _test() {
4+
let x = || 45;
5+
missing();
6+
//~^ ERROR cannot find function `missing` in this scope
7+
}
8+
9+
fn main() {}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find function `missing` in this scope
2+
--> $DIR/error-body.rs:5:5
3+
|
4+
LL | missing();
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)