@@ -12,9 +12,7 @@ use rustc_middle::ty::adjustment::{
12
12
Adjust , Adjustment , AllowTwoPhase , AutoBorrow , AutoBorrowMutability ,
13
13
} ;
14
14
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 } ;
18
16
use rustc_span:: source_map:: Spanned ;
19
17
use rustc_span:: symbol:: { sym, Ident } ;
20
18
use rustc_span:: Span ;
@@ -23,8 +21,6 @@ use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt as
23
21
use rustc_trait_selection:: traits:: { FulfillmentError , TraitEngine , TraitEngineExt } ;
24
22
use rustc_type_ir:: sty:: TyKind :: * ;
25
23
26
- use std:: ops:: ControlFlow ;
27
-
28
24
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
29
25
/// Checks a `a <op>= b`
30
26
pub fn check_binop_assign (
@@ -462,9 +458,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
462
458
}
463
459
464
460
if let Some ( missing_trait) = missing_trait {
465
- let mut visitor = TypeParamVisitor ( vec ! [ ] ) ;
466
- visitor. visit_ty ( lhs_ty) ;
467
-
468
461
if op. node == hir:: BinOpKind :: Add
469
462
&& self . check_str_addition (
470
463
lhs_expr, rhs_expr, lhs_ty, rhs_ty, & mut err, is_assign, op,
@@ -473,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473
466
// This has nothing here because it means we did string
474
467
// concatenation (e.g., "Hello " + "World!"). This means
475
468
// 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 ( ) {
477
470
// Look for a TraitPredicate in the Fulfillment errors,
478
471
// and use it to generate a suggestion.
479
472
//
@@ -513,7 +506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
513
506
) ;
514
507
}
515
508
}
516
- } else if * ty != lhs_ty {
509
+ } else {
517
510
// When we know that a missing bound is responsible, we don't show
518
511
// this note as it is redundant.
519
512
err. note ( & format ! (
@@ -650,14 +643,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
650
643
format ! ( "cannot apply unary operator `{}`" , op. as_str( ) ) ,
651
644
) ;
652
645
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
+ } ) ;
661
650
for pred in predicates {
662
651
self . suggest_restricting_param_bound (
663
652
& mut err,
@@ -972,17 +961,6 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
972
961
}
973
962
}
974
963
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
-
986
964
struct TypeParamEraser < ' a , ' tcx > ( & ' a FnCtxt < ' a , ' tcx > , Span ) ;
987
965
988
966
impl < ' tcx > TypeFolder < ' tcx > for TypeParamEraser < ' _ , ' tcx > {
0 commit comments