@@ -1618,50 +1618,57 @@ impl<'a> Parser<'a> {
16181618 {
16191619 let rfc_note = "anonymous parameters are removed in the 2018 edition (see RFC 1685)" ;
16201620
1621- let ( ident, self_sugg, param_sugg, type_sugg) = match pat. kind {
1622- PatKind :: Ident ( _, ident, _) => (
1623- ident,
1624- format ! ( "self: {}" , ident) ,
1625- format ! ( "{}: TypeName" , ident) ,
1626- format ! ( "_: {}" , ident) ,
1627- ) ,
1628- // Also catches `fn foo(&a)`.
1629- PatKind :: Ref ( ref pat, mutab)
1630- if matches ! ( pat. clone( ) . into_inner( ) . kind, PatKind :: Ident ( ..) ) =>
1631- {
1632- match pat. clone ( ) . into_inner ( ) . kind {
1633- PatKind :: Ident ( _, ident, _) => {
1634- let mutab = mutab. prefix_str ( ) ;
1635- (
1636- ident,
1637- format ! ( "self: &{}{}" , mutab, ident) ,
1638- format ! ( "{}: &{}TypeName" , ident, mutab) ,
1639- format ! ( "_: &{}{}" , mutab, ident) ,
1640- )
1621+ let ( ident, self_sugg, param_sugg, type_sugg, self_span, param_span, type_span) =
1622+ match pat. kind {
1623+ PatKind :: Ident ( _, ident, _) => (
1624+ ident,
1625+ "self: " . to_string ( ) ,
1626+ ": TypeName" . to_string ( ) ,
1627+ "_: " . to_string ( ) ,
1628+ pat. span . shrink_to_lo ( ) ,
1629+ pat. span . shrink_to_hi ( ) ,
1630+ pat. span . shrink_to_lo ( ) ,
1631+ ) ,
1632+ // Also catches `fn foo(&a)`.
1633+ PatKind :: Ref ( ref inner_pat, mutab)
1634+ if matches ! ( inner_pat. clone( ) . into_inner( ) . kind, PatKind :: Ident ( ..) ) =>
1635+ {
1636+ match inner_pat. clone ( ) . into_inner ( ) . kind {
1637+ PatKind :: Ident ( _, ident, _) => {
1638+ let mutab = mutab. prefix_str ( ) ;
1639+ (
1640+ ident,
1641+ "self: " . to_string ( ) ,
1642+ format ! ( "{}: &{}TypeName" , ident, mutab) ,
1643+ "_: " . to_string ( ) ,
1644+ pat. span . shrink_to_lo ( ) ,
1645+ pat. span ,
1646+ pat. span . shrink_to_lo ( ) ,
1647+ )
1648+ }
1649+ _ => unreachable ! ( ) ,
16411650 }
1642- _ => unreachable ! ( ) ,
1643- }
1644- }
1645- _ => {
1646- // Otherwise, try to get a type and emit a suggestion.
1647- if let Some ( ty) = pat. to_ty ( ) {
1648- err. span_suggestion_verbose (
1649- pat. span ,
1650- "explicitly ignore the parameter name" ,
1651- format ! ( "_: {}" , pprust:: ty_to_string( & ty) ) ,
1652- Applicability :: MachineApplicable ,
1653- ) ;
1654- err. note ( rfc_note) ;
16551651 }
1652+ _ => {
1653+ // Otherwise, try to get a type and emit a suggestion.
1654+ if let Some ( ty) = pat. to_ty ( ) {
1655+ err. span_suggestion_verbose (
1656+ pat. span ,
1657+ "explicitly ignore the parameter name" ,
1658+ format ! ( "_: {}" , pprust:: ty_to_string( & ty) ) ,
1659+ Applicability :: MachineApplicable ,
1660+ ) ;
1661+ err. note ( rfc_note) ;
1662+ }
16561663
1657- return None ;
1658- }
1659- } ;
1664+ return None ;
1665+ }
1666+ } ;
16601667
16611668 // `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
16621669 if first_param {
16631670 err. span_suggestion (
1664- pat . span ,
1671+ self_span ,
16651672 "if this is a `self` type, give it a parameter name" ,
16661673 self_sugg,
16671674 Applicability :: MaybeIncorrect ,
@@ -1671,14 +1678,14 @@ impl<'a> Parser<'a> {
16711678 // `fn foo(HashMap: TypeName<u32>)`.
16721679 if self . token != token:: Lt {
16731680 err. span_suggestion (
1674- pat . span ,
1681+ param_span ,
16751682 "if this is a parameter name, give it a type" ,
16761683 param_sugg,
16771684 Applicability :: HasPlaceholders ,
16781685 ) ;
16791686 }
16801687 err. span_suggestion (
1681- pat . span ,
1688+ type_span ,
16821689 "if this is a type, explicitly ignore the parameter name" ,
16831690 type_sugg,
16841691 Applicability :: MachineApplicable ,
0 commit comments