@@ -1442,62 +1442,54 @@ fn deny_equality_constraints(
1442
1442
let mut err = errors:: EqualityInWhere { span : predicate. span , assoc : None , assoc2 : None } ;
1443
1443
1444
1444
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
1445
- if let TyKind :: Path ( Some ( qself) , full_path) = & predicate. lhs_ty . kind {
1446
- if let TyKind :: Path ( None , path) = & qself. ty . kind {
1447
- match & path. segments [ ..] {
1448
- [ PathSegment { ident, args : None , .. } ] => {
1449
- for param in & generics. params {
1450
- if param. ident == * ident {
1451
- let param = ident;
1452
- match & full_path. segments [ qself. position ..] {
1453
- [ PathSegment { ident, args, .. } ] => {
1454
- // Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1455
- let mut assoc_path = full_path. clone ( ) ;
1456
- // Remove `Bar` from `Foo::Bar`.
1457
- assoc_path. segments . pop ( ) ;
1458
- let len = assoc_path. segments . len ( ) - 1 ;
1459
- let gen_args = args. as_deref ( ) . cloned ( ) ;
1460
- // Build `<Bar = RhsTy>`.
1461
- let arg = AngleBracketedArg :: Constraint ( AssocConstraint {
1462
- id : rustc_ast:: node_id:: DUMMY_NODE_ID ,
1463
- ident : * ident,
1464
- gen_args,
1465
- kind : AssocConstraintKind :: Equality {
1466
- term : predicate. rhs_ty . clone ( ) . into ( ) ,
1467
- } ,
1468
- span : ident. span ,
1469
- } ) ;
1470
- // Add `<Bar = RhsTy>` to `Foo`.
1471
- match & mut assoc_path. segments [ len] . args {
1472
- Some ( args) => match args. deref_mut ( ) {
1473
- GenericArgs :: Parenthesized ( _) => continue ,
1474
- GenericArgs :: AngleBracketed ( args) => {
1475
- args. args . push ( arg) ;
1476
- }
1477
- } ,
1478
- empty_args => {
1479
- * empty_args = Some (
1480
- AngleBracketedArgs {
1481
- span : ident. span ,
1482
- args : thin_vec ! [ arg] ,
1483
- }
1484
- . into ( ) ,
1485
- ) ;
1486
- }
1487
- }
1488
- err. assoc = Some ( errors:: AssociatedSuggestion {
1489
- span : predicate. span ,
1490
- ident : * ident,
1491
- param : * param,
1492
- path : pprust:: path_to_string ( & assoc_path) ,
1493
- } )
1494
- }
1495
- _ => { }
1496
- } ;
1445
+ if let TyKind :: Path ( Some ( qself) , full_path) = & predicate. lhs_ty . kind
1446
+ && let TyKind :: Path ( None , path) = & qself. ty . kind
1447
+ && let [ PathSegment { ident, args : None , .. } ] = & path. segments [ ..]
1448
+ {
1449
+ for param in & generics. params {
1450
+ if param. ident == * ident
1451
+ && let [ PathSegment { ident, args, .. } ] = & full_path. segments [ qself. position ..]
1452
+ {
1453
+ // Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1454
+ let mut assoc_path = full_path. clone ( ) ;
1455
+ // Remove `Bar` from `Foo::Bar`.
1456
+ assoc_path. segments . pop ( ) ;
1457
+ let len = assoc_path. segments . len ( ) - 1 ;
1458
+ let gen_args = args. as_deref ( ) . cloned ( ) ;
1459
+ // Build `<Bar = RhsTy>`.
1460
+ let arg = AngleBracketedArg :: Constraint ( AssocConstraint {
1461
+ id : rustc_ast:: node_id:: DUMMY_NODE_ID ,
1462
+ ident : * ident,
1463
+ gen_args,
1464
+ kind : AssocConstraintKind :: Equality {
1465
+ term : predicate. rhs_ty . clone ( ) . into ( ) ,
1466
+ } ,
1467
+ span : ident. span ,
1468
+ } ) ;
1469
+ // Add `<Bar = RhsTy>` to `Foo`.
1470
+ match & mut assoc_path. segments [ len] . args {
1471
+ Some ( args) => match args. deref_mut ( ) {
1472
+ GenericArgs :: Parenthesized ( _) => continue ,
1473
+ GenericArgs :: AngleBracketed ( args) => {
1474
+ args. args . push ( arg) ;
1497
1475
}
1476
+ } ,
1477
+ empty_args => {
1478
+ * empty_args = Some (
1479
+ AngleBracketedArgs {
1480
+ span : ident. span ,
1481
+ args : thin_vec ! [ arg] ,
1482
+ }
1483
+ . into ( ) ,
1484
+ ) ;
1498
1485
}
1499
1486
}
1500
- _ => { }
1487
+ err. assoc = Some ( errors:: AssociatedSuggestion {
1488
+ span : predicate. span ,
1489
+ ident : * ident,
1490
+ param : param. ident ,
1491
+ path : pprust:: path_to_string ( & assoc_path) ,
1492
+ } )
1501
1493
}
1502
1494
}
1503
1495
}
0 commit comments