diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index 41279588e6334..563ff056ae467 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::nll::ToRegionVid; use crate::path_utils::allow_two_phase_borrow; use crate::place_ext::PlaceExt; diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 08ea00d71ef9d..957ff8138b70c 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -4,13 +4,19 @@ use rustc_errors::{ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; +use crate::session_diagnostics::{ + AssignBorrowErr, BorrowAcrossDestructor, BorrowAcrossGeneratorYield, ClosureConstructLabel, + InteriorDropMoveErr, MoveBorrowedErr, PathShortLive, TwoClosuresUniquelyBorrowErr, + UseMutBorrowErr, +}; + impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { pub(crate) fn cannot_move_when_borrowed( &self, span: Span, desc: &str, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,) + self.infcx.tcx.sess.create_err(MoveBorrowedErr { desc, span }) } pub(crate) fn cannot_use_when_mutably_borrowed( @@ -20,17 +26,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { borrow_span: Span, borrow_desc: &str, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - span, - E0503, - "cannot use {} because it was mutably borrowed", - desc, - ); - - err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_desc)); - err.span_label(span, format!("use of borrowed {}", borrow_desc)); - err + self.infcx.tcx.sess.create_err(UseMutBorrowErr { desc, borrow_desc, span, borrow_span }) } pub(crate) fn cannot_mutably_borrow_multiply( @@ -90,26 +86,22 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { old_loan_span: Span, old_load_end_span: Option, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - new_loan_span, - E0524, - "two closures require unique access to {} at the same time", - desc, - ); + let case: ClosureConstructLabel; + let diff_span: Option; if old_loan_span == new_loan_span { - err.span_label( - old_loan_span, - "closures are constructed here in different iterations of loop", - ); + case = ClosureConstructLabel::Both { old_loan_span }; + diff_span = None; } else { - err.span_label(old_loan_span, "first closure is constructed here"); - err.span_label(new_loan_span, "second closure is constructed here"); + case = ClosureConstructLabel::First { old_loan_span }; + diff_span = Some(new_loan_span); } - if let Some(old_load_end_span) = old_load_end_span { - err.span_label(old_load_end_span, "borrow from first closure ends here"); - } - err + self.infcx.tcx.sess.create_err(TwoClosuresUniquelyBorrowErr { + desc, + case, + new_loan_span, + old_load_end_span, + diff_span, + }) } pub(crate) fn cannot_uniquely_borrow_by_one_closure( @@ -233,17 +225,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { borrow_span: Span, desc: &str, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - span, - E0506, - "cannot assign to {} because it is borrowed", - desc, - ); - - err.span_label(borrow_span, format!("borrow of {} occurs here", desc)); - err.span_label(span, format!("assignment to borrowed {} occurs here", desc)); - err + self.infcx.tcx.sess.create_err(AssignBorrowErr { desc, span, borrow_span }) } pub(crate) fn cannot_reassign_immutable( @@ -303,15 +285,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { move_from_span: Span, container_ty: Ty<'_>, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - move_from_span, - E0509, - "cannot move out of type `{}`, which implements the `Drop` trait", - container_ty, - ); - err.span_label(move_from_span, "cannot move out of here"); - err + self.infcx.tcx.sess.create_err(InteriorDropMoveErr { container_ty, move_from_span }) } pub(crate) fn cannot_act_on_moved_value( @@ -370,26 +344,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, yield_span: Span, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - let mut err = struct_span_err!( - self, - span, - E0626, - "borrow may still be in use when generator yields", - ); - err.span_label(yield_span, "possible yield occurs here"); - err + self.infcx.tcx.sess.create_err(BorrowAcrossGeneratorYield { span, yield_span }) } pub(crate) fn cannot_borrow_across_destructor( &self, borrow_span: Span, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - struct_span_err!( - self, - borrow_span, - E0713, - "borrow may still be in use when destructor runs", - ) + self.infcx.tcx.sess.create_err(BorrowAcrossDestructor { borrow_span }) } pub(crate) fn path_does_not_live_long_enough( @@ -397,7 +359,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { span: Span, path: &str, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { - struct_span_err!(self, span, E0597, "{} does not live long enough", path,) + self.infcx.tcx.sess.create_err(PathShortLive { path, span }) } pub(crate) fn cannot_return_reference_to_local( diff --git a/compiler/rustc_borrowck/src/constraint_generation.rs b/compiler/rustc_borrowck/src/constraint_generation.rs index 144fd15fc2407..65fbb8da44a11 100644 --- a/compiler/rustc_borrowck/src/constraint_generation.rs +++ b/compiler/rustc_borrowck/src/constraint_generation.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_infer::infer::InferCtxt; use rustc_middle::mir::visit::TyContext; use rustc_middle::mir::visit::Visitor; diff --git a/compiler/rustc_borrowck/src/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs index 609fbc2bc1515..a9e223cd0d592 100644 --- a/compiler/rustc_borrowck/src/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_data_structures::graph; use rustc_index::vec::IndexVec; use rustc_middle::mir::ConstraintCategory; diff --git a/compiler/rustc_borrowck/src/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs index df04128135b89..b42b987f40f60 100644 --- a/compiler/rustc_borrowck/src/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_data_structures::graph::scc::Sccs; use rustc_index::vec::IndexVec; use rustc_middle::mir::ConstraintCategory; diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index efc17a173f4d3..bb4a35f42753b 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! This file provides API for compiler consumers. use rustc_hir::def_id::LocalDefId; diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 9f7a4d49989ab..8070c0e6710ee 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; use rustc_middle::mir::{self, BasicBlock, Body, Location, Place}; diff --git a/compiler/rustc_borrowck/src/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs index a5c0d77429de8..8e62a0198be46 100644 --- a/compiler/rustc_borrowck/src/def_use.rs +++ b/compiler/rustc_borrowck/src/def_use.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_middle::mir::visit::{ MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext, }; diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index b1def189230f7..12f2b31addda6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_infer::infer::canonical::Canonical; use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError; diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 799b3f7f5756f..e16c60a49766d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -180,10 +180,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let move_spans = self.move_spans(moved_place.as_ref(), move_out.source); let move_span = move_spans.args_or_use(); - let move_msg = if move_spans.for_closure() { " into closure" } else { "" }; + let move_msg = if move_spans.for_closure() { "InClosure" } else { "" }; let loop_message = if location == move_out.source || move_site.traversed_back_edge { - ", in previous iteration of loop" + "InLoop" } else { "" }; diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 1c01e78abd422..c614c939ae9b0 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -16,6 +16,7 @@ use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, DesugaringKind, Span}; use crate::region_infer::{BlameConstraint, ExtraConstraintInfo}; +use crate::session_diagnostics::{BorrowUsedHere, UsedLaterDropped}; use crate::{ borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, WriteKind, @@ -66,6 +67,12 @@ impl<'tcx> BorrowExplanation<'tcx> { borrow_span: Option, multiple_borrow_span: Option<(Span, Span)>, ) { + let br_desc = match borrow_desc { + "first " => "first", + "immutable " => "immutable", + "mutable " => "mutable", + _ => "", + }; match *self { BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => { let message = match later_use_kind { @@ -120,13 +127,12 @@ impl<'tcx> BorrowExplanation<'tcx> { // path_span is only present in the case of closure capture assert!(matches!(later_use_kind, LaterUseKind::ClosureCapture)); if borrow_span.map(|sp| !sp.overlaps(var_or_use_span)).unwrap_or(true) { - let path_label = "used here by closure"; + err.subdiagnostic(BorrowUsedHere::ByClosure { path_span }); let capture_kind_label = message; err.span_label( var_or_use_span, format!("{}borrow later {}", borrow_desc, capture_kind_label), ); - err.span_label(path_span, path_label); } } } @@ -145,59 +151,47 @@ impl<'tcx> BorrowExplanation<'tcx> { } } } - let (dtor_desc, type_desc) = match ty.kind() { + let (dtor_code, type_code, type_desc) = match ty.kind() { // If type is an ADT that implements Drop, then // simplify output by reporting just the ADT name. ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => { - ("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did()))) + (0, 0, format!(" `{}`", tcx.def_path_str(adt.did()).to_string())) } // Otherwise, just report the whole type (and use // the intentionally fuzzy phrase "destructor") - ty::Closure(..) => ("destructor", "closure".to_owned()), - ty::Generator(..) => ("destructor", "generator".to_owned()), + ty::Closure(..) => (1, 1, "".to_owned()), + ty::Generator(..) => (1, 2, "".to_owned()), - _ => ("destructor", format!("type `{}`", local_decl.ty)), + _ => (1, 0, format!(" `{}`", local_decl.ty.to_string())), }; match local_names[dropped_local] { Some(local_name) if !local_decl.from_compiler_desugaring() => { - let message = format!( - "{B}borrow might be used here, when `{LOC}` is dropped \ - and runs the {DTOR} for {TYPE}", - B = borrow_desc, - LOC = local_name, - TYPE = type_desc, - DTOR = dtor_desc - ); - err.span_label(body.source_info(drop_loc).span, message); - + err.subdiagnostic(UsedLaterDropped::UsedHere { + borrow_desc: br_desc, + local_name, + type_desc, + type_code, + dtor_code, + span: body.source_info(drop_loc).span, + }); if should_note_order { - err.note( - "values in a scope are dropped \ - in the opposite order they are defined", - ); + err.subdiagnostic(UsedLaterDropped::OppositeOrder); } } _ => { - err.span_label( - local_decl.source_info.span, - format!( - "a temporary with access to the {B}borrow \ - is created here ...", - B = borrow_desc - ), - ); - let message = format!( - "... and the {B}borrow might be used here, \ - when that temporary is dropped \ - and runs the {DTOR} for {TYPE}", - B = borrow_desc, - TYPE = type_desc, - DTOR = dtor_desc - ); - err.span_label(body.source_info(drop_loc).span, message); - + err.subdiagnostic(UsedLaterDropped::TemporaryCreatedHere { + borrow_desc: br_desc, + span: local_decl.source_info.span, + }); + err.subdiagnostic(UsedLaterDropped::MightUsedHere { + borrow_desc: br_desc, + type_desc, + type_code, + dtor_code, + span: body.source_info(drop_loc).span, + }); if let Some(info) = &local_decl.is_block_tail { if info.tail_result_is_ignored { // #85581: If the first mutable borrow's scope contains @@ -208,31 +202,16 @@ impl<'tcx> BorrowExplanation<'tcx> { }) .unwrap_or(false) { - err.span_suggestion_verbose( - info.span.shrink_to_hi(), - "consider adding semicolon after the expression so its \ - temporaries are dropped sooner, before the local variables \ - declared by the block are dropped", - ";", - Applicability::MaybeIncorrect, - ); + err.subdiagnostic(UsedLaterDropped::AddSemicolon { + span: info.span.shrink_to_hi(), + }); } } else { - err.note( - "the temporary is part of an expression at the end of a \ - block;\nconsider forcing this temporary to be dropped sooner, \ - before the block's local variables are dropped", - ); - err.multipart_suggestion( - "for example, you could save the expression's value in a new \ - local variable `x` and then make `x` be the expression at the \ - end of the block", - vec![ - (info.span.shrink_to_lo(), "let x = ".to_string()), - (info.span.shrink_to_hi(), "; x".to_string()), - ], - Applicability::MaybeIncorrect, - ); + err.subdiagnostic(UsedLaterDropped::ManualDrop); + err.subdiagnostic(UsedLaterDropped::MoveBlockEnd { + lo_span: info.span.shrink_to_lo(), + hi_span: info.span.shrink_to_hi(), + }); }; } } diff --git a/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs b/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs index b3edc35dc3642..498e9834354b7 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use std::collections::BTreeSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; diff --git a/compiler/rustc_borrowck/src/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs index b5a3081e56a7a..15f42e26cbf4a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use std::collections::VecDeque; use std::rc::Rc; diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 7ccb679d88b2d..1ef5118ebe5a3 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -20,6 +20,8 @@ use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP}; use rustc_target::abi::VariantIdx; use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions; +use crate::session_diagnostics::{CaptureCausedBy, ClosureCannotAgain, NotImplCopy}; + use super::borrow_set::BorrowData; use super::MirBorrowckCtxt; @@ -117,14 +119,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if let Some((span, hir_place)) = self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id) { - diag.span_note( - *span, - &format!( - "closure cannot be invoked more than once because it moves the \ - variable `{}` out of its environment", - ty::place_to_string_for_capture(self.infcx.tcx, hir_place) - ), - ); + diag.subdiagnostic(ClosureCannotAgain::Invoke { + place: ty::place_to_string_for_capture(self.infcx.tcx, hir_place), + span: *span, + }); return; } } @@ -141,14 +139,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if let Some((span, hir_place)) = self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id) { - diag.span_note( - *span, - &format!( - "closure cannot be moved more than once as it is not `Copy` due to \ - moving the variable `{}` out of its environment", - ty::place_to_string_for_capture(self.infcx.tcx, hir_place) - ), - ); + diag.subdiagnostic(ClosureCannotAgain::Move { + place: ty::place_to_string_for_capture(self.infcx.tcx, hir_place), + span: *span, + }); } } } @@ -397,14 +391,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { span: Option, move_prefix: &str, ) { - let message = format!( - "{}move occurs because {} has type `{}`, which does not implement the `Copy` trait", - move_prefix, place_desc, ty, - ); if let Some(span) = span { - err.span_label(span, message); + err.subdiagnostic(NotImplCopy::Label { span, place_desc, ty, move_prefix }); } else { - err.note(&message); + err.subdiagnostic(NotImplCopy::Note { place_desc, ty, move_prefix }); } } @@ -987,37 +977,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { CallKind::FnCall { fn_trait_id, .. } if Some(fn_trait_id) == self.infcx.tcx.lang_items().fn_once_trait() => { - err.span_label( - fn_call_span, - &format!( - "{} {}moved due to this call{}", - place_name, partially_str, loop_message - ), - ); - err.span_note( - var_span, - "this value implements `FnOnce`, which causes it to be moved when called", - ); + err.subdiagnostic(CaptureCausedBy::Call { + place_name: &place_name, + partially_str, + loop_message, + span: fn_call_span, + }); + err.subdiagnostic(CaptureCausedBy::FnOnceVal { span: var_span }); } CallKind::Operator { self_arg, .. } => { let self_arg = self_arg.unwrap(); - err.span_label( - fn_call_span, - &format!( - "{} {}moved due to usage in operator{}", - place_name, partially_str, loop_message - ), - ); + err.subdiagnostic(CaptureCausedBy::OperatorUse { + place_name: &place_name, + partially_str, + loop_message, + span: fn_call_span, + }); if self.fn_self_span_reported.insert(fn_span) { - err.span_note( + err.subdiagnostic(CaptureCausedBy::OperatorCall { span: // Check whether the source is accessible if self.infcx.tcx.sess.source_map().is_span_accessible(self_arg.span) { self_arg.span } else { fn_call_span - }, - "calling this operator moves the left-hand side", - ); + }}); } } CallKind::Normal { self_arg, desugaring, is_option_or_result } => { @@ -1052,13 +1035,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } - err.span_label( - fn_call_span, - &format!( - "{} {}moved due to this implicit call to `.into_iter()`{}", - place_name, partially_str, loop_message - ), - ); + err.subdiagnostic(CaptureCausedBy::ImplicitCall { + place_name: &place_name, + partially_str, + loop_message, + span: fn_call_span, + }); // If the moved place was a `&mut` ref, then we can // suggest to reborrow it where it was moved, so it // will still be valid by the time we get to the usage. @@ -1081,27 +1063,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } } else { - err.span_label( - fn_call_span, - &format!( - "{} {}moved due to this method call{}", - place_name, partially_str, loop_message - ), - ); + err.subdiagnostic(CaptureCausedBy::MethodCall { + place_name: &place_name, + partially_str, + loop_message, + span: fn_call_span, + }); } // Avoid pointing to the same function in multiple different // error messages. if span != DUMMY_SP && self.fn_self_span_reported.insert(self_arg.span) { - err.span_note( - self_arg.span, - &format!("this function takes ownership of the receiver `self`, which moves {}", place_name) - ); + err.subdiagnostic(CaptureCausedBy::FnTakeSelf { + place_name: &place_name, + span: self_arg.span, + }); } if is_option_or_result && maybe_reinitialized_locations_is_empty { - err.span_label( - var_span, - "help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents", - ); + err.subdiagnostic(CaptureCausedBy::ConsiderManualBorrow { span: var_span }); } } // Other desugarings takes &self, which cannot cause a move @@ -1109,10 +1087,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } else { if move_span != span || !loop_message.is_empty() { - err.span_label( - move_span, - format!("value {}moved{} here{}", partially_str, move_msg, loop_message), - ); + err.subdiagnostic(CaptureCausedBy::ValueHere { + move_msg, + partially_str, + loop_message, + span: move_span, + }); } // If the move error occurs due to a loop, don't show // another message for the same span diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 5a47f45677ecb..4027acb7279dc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed}; use rustc_middle::mir::*; use rustc_middle::ty; @@ -8,6 +11,7 @@ use rustc_span::Span; use crate::diagnostics::{DescribePlaceOpt, UseSpans}; use crate::prefixes::PrefixSet; +use crate::session_diagnostics::AddMoveErr; use crate::MirBorrowckCtxt; // Often when desugaring a pattern match we may have many individual moves in @@ -503,9 +507,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let binding_span = bind_to.source_info.span; if j == 0 { - err.span_label(binding_span, "data moved here"); + err.subdiagnostic(AddMoveErr::Here { binding_span }); } else { - err.span_label(binding_span, "...and here"); + err.subdiagnostic(AddMoveErr::AndHere { binding_span }); } if binds_to.len() == 1 { @@ -520,10 +524,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } if binds_to.len() > 1 { - err.note( - "move occurs because these variables have types that \ - don't implement the `Copy` trait", - ); + err.subdiagnostic(AddMoveErr::MovedNotCopy); } } } diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 8ad40c0aa0a5d..3253bb2b7c53b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_errors::{ Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, }; @@ -16,6 +19,7 @@ use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, BytePos, Span}; use crate::diagnostics::BorrowedContentSource; +use crate::session_diagnostics::{FnMutBumpFn, ShowMutatingUpvar}; use crate::MirBorrowckCtxt; use rustc_const_eval::util::collect_writes::FindAssignments; @@ -817,8 +821,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if let Some((span, closure_kind_origin)) = &tables.closure_kind_origins().get(closure_hir_id) { + let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin); let reason = if let PlaceBase::Upvar(upvar_id) = closure_kind_origin.base { - let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin); let root_hir_id = upvar_id.var_path.hir_id; // we have an origin for this closure kind starting at this root variable so it's safe to unwrap here let captured_places = @@ -845,10 +849,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ty::UpvarCapture::ByRef( ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow, ) => { - capture_reason = format!("mutable borrow of `{upvar}`"); + capture_reason = format!("borrow"); } ty::UpvarCapture::ByValue => { - capture_reason = format!("possible mutation of `{upvar}`"); + capture_reason = format!("mutation"); } _ => bug!("upvar `{upvar}` borrowed, but not mutably"), } @@ -862,14 +866,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } else { bug!("not an upvar") }; - err.span_label( - *span, - format!( - "calling `{}` requires mutable binding due to {}", - self.describe_place(the_place_err).unwrap(), - reason - ), - ); + let place = self.describe_place(the_place_err).unwrap(); + err.subdiagnostic(ShowMutatingUpvar::RequireMutableBinding { + upvar, + place, + reason, + span: *span, + }); } } @@ -967,7 +970,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected. fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) { - err.span_label(sp, format!("cannot {act}")); + err.subdiagnostic(FnMutBumpFn::Cannot { act, sp }); let hir = self.infcx.tcx.hir(); let closure_id = self.mir_hir_id(); @@ -1021,9 +1024,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { _ => None, }; if let Some(span) = arg { - err.span_label(span, "change this to accept `FnMut` instead of `Fn`"); - err.span_label(func.span, "expects `Fn` instead of `FnMut`"); - err.span_label(closure_span, "in this closure"); + err.subdiagnostic(FnMutBumpFn::AcceptFnMut { span }); + err.subdiagnostic(FnMutBumpFn::AcceptFn { span: func.span }); + err.subdiagnostic(FnMutBumpFn::Here { span: closure_span }); look_at_return = false; } } @@ -1044,12 +1047,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { kind: hir::ImplItemKind::Fn(sig, _), .. }) => { - err.span_label(ident.span, ""); - err.span_label( - sig.decl.output.span(), - "change this to return `FnMut` instead of `Fn`", - ); - err.span_label(closure_span, "in this closure"); + err.subdiagnostic(FnMutBumpFn::EmptyLabel { span: ident.span }); + err.subdiagnostic(FnMutBumpFn::ReturnFnMut { span: sig.decl.output.span() }); + err.subdiagnostic(FnMutBumpFn::Here { span: closure_span }); } _ => {} } diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 35c3df768995a..768d2ddce3d05 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::RegionVid; use smallvec::SmallVec; use std::collections::BTreeMap; -use crate::MirBorrowckCtxt; +use crate::{session_diagnostics::OnLifetimeBound, MirBorrowckCtxt}; use super::{ErrorConstraintInfo, RegionName, RegionNameSource}; @@ -171,9 +171,7 @@ impl OutlivesSuggestionBuilder { if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) && !matches!(outlived_fr_name.source, RegionNameSource::Static) { - diag.help(&format!( - "consider adding the following bound: `{fr_name}: {outlived_fr_name}`", - )); + diag.subdiagnostic(OnLifetimeBound::Add { fr_name: &fr_name, outlived_fr_name: &outlived_fr_name }); } } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 43d67bfa72991..c52d08ad84462 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -25,6 +25,7 @@ use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; use crate::borrowck_errors; +use crate::nll::ConstraintDiagDescription; use crate::session_diagnostics::{ FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr, LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote, @@ -65,6 +66,24 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> { } } +impl<'tcx> ConstraintDiagDescription for ConstraintCategory<'tcx> { + fn arg_desc(&self) -> String { + // Must end with a space. Allows for empty names to be provided. + match self { + ConstraintCategory::Return(_) => "Return".to_string(), + ConstraintCategory::CallArgument(_) => "CallArgument".to_string(), + ConstraintCategory::ClosureUpvar(_) => "ClosureUpvar".to_string(), + + ConstraintCategory::Predicate(_) + | ConstraintCategory::Boring + | ConstraintCategory::BoringNoLocation + | ConstraintCategory::Internal => "other".to_string(), + + _ => format!("{:?}", self), + } + } +} + /// A collection of errors encountered during region inference. This is needed to efficiently /// report errors after borrow checking. /// @@ -689,8 +708,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let (_, mir_def_name) = self.infcx.tcx.article_and_description(self.mir_def_id().to_def_id()); - let err = LifetimeOutliveErr { span: *span }; - let mut diag = self.infcx.tcx.sess.create_err(err); + let mut diag = self.infcx.tcx.sess.create_err(LifetimeOutliveErr { span: *span }); let fr_name = self.give_region_a_name(*fr).unwrap(); fr_name.highlight_region_name(&mut diag); @@ -706,7 +724,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { }, _ => LifetimeReturnCategoryErr::ShortReturn { span: *span, - category_desc: category.description(), + category: category.arg_desc(), free_region_name: &fr_name, outlived_fr_name, }, diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 419e6c817915f..527e4d983ca7c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -10,6 +10,7 @@ use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; +use crate::session_diagnostics::RegionNameLabels; use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt}; /// A name for a particular region used in emitting diagnostics. This name could be a generated @@ -133,48 +134,58 @@ impl RegionName { RegionNameHighlight::MatchedAdtAndSegment(span), _, ) => { - diag.span_label(*span, format!("let's call this `{self}`")); + diag.subdiagnostic(RegionNameLabels::NameRegion { span: *span, rg_name: self }); } RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::Occluded( span, type_name, )) => { - diag.span_label( - *span, - format!("lifetime `{self}` appears in the type {type_name}"), - ); + diag.subdiagnostic(RegionNameLabels::LifetimeInType { + span: *span, + type_name: &type_name, + rg_name: self, + }); } RegionNameSource::AnonRegionFromOutput( RegionNameHighlight::Occluded(span, type_name), mir_description, ) => { - diag.span_label( - *span, - format!( - "return type{mir_description} `{type_name}` contains a lifetime `{self}`" - ), - ); + diag.subdiagnostic(RegionNameLabels::LifetimeInReturned { + span: *span, + mir_description, + type_name: &type_name, + rg_name: self, + }); } RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => { - diag.span_label( - *span, - format!("lifetime `{self}` appears in the type of `{upvar_name}`"), - ); + diag.subdiagnostic(RegionNameLabels::LifetimeInTypeOf { + span: *span, + upvar_name: upvar_name.to_ident_string(), + rg_name: self, + }); } RegionNameSource::AnonRegionFromOutput( RegionNameHighlight::CannotMatchHirTy(span, type_name), mir_description, ) => { - diag.span_label(*span, format!("return type{mir_description} is {type_name}")); + diag.subdiagnostic(RegionNameLabels::ReturnTypeIsTpye { + span: *span, + mir_description, + type_name: &type_name, + }); } RegionNameSource::AnonRegionFromYieldTy(span, type_name) => { - diag.span_label(*span, format!("yield type is {type_name}")); + diag.subdiagnostic(RegionNameLabels::YieldTypeIsTpye { + span: *span, + type_name: &type_name, + }); } RegionNameSource::AnonRegionFromImplSignature(span, location) => { - diag.span_label( - *span, - format!("lifetime `{self}` appears in the `impl`'s {location}"), - ); + diag.subdiagnostic(RegionNameLabels::LifetimeInImpl { + span: *span, + rg_name: self, + location: &location, + }); } RegionNameSource::Static => {} } @@ -704,8 +715,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { }; let mir_description = match hir.body(body).generator_kind { Some(hir::GeneratorKind::Async(gen)) => match gen { - hir::AsyncGeneratorKind::Block => " of async block", - hir::AsyncGeneratorKind::Closure => " of async closure", + hir::AsyncGeneratorKind::Block => "Block", + hir::AsyncGeneratorKind::Closure => "Closure", hir::AsyncGeneratorKind::Fn => { let parent_item = hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id); @@ -717,11 +728,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { if let hir::FnRetTy::Return(ret) = output { hir_ty = Some(self.get_future_inner_return_ty(*ret)); } - " of async function" + "Fn" } }, - Some(hir::GeneratorKind::Gen) => " of generator", - None => " of closure", + Some(hir::GeneratorKind::Gen) => "Gen", + None => "None", }; (span, mir_description, hir_ty) } diff --git a/compiler/rustc_borrowck/src/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs index 9ba29f04b1a9a..b385f95b67c6f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use crate::Upvar; use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext}; use rustc_index::vec::{Idx, IndexVec}; diff --git a/compiler/rustc_borrowck/src/facts.rs b/compiler/rustc_borrowck/src/facts.rs index 22134d5a71ce1..51ed27c167d38 100644 --- a/compiler/rustc_borrowck/src/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::location::{LocationIndex, LocationTable}; use crate::BorrowIndex; use polonius_engine::AllFacts as PoloniusFacts; diff --git a/compiler/rustc_borrowck/src/invalidation.rs b/compiler/rustc_borrowck/src/invalidation.rs index 3157f861d93be..f5317a143aed7 100644 --- a/compiler/rustc_borrowck/src/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{self, BasicBlock, Body, Location, NonDivergingIntrinsic, Place, Rvalue}; diff --git a/compiler/rustc_borrowck/src/location.rs b/compiler/rustc_borrowck/src/location.rs index 877944d3d70cb..9fa7e218b1b6f 100644 --- a/compiler/rustc_borrowck/src/location.rs +++ b/compiler/rustc_borrowck/src/location.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{BasicBlock, Body, Location}; diff --git a/compiler/rustc_borrowck/src/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs index 43253a2aab00c..b48f9f97daad8 100644 --- a/compiler/rustc_borrowck/src/member_constraints.rs +++ b/compiler/rustc_borrowck/src/member_constraints.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 12b2481cc7907..fd4205c2eb64f 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! The entry point of the NLL borrow checker. use rustc_data_structures::vec_map::VecMap; @@ -461,3 +463,7 @@ impl ToRegionVid for RegionVid { pub(crate) trait ConstraintDescription { fn description(&self) -> &'static str; } + +pub(crate) trait ConstraintDiagDescription { + fn arg_desc(&self) -> String; +} diff --git a/compiler/rustc_borrowck/src/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs index b2c8dfc82c206..f8a99a2699e6f 100644 --- a/compiler/rustc_borrowck/src/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; use crate::places_conflict; use crate::AccessDepth; diff --git a/compiler/rustc_borrowck/src/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs index 93d202e49a159..9f6b1fdfcb540 100644 --- a/compiler/rustc_borrowck/src/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::borrow_set::LocalsStateAtExit; use rustc_hir as hir; use rustc_middle::mir::ProjectionElem; diff --git a/compiler/rustc_borrowck/src/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs index 0e71efd6f8d3e..8a87d1972ebf3 100644 --- a/compiler/rustc_borrowck/src/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::ArtificialField; use crate::Overlap; use crate::{AccessDepth, Deep, Shallow}; diff --git a/compiler/rustc_borrowck/src/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs index 2b50cbac9a02d..6f28134986376 100644 --- a/compiler/rustc_borrowck/src/prefixes.rs +++ b/compiler/rustc_borrowck/src/prefixes.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! From the NLL RFC: "The deep [aka 'supporting'] prefixes for an //! place are formed by stripping away fields and derefs, except that //! we stop when we reach the deref of a shared reference. [...] " diff --git a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs index fe5193102f958..649ca4ab8b48b 100644 --- a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs +++ b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! As part of generating the regions, if you enable `-Zdump-mir=nll`, //! we will generate an annotated copy of the MIR that includes the //! state of region inference. This code handles emitting the region diff --git a/compiler/rustc_borrowck/src/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs index f31ccd74ca6f7..2e15586e03b3b 100644 --- a/compiler/rustc_borrowck/src/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! This module provides linkage between RegionInferenceContext and //! `rustc_graphviz` traits, specialized to attaching borrowck analysis //! data to rendered labels. diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 9d088642f7773..9e37405b0722a 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -16,7 +16,9 @@ use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; use rustc_trait_selection::traits::TraitEngineExt as _; -use crate::session_diagnostics::ConstNotUsedTraitAlias; +use crate::session_diagnostics::{ + ConstNotUsedTraitAlias, OpaqueTyDefineErrCause, OpaqueTypeNotDefine, UnusedTypeParameter, +}; use super::RegionInferenceContext; @@ -374,15 +376,12 @@ fn check_opaque_type_parameter_valid( let arg_is_param = match arg.unpack() { GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)), GenericArgKind::Lifetime(lt) if lt.is_static() => { - tcx.sess - .struct_span_err(span, "non-defining opaque type use in defining scope") - .span_label( - tcx.def_span(opaque_generics.param_at(i, tcx).def_id), - "cannot use static lifetime; use a bound lifetime \ - instead or remove the lifetime parameter from the \ - opaque type", - ) - .emit(); + tcx.sess.emit_err(OpaqueTypeNotDefine { + cause: OpaqueTyDefineErrCause::UsedStaticLifetime { + span: tcx.def_span(opaque_generics.param_at(i, tcx).def_id), + }, + span, + }); return false; } GenericArgKind::Lifetime(lt) => { @@ -396,17 +395,14 @@ fn check_opaque_type_parameter_valid( } else { // Prevent `fn foo() -> Foo` from being defining. let opaque_param = opaque_generics.param_at(i, tcx); - tcx.sess - .struct_span_err(span, "non-defining opaque type use in defining scope") - .span_note( - tcx.def_span(opaque_param.def_id), - &format!( - "used non-generic {} `{}` for generic parameter", - opaque_param.kind.descr(), - arg, - ), - ) - .emit(); + tcx.sess.emit_err(OpaqueTypeNotDefine { + cause: OpaqueTyDefineErrCause::NonGenericUsed { + span: tcx.def_span(opaque_param.def_id), + descr: &opaque_param.kind.descr(), + arg: arg.to_string(), + }, + span, + }); return false; } } @@ -418,6 +414,7 @@ fn check_opaque_type_parameter_valid( .into_iter() .map(|i| tcx.def_span(opaque_generics.param_at(i, tcx).def_id)) .collect(); + // FIXME(#100717) requires eager translation/list support tcx.sess .struct_span_err(span, "non-defining opaque type use in defining scope") .span_note(spans, &format!("{} used multiple times", descr)) @@ -515,18 +512,13 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> { self.tcx.lifetimes.re_static } None => { - self.tcx - .sess - .struct_span_err(self.span, "non-defining opaque type use in defining scope") - .span_label( - self.span, - format!( - "lifetime `{}` is part of concrete type but not used in \ - parameter list of the `impl Trait` type alias", - r - ), - ) - .emit(); + self.tcx.sess.emit_err(OpaqueTypeNotDefine { + cause: OpaqueTyDefineErrCause::UnusedLifetime { + span: self.span, + r: r.to_string(), + }, + span: self.span, + }); self.tcx().lifetimes.re_static } @@ -598,17 +590,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> { Some(u) => panic!("type mapped to unexpected kind: {:?}", u), None => { debug!(?param, ?self.map); - self.tcx - .sess - .struct_span_err( - self.span, - &format!( - "type parameter `{}` is part of concrete type but not \ - used in parameter list for the `impl Trait` type alias", - ty - ), - ) - .emit(); + self.tcx.sess.emit_err(UnusedTypeParameter { ty, span: self.span }); self.tcx().ty_error() } diff --git a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs index 1e6798eee3df8..167f664609698 100644 --- a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs +++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::constraints::ConstraintSccIndex; use crate::RegionInferenceContext; use itertools::Itertools; diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index de20a4bb465c2..7498ddccf196a 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::fx::FxIndexSet; use rustc_index::bit_set::SparseBitMatrix; use rustc_index::interval::IntervalSet; diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 63b2088f7fc09..3a40b6ddd7668 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_index::vec::IndexVec; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; use rustc_middle::mir::visit::{MutVisitor, TyContext}; diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 9f19453a1a658..defe96764c836 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,7 +1,7 @@ use rustc_errors::{IntoDiagnosticArg, MultiSpan}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; -use rustc_span::Span; +use rustc_span::{Span, Symbol}; use crate::diagnostics::RegionName; @@ -131,7 +131,7 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> { ShortReturn { #[primary_span] span: Span, - category_desc: &'static str, + category: String, free_region_name: &'a RegionName, outlived_fr_name: RegionName, }, @@ -157,3 +157,462 @@ pub(crate) enum RequireStaticErr { multi_span: MultiSpan, }, } + +#[derive(Subdiagnostic)] +pub(crate) enum AddMoveErr { + #[label(borrowck::data_moved_here)] + Here { + #[primary_span] + binding_span: Span, + }, + #[label(borrowck::and_data_moved_here)] + AndHere { + #[primary_span] + binding_span: Span, + }, + #[note(borrowck::moved_var_cannot_copy)] + MovedNotCopy, +} + +#[derive(Subdiagnostic)] +pub(crate) enum BorrowUsedHere { + #[label(borrowck::used_here_by_closure)] + ByClosure { + #[primary_span] + path_span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum UsedLaterDropped<'a> { + #[label(borrowck::drop_local_might_cause_borrow)] + UsedHere { + borrow_desc: &'a str, + local_name: Symbol, + dtor_code: u8, + type_code: u8, + type_desc: String, + #[primary_span] + span: Span, + }, + #[note(borrowck::var_dropped_in_wrong_order)] + OppositeOrder, + #[label(borrowck::temporary_access_to_borrow)] + TemporaryCreatedHere { + borrow_desc: &'a str, + #[primary_span] + span: Span, + }, + #[label(borrowck::drop_temporary_might_cause_borrow_use)] + MightUsedHere { + borrow_desc: &'a str, + dtor_code: u8, + type_code: u8, + type_desc: String, + #[primary_span] + span: Span, + }, + #[suggestion_verbose( + borrowck::consider_add_semicolon, + applicability = "maybe-incorrect", + code = ";" + )] + AddSemicolon { + #[primary_span] + span: Span, + }, + #[multipart_suggestion( + borrowck::consider_move_expression_end_of_block, + applicability = "maybe-incorrect" + )] + MoveBlockEnd { + #[suggestion_part(code = "let x = ")] + lo_span: Span, + #[suggestion_part(code = "; x")] + hi_span: Span, + }, + #[note(borrowck::consider_forcing_temporary_drop_sooner)] + ManualDrop, +} + +#[derive(Subdiagnostic)] +pub(crate) enum OnLifetimeBound<'a> { + #[help(borrowck::consider_add_lifetime_bound)] + Add { fr_name: &'a RegionName, outlived_fr_name: &'a RegionName }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum ClosureCannotAgain { + #[note(borrowck::closure_cannot_invoke_again)] + Invoke { + place: String, + #[primary_span] + span: Span, + }, + #[note(borrowck::closure_cannot_move_again)] + Move { + place: String, + #[primary_span] + span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum ShowMutatingUpvar { + #[label(borrowck::require_mutable_binding)] + RequireMutableBinding { + upvar: String, + place: String, + reason: String, + #[primary_span] + span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum CaptureCausedBy<'a> { + #[label(borrowck::moved_by_call)] + Call { + place_name: &'a str, + partially_str: &'a str, + loop_message: &'a str, + #[primary_span] + span: Span, + }, + #[note(borrowck::moved_fnonce_value)] + FnOnceVal { + #[primary_span] + span: Span, + }, + #[label(borrowck::moved_by_operator_use)] + OperatorUse { + place_name: &'a str, + partially_str: &'a str, + loop_message: &'a str, + #[primary_span] + span: Span, + }, + #[note(borrowck::lhs_moved_by_operator_call)] + OperatorCall { + #[primary_span] + span: Span, + }, + #[label(borrowck::moved_by_implicit_call)] + ImplicitCall { + place_name: &'a str, + partially_str: &'a str, + loop_message: &'a str, + #[primary_span] + span: Span, + }, + #[label(borrowck::moved_by_method_call)] + MethodCall { + place_name: &'a str, + partially_str: &'a str, + loop_message: &'a str, + #[primary_span] + span: Span, + }, + #[note(borrowck::function_takes_self_ownership)] + FnTakeSelf { + place_name: &'a str, + #[primary_span] + span: Span, + }, + #[label(borrowck::consider_borrow_content_of_type)] + ConsiderManualBorrow { + #[primary_span] + span: Span, + }, + #[label(borrowck::value_moved_here)] + ValueHere { + move_msg: &'a str, + partially_str: &'a str, + loop_message: &'a str, + #[primary_span] + span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum NotImplCopy<'a, 'tcx> { + #[label(borrowck::type_not_impl_Copy)] + Label { + place_desc: &'a str, + ty: Ty<'tcx>, + move_prefix: &'a str, + #[primary_span] + span: Span, + }, + #[note(borrowck::type_not_impl_Copy)] + Note { place_desc: &'a str, ty: Ty<'tcx>, move_prefix: &'a str }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum FnMutBumpFn<'a> { + #[label(borrowck::cannot_act)] + Cannot { + act: &'a str, + #[primary_span] + sp: Span, + }, + #[label(borrowck::expects_fnmut_not_fn)] + AcceptFnMut { + #[primary_span] + span: Span, + }, + #[label(borrowck::expects_fn_not_fnmut)] + AcceptFn { + #[primary_span] + span: Span, + }, + #[label(borrowck::empty_label)] + EmptyLabel { + #[primary_span] + span: Span, + }, + #[label(borrowck::in_this_closure)] + Here { + #[primary_span] + span: Span, + }, + #[label(borrowck::return_fnmut)] + ReturnFnMut { + #[primary_span] + span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum RegionNameLabels<'a> { + #[label(borrowck::name_this_region)] + NameRegion { + #[primary_span] + span: Span, + rg_name: &'a RegionName, + }, + #[label(borrowck::lifetime_appears_in_type)] + LifetimeInType { + #[primary_span] + span: Span, + type_name: &'a str, + rg_name: &'a RegionName, + }, + #[label(borrowck::return_type_has_lifetime)] + LifetimeInReturned { + #[primary_span] + span: Span, + mir_description: &'a str, + type_name: &'a str, + rg_name: &'a RegionName, + }, + #[label(borrowck::lifetime_appears_in_type_of)] + LifetimeInTypeOf { + #[primary_span] + span: Span, + upvar_name: String, + rg_name: &'a RegionName, + }, + #[label(borrowck::return_type_is_type)] + ReturnTypeIsTpye { + #[primary_span] + span: Span, + mir_description: &'a str, + type_name: &'a str, + }, + #[label(borrowck::yield_type_is_type)] + YieldTypeIsTpye { + #[primary_span] + span: Span, + type_name: &'a str, + }, + #[label(borrowck::lifetime_appears_here_in_impl)] + LifetimeInImpl { + #[primary_span] + span: Span, + rg_name: &'a RegionName, + location: &'a str, + }, +} + +#[derive(Diagnostic)] +#[diag(borrowck::type_parameter_not_used_in_trait_type_alias)] +pub(crate) struct UnusedTypeParameter<'tcx> { + pub ty: Ty<'tcx>, + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::non_defining_opaque_type)] +pub(crate) struct OpaqueTypeNotDefine { + #[subdiagnostic] + pub cause: OpaqueTyDefineErrCause, + #[primary_span] + pub span: Span, +} + +#[derive(Subdiagnostic)] +pub(crate) enum OpaqueTyDefineErrCause { + #[label(borrowck::lifetime_not_used_in_trait_type_alias)] + UnusedLifetime { + #[primary_span] + span: Span, + r: String, + }, + #[note(borrowck::used_non_generic_for_generic)] + NonGenericUsed { + #[primary_span] + span: Span, + descr: &'static str, + arg: String, + }, + #[label(borrowck::cannot_use_static_lifetime_here)] + UsedStaticLifetime { + #[primary_span] + span: Span, + }, +} + +#[derive(Subdiagnostic)] +pub(crate) enum DefiningTypeNote<'a> { + #[note(borrowck::define_type_with_closure_substs)] + Closure { type_name: &'a str, subsets: &'a str }, + #[note(borrowck::define_type_with_generator_substs)] + Generator { type_name: &'a str, subsets: &'a str }, + #[note(borrowck::define_type)] + FnDef { type_name: &'a str }, + #[note(borrowck::define_const_type)] + Const { type_name: &'a str }, + #[note(borrowck::define_inline_constant_type)] + InlineConst { type_name: &'a str }, +} + +#[derive(Diagnostic)] +#[diag(borrowck::borrowed_temporary_value_dropped, code = "E0716")] +pub(crate) struct TemporaryDroppedErr { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::thread_local_outlive_function, code = "E0712")] +pub(crate) struct ThreadLocalOutliveErr { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::closure_borrowing_outlive_function, code = "E0373")] +pub(crate) struct ClosureVarOutliveErr<'a> { + pub closure_kind: &'a str, + pub borrowed_path: &'a str, + #[primary_span] + #[label] + pub closure_span: Span, + #[label(borrowck::path_label)] + pub capture_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_return_ref_to_local, code = "E0515")] +pub(crate) struct ReturnRefLocalErr<'a> { + pub return_kind: &'a str, + pub reference: &'a str, + pub local: &'a str, + #[primary_span] + #[label] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::path_does_not_live_long_enough, code = "E0597")] +pub(crate) struct PathShortLive<'a> { + pub path: &'a str, + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_borrow_across_destructor, code = "E0713")] +pub(crate) struct BorrowAcrossDestructor { + #[primary_span] + pub borrow_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_borrow_across_generator_yield, code = "E0626")] +pub(crate) struct BorrowAcrossGeneratorYield { + #[primary_span] + pub span: Span, + #[label] + pub yield_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_move_out_of_interior_of_drop, code = "E0509")] +pub(crate) struct InteriorDropMoveErr<'a> { + pub container_ty: Ty<'a>, + #[primary_span] + #[label] + pub move_from_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_assign_to_borrowed, code = "E0506")] +pub(crate) struct AssignBorrowErr<'a> { + pub desc: &'a str, + #[primary_span] + #[label] + pub span: Span, + #[label(borrowck::borrow_here_label)] + pub borrow_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_uniquely_borrow_by_two_closures, code = "E0524")] +pub(crate) struct TwoClosuresUniquelyBorrowErr<'a> { + pub desc: &'a str, + #[subdiagnostic] + pub case: ClosureConstructLabel, + #[primary_span] + pub new_loan_span: Span, + #[label] + pub old_load_end_span: Option, + #[label(borrowck::new_span_label)] + pub diff_span: Option, +} + +#[derive(Subdiagnostic)] +pub(crate) enum ClosureConstructLabel { + #[label(borrowck::first_closure_constructed_here)] + First { + #[primary_span] + old_loan_span: Span, + }, + #[label(borrowck::closures_constructed_here)] + Both { + #[primary_span] + old_loan_span: Span, + }, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_use_when_mutably_borrowed, code = "E0503")] +pub(crate) struct UseMutBorrowErr<'a> { + pub desc: &'a str, + pub borrow_desc: &'a str, + #[primary_span] + #[label] + pub span: Span, + #[label(borrowck::borrow_span_label)] + pub borrow_span: Span, +} + +#[derive(Diagnostic)] +#[diag(borrowck::cannot_move_when_borrowed, code = "E0505")] +pub(crate) struct MoveBorrowedErr<'a> { + pub desc: &'a str, + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 9271a2f4dc718..329f1814015d0 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use std::fmt; use rustc_infer::infer::canonical::Canonical; diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 71eae0583cb48..ee0aa78dd6fb9 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_infer::infer::canonical::QueryOutlivesConstraint; use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::outlives::env::RegionBoundPairs; diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index e0140e281ee73..a1cd454a27793 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::frozen::Frozen; use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder}; use rustc_infer::infer::canonical::QueryRegionConstraints; diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 4431a2e8ec60d..884720674d4c7 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! This module contains code to equate the input/output types appearing //! in the MIR with the expected input/output types from the function //! signature. This requires a bit of processing, as the expected types diff --git a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs index fda2cee43fbf1..dd890bed651f2 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::vec_linked_list as vll; use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{PlaceContext, Visitor}; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index d5c401ae1c6ed..56e1b1b789f13 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use itertools::{Either, Itertools}; use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir::{Body, Local}; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index bc76a465e3c3a..0674eb424b0ac 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use crate::def_use::{self, DefUse}; use crate::location::{LocationIndex, LocationTable}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 42b577175e437..651601925d4ef 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::bit_set::HybridBitSet; use rustc_index::interval::IntervalSet; diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d03f036964857..7fba98ca148c5 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] //! This pass type-checks the MIR to ensure it is not broken. use std::rc::Rc; diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index c97a6a1a6587a..b2626751d5c90 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate}; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::traits::ObligationCause; diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 41fba8deb10e7..6811364739d99 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -27,6 +27,7 @@ use rustc_middle::ty::{InternalSubsts, SubstsRef}; use std::iter; use crate::nll::ToRegionVid; +use crate::session_diagnostics::DefiningTypeNote; #[derive(Debug)] pub struct UniversalRegions<'tcx> { @@ -328,11 +329,10 @@ impl<'tcx> UniversalRegions<'tcx> { pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diagnostic) { match self.defining_ty { DefiningTy::Closure(def_id, substs) => { - err.note(&format!( - "defining type: {} with closure substs {:#?}", - tcx.def_path_str_with_substs(def_id, substs), - &substs[tcx.generics_of(def_id).parent_count..], - )); + err.subdiagnostic(DefiningTypeNote::Closure { + type_name: &tcx.def_path_str_with_substs(def_id, substs), + subsets: &format!("{:#?}", &substs[tcx.generics_of(def_id).parent_count..]), + }); // FIXME: It'd be nice to print the late-bound regions // here, but unfortunately these wind up stored into @@ -345,11 +345,10 @@ impl<'tcx> UniversalRegions<'tcx> { }); } DefiningTy::Generator(def_id, substs, _) => { - err.note(&format!( - "defining type: {} with generator substs {:#?}", - tcx.def_path_str_with_substs(def_id, substs), - &substs[tcx.generics_of(def_id).parent_count..], - )); + err.subdiagnostic(DefiningTypeNote::Generator { + type_name: &tcx.def_path_str_with_substs(def_id, substs), + subsets: &format!("{:#?}", &substs[tcx.generics_of(def_id).parent_count..]), + }); // FIXME: As above, we'd like to print out the region // `r` but doing so is not stable across architectures @@ -360,22 +359,19 @@ impl<'tcx> UniversalRegions<'tcx> { }); } DefiningTy::FnDef(def_id, substs) => { - err.note(&format!( - "defining type: {}", - tcx.def_path_str_with_substs(def_id, substs), - )); + err.subdiagnostic(DefiningTypeNote::FnDef { + type_name: &tcx.def_path_str_with_substs(def_id, substs), + }); } DefiningTy::Const(def_id, substs) => { - err.note(&format!( - "defining constant type: {}", - tcx.def_path_str_with_substs(def_id, substs), - )); + err.subdiagnostic(DefiningTypeNote::Const { + type_name: &tcx.def_path_str_with_substs(def_id, substs), + }); } DefiningTy::InlineConst(def_id, substs) => { - err.note(&format!( - "defining inline constant type: {}", - tcx.def_path_str_with_substs(def_id, substs), - )); + err.subdiagnostic(DefiningTypeNote::InlineConst { + type_name: &tcx.def_path_str_with_substs(def_id, substs), + }); } } } diff --git a/compiler/rustc_borrowck/src/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs index 8833753b12c5d..e297b1230ea0c 100644 --- a/compiler/rustc_borrowck/src/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -1,3 +1,5 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ diff --git a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl index 67f2156f32e50..a84aba5e3b210 100644 --- a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl @@ -54,7 +54,325 @@ borrowck_returned_lifetime_wrong = {$mir_def_name} was supposed to return data with lifetime `{$outlived_fr_name}` but it is returning data with lifetime `{$fr_name}` borrowck_returned_lifetime_short = - {$category_desc}requires that `{$free_region_name}` must outlive `{$outlived_fr_name}` + {$category -> + [Assignment] assignment {""} + [Return] returning this value {""} + [Yield] yielding this value {""} + [UseAsConst] using this value as a constant {""} + [UseAsStatic] using this value as a static {""} + [Cast] cast {""} + [CallArgument] argument {""} + [TypeAnnotation] type annotation {""} + [ClosureBounds] closure body {""} + [SizedBound] proving this value is `Sized` {""} + [CopyBound] copying this value {""} + [OpaqueType] opaque type {""} + [ClosureUpvar] closure capture {""} + [Usage] this usage {""} + *[other] {""} + }requires that `{$free_region_name}` must outlive `{$outlived_fr_name}` borrowck_used_impl_require_static = the used `impl` has a `'static` requirement + +borrowck_data_moved_here = + data moved here + +borrowck_and_data_moved_here = ...and here + +borrowck_moved_var_cannot_copy = + move occurs because these variables have types that don't implement the `Copy` trait + +borrowck_used_here_by_closure = + used here by closure + +borrowck_drop_local_might_cause_borrow = + {$borrow_desc -> + [mutable] mutable {""} + [immutable] immutable {""} + [first] first {""} + *[other] {""} + }borrow might be used here, when `{$local_name}` is dropped and runs the {$dtor_code -> + [0] `Drop` code + *[1] destructor + } for {$type_code -> + [1] closure + [2] generator + *[0] type + }{$type_desc} + +borrowck_var_dropped_in_wrong_order = + values in a scope are dropped in the opposite order they are defined + +borrowck_temporary_access_to_borrow = + a temporary with access to the {$borrow_desc -> + [mutable] mutable {""} + [immutable] immutable {""} + [first] first {""} + *[other] {""} + }borrow is created here ... + +borrowck_drop_temporary_might_cause_borrow_use = ... and the {$borrow_desc -> + [mutable] mutable {""} + [immutable] immutable {""} + [first] first {""} + *[other] {""} + }borrow might be used here, when that temporary is dropped and runs the {$dtor_code -> + [0] `Drop` code + *[1] destructor + } for {$type_code -> + [1] closure + [2] generator + *[0] type + }{$type_desc} + +borrowck_consider_add_semicolon = + consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped + +borrowck_consider_move_expression_end_of_block = + for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block + +borrowck_consider_forcing_temporary_drop_sooner = + the temporary is part of an expression at the end of a block; + consider forcing this temporary to be dropped sooner, before the block's local variables are dropped + +borrowck_perhaps_save_in_new_local_to_drop = + for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block + +borrowck_outlive_constraint_need_borrow_for = + {$category}requires that {$desc} is borrowed for `{$region_name}` + +borrowck_outlive_constraint_need_borrow_lasts_for = + {$category}requires that {$borrow_desc} is borrowed for `{$region_name}` + +borrowck_consider_add_lifetime_bound = + consider adding the following bound: `{$fr_name}: {$outlived_fr_name}` + +borrowck_closure_cannot_invoke_again = + closure cannot be invoked more than once because it moves the variable `{$place}` out of its environment + +borrowck_closure_cannot_move_again = + closure cannot be moved more than once as it is not `Copy` due to moving the variable `{$place}` out of its environment + +borrowck_value_moved_here = + value {$partially_str}moved{$move_msg -> + [InClosure] {""} into closure + *[other] {""} + } here{$loop_message -> + [InLoop] {""}, in previous iteration of loop + *[other] {""} + } + +borrowck_consider_borrow_content_of_type = + help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents + +borrowck_function_takes_self_ownership = + this function takes ownership of the receiver `self`, which moves {$place_name} + +borrowck_moved_by_method_call = + {$place_name} {$partially_str}moved due to this method call{$loop_message -> + [InLoop] {""}, in previous iteration of loop + *[other] {""} + } + +borrowck_moved_by_implicit_call = + {$place_name} {$partially_str}moved due to this implicit call to `.into_iter()`{$loop_message -> + [InLoop] {""}, in previous iteration of loop + *[other] {""} + } + +borrowck_lhs_moved_by_operator_call = + calling this operator moves the left-hand side + +borrowck_moved_by_operator_use = + {$place_name} {$partially_str}moved due to usage in operator{$loop_message -> + [InLoop] {""}, in previous iteration of loop + *[other] {""} + } + +borrowck_moved_fnonce_value = + this value implements `FnOnce`, which causes it to be moved when called + +borrowck_moved_by_call = + {$place_name} {$partially_str}moved due to this call{$loop_message -> + [InLoop] {""}, in previous iteration of loop + *[other] {""} + } + +borrowck_type_not_impl_Copy = + {$move_prefix}move occurs because {$place_desc -> + [value] value + *[other] {$place_desc} + } has type `{$ty}`, which does not implement the `Copy` trait + +borrowck_outlive_constraint_need_borrow_lasts = + {$category}requires that `{$borrow_desc}` lasts for `{$region_name}` + +borrowck_require_mutable_binding = + calling `{$place}` requires mutable binding due to {$reason -> + [borrow] mutable borrow of `{$upvar}` + *[mutation] possible mutation of `{$upvar}` + } + +borrowck_cannot_act = + cannot {$act} + +borrowck_expects_fnmut_not_fn = + change this to accept `FnMut` instead of `Fn` + +borrowck_expects_fn_not_fnmut = + expects `Fn` instead of `FnMut` + +borrowck_empty_label = {""} + +borrowck_in_this_closure = + in this closure + +borrowck_return_fnmut = + change this to return `FnMut` instead of `Fn` + +borrowck_name_this_region = + let's call this `{$rg_name}` + +borrowck_lifetime_appears_in_type = + lifetime `{$rg_name}` appears in the type {$type_name} + +borrowck_return_type_has_lifetime = + return type{$mir_description -> + [Block] {""} of async block + [Closure] {""} of async closure + [Fn] {""} of async function + [Gen] {""} of generator + [None] {""} of closure + *[other] {""} + } `{$type_name}` contains a lifetime `{$rg_name}` + +borrowck_lifetime_appears_in_type_of = + lifetime `{$rg_name}` appears in the type of `{$upvar_name}` + +borrowck_return_type_is_type = + return type{$mir_description -> + [Block] {""} of async block + [Closure] {""} of async closure + [Fn] {""} of async function + [Gen] {""} of generator + [None] {""} of closure + *[other] {""} + } is {$type_name} + +borrowck_yield_type_is_type = + yield type is {$type_name} + +borrowck_lifetime_appears_here_in_impl = + lifetime `{$rg_name}` appears in the `impl`'s {$location} + +borrowck_type_parameter_not_used_in_trait_type_alias = + type parameter `{$ty}` is part of concrete type but not used in parameter list for the `impl Trait` type alias + +borrowck_non_defining_opaque_type = + non-defining opaque type use in defining scope + +borrowck_lifetime_not_used_in_trait_type_alias = + lifetime `{$r}` is part of concrete type but not used in parameter list of the `impl Trait` type alias + +borrowck_used_non_generic_for_generic = + used non-generic {$descr -> + [lifetime] lifetime + [type] type + *[constant] constant + } `{$arg}` for generic parameter + +borrowck_cannot_use_static_lifetime_here = + cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type + +borrowck_define_inline_constant_type = + defining inline constant type: {$type_name} + +borrowck_define_const_type = + defining constant type: {$type_name} + +borrowck_define_type = + defining type: {$type_name} + +borrowck_define_type_with_generator_substs = + defining type: {$type_name} with generator substs {$subsets} + +borrowck_define_type_with_closure_substs = + defining type: {$type_name} with closure substs {$subsets} + +borrowck_borrowed_temporary_value_dropped = + temporary value dropped while borrowed + +borrowck_thread_local_outlive_function = + thread-local variable borrowed past end of function + +borrowck_closure_borrowing_outlive_function = + {$closure_kind} may outlive the current function, but it borrows {$borrowed_path}, which is owned by the current function + .label = may outlive borrowed value {$borrowed_path} + .path_label = {$borrowed_path} is borrowed here + +borrowck_cannot_return_ref_to_local = + cannot {$return_kind} {$reference} {$local} + .label = {$return_kind}s a {$reference} data owned by the current function + +borrowck_path_does_not_live_long_enough = + {$path} does not live long enough + +borrowck_cannot_borrow_across_destructor = + borrow may still be in use when destructor runs + +borrowck_cannot_borrow_across_generator_yield = + borrow may still be in use when generator yields + .label = possible yield occurs here + +borrowck_cannot_move_out_of_interior_of_drop = + cannot move out of type `{$container_ty}`, which implements the `Drop` trait + .label = cannot move out of here + +borrowck_cannot_assign_to_borrowed = + cannot assign to {$desc -> + [value] value + *[other] {$desc} + } because it is borrowed + .label = assignment to borrowed {$desc -> + [value] value + *[other] {$desc} + } occurs here + .borrow_here_label = borrow of {$desc -> + [value] value + *[other] {$desc} + } occurs here + +borrowck_cannot_uniquely_borrow_by_two_closures = + two closures require unique access to {$desc -> + [value] value + *[other] {$desc} + } at the same time + .label = borrow from first closure ends here + .new_span_label = second closure is constructed here + +borrowck_first_closure_constructed_here = + first closure is constructed here + +borrowck_closures_constructed_here = + closures are constructed here in different iterations of loop + +borrowck_cannot_use_when_mutably_borrowed = + cannot use {$desc -> + [value] value + *[other] {$desc} + } because it was mutably borrowed + .label = use of borrowed {$borrow_desc -> + [value] value + *[other] {$borrow_desc} + } + .borrow_span_label = borrow of {$borrow_desc -> + [value] value + *[other] {$borrow_desc} + } occurs here + +borrowck_cannot_move_when_borrowed = + cannot move out of {$desc -> + [value] value + *[other] {$desc} + } because it is borrowed diff --git a/src/test/ui/borrowck/issue-82462.stderr b/src/test/ui/borrowck/issue-82462.stderr index a2c291f779792..5f37fa62c11e6 100644 --- a/src/test/ui/borrowck/issue-82462.stderr +++ b/src/test/ui/borrowck/issue-82462.stderr @@ -10,7 +10,7 @@ LL | v.push(*x); | ^^^^^^^^^^ mutable borrow occurs here LL | break; LL | } - | - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice` + | - ... and the immutable borrow might be used here, when that temporary is dropped and runs the destructor for type `DroppingSlice` | help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | diff --git a/src/test/ui/btreemap/btreemap_dropck.stderr b/src/test/ui/btreemap/btreemap_dropck.stderr index e953e7ae82bb8..2390b3e0b9ec3 100644 --- a/src/test/ui/btreemap/btreemap_dropck.stderr +++ b/src/test/ui/btreemap/btreemap_dropck.stderr @@ -6,7 +6,7 @@ LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]); LL | drop(s); | ^ move out of `s` occurs here LL | } - | - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap` + | - borrow might be used here, when `_map` is dropped and runs the destructor for type `BTreeMap` error: aborting due to previous error diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr index 5d53405579d9d..d3db3edd35e12 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `dt` is dropped and runs the `Drop` code for type `Dt` + | borrow might be used here, when `dt` is dropped and runs the destructor for type `Dt` | = note: values in a scope are dropped in the opposite order they are defined @@ -22,7 +22,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `pt` is dropped and runs the `Drop` code for type `Pt` + | borrow might be used here, when `pt` is dropped and runs the destructor for type `Pt` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr index 5055cdd8b2bf9..ec9220f5d18ae 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `dt` is dropped and runs the `Drop` code for type `Dt` + | borrow might be used here, when `dt` is dropped and runs the destructor for type `Dt` | = note: values in a scope are dropped in the opposite order they are defined @@ -22,7 +22,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `pt` is dropped and runs the `Drop` code for type `Pt` + | borrow might be used here, when `pt` is dropped and runs the destructor for type `Pt` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/dropck/dropck-eyepatch.stderr b/src/test/ui/dropck/dropck-eyepatch.stderr index 21295e6c6019e..2819209474958 100644 --- a/src/test/ui/dropck/dropck-eyepatch.stderr +++ b/src/test/ui/dropck/dropck-eyepatch.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `dt` is dropped and runs the `Drop` code for type `Dt` + | borrow might be used here, when `dt` is dropped and runs the destructor for type `Dt` | = note: values in a scope are dropped in the opposite order they are defined @@ -22,7 +22,7 @@ LL | } | - | | | `c_shortest` dropped here while still borrowed - | borrow might be used here, when `pt` is dropped and runs the `Drop` code for type `Pt` + | borrow might be used here, when `pt` is dropped and runs the destructor for type `Pt` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/dropck/dropck-union.stderr b/src/test/ui/dropck/dropck-union.stderr index 854e29385a81b..82c7e0eea8fa5 100644 --- a/src/test/ui/dropck/dropck-union.stderr +++ b/src/test/ui/dropck/dropck-union.stderr @@ -7,7 +7,7 @@ LL | } | - | | | `v` dropped here while still borrowed - | borrow might be used here, when `v` is dropped and runs the `Drop` code for type `Wrap` + | borrow might be used here, when `v` is dropped and runs the destructor for type `Wrap` error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0597.stderr b/src/test/ui/error-codes/E0597.stderr index b4a1180ad546c..a910be830ad8a 100644 --- a/src/test/ui/error-codes/E0597.stderr +++ b/src/test/ui/error-codes/E0597.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `y` dropped here while still borrowed - | borrow might be used here, when `x` is dropped and runs the `Drop` code for type `Foo` + | borrow might be used here, when `x` is dropped and runs the destructor for type `Foo` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/generator/dropck-resume.stderr b/src/test/ui/generator/dropck-resume.stderr index b0756eb5589b7..135fdd42a1d13 100644 --- a/src/test/ui/generator/dropck-resume.stderr +++ b/src/test/ui/generator/dropck-resume.stderr @@ -8,7 +8,7 @@ LL | r = y.as_ref().unwrap(); | ^^^^^^^^^^ immutable borrow occurs here LL | LL | } - | - mutable borrow might be used here, when `g` is dropped and runs the destructor for generator + | - mutable borrow might be used here, when `g` is dropped and runs the destructor for type error: aborting due to previous error diff --git a/src/test/ui/generator/dropck.stderr b/src/test/ui/generator/dropck.stderr index 7bb188352d7a2..f051c58e2cb13 100644 --- a/src/test/ui/generator/dropck.stderr +++ b/src/test/ui/generator/dropck.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `*cell` dropped here while still borrowed - | borrow might be used here, when `gen` is dropped and runs the destructor for generator + | borrow might be used here, when `gen` is dropped and runs the destructor for type | = note: values in a scope are dropped in the opposite order they are defined @@ -25,7 +25,7 @@ LL | } | - | | | `ref_` dropped here while still borrowed - | borrow might be used here, when `gen` is dropped and runs the destructor for generator + | borrow might be used here, when `gen` is dropped and runs the destructor for type | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/macros/format-args-temporaries-in-write.stderr b/src/test/ui/macros/format-args-temporaries-in-write.stderr index 03ecc4b4418c6..d9f87c5c12320 100644 --- a/src/test/ui/macros/format-args-temporaries-in-write.stderr +++ b/src/test/ui/macros/format-args-temporaries-in-write.stderr @@ -8,7 +8,7 @@ LL | write!(Out, "{}", mutex.lock()) /* no semicolon */ | a temporary with access to the borrow is created here ... LL | LL | }; - | -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` + | -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `MutexGuard` | | | `mutex` dropped here while still borrowed | @@ -28,7 +28,7 @@ LL | writeln!(Out, "{}", mutex.lock()) /* no semicolon */ | a temporary with access to the borrow is created here ... LL | LL | }; - | -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` + | -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `MutexGuard` | | | `mutex` dropped here while still borrowed | diff --git a/src/test/ui/nll/dont-print-desugared.stderr b/src/test/ui/nll/dont-print-desugared.stderr index fad6121cbca52..9243621035949 100644 --- a/src/test/ui/nll/dont-print-desugared.stderr +++ b/src/test/ui/nll/dont-print-desugared.stderr @@ -16,7 +16,7 @@ LL | } | - | | | `y` dropped here while still borrowed - | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/drop-no-may-dangle.stderr b/src/test/ui/nll/drop-no-may-dangle.stderr index cb28088095004..1d5b7571143b2 100644 --- a/src/test/ui/nll/drop-no-may-dangle.stderr +++ b/src/test/ui/nll/drop-no-may-dangle.stderr @@ -8,7 +8,7 @@ LL | v[0] += 1; | ^^^^^^^^^ assignment to borrowed `v[_]` occurs here ... LL | } - | - borrow might be used here, when `p` is dropped and runs the `Drop` code for type `WrapMayNotDangle` + | - borrow might be used here, when `p` is dropped and runs the destructor for type `WrapMayNotDangle` error[E0506]: cannot assign to `v[_]` because it is borrowed --> $DIR/drop-no-may-dangle.rs:21:5 @@ -19,7 +19,7 @@ LL | let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] }; LL | v[0] += 1; | ^^^^^^^^^ assignment to borrowed `v[_]` occurs here LL | } - | - borrow might be used here, when `p` is dropped and runs the `Drop` code for type `WrapMayNotDangle` + | - borrow might be used here, when `p` is dropped and runs the destructor for type `WrapMayNotDangle` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/issue-54382-use-span-of-tail-of-block.stderr b/src/test/ui/nll/issue-54382-use-span-of-tail-of-block.stderr index d8f43cbc92a1e..5dac1e5dcf7a7 100644 --- a/src/test/ui/nll/issue-54382-use-span-of-tail-of-block.stderr +++ b/src/test/ui/nll/issue-54382-use-span-of-tail-of-block.stderr @@ -11,7 +11,7 @@ LL | } | - `_thing1` dropped here while still borrowed LL | LL | ; - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | diff --git a/src/test/ui/nll/issue-54556-temps-in-tail-diagnostic.stderr b/src/test/ui/nll/issue-54556-temps-in-tail-diagnostic.stderr index 92f5ffdf388ed..5cdb1478ec5f9 100644 --- a/src/test/ui/nll/issue-54556-temps-in-tail-diagnostic.stderr +++ b/src/test/ui/nll/issue-54556-temps-in-tail-diagnostic.stderr @@ -10,7 +10,7 @@ LL | } | - `_thing1` dropped here while still borrowed LL | LL | ; - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | diff --git a/src/test/ui/nll/issue-54556-used-vs-unused-tails.stderr b/src/test/ui/nll/issue-54556-used-vs-unused-tails.stderr index 25226e2967353..fdcedad13e872 100644 --- a/src/test/ui/nll/issue-54556-used-vs-unused-tails.stderr +++ b/src/test/ui/nll/issue-54556-used-vs-unused-tails.stderr @@ -2,7 +2,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:10:55 | LL | { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; // suggest `;` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -17,7 +17,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:13:55 | LL | { { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } } ; // suggest `;` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -32,7 +32,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:16:55 | LL | { { let mut _t1 = D(Box::new("t1")); D(&_t1).end() }; } // suggest `;` - | --^^^^- -- ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- -- ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -47,7 +47,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:19:55 | LL | let _ = { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; // suggest `;` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -62,7 +62,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:22:55 | LL | let _u = { let mut _t1 = D(Box::new("t1")); D(&_t1).unit() } ; // suggest `;` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -77,7 +77,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:25:55 | LL | let _x = { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; // `let x = ...; x` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -94,7 +94,7 @@ error[E0597]: `_t1` does not live long enough --> $DIR/issue-54556-used-vs-unused-tails.rs:30:55 | LL | _y = { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; // `let x = ...; x` - | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | --^^^^- - - ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | | | | | | `_t1` dropped here while still borrowed | | borrowed value does not live long enough @@ -114,7 +114,7 @@ LL | fn f_local_ref() { let mut _t1 = D(Box::new("t1")); D(&_t1).unit() } // | --^^^^- - | | | | | | | `_t1` dropped here while still borrowed - | | | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | | | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... | @@ -130,7 +130,7 @@ LL | fn f() -> String { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } // | --^^^^- - | | | | | | | `_t1` dropped here while still borrowed - | | | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D` + | | | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `D` | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... | diff --git a/src/test/ui/nll/maybe-initialized-drop.stderr b/src/test/ui/nll/maybe-initialized-drop.stderr index 9825ba4611b7d..2abf9edc65d58 100644 --- a/src/test/ui/nll/maybe-initialized-drop.stderr +++ b/src/test/ui/nll/maybe-initialized-drop.stderr @@ -6,7 +6,7 @@ LL | let wrap = Wrap { p: &mut x }; LL | x = 1; | ^^^^^ assignment to borrowed `x` occurs here LL | } - | - borrow might be used here, when `wrap` is dropped and runs the `Drop` code for type `Wrap` + | - borrow might be used here, when `wrap` is dropped and runs the destructor for type `Wrap` error: aborting due to previous error diff --git a/src/test/ui/span/dropck_direct_cycle_with_drop.stderr b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr index 07ae138ac71ea..e767a6d71a821 100644 --- a/src/test/ui/span/dropck_direct_cycle_with_drop.stderr +++ b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `d2` dropped here while still borrowed - | borrow might be used here, when `d1` is dropped and runs the `Drop` code for type `D` + | borrow might be used here, when `d1` is dropped and runs the destructor for type `D` | = note: values in a scope are dropped in the opposite order they are defined @@ -22,7 +22,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `d1` is dropped and runs the `Drop` code for type `D` + | borrow might be used here, when `d1` is dropped and runs the destructor for type `D` error: aborting due to 2 previous errors diff --git a/src/test/ui/span/dropck_misc_variants.stderr b/src/test/ui/span/dropck_misc_variants.stderr index 76e90574cef44..cb670fdeb9c23 100644 --- a/src/test/ui/span/dropck_misc_variants.stderr +++ b/src/test/ui/span/dropck_misc_variants.stderr @@ -21,7 +21,7 @@ LL | } | - | | | `v` dropped here while still borrowed - | borrow might be used here, when `_w` is dropped and runs the destructor for closure + | borrow might be used here, when `_w` is dropped and runs the destructor for type | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr index 809e60a8c8aac..10429e37b3227 100644 --- a/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr +++ b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `_d` is dropped and runs the `Drop` code for type `D_Child` + | borrow might be used here, when `_d` is dropped and runs the destructor for type `D_Child` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr b/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr index 2e217066915d3..c79ed31d24a3c 100644 --- a/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr +++ b/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr @@ -7,7 +7,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `_d` is dropped and runs the `Drop` code for type `D_HasSelfMethod` + | borrow might be used here, when `_d` is dropped and runs the destructor for type `D_HasSelfMethod` | = note: values in a scope are dropped in the opposite order they are defined @@ -20,7 +20,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `_d` is dropped and runs the `Drop` code for type `D_HasMethodWithSelfArg` + | borrow might be used here, when `_d` is dropped and runs the destructor for type `D_HasMethodWithSelfArg` | = note: values in a scope are dropped in the opposite order they are defined @@ -33,7 +33,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `_d` is dropped and runs the `Drop` code for type `D_HasType` + | borrow might be used here, when `_d` is dropped and runs the destructor for type `D_HasType` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue-24895-copy-clone-dropck.stderr b/src/test/ui/span/issue-24895-copy-clone-dropck.stderr index 18a3dc9e6defa..43ee38c5a31ed 100644 --- a/src/test/ui/span/issue-24895-copy-clone-dropck.stderr +++ b/src/test/ui/span/issue-24895-copy-clone-dropck.stderr @@ -7,7 +7,7 @@ LL | } | - | | | `d1` dropped here while still borrowed - | borrow might be used here, when `d2` is dropped and runs the `Drop` code for type `D` + | borrow might be used here, when `d2` is dropped and runs the destructor for type `D` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue-26656.stderr b/src/test/ui/span/issue-26656.stderr index 1e939c484fb7b..96024918d0b9c 100644 --- a/src/test/ui/span/issue-26656.stderr +++ b/src/test/ui/span/issue-26656.stderr @@ -7,7 +7,7 @@ LL | } | - | | | `ticking` dropped here while still borrowed - | borrow might be used here, when `zook` is dropped and runs the `Drop` code for type `Zook` + | borrow might be used here, when `zook` is dropped and runs the destructor for type `Zook` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue-29106.stderr b/src/test/ui/span/issue-29106.stderr index 71fbd60ee733b..7e81f24bda816 100644 --- a/src/test/ui/span/issue-29106.stderr +++ b/src/test/ui/span/issue-29106.stderr @@ -7,7 +7,7 @@ LL | } | - | | | `x` dropped here while still borrowed - | borrow might be used here, when `y` is dropped and runs the `Drop` code for type `Arc` + | borrow might be used here, when `y` is dropped and runs the destructor for type `Arc` | = note: values in a scope are dropped in the opposite order they are defined @@ -20,7 +20,7 @@ LL | } | - | | | `x` dropped here while still borrowed - | borrow might be used here, when `y` is dropped and runs the `Drop` code for type `Rc` + | borrow might be used here, when `y` is dropped and runs the destructor for type `Rc` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue28498-reject-ex1.stderr b/src/test/ui/span/issue28498-reject-ex1.stderr index 86e2d8c56b08f..020cdce6224d3 100644 --- a/src/test/ui/span/issue28498-reject-ex1.stderr +++ b/src/test/ui/span/issue28498-reject-ex1.stderr @@ -8,7 +8,7 @@ LL | } | - | | | here, drop of `foo` needs exclusive access to `foo.data`, because the type `Foo>` implements the `Drop` trait - | borrow might be used here, when `foo` is dropped and runs the `Drop` code for type `Foo` + | borrow might be used here, when `foo` is dropped and runs the destructor for type `Foo` | = note: consider using a `let` binding to create a longer lived value diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.stderr b/src/test/ui/span/issue28498-reject-lifetime-param.stderr index 3119ddd03cc26..d73bd63fb709e 100644 --- a/src/test/ui/span/issue28498-reject-lifetime-param.stderr +++ b/src/test/ui/span/issue28498-reject-lifetime-param.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `first_dropped` dropped here while still borrowed - | borrow might be used here, when `foo1` is dropped and runs the `Drop` code for type `Foo` + | borrow might be used here, when `foo1` is dropped and runs the destructor for type `Foo` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.stderr b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr index 60e8a648cd597..498fa01ddbdcd 100644 --- a/src/test/ui/span/issue28498-reject-passed-to-fn.stderr +++ b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `first_dropped` dropped here while still borrowed - | borrow might be used here, when `foo1` is dropped and runs the `Drop` code for type `Foo` + | borrow might be used here, when `foo1` is dropped and runs the destructor for type `Foo` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/issue28498-reject-trait-bound.stderr b/src/test/ui/span/issue28498-reject-trait-bound.stderr index 22e4a8205b617..ca243a01fc790 100644 --- a/src/test/ui/span/issue28498-reject-trait-bound.stderr +++ b/src/test/ui/span/issue28498-reject-trait-bound.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `first_dropped` dropped here while still borrowed - | borrow might be used here, when `foo1` is dropped and runs the `Drop` code for type `Foo` + | borrow might be used here, when `foo1` is dropped and runs the destructor for type `Foo` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/send-is-not-static-std-sync.stderr b/src/test/ui/span/send-is-not-static-std-sync.stderr index 5d493a3e4ee55..2645584fd9d5d 100644 --- a/src/test/ui/span/send-is-not-static-std-sync.stderr +++ b/src/test/ui/span/send-is-not-static-std-sync.stderr @@ -62,7 +62,7 @@ LL | } | - `z` dropped here while still borrowed ... LL | } - | - borrow might be used here, when `tx` is dropped and runs the `Drop` code for type `Sender` + | - borrow might be used here, when `tx` is dropped and runs the destructor for type `Sender` | = note: values in a scope are dropped in the opposite order they are defined diff --git a/src/test/ui/span/vec_refs_data_with_early_death.stderr b/src/test/ui/span/vec_refs_data_with_early_death.stderr index 684e784531325..077699cb8dde9 100644 --- a/src/test/ui/span/vec_refs_data_with_early_death.stderr +++ b/src/test/ui/span/vec_refs_data_with_early_death.stderr @@ -8,7 +8,7 @@ LL | } | - | | | `x` dropped here while still borrowed - | borrow might be used here, when `v` is dropped and runs the `Drop` code for type `Bag` + | borrow might be used here, when `v` is dropped and runs the destructor for type `Bag` | = note: values in a scope are dropped in the opposite order they are defined @@ -22,7 +22,7 @@ LL | } | - | | | `y` dropped here while still borrowed - | borrow might be used here, when `v` is dropped and runs the `Drop` code for type `Bag` + | borrow might be used here, when `v` is dropped and runs the destructor for type `Bag` | = note: values in a scope are dropped in the opposite order they are defined