@@ -1039,6 +1039,13 @@ impl<'a> MethodDef<'a> {
10391039 let span = trait_. span ;
10401040 let mut patterns = Vec :: new ( ) ;
10411041 for i in 0 ..self_args. len ( ) {
1042+ // Currently supports mutability only for `&mut self`
1043+ let mutbl = match ( i, & self . explicit_self ) {
1044+ ( 0 , Some ( Some ( PtrTy :: Borrowed ( _, mutbl) ) ) ) => * mutbl,
1045+ ( 0 , Some ( Some ( PtrTy :: Raw ( mutbl) ) ) ) => * mutbl,
1046+ _ => ast:: Mutability :: Not ,
1047+ } ;
1048+
10421049 // We could use `type_ident` instead of `Self`, but in the case of a type parameter
10431050 // shadowing the struct name, that causes a second, unnecessary E0578 error. #97343
10441051 let struct_path = cx. path ( span, vec ! [ Ident :: new( kw:: SelfUpper , type_ident. span) ] ) ;
@@ -1047,7 +1054,7 @@ impl<'a> MethodDef<'a> {
10471054 struct_path,
10481055 struct_def,
10491056 & format ! ( "__self_{}" , i) ,
1050- ast :: Mutability :: Not ,
1057+ mutbl ,
10511058 use_temporaries,
10521059 ) ;
10531060 patterns. push ( pat) ;
@@ -1250,28 +1257,35 @@ impl<'a> MethodDef<'a> {
12501257 . enumerate ( )
12511258 . filter ( |& ( _, v) | !( self . unify_fieldless_variants && v. data . fields ( ) . is_empty ( ) ) )
12521259 . map ( |( index, variant) | {
1253- let mk_self_pat = |cx : & mut ExtCtxt < ' _ > , self_arg_name : & str | {
1254- let ( p, idents) = trait_. create_enum_variant_pattern (
1255- cx,
1256- type_ident,
1257- variant,
1258- self_arg_name,
1259- ast:: Mutability :: Not ,
1260- ) ;
1261- ( cx. pat ( span, PatKind :: Ref ( p, ast:: Mutability :: Not ) ) , idents)
1260+ // Support mutability only for `&mut self` for now.
1261+ let self_mutbl = match & self . explicit_self {
1262+ Some ( Some ( PtrTy :: Borrowed ( _, mutbl) ) ) => * mutbl,
1263+ Some ( Some ( PtrTy :: Raw ( mutbl) ) ) => * mutbl,
1264+ _ => ast:: Mutability :: Not ,
12621265 } ;
1266+ let mk_self_pat =
1267+ |cx : & mut ExtCtxt < ' _ > , self_arg_name : & str , mutbl : ast:: Mutability | {
1268+ let ( p, idents) = trait_. create_enum_variant_pattern (
1269+ cx,
1270+ type_ident,
1271+ variant,
1272+ self_arg_name,
1273+ mutbl,
1274+ ) ;
1275+ ( cx. pat ( span, PatKind :: Ref ( p, mutbl) ) , idents)
1276+ } ;
12631277
12641278 // A single arm has form (&VariantK, &VariantK, ...) => BodyK
12651279 // (see "Final wrinkle" note below for why.)
12661280 let mut subpats = Vec :: with_capacity ( self_arg_names. len ( ) ) ;
12671281 let mut self_pats_idents = Vec :: with_capacity ( self_arg_names. len ( ) - 1 ) ;
12681282 let first_self_pat_idents = {
1269- let ( p, idents) = mk_self_pat ( cx, & self_arg_names[ 0 ] ) ;
1283+ let ( p, idents) = mk_self_pat ( cx, & self_arg_names[ 0 ] , self_mutbl ) ;
12701284 subpats. push ( p) ;
12711285 idents
12721286 } ;
12731287 for self_arg_name in & self_arg_names[ 1 ..] {
1274- let ( p, idents) = mk_self_pat ( cx, & self_arg_name) ;
1288+ let ( p, idents) = mk_self_pat ( cx, & self_arg_name, ast :: Mutability :: Not ) ;
12751289 subpats. push ( p) ;
12761290 self_pats_idents. push ( idents) ;
12771291 }
0 commit comments