Skip to content

Commit 8a19fe1

Browse files
committed
Auto merge of #150408 - jackh726:multistep-coercion-cleanup, r=<try>
[CRATER] Require equality for symmetric LUB coercion
2 parents 5944b12 + 370fc9b commit 8a19fe1

14 files changed

Lines changed: 756 additions & 205 deletions

File tree

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174174
// We won't diverge unless the scrutinee or all arms diverge.
175175
self.diverges.set(scrut_diverges | all_arms_diverge);
176176

177-
coercion.complete(self)
177+
let cause = ObligationCause::dummy();
178+
//let coerce_never = self.tcx.expr_guaranteed_to_constitute_read_for_never(expr);
179+
let coerce_never = true;
180+
tracing::debug!("calling complete in check_expr_match");
181+
coercion.complete(self, &cause, coerce_never)
178182
}
179183

180184
fn explain_never_type_coerced_to_unit(

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ pub(super) fn check_fn<'a, 'tcx>(
134134
// really expected to fail, since the coercions would have failed
135135
// earlier when trying to find a LUB.
136136
let coercion = fcx.ret_coercion.take().unwrap().into_inner();
137-
let mut actual_return_ty = coercion.complete(fcx);
137+
let cause = ObligationCause::dummy();
138+
tracing::debug!("calling complete in check_fn");
139+
let mut actual_return_ty = coercion.complete(fcx, &cause, true);
138140
debug!("actual_return_ty = {:?}", actual_return_ty);
139141
if let ty::Dynamic(..) = declared_ret_ty.kind() {
140142
// We have special-cased the case where the function is declared

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
1111
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, InferResult};
1212
use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
1313
use rustc_macros::{TypeFoldable, TypeVisitable};
14-
use rustc_middle::span_bug;
14+
use rustc_middle::{bug, span_bug};
1515
use rustc_middle::ty::{
1616
self, ClosureKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
1717
TypeVisitableExt, TypeVisitor,
@@ -340,6 +340,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
340340
(None, None)
341341
}
342342
},
343+
ty::Closure(_, args) => match closure_kind {
344+
hir::ClosureKind::Closure => {
345+
let closure_args = args.as_closure();
346+
let sig = closure_args.sig();
347+
tracing::debug!(?closure_args, ?sig);
348+
let sig = sig.map_bound(|sig| {
349+
let inputs = sig.inputs_and_output.first().unwrap();
350+
let inputs = match inputs.kind() {
351+
ty::Tuple(tys) => tys,
352+
_ => bug!(),
353+
};
354+
let output = sig.inputs_and_output.last().unwrap();
355+
let inputs_and_output = self.tcx.mk_type_list(&inputs.iter().chain([*output]).collect::<smallvec::SmallVec<[_; 4]>>());
356+
ty::FnSig {
357+
abi: sig.abi,
358+
safety: sig.safety,
359+
c_variadic: sig.c_variadic,
360+
inputs_and_output,
361+
}
362+
});
363+
tracing::debug!(?sig);
364+
let expected_sig = ExpectedSig { cause_span: None, sig };
365+
let kind = closure_args.kind_ty().to_opt_closure_kind();
366+
(Some(expected_sig), kind)
367+
}
368+
hir::ClosureKind::Coroutine(_) | hir::ClosureKind::CoroutineClosure(_) => {
369+
(None, None)
370+
}
371+
}
343372
_ => (None, None),
344373
}
345374
}

0 commit comments

Comments
 (0)