diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 7b5fce4abbc..b8965b46d54 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -22,7 +22,7 @@ use super::{InitializationRequiringAction, PrefixSet}; use super::error_reporting::{IncludingDowncast, UseSpans}; use crate::dataflow::drop_flag_effects; use crate::dataflow::indexes::{MovePathIndex, MoveOutIndex}; -use crate::util::borrowck_errors::{BorrowckErrors, Origin}; +use crate::util::borrowck_errors::BorrowckErrors; #[derive(Debug)] struct MoveSite { @@ -94,7 +94,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { desired_action.as_noun(), &self.describe_place_with_options(moved_place, IncludingDowncast(true)) .unwrap_or_else(|| "_".to_owned()), - Origin::Mir, ); err.span_label(span, format!("use of possibly uninitialized {}", item_msg)); @@ -125,7 +124,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { desired_action.as_noun(), msg, self.describe_place_with_options(&moved_place, IncludingDowncast(true)), - Origin::Mir, ); self.add_moved_or_invoked_closure_note( @@ -286,7 +284,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = tcx.cannot_move_when_borrowed( span, &self.describe_place(place).unwrap_or_else(|| "_".to_owned()), - Origin::Mir, ); err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_msg)); err.span_label(span, format!("move out of {} occurs here", value_msg)); @@ -331,7 +328,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_span, &self.describe_place(&borrow.borrowed_place) .unwrap_or_else(|| "_".to_owned()), - Origin::Mir, ); borrow_spans.var_span_label(&mut err, { @@ -398,7 +394,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { rgt, &msg_borrow, None, - Origin::Mir, ) } (BorrowKind::Mut { .. }, _, lft, BorrowKind::Shared, rgt, _) => { @@ -413,7 +408,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { rgt, &msg_borrow, None, - Origin::Mir, ) } @@ -426,7 +420,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { issued_span, &msg_borrow, None, - Origin::Mir, ) } @@ -437,7 +430,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &desc_place, issued_span, None, - Origin::Mir, ) } @@ -448,7 +440,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { issued_span, &desc_place, "mutably borrow", - Origin::Mir, ); borrow_spans.var_span_label( &mut err, @@ -471,7 +462,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "it", "", None, - Origin::Mir, ) }, @@ -487,7 +477,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "", None, second_borrow_desc, - Origin::Mir, ) } @@ -503,7 +492,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "", None, second_borrow_desc, - Origin::Mir, ) } @@ -836,7 +824,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.infcx.tcx.path_does_not_live_long_enough( borrow_span, &format!("`{}`", name), - Origin::Mir, ); if let Some(annotation) = self.annotate_argument_and_return_for_borrow(borrow) { @@ -927,7 +914,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.infcx .tcx - .cannot_borrow_across_destructor(borrow_span, Origin::Mir); + .cannot_borrow_across_destructor(borrow_span); let what_was_dropped = match self.describe_place(place) { Some(name) => format!("`{}`", name.as_str()), @@ -980,7 +967,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut err = self.infcx .tcx - .thread_local_value_does_not_live_long_enough(borrow_span, Origin::Mir); + .thread_local_value_does_not_live_long_enough(borrow_span); err.span_label( borrow_span, @@ -1025,7 +1012,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } let tcx = self.infcx.tcx; - let mut err = tcx.temporary_value_borrowed_for_too_long(proper_span, Origin::Mir); + let mut err = tcx.temporary_value_borrowed_for_too_long(proper_span); err.span_label( proper_span, "creates a temporary which is freed while still in use", @@ -1137,7 +1124,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { return_kind, reference_desc, &place_desc, - Origin::Mir, ); if return_span != borrow_span { @@ -1162,7 +1148,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { args_span, captured_var, var_span, - Origin::Mir, ); let suggestion = match tcx.sess.source_map().span_to_snippet(args_span) { @@ -1218,7 +1203,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { "function" }; - let mut err = tcx.borrowed_data_escapes_closure(escape_span, escapes_from, Origin::Mir); + let mut err = tcx.borrowed_data_escapes_closure(escape_span, escapes_from); err.span_label( upvar_span, @@ -1367,7 +1352,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { loan_span, &self.describe_place(place).unwrap_or_else(|| "_".to_owned()), "assign", - Origin::Mir, ); loan_spans.var_span_label( &mut err, @@ -1383,7 +1367,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { span, loan_span, &self.describe_place(place).unwrap_or_else(|| "_".to_owned()), - Origin::Mir, ); loan_spans.var_span_label( @@ -1448,7 +1431,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { span, place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"), from_arg, - Origin::Mir, ); let msg = if from_arg { "cannot assign to immutable argument" diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 31a9766af30..b7944c3a748 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -41,7 +41,7 @@ use crate::dataflow::MoveDataParamEnv; use crate::dataflow::{do_dataflow, DebugFormatted}; use crate::dataflow::EverInitializedPlaces; use crate::dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; -use crate::util::borrowck_errors::{BorrowckErrors, Origin}; +use crate::util::borrowck_errors::BorrowckErrors; use self::borrow_set::{BorrowData, BorrowSet}; use self::flows::Flows; @@ -1503,7 +1503,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .cannot_borrow_across_generator_yield( self.retrieve_borrow_spans(borrow).var_or_use(), yield_span, - Origin::Mir, ); err.buffer(&mut self.errors_buffer); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 3130b7cec5b..6110c9baaac 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -12,7 +12,7 @@ use crate::dataflow::move_paths::{ IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, }; -use crate::util::borrowck_errors::{BorrowckErrors, Origin}; +use crate::util::borrowck_errors::BorrowckErrors; // Often when desugaring a pattern match we may have many individual moves in // MIR that are all part of one operation from the user's point-of-view. For @@ -255,11 +255,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => { self.infcx.tcx - .cannot_move_out_of_interior_of_drop(span, ty, Origin::Mir) + .cannot_move_out_of_interior_of_drop(span, ty) } IllegalMoveOriginKind::InteriorOfSliceOrArray { ty, is_index } => self.infcx.tcx.cannot_move_out_of_interior_noncopy( - span, ty, Some(*is_index), Origin::Mir + span, ty, Some(*is_index), ), }, span, @@ -293,7 +293,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ) }; - self.infcx.tcx.cannot_move_out_of(span, &description, Origin::Mir) + self.infcx.tcx.cannot_move_out_of(span, &description) } fn report_cannot_move_from_borrowed_content( @@ -302,8 +302,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { deref_target_place: &Place<'tcx>, span: Span, ) -> DiagnosticBuilder<'a> { - let origin = Origin::Mir; - // Inspect the type of the content behind the // borrow to provide feedback about why this // was a move rather than a copy. @@ -322,7 +320,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let mut err = self.infcx.tcx.cannot_move_out_of( span, &format!("`{}` in pattern guard", decl.name.unwrap()), - origin, ); err.note( "variables bound in patterns cannot be moved from \ @@ -334,9 +331,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { debug!("report: ty={:?}", ty); let mut err = match ty.sty { ty::Array(..) | ty::Slice(..) => - self.infcx.tcx.cannot_move_out_of_interior_noncopy( - span, ty, None, origin - ), + self.infcx.tcx.cannot_move_out_of_interior_noncopy(span, ty, None), ty::Closure(def_id, closure_substs) if def_id == self.mir_def_id && upvar_field.is_some() => { @@ -378,7 +373,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { closure_kind_ty, closure_kind, place_description, ); - let mut diag = self.infcx.tcx.cannot_move_out_of(span, &place_description, origin); + let mut diag = self.infcx.tcx.cannot_move_out_of(span, &place_description); diag.span_label(upvar_span, "captured outer variable"); @@ -391,14 +386,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { self.infcx.tcx.cannot_move_out_of( span, &format!("`{}` which is behind a {}", place_desc, source_desc), - origin, ) } (_, _) => { self.infcx.tcx.cannot_move_out_of( span, &source.describe_for_unnamed_place(), - origin, ) } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 04814a15c62..c15b33cdaaa 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -9,7 +9,7 @@ use syntax_pos::symbol::kw; use crate::borrow_check::MirBorrowckCtxt; use crate::borrow_check::error_reporting::BorrowedContentSource; -use crate::util::borrowck_errors::{BorrowckErrors, Origin}; +use crate::util::borrowck_errors::BorrowckErrors; use crate::util::collect_writes::FindAssignments; use crate::util::suggest_ref_mut; use rustc_errors::Applicability; @@ -161,15 +161,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let span = match error_access { AccessKind::Move => { - err = self.infcx.tcx - .cannot_move_out_of(span, &(item_msg + &reason), Origin::Mir); + err = self.infcx.tcx.cannot_move_out_of(span, &(item_msg + &reason)); err.span_label(span, "cannot move"); err.buffer(&mut self.errors_buffer); return; } AccessKind::Mutate => { - err = self.infcx.tcx - .cannot_assign(span, &(item_msg + &reason), Origin::Mir); + err = self.infcx.tcx.cannot_assign(span, &(item_msg + &reason)); act = "assign"; acted_on = "written"; span @@ -184,7 +182,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { borrow_span, &item_msg, &reason, - Origin::Mir, ); borrow_spans.var_span_label( &mut err, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 9e08961f440..a255f7182e3 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -4,7 +4,7 @@ use crate::borrow_check::nll::region_infer::RegionInferenceContext; use crate::borrow_check::nll::type_check::Locations; use crate::borrow_check::nll::universal_regions::DefiningTy; use crate::borrow_check::nll::ConstraintDescription; -use crate::util::borrowck_errors::{BorrowckErrors, Origin}; +use crate::util::borrowck_errors::BorrowckErrors; use crate::borrow_check::Upvar; use rustc::hir::def_id::DefId; use rustc::infer::error_reporting::nice_region_error::NiceRegionError; @@ -489,7 +489,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let mut diag = infcx .tcx - .borrowed_data_escapes_closure(span, escapes_from, Origin::Mir); + .borrowed_data_escapes_closure(span, escapes_from); if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span { diag.span_label( diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 7c7e4de316f..d7fbb76b38c 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -2,13 +2,7 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc_errors::{DiagnosticBuilder, DiagnosticId}; use syntax_pos::{MultiSpan, Span}; -// FIXME(chrisvittal) remove Origin entirely -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum Origin { - Mir, -} - -pub trait BorrowckErrors<'cx>: Sized + Copy { +pub(crate) trait BorrowckErrors<'cx>: Sized + Copy { fn struct_span_err_with_code>( self, sp: S, @@ -22,7 +16,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, span: Span, desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -39,7 +32,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { desc: &str, borrow_span: Span, borrow_desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -62,7 +54,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { span: Span, verb: &str, desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -82,7 +73,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { old_loan_span: Span, old_opt_via: &str, old_load_end_span: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let via = |msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via `{}`)", msg) }; @@ -130,7 +120,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { desc: &str, old_loan_span: Span, old_load_end_span: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -164,7 +153,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { noun_old: &str, old_opt_via: &str, previous_end_span: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -197,7 +185,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { old_opt_via: &str, previous_end_span: Option, second_borrow_desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -234,7 +221,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { kind_old: &str, msg_old: &str, old_load_end_span: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let via = |msg: &str| if msg.is_empty() { msg.to_string() } else { format!(" (via `{}`)", msg) }; @@ -282,7 +268,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { span: Span, borrow_span: Span, desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -305,7 +290,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { span: Span, desc: &str, is_arg: bool, - _: Origin, ) -> DiagnosticBuilder<'cx> { let msg = if is_arg { "to immutable argument" @@ -322,7 +306,7 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { ) } - fn cannot_assign(self, span: Span, desc: &str, _: Origin) -> DiagnosticBuilder<'cx> { + fn cannot_assign(self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { struct_span_err!(self, span, E0594, "cannot assign to {}", desc) } @@ -330,7 +314,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, move_from_span: Span, move_from_desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -349,7 +332,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { move_from_span: Span, ty: Ty<'_>, is_index: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let type_name = match (&ty.sty, is_index) { (&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array", @@ -372,7 +354,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, move_from_span: Span, container_ty: Ty<'_>, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -391,7 +372,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { verb: &str, optional_adverb_for_moved: &str, moved_path: Option, - _: Origin, ) -> DiagnosticBuilder<'cx> { let moved_path = moved_path .map(|mp| format!(": `{}`", mp)) @@ -413,7 +393,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { span: Span, path: &str, reason: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -431,7 +410,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { match_span: Span, match_place: &str, action: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -450,7 +428,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, span: Span, yield_span: Span, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -465,7 +442,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { fn cannot_borrow_across_destructor( self, borrow_span: Span, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -479,7 +455,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, span: Span, path: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -496,7 +471,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { return_kind: &str, reference_desc: &str, path_desc: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -521,7 +495,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { closure_span: Span, borrowed_path: &str, capture_span: Span, - _: Origin, ) -> DiagnosticBuilder<'cx> { let mut err = struct_span_err!( self, @@ -544,7 +517,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { self, escape_span: Span, escapes_from: &str, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -558,7 +530,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { fn thread_local_value_does_not_live_long_enough( self, span: Span, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self, @@ -571,7 +542,6 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { fn temporary_value_borrowed_for_too_long( self, span: Span, - _: Origin, ) -> DiagnosticBuilder<'cx> { struct_span_err!( self,