Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,16 @@ impl<'tcx> LocalDecl<'tcx> {
}
}

/// Returns `true` if this is a reference to a variable bound in a `match`
/// expression that is used to access said variable for the guard of the
/// match arm.
pub fn is_ref_for_guard(&self) -> bool {
match self.is_user_variable {
Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) => true,
_ => false,
}
}

/// Returns `true` is the local is from a compiler desugaring, e.g.,
/// `__next` from a `for` loop.
#[inline]
Expand Down
24 changes: 10 additions & 14 deletions src/librustc_mir/borrow_check/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);
}
}
if let Place::Base(PlaceBase::Local(local)) = place {
let span = if let Place::Base(PlaceBase::Local(local)) = place {
let decl = &self.mir.local_decls[*local];
err.span_label(
decl.source_info.span,
format!(
"move occurs because {} has type `{}`, \
which does not implement the `Copy` trait",
note_msg, ty,
));
Some(decl.source_info.span)
} else {
err.note(&format!(
"move occurs because {} has type `{}`, \
which does not implement the `Copy` trait",
note_msg, ty
));
}
None
};
self.note_type_does_not_implement_copy(
&mut err,
&note_msg,
ty,
span,
);
}

if let Some((_, mut old_err)) = self.move_error_reported
Expand Down
30 changes: 24 additions & 6 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use rustc::hir;
use rustc::hir::def::Namespace;
use rustc::hir::def_id::DefId;
use rustc::mir::{
AggregateKind, BindingForm, ClearCrossCrate, Constant, Field, Local,
LocalKind, Location, Operand, Place, PlaceBase, ProjectionElem, Rvalue,
Statement, StatementKind, Static, StaticKind, TerminatorKind,
AggregateKind, Constant, Field, Local, LocalKind, Location, Operand,
Place, PlaceBase, ProjectionElem, Rvalue, Statement, StatementKind, Static,
StaticKind, TerminatorKind,
};
use rustc::ty::{self, DefIdTree, Ty};
use rustc::ty::layout::VariantIdx;
Expand Down Expand Up @@ -180,9 +180,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
&including_downcast,
)?;
} else if let Place::Base(PlaceBase::Local(local)) = proj.base {
if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) =
self.mir.local_decls[local].is_user_variable
{
if self.mir.local_decls[local].is_ref_for_guard() {
self.append_place_to_string(
&proj.base,
buf,
Expand Down Expand Up @@ -383,6 +381,26 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
false
}
}

/// Add a note that a type does not implement `Copy`
pub(super) fn note_type_does_not_implement_copy(
&self,
err: &mut DiagnosticBuilder<'a>,
place_desc: &str,
ty: Ty<'tcx>,
span: Option<Span>,
) {
let message = format!(
"move occurs because {} has type `{}`, which does not implement the `Copy` trait",
place_desc,
ty,
);
if let Some(span) = span {
err.span_label(span, message);
} else {
err.note(&message);
}
}
}

impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Expand Down
Loading