code review fixes

This commit is contained in:
Saleem Jaffer 2019-03-24 08:59:11 +05:30
parent 752544b284
commit fb93f10dac
6 changed files with 81 additions and 115 deletions

View File

@ -725,17 +725,14 @@ fn super_place(&mut self,
place: & $($mutability)? Place<'tcx>,
context: PlaceContext<'tcx>,
location: Location) {
use crate::mir::{Static, StaticKind};
match place {
Place::Base(PlaceBase::Local(local)) => {
self.visit_local(local, context, location);
}
Place::Base(
PlaceBase::Static(box Static{kind: StaticKind::Static(def_id), ..})
) => {
self.visit_def_id(& $($mutability)? *def_id, location)
}
Place::Base(PlaceBase::Static(box Static{ty, ..})) => {
Place::Base(PlaceBase::Static(box Static { kind, ty })) => {
if let StaticKind::Static(def_id) = kind {
self.visit_def_id(& $($mutability)? *def_id, location)
}
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
}
Place::Projection(proj) => {

View File

@ -1313,7 +1313,7 @@ fn check_for_invalidation_at_exit(
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {
(true, false)
}
Place::Base(PlaceBase::Static(box Static{ kind: _, .. })) => {
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(_), .. })) => {
// Thread-locals might be dropped after the function exits, but
// "true" statics will never be.
(true, self.is_place_thread_local(&root_place))

View File

@ -449,57 +449,49 @@ fn sanitize_place(
context: PlaceContext<'_>,
) -> PlaceTy<'tcx> {
debug!("sanitize_place: {:?}", place);
let place_ty = match *place {
let place_ty = match place {
Place::Base(PlaceBase::Local(index)) => PlaceTy::Ty {
ty: self.mir.local_decls[index].ty,
ty: self.mir.local_decls[*index].ty,
},
Place::Base(
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted), ty: sty })
) => {
Place::Base(PlaceBase::Static(box Static { kind, ty: sty })) => {
let sty = self.sanitize_type(place, sty);
if !self.errors_reported {
let promoted_mir = &self.mir.promoted[promoted];
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,
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 ({:?}: {:?}): {:?}",
promoted_ty,
ty,
sty,
terr
);
};
};
}
PlaceTy::Ty { ty: sty }
}
Place::Base(
PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), ty: sty })
) => {
let sty = self.sanitize_type(place, sty);
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
);
match kind {
StaticKind::Promoted(promoted) => {
if !self.errors_reported {
let promoted_mir = &self.mir.promoted[*promoted];
self.sanitize_promoted(promoted_mir, location);
let promoted_ty = promoted_mir.return_ty();
check_err(self, place, promoted_ty, sty);
}
}
StaticKind::Static(def_id) => {
let ty = self.tcx().type_of(*def_id);
let ty = self.cx.normalize(ty, location);
check_err(self, place, ty, sty);
}
}
PlaceTy::Ty { ty: sty }
}

View File

@ -2,7 +2,7 @@
use crate::borrow_check::Overlap;
use crate::borrow_check::{Deep, Shallow, AccessDepth};
use rustc::hir;
use rustc::mir::{BorrowKind, Mir, Place, PlaceBase, Projection, ProjectionElem, Static, StaticKind};
use rustc::mir::{BorrowKind, Mir, Place, PlaceBase, Projection, ProjectionElem, StaticKind};
use rustc::ty::{self, TyCtxt};
use std::cmp::max;
@ -370,71 +370,47 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
Overlap::Disjoint
}
}
(
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(def_id_1), .. })),
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(def_id_2), .. })),
) => {
if *def_id_1 != *def_id_2 {
debug!("place_element_conflict: DISJOINT-STATIC");
Overlap::Disjoint
} else if tcx.is_static(*def_id_1) == Some(hir::Mutability::MutMutable) {
// We ignore mutable statics - they can only be unsafe code.
debug!("place_element_conflict: IGNORE-STATIC-MUT");
Overlap::Disjoint
} else {
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
Overlap::EqualOrDisjoint
}
}
(
Place::Base(
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted_1), ty })
),
Place::Base(
PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted_2), .. })
),
) => {
if *promoted_1 == *promoted_2 {
if let ty::Array(_, size) = ty.sty {
if size.unwrap_usize(tcx) == 0 {
// Ignore conflicts with promoted [T; 0].
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
return Overlap::Disjoint;
(Place::Base(PlaceBase::Static(s1)), Place::Base(PlaceBase::Static(s2))) => {
match (&s1.kind, &s2.kind) {
(StaticKind::Static(def_id_1), StaticKind::Static(def_id_2)) => {
if def_id_1 != def_id_2 {
debug!("place_element_conflict: DISJOINT-STATIC");
Overlap::Disjoint
} else if tcx.is_static(*def_id_1) == Some(hir::Mutability::MutMutable) {
// We ignore mutable statics - they can only be unsafe code.
debug!("place_element_conflict: IGNORE-STATIC-MUT");
Overlap::Disjoint
} else {
debug!("place_element_conflict: DISJOINT-OR-EQ-STATIC");
Overlap::EqualOrDisjoint
}
},
(StaticKind::Promoted(promoted_1), StaticKind::Promoted(promoted_2)) => {
if promoted_1 == promoted_2 {
if let ty::Array(_, size) = s1.ty.sty {
if size.unwrap_usize(tcx) == 0 {
// Ignore conflicts with promoted [T; 0].
debug!("place_element_conflict: IGNORE-LEN-0-PROMOTED");
return Overlap::Disjoint;
}
}
// the same promoted - base case, equal
debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
Overlap::EqualOrDisjoint
} else {
// different promoteds - base case, disjoint
debug!("place_element_conflict: DISJOINT-PROMOTED");
Overlap::Disjoint
}
},
(_, _) => {
debug!("place_element_conflict: DISJOINT-STATIC-PROMOTED");
Overlap::Disjoint
}
// the same promoted - base case, equal
debug!("place_element_conflict: DISJOINT-OR-EQ-PROMOTED");
Overlap::EqualOrDisjoint
} else {
// different promoteds - base case, disjoint
debug!("place_element_conflict: DISJOINT-PROMOTED");
Overlap::Disjoint
}
}
(
Place::Base(PlaceBase::Local(_)),
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }))
) |
(
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. })),
Place::Base(PlaceBase::Local(_))
) |
(
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. })),
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. }))
) |
(
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. })),
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }))
) |
(
Place::Base(PlaceBase::Local(_)),
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. }))
) |
(
Place::Base(PlaceBase::Static(box Static { kind: StaticKind::Static(_), .. })),
Place::Base(PlaceBase::Local(_))
) => {
(Place::Base(PlaceBase::Local(_)), Place::Base(PlaceBase::Static(_))) |
(Place::Base(PlaceBase::Static(_)), Place::Base(PlaceBase::Local(_))) => {
debug!("place_element_conflict: DISJOINT-STATIC-LOCAL-PROMOTED");
Overlap::Disjoint
}

View File

@ -292,8 +292,7 @@ fn promote_candidate(mut self, candidate: Candidate) {
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);
promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
Place::Base(
PlaceBase::Static(box Static{ kind: StaticKind::Promoted(promoted_id), ty })
)

View File

@ -930,7 +930,9 @@ fn visit_place(&mut self,
self.super_place(place, context, location);
match *place {
Place::Base(PlaceBase::Local(_)) => {}
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {}
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Promoted(_), .. })) => {
unreachable!()
}
Place::Base(PlaceBase::Static(box Static{ kind: StaticKind::Static(def_id), .. })) => {
if self.tcx
.get_attrs(def_id)