From 9bdfde0be460c096e8aecfdfe6c6eeac2e173fe4 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 4 Jul 2021 11:43:22 -0400 Subject: [PATCH] remove some ad-hoc has_infer_types checks that aren't needed anymore --- .../diagnostics/conflict_errors.rs | 28 +++++++++---------- compiler/rustc_typeck/src/check/cast.rs | 15 +++------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs index c1c875eac558..4be4372c0393 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::{ FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, }; -use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable}; +use rustc_middle::ty::{self, suggest_constraining_type_param, Ty}; use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::sym; use rustc_span::{Span, DUMMY_SP}; @@ -1329,20 +1329,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let return_ty = tcx.erase_regions(return_ty); // to avoid panics - if !return_ty.has_infer_types() { - if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator) { - if tcx - .type_implements_trait((iter_trait, return_ty, ty_params, self.param_env)) - .must_apply_modulo_regions() - { - if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) { - err.span_suggestion_hidden( - return_span, - "use `.collect()` to allocate the iterator", - format!("{}{}", snippet, ".collect::>()"), - Applicability::MaybeIncorrect, - ); - } + if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator) { + if tcx + .type_implements_trait((iter_trait, return_ty, ty_params, self.param_env)) + .must_apply_modulo_regions() + { + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) { + err.span_suggestion_hidden( + return_span, + "use `.collect()` to allocate the iterator", + format!("{}{}", snippet, ".collect::>()"), + Applicability::MaybeIncorrect, + ); } } } diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 7ff4a108dabc..b0c25c86dd31 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -442,17 +442,10 @@ impl<'a, 'tcx> CastCheck<'tcx> { let ty_params = fcx.tcx.mk_substs_trait(expr_ty, &[]); // Check for infer types because cases like `Option<{integer}>` would // panic otherwise. - if !expr_ty.has_infer_types() - && !ty.has_infer_types() - && fcx - .tcx - .type_implements_trait(( - from_trait, - ty, - ty_params, - fcx.param_env, - )) - .must_apply_modulo_regions() + if fcx + .tcx + .type_implements_trait((from_trait, ty, ty_params, fcx.param_env)) + .must_apply_modulo_regions() { label = false; err.span_suggestion(