Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4435bb0

Browse files
authoredMar 27, 2022
Rollup merge of #91981 - estebank:tweakaroo, r=lcnr
Recover suggestions and useful information lost in previous PR Follow up to #91898.
2 parents 551b4fa + f479e26 commit 4435bb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+209
-60
lines changed
 

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
333333
)
334334
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
335335
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
336+
(&ty::Ref(reg_a, ty_a, mut_a), &ty::Ref(reg_b, ty_b, mut_b)) => {
337+
reg_a == reg_b && mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
338+
}
336339
_ => a == b,
337340
}
338341
}
@@ -602,7 +605,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
602605
match *cause.code() {
603606
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
604607
let ty = self.resolve_vars_if_possible(root_ty);
605-
if ty.is_suggestable() {
608+
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
609+
{
606610
// don't show type `_`
607611
err.span_label(span, format!("this expression has type `{}`", ty));
608612
}

‎compiler/rustc_infer/src/infer/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14341434
value.fold_with(&mut r)
14351435
}
14361436

1437+
pub fn resolve_numeric_literals_with_default<T>(&self, value: T) -> T
1438+
where
1439+
T: TypeFoldable<'tcx>,
1440+
{
1441+
if !value.needs_infer() {
1442+
return value; // Avoid duplicated subst-folding.
1443+
}
1444+
let mut r = InferenceLiteralEraser { tcx: self.tcx };
1445+
value.fold_with(&mut r)
1446+
}
1447+
14371448
/// Returns the first unresolved variable contained in `T`. In the
14381449
/// process of visiting `T`, this will resolve (where possible)
14391450
/// type variables in `T`, but it never constructs the final,
@@ -1785,6 +1796,26 @@ impl<'tcx> TyOrConstInferVar<'tcx> {
17851796
}
17861797
}
17871798

1799+
/// Replace `{integer}` with `i32` and `{float}` with `f64`.
1800+
/// Used only for diagnostics.
1801+
struct InferenceLiteralEraser<'tcx> {
1802+
tcx: TyCtxt<'tcx>,
1803+
}
1804+
1805+
impl<'tcx> TypeFolder<'tcx> for InferenceLiteralEraser<'tcx> {
1806+
fn tcx(&self) -> TyCtxt<'tcx> {
1807+
self.tcx
1808+
}
1809+
1810+
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1811+
match ty.kind() {
1812+
ty::Infer(ty::IntVar(_) | ty::FreshIntTy(_)) => self.tcx.types.i32,
1813+
ty::Infer(ty::FloatVar(_) | ty::FreshFloatTy(_)) => self.tcx.types.f64,
1814+
_ => ty.super_fold_with(self),
1815+
}
1816+
}
1817+
}
1818+
17881819
struct ShallowResolver<'a, 'tcx> {
17891820
infcx: &'a InferCtxt<'a, 'tcx>,
17901821
}

0 commit comments

Comments
 (0)
Please sign in to comment.