@@ -312,26 +312,19 @@ impl MutabilityCategory {
312312 }
313313 }
314314
315- fn from_def ( def : & def:: Def ) -> MutabilityCategory {
316- match * def {
317- def:: DefFn ( ..) | def:: DefStaticMethod ( ..) | def:: DefSelfTy ( ..) |
318- def:: DefMod ( ..) | def:: DefForeignMod ( ..) | def:: DefVariant ( ..) |
319- def:: DefTy ( ..) | def:: DefTrait ( ..) | def:: DefPrimTy ( ..) |
320- def:: DefTyParam ( ..) | def:: DefUse ( ..) | def:: DefStruct ( ..) |
321- def:: DefTyParamBinder ( ..) | def:: DefRegion ( ..) | def:: DefLabel ( ..) |
322- def:: DefMethod ( ..) | def:: DefAssociatedTy ( ..) => {
323- fail ! ( "no MutabilityCategory for def: {}" , * def)
324- }
325-
326- def:: DefStatic ( _, false ) => McImmutable ,
327- def:: DefStatic ( _, true ) => McDeclared ,
328-
329- def:: DefLocal ( _, binding_mode) => match binding_mode {
330- ast:: BindByValue ( ast:: MutMutable ) => McDeclared ,
331- _ => McImmutable
315+ fn from_local ( tcx : & ty:: ctxt , id : ast:: NodeId ) -> MutabilityCategory {
316+ match tcx. map . get ( id) {
317+ ast_map:: NodeLocal ( p) | ast_map:: NodeArg ( p) => match p. node {
318+ ast:: PatIdent ( bind_mode, _, _) => {
319+ if bind_mode == ast:: BindByValue ( ast:: MutMutable ) {
320+ McDeclared
321+ } else {
322+ McImmutable
323+ }
324+ }
325+ _ => tcx. sess . span_bug ( p. span , "expected identifier pattern" )
332326 } ,
333-
334- def:: DefUpvar ( _, def, _, _) => MutabilityCategory :: from_def ( & * def)
327+ _ => tcx. sess . span_bug ( tcx. map . span ( id) , "expected identifier pattern" )
335328 }
336329 }
337330
@@ -544,12 +537,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
544537 } ) )
545538 }
546539
547- def:: DefStatic ( _, _ ) => {
540+ def:: DefStatic ( _, mutbl ) => {
548541 Ok ( Rc :: new ( cmt_ {
549542 id : id,
550543 span : span,
551544 cat : cat_static_item,
552- mutbl : MutabilityCategory :: from_def ( & def ) ,
545+ mutbl : if mutbl { McDeclared } else { McImmutable } ,
553546 ty : expr_ty
554547 } ) )
555548 }
@@ -582,7 +575,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
582575 onceness : closure_ty. onceness ,
583576 capturing_proc : fn_node_id,
584577 } ) ,
585- mutbl : MutabilityCategory :: from_def ( & def ) ,
578+ mutbl : MutabilityCategory :: from_local ( self . tcx ( ) , var_id ) ,
586579 ty : expr_ty
587580 } ) )
588581 }
@@ -605,7 +598,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
605598 onceness : onceness,
606599 capturing_proc : fn_node_id,
607600 } ) ,
608- mutbl : MutabilityCategory :: from_def ( & def ) ,
601+ mutbl : MutabilityCategory :: from_local ( self . tcx ( ) , var_id ) ,
609602 ty : expr_ty
610603 } ) )
611604 }
@@ -619,12 +612,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
619612 }
620613 }
621614
622- def:: DefLocal ( vid, _ ) => {
615+ def:: DefLocal ( vid) => {
623616 Ok ( Rc :: new ( cmt_ {
624617 id : id,
625618 span : span,
626619 cat : cat_local ( vid) ,
627- mutbl : MutabilityCategory :: from_def ( & def ) ,
620+ mutbl : MutabilityCategory :: from_local ( self . tcx ( ) , vid ) ,
628621 ty : expr_ty
629622 } ) )
630623 }
0 commit comments