Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saleem Jaffer committed Mar 21, 2019
1 parent 8829dda commit cf2f1bb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 56 deletions.
8 changes: 4 additions & 4 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,13 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// and we can then extract the value by evaluating the promoted.
mir::Operand::Copy(
Place::Base(PlaceBase::Static(
box mir::Static {promoted: Some(promoted), ty, ..}
))
box mir::Static {promoted: Some(promoted), ty, ..}
))
) |
mir::Operand::Move(
Place::Base(PlaceBase::Static(
box mir::Static {promoted: Some(promoted), ty, ..}
))
box mir::Static {promoted: Some(promoted), ty, ..}
))
) => {
let param_env = ty::ParamEnv::reveal_all();
let cid = mir::interpret::GlobalId {
Expand Down
58 changes: 24 additions & 34 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,52 +455,42 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
},
Place::Base(PlaceBase::Static(box Static { def_id, ty: sty, promoted })) => {
let sty = self.sanitize_type(place, sty);
let check_err =
|verifier: &mut TypeVerifier<'a, 'b, 'gcx, 'tcx> ,
place: &Place<'tcx>,
ty,
sty| {
if let Err(terr) = verifier.cx.eq_types(
sty,
ty,
location.to_locations(),
ConstraintCategory::Boring,
) {
span_mirbug!(
verifier,
place,
"bad promoted type ({:?}: {:?}): {:?}",
ty,
sty,
terr
);
};
};
match promoted {
Some(pr) => {
if !self.errors_reported {
let promoted_mir = &self.mir.promoted[pr];
self.sanitize_promoted(promoted_mir, location);

let promoted_ty = promoted_mir.return_ty();

if let Err(terr) = self.cx.eq_types(
sty,
promoted_ty,
location.to_locations(),
ConstraintCategory::Boring,
) {
span_mirbug!(
self,
place,
"bad promoted type ({:?}: {:?}): {:?}",
promoted_ty,
sty,
terr
);
};
check_err(self, place, promoted_ty, sty);
}
}
None => {
let ty = self.tcx().type_of(def_id);
let ty = self.cx.normalize(ty, location);
if let Err(terr) =
self.cx
.eq_types(
ty,
sty,
location.to_locations(),
ConstraintCategory::Boring
)
{
span_mirbug!(
self,
place,
"bad static type ({:?}: {:?}): {:?}",
ty,
sty,
terr
);
};

check_err(self, place, ty, sty);
}
}
PlaceTy::Ty { ty: sty }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
// an `Index` projection would throw us off-track.
_ => None,
},
Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => {
Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ..})) => {
let generics = self.tcx.generics_of(self.source.def_id());
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
Expand Down
11 changes: 3 additions & 8 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,14 +692,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
// Return pointer; update the place itself
*place = self.destination.clone();
},
Place::Base(PlaceBase::Static(ref mut static_)) => {
match static_.promoted {
Some(promoted) => {
if let Some(p) = self.promoted_map.get(promoted).cloned() {
static_.promoted = Some(p);
}
}
None => self.super_place(place, _ctxt, _location)
Place::Base(PlaceBase::Static(box Static { promoted: Some(promoted), .. })) => {
if let Some(p) = self.promoted_map.get(*promoted).cloned() {
*promoted = p;
}
},
_ => self.super_place(place, _ctxt, _location)
Expand Down
15 changes: 6 additions & 9 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct Promoter<'a, 'tcx: 'a> {
/// If true, all nested temps are also kept in the
/// source MIR, not moved to the promoted MIR.
keep_original: bool,
def_id: DefId
def_id: DefId,
}

impl<'a, 'tcx> Promoter<'a, 'tcx> {
Expand Down Expand Up @@ -291,17 +291,14 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
fn promote_candidate(mut self, candidate: Candidate) {
use rustc::mir::Static;
let mut operand = {
let def_id = self.def_id.clone();
let def_id = self.def_id;
let promoted = &mut self.promoted;
let promoted_id = Promoted::new(self.source.promoted.len());
let mut promoted_place = |ty, span| {
promoted.span = span;
promoted.local_decls[RETURN_PLACE] =
LocalDecl::new_return_place(ty, span);
Place::Base(PlaceBase::Static(
Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) })
)
)
promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
Place::Base(
PlaceBase::Static(Box::new(Static { def_id, ty, promoted: Some(promoted_id) })))
};
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
match candidate {
Expand Down Expand Up @@ -421,7 +418,7 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
source: mir,
temps: &mut temps,
keep_original: false,
def_id
def_id,
};
promoter.promote_candidate(candidate);
}
Expand Down

0 comments on commit cf2f1bb

Please sign in to comment.