@@ -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 } ;
@@ -786,17 +787,29 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
786
787
span : Span ,
787
788
expr_ty : Ty < ' tcx > )
788
789
-> cmt < ' tcx > {
789
- match self . typer . temporary_scope ( id) {
790
- Some ( scope) => {
791
- match expr_ty. sty {
792
- ty:: ty_vec( _, Some ( 0 ) ) => self . cat_rvalue ( id, span, ty:: ReStatic , expr_ty) ,
793
- _ => self . cat_rvalue ( id, span, ty:: ReScope ( scope) , expr_ty)
794
- }
790
+ let qualif = self . tcx ( ) . const_qualif_map . borrow ( ) . get ( & id) . cloned ( )
791
+ . unwrap_or ( check_const:: NOT_CONST ) ;
792
+
793
+ // Only promote `[T; 0]` before an RFC for rvalue promotions
794
+ // is accepted.
795
+ let qualif = match expr_ty. sty {
796
+ ty:: ty_vec( _, Some ( 0 ) ) => qualif,
797
+ _ => check_const:: NOT_CONST
798
+ } ;
799
+
800
+ let re = match qualif & check_const:: NON_STATIC_BORROWS {
801
+ check_const:: PURE_CONST => {
802
+ // Constant rvalues get promoted to 'static.
803
+ ty:: ReStatic
795
804
}
796
- None => {
797
- self . cat_rvalue ( id, span, ty:: ReStatic , expr_ty)
805
+ _ => {
806
+ match self . typer . temporary_scope ( id) {
807
+ Some ( scope) => ty:: ReScope ( scope) ,
808
+ None => ty:: ReStatic
809
+ }
798
810
}
799
- }
811
+ } ;
812
+ self . cat_rvalue ( id, span, re, expr_ty)
800
813
}
801
814
802
815
pub fn cat_rvalue ( & self ,
0 commit comments