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