parent
bab4c13f64
commit
0eb8b32de3
@ -1921,17 +1921,16 @@ pub(crate) fn report_illegal_reassignment(
|
||||
err.span_label(assigned_span, format!("first assignment to {}", place_description));
|
||||
}
|
||||
}
|
||||
if let Some(decl) = local_decl {
|
||||
if let Some(name) = local_name {
|
||||
if decl.can_be_made_mutable() {
|
||||
err.span_suggestion(
|
||||
decl.source_info.span,
|
||||
"consider making this binding mutable",
|
||||
format!("mut {}", name),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(decl) = local_decl
|
||||
&& let Some(name) = local_name
|
||||
&& decl.can_be_made_mutable()
|
||||
{
|
||||
err.span_suggestion(
|
||||
decl.source_info.span,
|
||||
"consider making this binding mutable",
|
||||
format!("mut {}", name),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err.span_label(span, msg);
|
||||
self.buffer_error(err);
|
||||
|
@ -375,15 +375,12 @@ pub(crate) fn explain_why_borrow_contains_point(
|
||||
|
||||
Some(Cause::DropVar(local, location)) => {
|
||||
let mut should_note_order = false;
|
||||
if self.local_names[local].is_some() {
|
||||
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
|
||||
if let Some(borrowed_local) = place.as_local() {
|
||||
if self.local_names[borrowed_local].is_some() && local != borrowed_local
|
||||
{
|
||||
should_note_order = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.local_names[local].is_some()
|
||||
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
|
||||
&& let Some(borrowed_local) = place.as_local()
|
||||
&& self.local_names[borrowed_local].is_some() && local != borrowed_local
|
||||
{
|
||||
should_note_order = true;
|
||||
}
|
||||
|
||||
BorrowExplanation::UsedLaterWhenDropped {
|
||||
|
@ -1086,21 +1086,17 @@ fn get_mut_span_in_struct_field<'tcx>(
|
||||
field: &mir::Field,
|
||||
) -> Option<Span> {
|
||||
// Expect our local to be a reference to a struct of some kind.
|
||||
if let ty::Ref(_, ty, _) = ty.kind() {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
let field = def.all_fields().nth(field.index())?;
|
||||
// Use the HIR types to construct the diagnostic message.
|
||||
let node = tcx.hir().find_by_def_id(field.did.as_local()?)?;
|
||||
// Now we're dealing with the actual struct that we're going to suggest a change to,
|
||||
// we can expect a field that is an immutable reference to a type.
|
||||
if let hir::Node::Field(field) = node {
|
||||
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
|
||||
field.ty.kind
|
||||
{
|
||||
return Some(lifetime.span.between(ty.span));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let ty::Ref(_, ty, _) = ty.kind()
|
||||
&& let ty::Adt(def, _) = ty.kind()
|
||||
&& let field = def.all_fields().nth(field.index())?
|
||||
// Use the HIR types to construct the diagnostic message.
|
||||
&& let node = tcx.hir().find_by_def_id(field.did.as_local()?)?
|
||||
// Now we're dealing with the actual struct that we're going to suggest a change to,
|
||||
// we can expect a field that is an immutable reference to a type.
|
||||
&& let hir::Node::Field(field) = node
|
||||
&& let hir::TyKind::Rptr(lt, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind
|
||||
{
|
||||
return Some(lt.span.between(ty.span));
|
||||
}
|
||||
|
||||
None
|
||||
|
@ -140,14 +140,11 @@ pub(super) fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid> {
|
||||
|
||||
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
|
||||
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
|
||||
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref() {
|
||||
if let ty::BoundRegionKind::BrEnv = free_region.bound_region {
|
||||
if let DefiningTy::Closure(_, substs) =
|
||||
self.regioncx.universal_regions().defining_ty
|
||||
{
|
||||
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
|
||||
}
|
||||
}
|
||||
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref()
|
||||
&& let ty::BoundRegionKind::BrEnv = free_region.bound_region
|
||||
&& let DefiningTy::Closure(_, substs) = self.regioncx.universal_regions().defining_ty
|
||||
{
|
||||
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
|
||||
}
|
||||
|
||||
false
|
||||
|
@ -1,15 +1,16 @@
|
||||
//! This query borrow-checks the MIR to (further) ensure it is not broken.
|
||||
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(let_else)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_middle;
|
||||
@ -159,16 +160,14 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||
for var_debug_info in &input_body.var_debug_info {
|
||||
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
|
||||
if let Some(local) = place.as_local() {
|
||||
if let Some(prev_name) = local_names[local] {
|
||||
if var_debug_info.name != prev_name {
|
||||
span_bug!(
|
||||
var_debug_info.source_info.span,
|
||||
"local {:?} has many names (`{}` vs `{}`)",
|
||||
local,
|
||||
prev_name,
|
||||
var_debug_info.name
|
||||
);
|
||||
}
|
||||
if let Some(prev_name) = local_names[local] && var_debug_info.name != prev_name {
|
||||
span_bug!(
|
||||
var_debug_info.source_info.span,
|
||||
"local {:?} has many names (`{}` vs `{}`)",
|
||||
local,
|
||||
prev_name,
|
||||
var_debug_info.name
|
||||
);
|
||||
}
|
||||
local_names[local] = Some(var_debug_info.name);
|
||||
}
|
||||
|
@ -60,10 +60,8 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(
|
||||
|
||||
// This Local/Local case is handled by the more general code below, but
|
||||
// it's so common that it's a speed win to check for it first.
|
||||
if let Some(l1) = borrow_place.as_local() {
|
||||
if let Some(l2) = access_place.as_local() {
|
||||
return l1 == l2;
|
||||
}
|
||||
if let Some(l1) = borrow_place.as_local() && let Some(l2) = access_place.as_local() {
|
||||
return l1 == l2;
|
||||
}
|
||||
|
||||
place_components_conflict(tcx, body, borrow_place, borrow_kind, access_place, access, bias)
|
||||
|
Loading…
Reference in New Issue
Block a user