Skip to content

Commit 7fb1c22

Browse files
author
Saleem Jaffer
committed
promoted is still left in 2 places
1 parent 03dafa7 commit 7fb1c22

22 files changed

+336
-283
lines changed

src/librustc/mir/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,9 +1913,6 @@ pub enum PlaceBase<'tcx> {
19131913

19141914
/// static or static mut variable
19151915
Static(Box<Static<'tcx>>),
1916-
1917-
/// Constant code promoted to an injected static
1918-
Promoted(Box<(Promoted, Ty<'tcx>)>),
19191916
}
19201917

19211918
/// The `DefId` of a static, along with its normalized type (which is
@@ -1924,11 +1921,13 @@ pub enum PlaceBase<'tcx> {
19241921
pub struct Static<'tcx> {
19251922
pub def_id: DefId,
19261923
pub ty: Ty<'tcx>,
1924+
pub promoted: Option<Promoted>,
19271925
}
19281926

19291927
impl_stable_hash_for!(struct Static<'tcx> {
19301928
def_id,
1931-
ty
1929+
ty,
1930+
promoted
19321931
});
19331932

19341933
/// The `Projection` data structure defines things of the form `B.x`
@@ -2048,7 +2047,7 @@ impl<'tcx> Place<'tcx> {
20482047
match self {
20492048
Place::Base(PlaceBase::Local(local)) => Some(*local),
20502049
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2051-
Place::Base(PlaceBase::Promoted(..)) | Place::Base(PlaceBase::Static(..)) => None,
2050+
Place::Base(PlaceBase::Static(..)) => None,
20522051
}
20532052
}
20542053
}
@@ -2059,18 +2058,22 @@ impl<'tcx> Debug for Place<'tcx> {
20592058

20602059
match *self {
20612060
Base(PlaceBase::Local(id)) => write!(fmt, "{:?}", id),
2062-
Base(PlaceBase::Static(box self::Static { def_id, ty })) => write!(
2063-
fmt,
2064-
"({}: {:?})",
2065-
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
2066-
ty
2067-
),
2068-
Base(PlaceBase::Promoted(ref promoted)) => write!(
2069-
fmt,
2070-
"({:?}: {:?})",
2071-
promoted.0,
2072-
promoted.1
2073-
),
2061+
Base(PlaceBase::Static(box self::Static { def_id, ty, promoted })) => {
2062+
match promoted {
2063+
None => write!(
2064+
fmt,
2065+
"({}: {:?})",
2066+
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
2067+
ty
2068+
),
2069+
Some(pr) => write!(
2070+
fmt,
2071+
"({:?}: {:?})",
2072+
pr,
2073+
ty
2074+
),
2075+
}
2076+
},
20742077
Projection(ref data) => match data.elem {
20752078
ProjectionElem::Downcast(ref adt_def, index) => {
20762079
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)

src/librustc/mir/tcx.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ impl<'tcx> Place<'tcx> {
160160
match *self {
161161
Place::Base(PlaceBase::Local(index)) =>
162162
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
163-
Place::Base(PlaceBase::Promoted(ref data)) => PlaceTy::Ty { ty: data.1 },
164163
Place::Base(PlaceBase::Static(ref data)) =>
165164
PlaceTy::Ty { ty: data.ty },
166165
Place::Projection(ref proj) =>

src/librustc/mir/visit.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,18 @@ macro_rules! make_mir_visitor {
737737
self.visit_local(local, context, location);
738738
}
739739
Place::Base(PlaceBase::Static(static_)) => {
740+
match static_.promoted {
741+
None => {
742+
self.visit_static(static_, context, location);
743+
}
744+
Some(_) => {
745+
self.visit_ty(
746+
& $($mutability)? static_.ty, TyContext::Location(location)
747+
);
748+
}
749+
}
740750
self.visit_static(static_, context, location);
741751
}
742-
Place::Base(PlaceBase::Promoted(promoted)) => {
743-
self.visit_ty(& $($mutability)? promoted.1, TyContext::Location(location));
744-
},
745752
Place::Projection(proj) => {
746753
self.visit_projection(proj, context, location);
747754
}
@@ -752,7 +759,7 @@ macro_rules! make_mir_visitor {
752759
static_: & $($mutability)? Static<'tcx>,
753760
_context: PlaceContext<'tcx>,
754761
location: Location) {
755-
let Static { def_id, ty } = static_;
762+
let Static { def_id, ty, promoted: _ } = static_;
756763
self.visit_def_id(def_id, location);
757764
self.visit_ty(ty, TyContext::Location(location));
758765
}

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,14 +1598,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15981598
including_downcast: &IncludingDowncast,
15991599
) -> Result<(), ()> {
16001600
match *place {
1601-
Place::Base(PlaceBase::Promoted(_)) => {
1602-
buf.push_str("promoted");
1603-
}
16041601
Place::Base(PlaceBase::Local(local)) => {
16051602
self.append_local_to_string(local, buf)?;
16061603
}
16071604
Place::Base(PlaceBase::Static(ref static_)) => {
1608-
buf.push_str(&self.infcx.tcx.item_name(static_.def_id).to_string());
1605+
match static_.promoted {
1606+
Some(_) => {
1607+
buf.push_str("promoted");
1608+
}
1609+
None => {
1610+
buf.push_str(&self.infcx.tcx.item_name(static_.def_id).to_string());
1611+
}
1612+
}
16091613
}
16101614
Place::Projection(ref proj) => {
16111615
match proj.elem {
@@ -1744,8 +1748,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17441748
let local = &self.mir.local_decls[local];
17451749
self.describe_field_from_ty(&local.ty, field)
17461750
}
1747-
Place::Base(PlaceBase::Promoted(ref prom)) =>
1748-
self.describe_field_from_ty(&prom.1, field),
17491751
Place::Base(PlaceBase::Static(ref static_)) =>
17501752
self.describe_field_from_ty(&static_.ty, field),
17511753
Place::Projection(ref proj) => match proj.elem {
@@ -1828,8 +1830,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18281830
let tcx = self.infcx.tcx;
18291831
match place {
18301832
Place::Base(PlaceBase::Local(_)) |
1831-
Place::Base(PlaceBase::Static(_)) |
1832-
Place::Base(PlaceBase::Promoted(_)) => {
1833+
Place::Base(PlaceBase::Static(_)) => {
18331834
StorageDeadOrDrop::LocalStorageDead
18341835
}
18351836
Place::Projection(box PlaceProjection { base, elem }) => {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12261226
}
12271227
Operand::Move(Place::Base(PlaceBase::Static(..)))
12281228
| Operand::Copy(Place::Base(PlaceBase::Static(..)))
1229-
| Operand::Move(Place::Base(PlaceBase::Promoted(..)))
1230-
| Operand::Copy(Place::Base(PlaceBase::Promoted(..)))
12311229
| Operand::Constant(..) => {}
12321230
}
12331231
}
@@ -1310,12 +1308,16 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13101308
//
13111309
// FIXME: allow thread-locals to borrow other thread locals?
13121310
let (might_be_alive, will_be_dropped) = match root_place {
1313-
Place::Base(PlaceBase::Promoted(_)) => (true, false),
1314-
Place::Base(PlaceBase::Static(_)) => {
1315-
// Thread-locals might be dropped after the function exits, but
1316-
// "true" statics will never be.
1317-
let is_thread_local = self.is_place_thread_local(&root_place);
1318-
(true, is_thread_local)
1311+
Place::Base(PlaceBase::Static(st)) => {
1312+
match st.promoted {
1313+
None => {
1314+
// Thread-locals might be dropped after the function exits, but
1315+
// "true" statics will never be.
1316+
let is_thread_local = self.is_place_thread_local(&root_place);
1317+
(true, is_thread_local)
1318+
}
1319+
Some(_) => (true, false),
1320+
}
13191321
}
13201322
Place::Base(PlaceBase::Local(_)) => {
13211323
// Locals are always dropped at function exit, and if they
@@ -1578,7 +1580,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15781580
match *last_prefix {
15791581
Place::Base(PlaceBase::Local(_)) => panic!("should have move path for every Local"),
15801582
Place::Projection(_) => panic!("PrefixSet::All meant don't stop for Projection"),
1581-
Place::Base(PlaceBase::Promoted(_)) |
15821583
Place::Base(PlaceBase::Static(_)) => Err(NoMovePathFound::ReachedStatic),
15831584
}
15841585
}
@@ -1605,7 +1606,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16051606
let mut place = place;
16061607
loop {
16071608
match *place {
1608-
Place::Base(PlaceBase::Promoted(_)) |
16091609
Place::Base(PlaceBase::Local(_)) | Place::Base(PlaceBase::Static(_)) => {
16101610
// assigning to `x` does not require `x` be initialized.
16111611
break;
@@ -1953,10 +1953,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19531953
self.used_mut_upvars.push(field);
19541954
}
19551955
}
1956-
RootPlace {
1957-
place: Place::Base(PlaceBase::Promoted(..)),
1958-
is_local_mutation_allowed: _,
1959-
} => {}
19601956
RootPlace {
19611957
place: Place::Base(PlaceBase::Static(..)),
19621958
is_local_mutation_allowed: _,
@@ -1994,18 +1990,28 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19941990
}
19951991
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
19961992
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
1997-
Place::Base(PlaceBase::Promoted(_)) => Ok(RootPlace {
1998-
place,
1999-
is_local_mutation_allowed,
2000-
}),
1993+
// Place::Base(PlaceBase::Promoted(_)) => Ok(RootPlace {
1994+
// place,
1995+
// is_local_mutation_allowed,
1996+
// }),
20011997
Place::Base(PlaceBase::Static(ref static_)) => {
2002-
if self.infcx.tcx.is_static(static_.def_id) != Some(hir::Mutability::MutMutable) {
2003-
Err(place)
2004-
} else {
2005-
Ok(RootPlace {
2006-
place,
2007-
is_local_mutation_allowed,
2008-
})
1998+
match static_.promoted {
1999+
Some(_) => {
2000+
Ok(RootPlace {
2001+
place,
2002+
is_local_mutation_allowed,
2003+
})
2004+
}
2005+
None => {
2006+
if self.infcx.tcx.is_static(static_.def_id) != Some(hir::Mutability::MutMutable) {
2007+
Err(place)
2008+
} else {
2009+
Ok(RootPlace {
2010+
place,
2011+
is_local_mutation_allowed,
2012+
})
2013+
}
2014+
}
20092015
}
20102016
}
20112017
Place::Projection(ref proj) => {

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,19 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
129129
}
130130
}
131131

132-
Place::Base(PlaceBase::Promoted(_)) => unreachable!(),
133-
134-
Place::Base(PlaceBase::Static(box Static { def_id, ty: _ })) => {
135-
if let Place::Base(PlaceBase::Static(_)) = access_place {
136-
item_msg = format!("immutable static item `{}`", access_place_desc.unwrap());
137-
reason = String::new();
138-
} else {
139-
item_msg = format!("`{}`", access_place_desc.unwrap());
140-
let static_name = &self.infcx.tcx.item_name(*def_id);
141-
reason = format!(", as `{}` is an immutable static item", static_name);
132+
Place::Base(PlaceBase::Static(box Static { def_id, ty: _, promoted })) => {
133+
match promoted {
134+
Some(_) => unreachable!(),
135+
None => {
136+
if let Place::Base(PlaceBase::Static(_)) = access_place {
137+
item_msg = format!("immutable static item `{}`", access_place_desc.unwrap());
138+
reason = String::new();
139+
} else {
140+
item_msg = format!("`{}`", access_place_desc.unwrap());
141+
let static_name = &self.infcx.tcx.item_name(*def_id);
142+
reason = format!(", as `{}` is an immutable static item", static_name);
143+
}
144+
}
142145
}
143146
}
144147

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -453,51 +453,55 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
453453
Place::Base(PlaceBase::Local(index)) => PlaceTy::Ty {
454454
ty: self.mir.local_decls[index].ty,
455455
},
456-
Place::Base(PlaceBase::Promoted(box (index, sty))) => {
457-
let sty = self.sanitize_type(place, sty);
458-
459-
if !self.errors_reported {
460-
let promoted_mir = &self.mir.promoted[index];
461-
self.sanitize_promoted(promoted_mir, location);
462-
463-
let promoted_ty = promoted_mir.return_ty();
464-
465-
if let Err(terr) = self.cx.eq_types(
466-
sty,
467-
promoted_ty,
468-
location.to_locations(),
469-
ConstraintCategory::Boring,
470-
) {
471-
span_mirbug!(
472-
self,
473-
place,
474-
"bad promoted type ({:?}: {:?}): {:?}",
475-
promoted_ty,
476-
sty,
477-
terr
478-
);
479-
};
480-
}
481-
PlaceTy::Ty { ty: sty }
482-
}
483-
Place::Base(PlaceBase::Static(box Static { def_id, ty: sty })) => {
484-
let sty = self.sanitize_type(place, sty);
485-
let ty = self.tcx().type_of(def_id);
486-
let ty = self.cx.normalize(ty, location);
487-
if let Err(terr) =
488-
self.cx
489-
.eq_types(ty, sty, location.to_locations(), ConstraintCategory::Boring)
490-
{
491-
span_mirbug!(
492-
self,
493-
place,
494-
"bad static type ({:?}: {:?}): {:?}",
495-
ty,
496-
sty,
497-
terr
498-
);
456+
Place::Base(PlaceBase::Static(box Static { def_id, ty: sty, promoted })) => {
457+
match promoted {
458+
Some(pr) => {
459+
let sty = self.sanitize_type(place, sty);
460+
461+
if !self.errors_reported {
462+
let promoted_mir = &self.mir.promoted[pr];
463+
self.sanitize_promoted(promoted_mir, location);
464+
465+
let promoted_ty = promoted_mir.return_ty();
466+
467+
if let Err(terr) = self.cx.eq_types(
468+
sty,
469+
promoted_ty,
470+
location.to_locations(),
471+
ConstraintCategory::Boring,
472+
) {
473+
span_mirbug!(
474+
self,
475+
place,
476+
"bad promoted type ({:?}: {:?}): {:?}",
477+
promoted_ty,
478+
sty,
479+
terr
480+
);
481+
};
482+
}
483+
PlaceTy::Ty { ty: sty }
484+
}
485+
None => {
486+
let sty = self.sanitize_type(place, sty);
487+
let ty = self.tcx().type_of(def_id);
488+
let ty = self.cx.normalize(ty, location);
489+
if let Err(terr) =
490+
self.cx
491+
.eq_types(ty, sty, location.to_locations(), ConstraintCategory::Boring)
492+
{
493+
span_mirbug!(
494+
self,
495+
place,
496+
"bad static type ({:?}: {:?}): {:?}",
497+
ty,
498+
sty,
499+
terr
500+
);
501+
}
502+
PlaceTy::Ty { ty: sty }
503+
}
499504
}
500-
PlaceTy::Ty { ty: sty }
501505
}
502506
Place::Projection(ref proj) => {
503507
let base_context = if context.is_mutating_use() {

src/librustc_mir/borrow_check/path_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ pub(super) fn is_active<'tcx>(
138138
/// This is called for all Yield statements on movable generators
139139
pub(super) fn borrow_of_local_data<'tcx>(place: &Place<'tcx>) -> bool {
140140
match place {
141-
Place::Base(PlaceBase::Promoted(_)) |
142141
Place::Base(PlaceBase::Static(..)) => false,
143142
Place::Base(PlaceBase::Local(..)) => true,
144143
Place::Projection(box proj) => {

0 commit comments

Comments
 (0)