Remove TypeParamVisitor

This commit is contained in:
Michael Goulet 2022-09-04 21:55:38 +00:00
parent d0746e8863
commit 0dbbf0f493

View File

@ -12,9 +12,7 @@
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor,
};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
@ -23,8 +21,6 @@
use rustc_trait_selection::traits::{FulfillmentError, TraitEngine, TraitEngineExt};
use rustc_type_ir::sty::TyKind::*;
use std::ops::ControlFlow;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Checks a `a <op>= b`
pub fn check_binop_assign(
@ -462,9 +458,6 @@ fn check_overloaded_binop(
}
if let Some(missing_trait) = missing_trait {
let mut visitor = TypeParamVisitor(vec![]);
visitor.visit_ty(lhs_ty);
if op.node == hir::BinOpKind::Add
&& self.check_str_addition(
lhs_expr, rhs_expr, lhs_ty, rhs_ty, &mut err, is_assign, op,
@ -473,7 +466,7 @@ fn check_overloaded_binop(
// This has nothing here because it means we did string
// concatenation (e.g., "Hello " + "World!"). This means
// we don't want the note in the else clause to be emitted
} else if let [ty] = &visitor.0[..] {
} else if lhs_ty.has_param_types_or_consts() {
// Look for a TraitPredicate in the Fulfillment errors,
// and use it to generate a suggestion.
//
@ -513,7 +506,7 @@ fn check_overloaded_binop(
);
}
}
} else if *ty != lhs_ty {
} else {
// When we know that a missing bound is responsible, we don't show
// this note as it is redundant.
err.note(&format!(
@ -650,14 +643,10 @@ pub fn check_user_unop(
format!("cannot apply unary operator `{}`", op.as_str()),
);
let mut visitor = TypeParamVisitor(vec![]);
visitor.visit_ty(operand_ty);
if let [_] = &visitor.0[..] && let ty::Param(_) = *operand_ty.kind() {
let predicates = errors
.iter()
.filter_map(|error| {
error.obligation.predicate.to_opt_poly_trait_pred()
});
if operand_ty.has_param_types_or_consts() {
let predicates = errors.iter().filter_map(|error| {
error.obligation.predicate.to_opt_poly_trait_pred()
});
for pred in predicates {
self.suggest_restricting_param_bound(
&mut err,
@ -972,17 +961,6 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
}
}
struct TypeParamVisitor<'tcx>(Vec<Ty<'tcx>>);
impl<'tcx> TypeVisitor<'tcx> for TypeParamVisitor<'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::Param(_) = ty.kind() {
self.0.push(ty);
}
ty.super_visit_with(self)
}
}
struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span);
impl<'tcx> TypeFolder<'tcx> for TypeParamEraser<'_, 'tcx> {