@@ -640,7 +640,7 @@ impl<'a> Parser<'a> {
640
640
}
641
641
}
642
642
Err ( mut err) => {
643
- // We could 't parse generic parameters, unlikely to be a turbofish. Rely on
643
+ // We couldn 't parse generic parameters, unlikely to be a turbofish. Rely on
644
644
// generic parse error instead.
645
645
err. cancel ( ) ;
646
646
* self = snapshot;
@@ -1242,7 +1242,7 @@ impl<'a> Parser<'a> {
1242
1242
let is_question = self . eat ( & token:: Question ) ; // Handle `await? <expr>`.
1243
1243
let expr = if self . token == token:: OpenDelim ( token:: Brace ) {
1244
1244
// Handle `await { <expr> }`.
1245
- // This needs to be handled separatedly from the next arm to avoid
1245
+ // This needs to be handled separately from the next arm to avoid
1246
1246
// interpreting `await { <expr> }?` as `<expr>?.await`.
1247
1247
self . parse_block_expr ( None , self . token . span , BlockCheckMode :: Default , AttrVec :: new ( ) )
1248
1248
} else {
@@ -1618,6 +1618,8 @@ impl<'a> Parser<'a> {
1618
1618
|| self . token == token:: Lt
1619
1619
|| self . token == token:: CloseDelim ( token:: Paren ) )
1620
1620
{
1621
+ let rfc_note = "anonymous parameters are removed in the 2018 edition (see RFC 1685)" ;
1622
+
1621
1623
let ( ident, self_sugg, param_sugg, type_sugg) = match pat. kind {
1622
1624
PatKind :: Ident ( _, ident, _) => (
1623
1625
ident,
@@ -1626,7 +1628,9 @@ impl<'a> Parser<'a> {
1626
1628
format ! ( "_: {}" , ident) ,
1627
1629
) ,
1628
1630
// Also catches `fn foo(&a)`.
1629
- PatKind :: Ref ( ref pat, mutab) => {
1631
+ PatKind :: Ref ( ref pat, mutab)
1632
+ if matches ! ( pat. clone( ) . into_inner( ) . kind, PatKind :: Ident ( ..) ) =>
1633
+ {
1630
1634
match pat. clone ( ) . into_inner ( ) . kind {
1631
1635
PatKind :: Ident ( _, ident, _) => {
1632
1636
let mutab = mutab. prefix_str ( ) ;
@@ -1637,20 +1641,23 @@ impl<'a> Parser<'a> {
1637
1641
format ! ( "_: &{}{}" , mutab, ident) ,
1638
1642
)
1639
1643
}
1640
- PatKind :: Path ( ..) => {
1641
- err. note ( "anonymous parameters are removed in the 2018 edition (see RFC 1685)" ) ;
1642
- return None ;
1643
- }
1644
- _ => return None ,
1644
+ _ => unreachable ! ( ) ,
1645
1645
}
1646
1646
}
1647
- // Also catches `fn foo(<Bar as T>::Baz)`
1648
- PatKind :: Path ( ..) => {
1649
- err. note ( "anonymous parameters are removed in the 2018 edition (see RFC 1685)" ) ;
1647
+ _ => {
1648
+ // Otherwise, try to get a type and emit a suggestion.
1649
+ if let Some ( ty) = pat. to_ty ( ) {
1650
+ err. span_suggestion_verbose (
1651
+ pat. span ,
1652
+ "explicitly ignore the parameter name" ,
1653
+ format ! ( "_: {}" , pprust:: ty_to_string( & ty) ) ,
1654
+ Applicability :: MachineApplicable ,
1655
+ ) ;
1656
+ err. note ( rfc_note) ;
1657
+ }
1658
+
1650
1659
return None ;
1651
1660
}
1652
- // Ignore other `PatKind`.
1653
- _ => return None ,
1654
1661
} ;
1655
1662
1656
1663
// `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
@@ -1678,7 +1685,7 @@ impl<'a> Parser<'a> {
1678
1685
type_sugg,
1679
1686
Applicability :: MachineApplicable ,
1680
1687
) ;
1681
- err. note ( "anonymous parameters are removed in the 2018 edition (see RFC 1685)" ) ;
1688
+ err. note ( rfc_note ) ;
1682
1689
1683
1690
// Don't attempt to recover by using the `X` in `X<Y>` as the parameter name.
1684
1691
return if self . token == token:: Lt { None } else { Some ( ident) } ;
0 commit comments