Skip to content

Commit 2f436d5

Browse files
committed
Auto merge of #150408 - jackh726:multistep-coercion-cleanup, r=<try>
[CRATER] Require equality for symmetric LUB coercion
2 parents 1210e9f + 690f50a commit 2f436d5

20 files changed

Lines changed: 1686 additions & 216 deletions

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ 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+
let expected = expected.coercion_target_type(self, expr.span);
182+
coercion.complete(self, &cause, expected, coerce_never)
178183
}
179184

180185
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, ret_ty, 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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ 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;
1514
use rustc_middle::ty::{
1615
self, ClosureKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
1716
TypeVisitableExt, TypeVisitor,
1817
};
18+
use rustc_middle::{bug, span_bug};
1919
use rustc_span::def_id::LocalDefId;
2020
use rustc_span::{DUMMY_SP, Span};
2121
use rustc_trait_selection::error_reporting::traits::ArgKind;
@@ -340,6 +340,37 @@ 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(
356+
&inputs.iter().chain([*output]).collect::<smallvec::SmallVec<[_; 4]>>(),
357+
);
358+
ty::FnSig {
359+
abi: sig.abi,
360+
safety: sig.safety,
361+
c_variadic: sig.c_variadic,
362+
inputs_and_output,
363+
}
364+
});
365+
tracing::debug!(?sig);
366+
let expected_sig = ExpectedSig { cause_span: None, sig };
367+
let kind = closure_args.kind_ty().to_opt_closure_kind();
368+
(Some(expected_sig), kind)
369+
}
370+
hir::ClosureKind::Coroutine(_) | hir::ClosureKind::CoroutineClosure(_) => {
371+
(None, None)
372+
}
373+
},
343374
_ => (None, None),
344375
}
345376
}

0 commit comments

Comments
 (0)