Skip to content

Commit c50bbc2

Browse files
committed
remove try_structurally_resolve_type
1 parent dbba04e commit c50bbc2

13 files changed

Lines changed: 41 additions & 125 deletions

File tree

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6060
// type in that case)
6161
let mut all_arms_diverge = Diverges::WarnedAlways;
6262

63-
let expected =
64-
orig_expected.try_structurally_resolve_and_adjust_for_branches(self, expr.span);
63+
let expected = orig_expected.try_structurally_resolve_and_adjust_for_branches(self);
6564
debug!(?expected);
6665

6766
let mut coercion = {

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7979
_ => self.check_expr(callee_expr),
8080
};
8181

82-
let expr_ty = self.try_structurally_resolve_type(call_expr.span, original_callee_ty);
82+
let expr_ty = self.resolve_vars_with_obligations(original_callee_ty);
8383

8484
let mut autoderef = self.autoderef(callee_expr.span, expr_ty);
8585
let mut result = None;
@@ -211,8 +211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211211
arg_exprs: &'tcx [hir::Expr<'tcx>],
212212
autoderef: &Autoderef<'a, 'tcx>,
213213
) -> Option<CallStep<'tcx>> {
214-
let adjusted_ty =
215-
self.try_structurally_resolve_type(autoderef.span(), autoderef.final_ty());
214+
let adjusted_ty = self.resolve_vars_with_obligations(autoderef.final_ty());
216215

217216
// If the callee is a function pointer or a closure, then we're all set.
218217
match *adjusted_ty.kind() {

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
102102
return Ok(Some(PointerKind::Thin));
103103
}
104104

105-
let t = self.try_structurally_resolve_type(span, t);
105+
let t = self.resolve_vars_with_obligations(t);
106106

107107
Ok(match *t.kind() {
108108
ty::Slice(_) | ty::Str => Some(PointerKind::Length),
@@ -1041,8 +1041,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
10411041
mut m_cast: ty::TypeAndMut<'tcx>,
10421042
) -> Result<CastKind, CastError<'tcx>> {
10431043
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
1044-
m_expr.ty = fcx.try_structurally_resolve_type(self.expr_span, m_expr.ty);
1045-
m_cast.ty = fcx.try_structurally_resolve_type(self.cast_span, m_cast.ty);
1044+
m_expr.ty = fcx.resolve_vars_with_obligations(m_expr.ty);
1045+
m_cast.ty = fcx.resolve_vars_with_obligations(m_cast.ty);
10461046

10471047
if m_expr.mutbl >= m_cast.mutbl
10481048
&& let ty::Array(ety, _) = m_expr.ty.kind()

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5959
// closure sooner rather than later, so first examine the expected
6060
// type, and see if can glean a closure kind from there.
6161
let (expected_sig, expected_kind) = match expected.to_option(self) {
62-
Some(ty) => self.deduce_closure_signature(
63-
self.try_structurally_resolve_type(expr_span, ty),
64-
closure.kind,
65-
),
62+
Some(ty) => {
63+
self.deduce_closure_signature(self.resolve_vars_with_obligations(ty), closure.kind)
64+
}
6665
None => (None, None),
6766
};
6867

@@ -963,7 +962,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
963962

964963
let closure_span = self.tcx.def_span(body_def_id);
965964
let ret_ty = ret_coercion.borrow().expected_ty();
966-
let ret_ty = self.try_structurally_resolve_type(closure_span, ret_ty);
965+
let ret_ty = self.resolve_vars_with_obligations(ret_ty);
967966

968967
let get_future_output = |predicate: ty::Predicate<'tcx>, span| {
969968
// Search for a pending obligation like

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,17 +1051,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10511051
&self,
10521052
expr: &'tcx hir::Expr<'tcx>,
10531053
expr_ty: Ty<'tcx>,
1054-
mut target: Ty<'tcx>,
1054+
target: Ty<'tcx>,
10551055
allow_two_phase: AllowTwoPhase,
10561056
cause: Option<ObligationCause<'tcx>>,
10571057
) -> RelateResult<'tcx, Ty<'tcx>> {
1058-
let source = self.try_structurally_resolve_type(expr.span, expr_ty);
1059-
if self.next_trait_solver() {
1060-
target = self.try_structurally_resolve_type(
1061-
cause.as_ref().map_or(expr.span, |cause| cause.span),
1062-
target,
1063-
);
1064-
}
1058+
let source = self.resolve_vars_with_obligations(expr_ty);
10651059
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
10661060

10671061
let cause =
@@ -1244,8 +1238,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12441238
new: &hir::Expr<'_>,
12451239
new_ty: Ty<'tcx>,
12461240
) -> RelateResult<'tcx, Ty<'tcx>> {
1247-
let prev_ty = self.try_structurally_resolve_type(cause.span, prev_ty);
1248-
let new_ty = self.try_structurally_resolve_type(new.span, new_ty);
1241+
let prev_ty = self.resolve_vars_with_obligations(prev_ty);
1242+
let new_ty = self.resolve_vars_with_obligations(new_ty);
12491243
debug!(
12501244
"coercion::try_find_coercion_lub({:?}, {:?}, exprs={:?} exprs)",
12511245
prev_ty,

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
260260
mut expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
261261
allow_two_phase: AllowTwoPhase,
262262
) -> Result<Ty<'tcx>, Diag<'a>> {
263-
let expected = if self.next_trait_solver() {
264-
expected
265-
} else {
266-
self.resolve_vars_with_obligations(expected)
267-
};
263+
let expected = self.resolve_vars_with_obligations(expected);
268264

269265
let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
270266
Ok(ty) => return Ok(ty),

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ impl<'a, 'tcx> Expectation<'tcx> {
4343
pub(super) fn try_structurally_resolve_and_adjust_for_branches(
4444
&self,
4545
fcx: &FnCtxt<'a, 'tcx>,
46-
span: Span,
4746
) -> Expectation<'tcx> {
4847
match *self {
4948
ExpectHasType(ety) => {
50-
let ety = fcx.try_structurally_resolve_type(span, ety);
49+
let ety = fcx.resolve_vars_with_obligations(ety);
5150
if !ety.is_ty_var() { ExpectHasType(ety) } else { NoExpectation }
5251
}
5352
ExpectRvalueLikeUnsized(ety) => ExpectRvalueLikeUnsized(ety),

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8282

8383
// While we don't allow *arbitrary* coercions here, we *do* allow
8484
// coercions from ! to `expected`.
85-
if self.try_structurally_resolve_type(expr.span, ty).is_never()
85+
if self.resolve_vars_with_obligations(ty).is_never()
8686
&& self.tcx.expr_guaranteed_to_constitute_read_for_never(expr)
8787
{
8888
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
@@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
300300
// unless it's a place expression that isn't being read from, in which case
301301
// diverging would be unsound since we may never actually read the `!`.
302302
// e.g. `let _ = *never_ptr;` with `never_ptr: *const !`.
303-
if self.try_structurally_resolve_type(expr.span, ty).is_never()
303+
if self.resolve_vars_with_obligations(ty).is_never()
304304
&& self.tcx.expr_guaranteed_to_constitute_read_for_never(expr)
305305
{
306306
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
@@ -454,7 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454454
expr: &'tcx hir::Expr<'tcx>,
455455
) -> Ty<'tcx> {
456456
let hint = expected.only_has_type(self).map_or(NoExpectation, |ty| {
457-
match self.try_structurally_resolve_type(expr.span, ty).kind() {
457+
match self.resolve_vars_with_obligations(ty).kind() {
458458
ty::Ref(_, ty, _) | ty::RawPtr(ty, _) => {
459459
if oprnd.is_syntactic_place_expr() {
460460
// Places may legitimately have unsized types.
@@ -1187,7 +1187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11871187
let cond_diverges = self.diverges.get();
11881188
self.diverges.set(Diverges::Maybe);
11891189

1190-
let expected = orig_expected.try_structurally_resolve_and_adjust_for_branches(self, sp);
1190+
let expected = orig_expected.try_structurally_resolve_and_adjust_for_branches(self);
11911191
let then_ty = self.check_expr_with_expectation(then_expr, expected);
11921192
let then_diverges = self.diverges.get();
11931193
self.diverges.set(Diverges::Maybe);
@@ -1457,7 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14571457
expected: Expectation<'tcx>,
14581458
) -> Ty<'tcx> {
14591459
let rcvr_t = self.check_expr(rcvr);
1460-
let rcvr_t = self.try_structurally_resolve_type(rcvr.span, rcvr_t);
1460+
let rcvr_t = self.resolve_vars_with_obligations(rcvr_t);
14611461

14621462
match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args) {
14631463
Ok(method) => {
@@ -1644,11 +1644,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16441644
let coerce_to = expected
16451645
.to_option(self)
16461646
.and_then(|uty| {
1647-
self.try_structurally_resolve_type(expr.span, uty)
1647+
self.resolve_vars_with_obligations(uty)
16481648
.builtin_index()
16491649
// Avoid using the original type variable as the coerce_to type, as it may resolve
16501650
// during the first coercion instead of being the LUB type.
1651-
.filter(|t| !self.try_structurally_resolve_type(expr.span, *t).is_ty_var())
1651+
.filter(|t| !self.resolve_vars_with_obligations(*t).is_ty_var())
16521652
})
16531653
.unwrap_or_else(|| self.next_ty_var(expr.span));
16541654
let mut coerce = CoerceMany::with_capacity(coerce_to, args.len());
@@ -1773,7 +1773,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17731773
) -> Ty<'tcx> {
17741774
let mut expectations = expected
17751775
.only_has_type(self)
1776-
.and_then(|ty| self.try_structurally_resolve_type(expr.span, ty).opt_tuple_fields())
1776+
.and_then(|ty| self.resolve_vars_with_obligations(ty).opt_tuple_fields())
17771777
.unwrap_or_default()
17781778
.iter();
17791779

@@ -1847,7 +1847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18471847
) {
18481848
let tcx = self.tcx;
18491849

1850-
let adt_ty = self.try_structurally_resolve_type(path_span, adt_ty);
1850+
let adt_ty = self.resolve_vars_with_obligations(adt_ty);
18511851
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
18521852
self.fudge_inference_if_ok(|| {
18531853
let ocx = ObligationCtxt::new(self);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
470470
let tail = self.tcx.struct_tail_raw(
471471
ty,
472472
&self.misc(span),
473-
|ty| {
474-
if self.next_trait_solver() {
475-
self.try_structurally_resolve_type(span, ty)
476-
} else {
477-
self.normalize(span, Unnormalized::new_wip(ty))
478-
}
479-
},
473+
|ty| self.normalize(span, Unnormalized::new_wip(ty)),
480474
|| {},
481475
);
482476
// Sized types have static alignment, and so do slices.
@@ -1432,35 +1426,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14321426
}
14331427
}
14341428

1435-
/// Try to resolve `ty` to a structural type, normalizing aliases.
1436-
///
1437-
/// In case there is still ambiguity, the returned type may be an inference
1438-
/// variable. This is different from `structurally_resolve_type` which errors
1439-
/// in this case.
1440-
#[instrument(level = "debug", skip(self, sp), ret)]
1441-
pub(crate) fn try_structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1442-
if self.next_trait_solver()
1443-
&& let ty::Alias(..) = ty.kind()
1444-
{
1445-
// We need to use a separate variable here as otherwise the temporary for
1446-
// `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting
1447-
// in a reentrant borrow, causing an ICE.
1448-
let result = self.at(&self.misc(sp), self.param_env).structurally_normalize_ty(
1449-
Unnormalized::new_wip(ty),
1450-
&mut **self.fulfillment_cx.borrow_mut(),
1451-
);
1452-
match result {
1453-
Ok(normalized_ty) => normalized_ty,
1454-
Err(errors) => {
1455-
let guar = self.err_ctxt().report_fulfillment_errors(errors);
1456-
return Ty::new_error(self.tcx, guar);
1457-
}
1458-
}
1459-
} else {
1460-
self.resolve_vars_with_obligations(ty)
1461-
}
1462-
}
1463-
14641429
#[instrument(level = "debug", skip(self, sp), ret)]
14651430
pub(crate) fn try_structurally_resolve_const(
14661431
&self,
@@ -1502,7 +1467,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15021467
/// If no resolution is possible, then an error is reported.
15031468
/// Numeric inference variables may be left unresolved.
15041469
pub(crate) fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1505-
let ty = self.try_structurally_resolve_type(sp, ty);
1470+
let ty = self.resolve_vars_with_obligations(ty);
15061471

15071472
if !ty.is_ty_var() { ty } else { self.type_must_be_known_at_this_point(sp, ty) }
15081473
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,29 +218,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218218
self.check_place_expr_if_unsized(fn_input_ty, arg_expr);
219219
}
220220

221-
let formal_input_tys_ns;
222-
let formal_input_tys = if self.next_trait_solver() {
223-
// In the new solver, the normalizations are done lazily.
224-
// Because of this, if we encounter unnormalized alias types inside this
225-
// fudge scope, we might lose the relationships between them and other vars
226-
// when fudging inference variables created here.
227-
// So, we utilize generalization to normalize aliases by adding a new
228-
// inference var and equating it with the type we want to pull out of the
229-
// fudge scope.
230-
formal_input_tys_ns = formal_input_tys
231-
.iter()
232-
.map(|&ty| {
233-
let generalized_ty = self.next_ty_var(call_span);
234-
self.demand_eqtype(call_span, ty, generalized_ty);
235-
generalized_ty
236-
})
237-
.collect_vec();
238-
239-
formal_input_tys_ns.as_slice()
240-
} else {
241-
formal_input_tys
242-
};
243-
244221
// First, let's unify the formal method signature with the expectation eagerly.
245222
// We use this to guide coercion inference; it's output is "fudged" which means
246223
// any remaining type variables are assigned to new, unrelated variables. This

0 commit comments

Comments
 (0)