Skip to content

Commit 23c87a1

Browse files
author
Saleem Jaffer
committed
fixed all compilation errors
1 parent a837b8a commit 23c87a1

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::middle::lang_items;
22
use rustc::ty::{self, Ty, TypeFoldable};
33
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
4-
use rustc::mir;
4+
use rustc::mir::{self, Place, PlaceBase};
55
use rustc::mir::interpret::EvalErrorKind;
66
use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
77
use rustc_target::spec::abi::Abi;
@@ -621,15 +621,19 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
621621
// but specified directly in the code. This means it gets promoted
622622
// and we can then extract the value by evaluating the promoted.
623623
mir::Operand::Copy(
624-
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
624+
Place::Base(PlaceBase::Static(
625+
box mir::Static {promoted: Some(promoted), ty, ..}
626+
))
625627
) |
626628
mir::Operand::Move(
627-
mir::Place::Base(mir::PlaceBase::Promoted(box(index, ty)))
629+
Place::Base(PlaceBase::Static(
630+
box mir::Static {promoted: Some(promoted), ty, ..}
631+
))
628632
) => {
629633
let param_env = ty::ParamEnv::reveal_all();
630634
let cid = mir::interpret::GlobalId {
631635
instance: self.instance,
632-
promoted: Some(index),
636+
promoted: Some(promoted),
633637
};
634638
let c = bx.tcx().const_eval(param_env.and(cid));
635639
let (llval, ty) = self.simd_shuffle_indices(

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,13 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
408408

409409
let result = match *place {
410410
mir::Place::Base(mir::PlaceBase::Local(_)) => bug!(), // handled above
411-
mir::Place::Base(mir::PlaceBase::Promoted(box (index, ty))) => {
411+
mir::Place::Base(
412+
mir::PlaceBase::Static(box mir::Static { def_id: _, ty, promoted: Some(promoted) })
413+
) => {
412414
let param_env = ty::ParamEnv::reveal_all();
413415
let cid = mir::interpret::GlobalId {
414416
instance: self.instance,
415-
promoted: Some(index),
417+
promoted: Some(promoted),
416418
};
417419
let layout = cx.layout_of(self.monomorphize(&ty));
418420
match bx.tcx().const_eval(param_env.and(cid)) {
@@ -435,7 +437,9 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
435437
}
436438
}
437439
}
438-
mir::Place::Base(mir::PlaceBase::Static(box mir::Static { def_id, ty })) => {
440+
mir::Place::Base(
441+
mir::PlaceBase::Static(box mir::Static { def_id, ty, promoted: None })
442+
) => {
439443
// NB: The layout of a static may be unsized as is the case when working
440444
// with a static that is an extern_type.
441445
let layout = cx.layout_of(self.monomorphize(&ty));

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,20 +1983,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19831983
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
19841984
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
19851985
Place::Base(PlaceBase::Static(ref static_)) => {
1986-
if static_.promoted.is_some() {
1986+
if static_.promoted.is_some() ||
1987+
(static_.promoted.is_none() &&
1988+
self.infcx.tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable)
1989+
){
19871990
Ok(RootPlace {
19881991
place,
19891992
is_local_mutation_allowed,
19901993
})
19911994
} else {
1992-
if self.infcx.tcx.is_static(static_.def_id) != Some(hir::Mutability::MutMutable) {
1993-
Err(place)
1994-
} else {
1995-
Ok(RootPlace {
1996-
place,
1997-
is_local_mutation_allowed,
1998-
})
1999-
}
1995+
Err(place)
20001996
}
20011997
}
20021998
Place::Projection(ref proj) => {

src/librustc_mir/borrow_check/place_ext.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
5050
}
5151
}
5252
Place::Base(PlaceBase::Static(static_)) => {
53-
if static_.promoted.is_none() {
54-
tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable)
55-
} else {
56-
false
57-
}
53+
static_.promoted.is_none() &&
54+
(tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable))
5855
}
5956
Place::Projection(proj) => match proj.elem {
6057
ProjectionElem::Field(..)

src/librustc_mir/borrow_check/places_conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
403403
Overlap::Disjoint
404404
}
405405
},
406-
(p1_, p2_) => {
406+
(_, _) => {
407407
debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
408408
Overlap::Disjoint
409409
}

src/librustc_mir/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ where
584584
use rustc::mir::PlaceBase;
585585
use rustc::mir::Static;
586586
Ok(match *mir_place {
587-
Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty, ..})) => {
587+
Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => {
588588
let instance = self.frame().instance;
589589
self.const_eval_raw(GlobalId {
590590
instance,

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
283283
// an `Index` projection would throw us off-track.
284284
_ => None,
285285
},
286-
Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty, ..})) => {
286+
Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => {
287287
let generics = self.tcx.generics_of(self.source.def_id());
288288
if generics.requires_monomorphization(self.tcx) {
289289
// FIXME: can't handle code with generics

src/librustc_mir/transform/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
702702
None => self.super_place(place, _ctxt, _location)
703703
}
704704
},
705+
_ => self.super_place(place, _ctxt, _location)
705706
}
706707
}
707708

src/librustc_mir/transform/promote_consts.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! initialization and can otherwise silence errors, if
1313
//! move analysis runs after promotion on broken MIR.
1414
15+
use rustc::hir::def_id::DefId;
1516
use rustc::mir::*;
1617
use rustc::mir::visit::{PlaceContext, MutatingUseContext, MutVisitor, Visitor};
1718
use rustc::mir::traversal::ReversePostorder;
@@ -151,7 +152,8 @@ struct Promoter<'a, 'tcx: 'a> {
151152

152153
/// If true, all nested temps are also kept in the
153154
/// source MIR, not moved to the promoted MIR.
154-
keep_original: bool
155+
keep_original: bool,
156+
def_id: DefId
155157
}
156158

157159
impl<'a, 'tcx> Promoter<'a, 'tcx> {
@@ -287,14 +289,19 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
287289
}
288290

289291
fn promote_candidate(mut self, candidate: Candidate) {
292+
use rustc::mir::Static;
290293
let mut operand = {
294+
let def_id = self.def_id.clone();
291295
let promoted = &mut self.promoted;
292296
let promoted_id = Promoted::new(self.source.promoted.len());
293297
let mut promoted_place = |ty, span| {
294298
promoted.span = span;
295299
promoted.local_decls[RETURN_PLACE] =
296300
LocalDecl::new_return_place(ty, span);
297-
Place::Base(PlaceBase::Promoted(box (promoted_id, ty)))
301+
Place::Base(PlaceBase::Static(
302+
Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) })
303+
)
304+
)
298305
};
299306
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
300307
match candidate {
@@ -367,7 +374,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
367374
pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
368375
tcx: TyCtxt<'a, 'tcx, 'tcx>,
369376
mut temps: IndexVec<Local, TempState>,
370-
candidates: Vec<Candidate>) {
377+
candidates: Vec<Candidate>,
378+
def_id: DefId) {
371379
// Visit candidates in reverse, in case they're nested.
372380
debug!("promote_candidates({:?})", candidates);
373381

@@ -412,7 +420,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
412420
tcx,
413421
source: mir,
414422
temps: &mut temps,
415-
keep_original: false
423+
keep_original: false,
424+
def_id
416425
};
417426
promoter.promote_candidate(candidate);
418427
}

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
922922
match *place {
923923
Place::Base(PlaceBase::Local(_)) => {}
924924
Place::Base(PlaceBase::Static(ref global)) => {
925-
assert!(global.promoted.is_none(), {});
925+
assert!(global.promoted.is_none());
926926
if self.tcx
927927
.get_attrs(global.def_id)
928928
.iter()
@@ -1516,7 +1516,7 @@ impl MirPass for QualifyAndPromoteConstants {
15161516
};
15171517

15181518
// Do the actual promotion, now that we know what's viable.
1519-
promote_consts::promote_candidates(mir, tcx, temps, candidates);
1519+
promote_consts::promote_candidates(mir, tcx, temps, candidates, def_id);
15201520
} else {
15211521
if !mir.control_flow_destroyed.is_empty() {
15221522
let mut locals = mir.vars_iter();

0 commit comments

Comments
 (0)