@@ -71,6 +71,7 @@ pub use self::Note::*;
71
71
pub use self :: deref_kind:: * ;
72
72
pub use self :: categorization:: * ;
73
73
74
+ use middle:: check_const;
74
75
use middle:: def;
75
76
use middle:: region;
76
77
use middle:: ty:: { self , Ty } ;
@@ -808,17 +809,29 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
808
809
span : Span ,
809
810
expr_ty : Ty < ' tcx > )
810
811
-> 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
817
826
}
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
+ }
820
832
}
821
- }
833
+ } ;
834
+ self . cat_rvalue ( id, span, re, expr_ty)
822
835
}
823
836
824
837
pub fn cat_rvalue ( & self ,
0 commit comments