Skip to content

Commit 4ae519f

Browse files
committed
ExprKind::StaticRef changes
1 parent 095fca2 commit 4ae519f

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_index::newtype_index;
1717
use rustc_index::vec::IndexVec;
1818
use rustc_middle::infer::canonical::Canonical;
1919
use rustc_middle::middle::region;
20+
use rustc_middle::mir::interpret::AllocId;
2021
use rustc_middle::mir::{
2122
BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection,
2223
};
@@ -419,7 +420,8 @@ pub enum ExprKind<'tcx> {
419420
/// This is only distinguished from `Literal` so that we can register some
420421
/// info for diagnostics.
421422
StaticRef {
422-
literal: Const<'tcx>,
423+
alloc_id: AllocId,
424+
ty: Ty<'tcx>,
423425
def_id: DefId,
424426
},
425427
/// Inline assembly, i.e. `asm!()`.

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
123123
}
124124
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
125125
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
126-
StaticRef { literal, def_id: _ } => visitor.visit_const(literal),
126+
StaticRef { .. } => {}
127127
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
128128
for op in &**operands {
129129
use InlineAsmOperand::*;

compiler/rustc_mir_build/src/build/expr/as_constant.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! See docs in build/expr/mod.rs
22
33
use crate::build::Builder;
4+
use rustc_middle::mir::interpret::{ConstValue, Scalar};
45
use rustc_middle::mir::*;
56
use rustc_middle::thir::*;
67
use rustc_middle::ty::CanonicalUserTypeAnnotation;
@@ -23,11 +24,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2324
inferred_ty: ty,
2425
})
2526
});
27+
2628
assert_eq!(literal.ty(), ty);
2729
Constant { span, user_ty, literal: literal.into() }
2830
}
29-
ExprKind::StaticRef { literal, .. } => {
30-
Constant { span, user_ty: None, literal: literal.into() }
31+
ExprKind::StaticRef { alloc_id, ty, .. } => {
32+
let const_val =
33+
ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &this.tcx));
34+
let literal = ConstantKind::Val(const_val, ty);
35+
36+
Constant { span, user_ty: None, literal }
3137
}
3238
ExprKind::ConstBlock { value } => {
3339
Constant { span: span, user_ty: None, literal: value.into() }

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_middle::hir::place::Place as HirPlace;
88
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
99
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
1010
use rustc_middle::middle::region;
11-
use rustc_middle::mir::interpret::Scalar;
1211
use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp};
1312
use rustc_middle::thir::*;
1413
use rustc_middle::ty::adjustment::{
@@ -941,15 +940,8 @@ impl<'tcx> Cx<'tcx> {
941940
let kind = if self.tcx.is_thread_local_static(id) {
942941
ExprKind::ThreadLocalRef(id)
943942
} else {
944-
let ptr = self.tcx.create_static_alloc(id);
945-
ExprKind::StaticRef {
946-
literal: ty::Const::from_scalar(
947-
self.tcx,
948-
Scalar::from_pointer(ptr.into(), &self.tcx),
949-
ty,
950-
),
951-
def_id: id,
952-
}
943+
let alloc_id = self.tcx.create_static_alloc(id);
944+
ExprKind::StaticRef { alloc_id, ty, def_id: id }
953945
};
954946
ExprKind::Deref {
955947
arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }),

0 commit comments

Comments
 (0)