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