@@ -71,6 +71,7 @@ pub use self::Note::*;
7171pub use self :: deref_kind:: * ;
7272pub use self :: categorization:: * ;
7373
74+ use middle:: check_const;
7475use middle:: def;
7576use middle:: region;
7677use middle:: ty:: { self , Ty } ;
@@ -808,17 +809,29 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
808809 span : Span ,
809810 expr_ty : Ty < ' tcx > )
810811 -> cmt < ' tcx > {
811- match self . typer . temporary_scope ( id) {
812- Some ( scope) => {
813- match expr_ty. sty {
814- ty:: ty_vec( _, Some ( 0 ) ) => self . cat_rvalue ( id, span, ty:: ReStatic , expr_ty) ,
815- _ => self . cat_rvalue ( id, span, ty:: ReScope ( scope) , expr_ty)
816- }
812+ let qualif = self . tcx ( ) . const_qualif_map . borrow ( ) . get ( & id) . cloned ( )
813+ . unwrap_or ( check_const:: NOT_CONST ) ;
814+
815+ // Only promote `[T; 0]` before an RFC for rvalue promotions
816+ // is accepted.
817+ let qualif = match expr_ty. sty {
818+ ty:: ty_vec( _, Some ( 0 ) ) => qualif,
819+ _ => check_const:: NOT_CONST
820+ } ;
821+
822+ let re = match qualif & check_const:: NON_STATIC_BORROWS {
823+ check_const:: PURE_CONST => {
824+ // Constant rvalues get promoted to 'static.
825+ ty:: ReStatic
817826 }
818- None => {
819- self . cat_rvalue ( id, span, ty:: ReStatic , expr_ty)
827+ _ => {
828+ match self . typer . temporary_scope ( id) {
829+ Some ( scope) => ty:: ReScope ( scope) ,
830+ None => ty:: ReStatic
831+ }
820832 }
821- }
833+ } ;
834+ self . cat_rvalue ( id, span, re, expr_ty)
822835 }
823836
824837 pub fn cat_rvalue ( & self ,
0 commit comments