Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #63214

Merged
merged 42 commits into from
Aug 2, 2019
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0aa9658
changing the fields of InterpError
saleemjaffer Jul 25, 2019
01859bb
grouping the variants of InterpError
saleemjaffer Jul 26, 2019
fc48f3e
more grouping of the variants in InterpError
saleemjaffer Jul 26, 2019
eeb2335
moving remaining variants to UnsupportedInfo
saleemjaffer Jul 26, 2019
4f0ab6c
code review fixes
saleemjaffer Jul 26, 2019
307798a
fixing fallout due to InterpError refactor
saleemjaffer Jul 27, 2019
aa3d40c
tidy fixes
saleemjaffer Jul 27, 2019
9782b37
implementing Debug for UnsupportedInfo
saleemjaffer Jul 28, 2019
8e9d0fa
adding a err macro for each of the InterpError variants
saleemjaffer Jul 29, 2019
654519d
use PanicInfo and UnsupportedOpInfo
saleemjaffer Jul 29, 2019
03d47be
code review fixes
saleemjaffer Jul 29, 2019
9f8b099
code review fixes
saleemjaffer Jul 29, 2019
5bb06b3
code review fixes
saleemjaffer Jul 29, 2019
9620521
code review fixes
saleemjaffer Jul 30, 2019
2a33fbf
addding an interp_error module
saleemjaffer Jul 30, 2019
69daf84
adding throw_ and err_ macros for InterpError
saleemjaffer Jul 30, 2019
b60a336
tidy fixes
saleemjaffer Jul 30, 2019
fc5df1d
renaming err to err_unsup
saleemjaffer Jul 30, 2019
35417e7
renaming throw_err_* to throw_*
saleemjaffer Jul 30, 2019
5585445
throw_X macros use err_X macros
saleemjaffer Jul 30, 2019
87e73c1
Remove redundant method with const variable resolution
varkor Jul 31, 2019
152f0d3
code review fixes
saleemjaffer Jul 31, 2019
a1e59d1
code review fixes
saleemjaffer Jul 31, 2019
c17d11f
code review fixes
saleemjaffer Jul 31, 2019
0c4513e
code review fixes
saleemjaffer Aug 1, 2019
00d32e8
code review fixes
saleemjaffer Aug 1, 2019
b5c04e6
FixedSizeArray: Add missing links in doc comments.
waywardmonkeys Aug 1, 2019
cbac781
More questionmarks in doctests
llogiq Jul 13, 2019
86633b6
Fix typos in doc comments.
waywardmonkeys Aug 1, 2019
ae65848
Remove extraneous {} in use stmts in doc comments.
waywardmonkeys Aug 1, 2019
325c6a5
Futures: Add link to Waker in trait doc.
waywardmonkeys Aug 1, 2019
cefbf4d
Allow trailing comma in macro 2.0 declarations.
rbartlensky Aug 1, 2019
b3321fb
Fix ICE in #63135
ExpHP Aug 1, 2019
2aa368a
Add check-pass test for #63102.
rbartlensky Aug 1, 2019
7052c35
Make is_mutable use PlaceRef instead of it's fields
spastorino Aug 1, 2019
6b951c2
Rollup merge of #62663 - llogiq:more-questionmark-docs, r=GuillaumeGomez
Centril Aug 2, 2019
51dc78e
Rollup merge of #62969 - saleemjaffer:declutter_interperror, r=RalfJung
Centril Aug 2, 2019
5155c7e
Rollup merge of #63153 - varkor:remove-resolve_const_var, r=cramertj
Centril Aug 2, 2019
dbfe12d
Rollup merge of #63189 - waywardmonkeys:doc-improvements, r=Centril
Centril Aug 2, 2019
89dce46
Rollup merge of #63198 - rbartlensky:fix-macro-trailing-comma, r=petr…
Centril Aug 2, 2019
3396550
Rollup merge of #63202 - exphp-forks:parser-ice-63135, r=estebank
Centril Aug 2, 2019
97098f4
Rollup merge of #63203 - spastorino:is-mutable-use-place-ref, r=oli-obk
Centril Aug 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make is_mutable use PlaceRef instead of it's fields
  • Loading branch information
spastorino committed Aug 1, 2019
commit 7052c356982947486403a07f7f43b9e57ac875c7
133 changes: 71 additions & 62 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
@@ -1942,7 +1942,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
BorrowKind::Mut { .. } => is_local_mutation_allowed,
BorrowKind::Shared | BorrowKind::Shallow => unreachable!(),
};
match self.is_mutable(&place.base, &place.projection, is_local_mutation_allowed) {
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
Ok(root_place) => {
self.add_used_mut(root_place, flow_state);
return false;
@@ -1954,7 +1954,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
Reservation(WriteKind::Mutate) | Write(WriteKind::Mutate) => {
match self.is_mutable(&place.base, &place.projection, is_local_mutation_allowed) {
match self.is_mutable(place.as_ref(), is_local_mutation_allowed) {
Ok(root_place) => {
self.add_used_mut(root_place, flow_state);
return false;
@@ -1974,8 +1974,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
| Write(wk @ WriteKind::StorageDeadOrDrop)
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shared))
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shallow)) => {
if let (Err(_place_err), true) = (
self.is_mutable(&place.base, &place.projection, is_local_mutation_allowed),
if let (Err(place_err), true) = (
self.is_mutable(place.as_ref(), is_local_mutation_allowed),
self.errors_buffer.is_empty()
) {
if self.infcx.tcx.migrate_borrowck() {
@@ -1996,10 +1996,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.report_mutability_error(
place,
span,
PlaceRef {
base: _place_err.0,
projection: _place_err.1,
},
place_err,
error_access,
location,
);
@@ -2033,10 +2030,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.report_mutability_error(
place,
span,
PlaceRef {
base: the_place_err.0,
projection: the_place_err.1,
},
the_place_err,
error_access,
location,
);
@@ -2107,78 +2101,86 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// Returns the root place if the place passed in is a projection.
fn is_mutable<'d>(
&self,
place_base: &'d PlaceBase<'tcx>,
place_projection: &'d Option<Box<Projection<'tcx>>>,
place: PlaceRef<'d, 'tcx>,
is_local_mutation_allowed: LocalMutationIsAllowed,
) -> Result<RootPlace<'d, 'tcx>, (&'d PlaceBase<'tcx>, &'d Option<Box<Projection<'tcx>>>)> {
match (place_base, place_projection) {
(PlaceBase::Local(local), None) => {
) -> Result<RootPlace<'d, 'tcx>, PlaceRef<'d, 'tcx>> {
match place {
PlaceRef {
base: PlaceBase::Local(local),
projection: None,
} => {
let local = &self.body.local_decls[*local];
match local.mutability {
Mutability::Not => match is_local_mutation_allowed {
LocalMutationIsAllowed::Yes => Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed: LocalMutationIsAllowed::Yes,
}),
LocalMutationIsAllowed::ExceptUpvars => Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed: LocalMutationIsAllowed::ExceptUpvars,
}),
LocalMutationIsAllowed::No => Err((place_base, place_projection)),
LocalMutationIsAllowed::No => Err(place),
},
Mutability::Mut => Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed,
}),
}
}
// The rules for promotion are made by `qualify_consts`, there wouldn't even be a
// `Place::Promoted` if the promotion weren't 100% legal. So we just forward this
(PlaceBase::Static(box Static {
kind: StaticKind::Promoted(_),
..
}), None) =>
PlaceRef {
base: PlaceBase::Static(box Static {
kind: StaticKind::Promoted(_),
..
}),
projection: None,
} =>
Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed,
}),
(PlaceBase::Static(box Static {
kind: StaticKind::Static(def_id),
..
}), None) => {
PlaceRef {
base: PlaceBase::Static(box Static {
kind: StaticKind::Static(def_id),
..
}),
projection: None,
} => {
if !self.infcx.tcx.is_mutable_static(*def_id) {
Err((place_base, place_projection))
Err(place)
} else {
Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed,
})
}
}
(_, Some(ref proj)) => {
PlaceRef {
base: _,
projection: Some(proj),
} => {
match proj.elem {
ProjectionElem::Deref => {
let base_ty =
Place::ty_from(place_base, &proj.base, self.body, self.infcx.tcx).ty;
Place::ty_from(place.base, &proj.base, self.body, self.infcx.tcx).ty;

// Check the kind of deref to decide
match base_ty.sty {
ty::Ref(_, _, mutbl) => {
match mutbl {
// Shared borrowed data is never mutable
hir::MutImmutable => Err((place_base, place_projection)),
hir::MutImmutable => Err(place),
// Mutably borrowed data is mutable, but only if we have a
// unique path to the `&mut`
hir::MutMutable => {
let mode = match self.is_upvar_field_projection(PlaceRef {
base: &place_base,
projection: &place_projection,
}) {
let mode = match self.is_upvar_field_projection(place) {
Some(field)
if self.upvars[field.index()].by_ref =>
{
@@ -2187,28 +2189,34 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
_ => LocalMutationIsAllowed::Yes,
};

self.is_mutable(place_base, &proj.base, mode)
self.is_mutable(PlaceRef {
base: place.base,
projection: &proj.base,
}, mode)
}
}
}
ty::RawPtr(tnm) => {
match tnm.mutbl {
// `*const` raw pointers are not mutable
hir::MutImmutable => Err((place_base, place_projection)),
hir::MutImmutable => Err(place),
// `*mut` raw pointers are always mutable, regardless of
// context. The users have to check by themselves.
hir::MutMutable => {
Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed,
})
}
}
}
// `Box<T>` owns its content, so mutable if its location is mutable
_ if base_ty.is_box() => {
self.is_mutable(place_base, &proj.base, is_local_mutation_allowed)
self.is_mutable(PlaceRef {
base: place.base,
projection: &proj.base,
}, is_local_mutation_allowed)
}
// Deref should only be for reference, pointers or boxes
_ => bug!("Deref of unexpected type: {:?}", base_ty),
@@ -2221,21 +2229,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
| ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. }
| ProjectionElem::Downcast(..) => {
let upvar_field_projection = self.is_upvar_field_projection(PlaceRef {
base: &place_base,
projection: &place_projection,
});
let upvar_field_projection = self.is_upvar_field_projection(place);
if let Some(field) = upvar_field_projection {
let upvar = &self.upvars[field.index()];
debug!(
"upvar.mutability={:?} local_mutation_is_allowed={:?} \
place={:?} {:?}",
upvar, is_local_mutation_allowed, place_base, place_projection
place={:?}",
upvar, is_local_mutation_allowed, place
);
match (upvar.mutability, is_local_mutation_allowed) {
(Mutability::Not, LocalMutationIsAllowed::No)
| (Mutability::Not, LocalMutationIsAllowed::ExceptUpvars) => {
Err((place_base, place_projection))
Err(place)
}
(Mutability::Not, LocalMutationIsAllowed::Yes)
| (Mutability::Mut, _) => {
@@ -2265,18 +2270,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// });
// }
// ```
let _ = self.is_mutable(place_base,
&proj.base,
is_local_mutation_allowed)?;
let _ = self.is_mutable(PlaceRef {
base: place.base,
projection: &proj.base,
}, is_local_mutation_allowed)?;
Ok(RootPlace {
place_base,
place_projection,
place_base: place.base,
place_projection: place.projection,
is_local_mutation_allowed,
})
}
}
} else {
self.is_mutable(place_base, &proj.base, is_local_mutation_allowed)
self.is_mutable(PlaceRef {
base: place.base,
projection: &proj.base,
}, is_local_mutation_allowed)
}
}
}