Skip to content

Commit 652601a

Browse files
committed
rustc: categorize rvalue borrows based on their const-qualification.
1 parent a26b82c commit 652601a

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};
@@ -786,17 +787,29 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
786787
span: Span,
787788
expr_ty: Ty<'tcx>)
788789
-> 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
795804
}
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+
}
798810
}
799-
}
811+
};
812+
self.cat_rvalue(id, span, re, expr_ty)
800813
}
801814

802815
pub fn cat_rvalue(&self,

0 commit comments

Comments
 (0)