Skip to content

Commit

Permalink
remove some ad-hoc has_infer_types checks that aren't needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jul 4, 2021
1 parent 75c1722 commit 9bdfde0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
28 changes: 13 additions & 15 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<Vec<_>>()"),
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::<Vec<_>>()"),
Applicability::MaybeIncorrect,
);
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions compiler/rustc_typeck/src/check/cast.rs
Expand Up @@ -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(
Expand Down

0 comments on commit 9bdfde0

Please sign in to comment.