Skip to content

Commit df3cc0c

Browse files
committed
rustc: categorize rvalue borrows based on their const-qualification.
1 parent 08967c7 commit df3cc0c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub use self::Note::*;
7171
pub use self::deref_kind::*;
7272
pub use self::categorization::*;
7373

74+
use middle::check_const;
7475
use middle::def;
7576
use middle::region;
7677
use 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

Comments
 (0)