Skip to content

Commit fb93f10

Browse files
author
Saleem Jaffer
committed
code review fixes
1 parent 752544b commit fb93f10

File tree

6 files changed

+81
-115
lines changed

6 files changed

+81
-115
lines changed

src/librustc/mir/visit.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -725,17 +725,14 @@ macro_rules! make_mir_visitor {
725725
place: & $($mutability)? Place<'tcx>,
726726
context: PlaceContext<'tcx>,
727727
location: Location) {
728-
use crate::mir::{Static, StaticKind};
729728
match place {
730729
Place::Base(PlaceBase::Local(local)) => {
731730
self.visit_local(local, context, location);
732731
}
733-
Place::Base(
734-
PlaceBase::Static(box Static{kind: StaticKind::Static(def_id), ..})
735-
) => {
736-
self.visit_def_id(& $($mutability)? *def_id, location)
737-
}
738-
Place::Base(PlaceBase::Static(box Static{ty, ..})) => {
732+
Place::Base(PlaceBase::Static(box Static { kind, ty })) => {
733+
if let StaticKind::Static(def_id) = kind {
734+
self.visit_def_id(& $($mutability)? *def_id, location)
735+
}
739736
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
740737
}
741738
Place::Projection(proj) => {

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13131313
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {
13141314
(true, false)
13151315
}
1316-
Place::Base(PlaceBase::Static(box Static{ kind: _, .. })) => {
1316+
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(_), .. })) => {
13171317
// Thread-locals might be dropped after the function exits, but
13181318
// "true" statics will never be.
13191319
(true, self.is_place_thread_local(&root_place))

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

+34-42
Original file line numberDiff line numberDiff line change
@@ -449,57 +449,49 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
449449
context: PlaceContext<'_>,
450450
) -> PlaceTy<'tcx> {
451451
debug!("sanitize_place: {:?}", place);
452-
let place_ty = match *place {
452+
let place_ty = match place {
453453
Place::Base(PlaceBase::Local(index)) => PlaceTy::Ty {
454-
ty: self.mir.local_decls[index].ty,
454+
ty: self.mir.local_decls[*index].ty,
455455
},
456-
Place::Base(
457-
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted), ty: sty })
458-
) => {
456+
Place::Base(PlaceBase::Static(box Static { kind, ty: sty })) => {
459457
let sty = self.sanitize_type(place, sty);
460-
461-
if !self.errors_reported {
462-
let promoted_mir = &self.mir.promoted[promoted];
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,
458+
let check_err =
459+
|verifier: &mut TypeVerifier<'a, 'b, 'gcx, 'tcx>,
460+
place: &Place<'tcx>,
461+
ty,
462+
sty| {
463+
if let Err(terr) = verifier.cx.eq_types(
464+
sty,
465+
ty,
466+
location.to_locations(),
467+
ConstraintCategory::Boring,
468+
) {
469+
span_mirbug!(
470+
verifier,
475471
place,
476472
"bad promoted type ({:?}: {:?}): {:?}",
477-
promoted_ty,
473+
ty,
478474
sty,
479475
terr
480476
);
477+
};
481478
};
482-
}
483-
PlaceTy::Ty { ty: sty }
484-
}
485-
Place::Base(
486-
PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), ty: sty })
487-
) => {
488-
let sty = self.sanitize_type(place, sty);
489-
let ty = self.tcx().type_of(def_id);
490-
let ty = self.cx.normalize(ty, location);
491-
if let Err(terr) =
492-
self.cx
493-
.eq_types(ty, sty, location.to_locations(), ConstraintCategory::Boring)
494-
{
495-
span_mirbug!(
496-
self,
497-
place,
498-
"bad static type ({:?}: {:?}): {:?}",
499-
ty,
500-
sty,
501-
terr
502-
);
479+
match kind {
480+
StaticKind::Promoted(promoted) => {
481+
if !self.errors_reported {
482+
let promoted_mir = &self.mir.promoted[*promoted];
483+
self.sanitize_promoted(promoted_mir, location);
484+
485+
let promoted_ty = promoted_mir.return_ty();
486+
check_err(self, place, promoted_ty, sty);
487+
}
488+
}
489+
StaticKind::Static(def_id) => {
490+
let ty = self.tcx().type_of(*def_id);
491+
let ty = self.cx.normalize(ty, location);
492+
493+
check_err(self, place, ty, sty);
494+
}
503495
}
504496
PlaceTy::Ty { ty: sty }
505497
}

src/librustc_mir/borrow_check/places_conflict.rs

+38-62
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::borrow_check::ArtificialField;
22
use crate::borrow_check::Overlap;
33
use crate::borrow_check::{Deep, Shallow, AccessDepth};
44
use rustc::hir;
5-
use rustc::mir::{BorrowKind, Mir, Place, PlaceBase, Projection, ProjectionElem, Static, StaticKind};
5+
use rustc::mir::{BorrowKind, Mir, Place, PlaceBase, Projection, ProjectionElem, StaticKind};
66
use rustc::ty::{self, TyCtxt};
77
use std::cmp::max;
88

@@ -370,71 +370,47 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
370370
Overlap::Disjoint
371371
}
372372
}
373-
(
374-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(def_id_1), .. })),
375-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(def_id_2), .. })),
376-
) => {
377-
if *def_id_1 != *def_id_2 {
378-
debug!("place_element_conflict: DISJOINT-STATIC");
379-
Overlap::Disjoint
380-
} else if tcx.is_static(*def_id_1) == Some(hir::Mutability::MutMutable) {
381-
// We ignore mutable statics - they can only be unsafe code.
382-
debug!("place_element_conflict: IGNORE-STATIC-MUT");
383-
Overlap::Disjoint
384-
} else {
385-
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
386-
Overlap::EqualOrDisjoint
387-
}
388-
}
389-
(
390-
Place::Base(
391-
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted_1), ty })
392-
),
393-
Place::Base(
394-
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted_2), .. })
395-
),
396-
) => {
397-
if *promoted_1 == *promoted_2 {
398-
if let ty::Array(_, size) = ty.sty {
399-
if size.unwrap_usize(tcx) == 0 {
400-
// Ignore conflicts with promoted [T; 0].
401-
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
402-
return Overlap::Disjoint;
373+
(Place::Base(PlaceBase::Static(s1)), Place::Base(PlaceBase::Static(s2))) => {
374+
match (&s1.kind, &s2.kind) {
375+
(StaticKind::Static(def_id_1), StaticKind::Static(def_id_2)) => {
376+
if def_id_1 != def_id_2 {
377+
debug!("place_element_conflict: DISJOINT-STATIC");
378+
Overlap::Disjoint
379+
} else if tcx.is_static(*def_id_1) == Some(hir::Mutability::MutMutable) {
380+
// We ignore mutable statics - they can only be unsafe code.
381+
debug!("place_element_conflict: IGNORE-STATIC-MUT");
382+
Overlap::Disjoint
383+
} else {
384+
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
385+
Overlap::EqualOrDisjoint
403386
}
387+
},
388+
(StaticKind::Promoted(promoted_1), StaticKind::Promoted(promoted_2)) => {
389+
if promoted_1 == promoted_2 {
390+
if let ty::Array(_, size) = s1.ty.sty {
391+
if size.unwrap_usize(tcx) == 0 {
392+
// Ignore conflicts with promoted [T; 0].
393+
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
394+
return Overlap::Disjoint;
395+
}
396+
}
397+
// the same promoted - base case, equal
398+
debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
399+
Overlap::EqualOrDisjoint
400+
} else {
401+
// different promoteds - base case, disjoint
402+
debug!("place_element_conflict: DISJOINT-PROMOTED");
403+
Overlap::Disjoint
404+
}
405+
},
406+
(_, _) => {
407+
debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
408+
Overlap::Disjoint
404409
}
405-
// the same promoted - base case, equal
406-
debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
407-
Overlap::EqualOrDisjoint
408-
} else {
409-
// different promoteds - base case, disjoint
410-
debug!("place_element_conflict: DISJOINT-PROMOTED");
411-
Overlap::Disjoint
412410
}
413411
}
414-
(
415-
Place::Base(PlaceBase::Local(_)),
416-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }))
417-
) |
418-
(
419-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. })),
420-
Place::Base(PlaceBase::Local(_))
421-
) |
422-
(
423-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. })),
424-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. }))
425-
) |
426-
(
427-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. })),
428-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }))
429-
) |
430-
(
431-
Place::Base(PlaceBase::Local(_)),
432-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. }))
433-
) |
434-
(
435-
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. })),
436-
Place::Base(PlaceBase::Local(_))
437-
) => {
412+
(Place::Base(PlaceBase::Local(_)), Place::Base(PlaceBase::Static(_))) |
413+
(Place::Base(PlaceBase::Static(_)), Place::Base(PlaceBase::Local(_))) => {
438414
debug!("place_element_conflict: DISJOINT-STATIC-LOCAL-PROMOTED");
439415
Overlap::Disjoint
440416
}

src/librustc_mir/transform/promote_consts.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
292292
let promoted_id = Promoted::new(self.source.promoted.len());
293293
let mut promoted_place = |ty, span| {
294294
promoted.span = span;
295-
promoted.local_decls[RETURN_PLACE] =
296-
LocalDecl::new_return_place(ty, span);
295+
promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
297296
Place::Base(
298297
PlaceBase::Static(box Static{ kind: StaticKind::Promoted(promoted_id), ty })
299298
)

src/librustc_mir/transform/qualify_consts.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
930930
self.super_place(place, context, location);
931931
match *place {
932932
Place::Base(PlaceBase::Local(_)) => {}
933-
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {}
933+
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {
934+
unreachable!()
935+
}
934936
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(def_id), .. })) => {
935937
if self.tcx
936938
.get_attrs(def_id)

0 commit comments

Comments
 (0)