Skip to content

Commit 0dbbf0f

Browse files
Remove TypeParamVisitor
1 parent d0746e8 commit 0dbbf0f

File tree

1 file changed

+7
-29
lines changed
  • compiler/rustc_typeck/src/check

1 file changed

+7
-29
lines changed

compiler/rustc_typeck/src/check/op.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_middle::ty::adjustment::{
1212
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
1313
};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
15-
use rustc_middle::ty::{
16-
self, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor,
17-
};
15+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
1816
use rustc_span::source_map::Spanned;
1917
use rustc_span::symbol::{sym, Ident};
2018
use rustc_span::Span;
@@ -23,8 +21,6 @@ use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt as
2321
use rustc_trait_selection::traits::{FulfillmentError, TraitEngine, TraitEngineExt};
2422
use rustc_type_ir::sty::TyKind::*;
2523

26-
use std::ops::ControlFlow;
27-
2824
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2925
/// Checks a `a <op>= b`
3026
pub fn check_binop_assign(
@@ -462,9 +458,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
462458
}
463459

464460
if let Some(missing_trait) = missing_trait {
465-
let mut visitor = TypeParamVisitor(vec![]);
466-
visitor.visit_ty(lhs_ty);
467-
468461
if op.node == hir::BinOpKind::Add
469462
&& self.check_str_addition(
470463
lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, is_assign, op,
@@ -473,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473466
// This has nothing here because it means we did string
474467
// concatenation (e.g., "Hello " + "World!"). This means
475468
// we don't want the note in the else clause to be emitted
476-
} else if let [ty] = &visitor.0[..] {
469+
} else if lhs_ty.has_param_types_or_consts() {
477470
// Look for a TraitPredicate in the Fulfillment errors,
478471
// and use it to generate a suggestion.
479472
//
@@ -513,7 +506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
513506
);
514507
}
515508
}
516-
} else if *ty != lhs_ty {
509+
} else {
517510
// When we know that a missing bound is responsible, we don't show
518511
// this note as it is redundant.
519512
err.note(&format!(
@@ -650,14 +643,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
650643
format!("cannot apply unary operator `{}`", op.as_str()),
651644
);
652645

653-
let mut visitor = TypeParamVisitor(vec![]);
654-
visitor.visit_ty(operand_ty);
655-
if let [_] = &visitor.0[..] && let ty::Param(_) = *operand_ty.kind() {
656-
let predicates = errors
657-
.iter()
658-
.filter_map(|error| {
659-
error.obligation.predicate.to_opt_poly_trait_pred()
660-
});
646+
if operand_ty.has_param_types_or_consts() {
647+
let predicates = errors.iter().filter_map(|error| {
648+
error.obligation.predicate.to_opt_poly_trait_pred()
649+
});
661650
for pred in predicates {
662651
self.suggest_restricting_param_bound(
663652
&mut err,
@@ -972,17 +961,6 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
972961
}
973962
}
974963

975-
struct TypeParamVisitor<'tcx>(Vec<Ty<'tcx>>);
976-
977-
impl<'tcx> TypeVisitor<'tcx> for TypeParamVisitor<'tcx> {
978-
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
979-
if let ty::Param(_) = ty.kind() {
980-
self.0.push(ty);
981-
}
982-
ty.super_visit_with(self)
983-
}
984-
}
985-
986964
struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span);
987965

988966
impl<'tcx> TypeFolder<'tcx> for TypeParamEraser<'_, 'tcx> {

0 commit comments

Comments
 (0)