Convert to inline diagnostics in rustc_borrowck
This commit is contained in:
parent
66daca1a85
commit
dd61998e74
9 changed files with 233 additions and 395 deletions
|
|
@ -3571,7 +3571,6 @@ dependencies = [
|
||||||
"rustc_abi",
|
"rustc_abi",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
"rustc_errors",
|
"rustc_errors",
|
||||||
"rustc_fluent_macro",
|
|
||||||
"rustc_graphviz",
|
"rustc_graphviz",
|
||||||
"rustc_hir",
|
"rustc_hir",
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
|
|
@ -3771,7 +3770,6 @@ dependencies = [
|
||||||
"rustc_abi",
|
"rustc_abi",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
"rustc_borrowck",
|
|
||||||
"rustc_codegen_ssa",
|
"rustc_codegen_ssa",
|
||||||
"rustc_const_eval",
|
"rustc_const_eval",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ polonius-engine = "0.13.0"
|
||||||
rustc_abi = { path = "../rustc_abi" }
|
rustc_abi = { path = "../rustc_abi" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_errors = { path = "../rustc_errors" }
|
rustc_errors = { path = "../rustc_errors" }
|
||||||
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
|
|
||||||
rustc_graphviz = { path = "../rustc_graphviz" }
|
rustc_graphviz = { path = "../rustc_graphviz" }
|
||||||
rustc_hir = { path = "../rustc_hir" }
|
rustc_hir = { path = "../rustc_hir" }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
|
|
|
||||||
|
|
@ -1,296 +0,0 @@
|
||||||
borrowck_assign_due_to_use_closure =
|
|
||||||
assignment occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_assign_due_to_use_coroutine =
|
|
||||||
assign occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_assign_part_due_to_use_closure =
|
|
||||||
assignment to part occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_assign_part_due_to_use_coroutine =
|
|
||||||
assign to part occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_borrow_due_to_use_closure =
|
|
||||||
borrow occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_borrow_due_to_use_coroutine =
|
|
||||||
borrow occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_calling_operator_moves =
|
|
||||||
calling this operator moves the value
|
|
||||||
|
|
||||||
borrowck_calling_operator_moves_lhs =
|
|
||||||
calling this operator moves the left-hand side
|
|
||||||
|
|
||||||
borrowck_cannot_move_when_borrowed =
|
|
||||||
cannot move out of {$place ->
|
|
||||||
[value] value
|
|
||||||
*[other] {$place}
|
|
||||||
} because it is borrowed
|
|
||||||
.label = borrow of {$borrow_place ->
|
|
||||||
[value] value
|
|
||||||
*[other] {$borrow_place}
|
|
||||||
} occurs here
|
|
||||||
.move_label = move out of {$value_place ->
|
|
||||||
[value] value
|
|
||||||
*[other] {$value_place}
|
|
||||||
} occurs here
|
|
||||||
|
|
||||||
borrowck_capture_immute =
|
|
||||||
capture is immutable because of use here
|
|
||||||
|
|
||||||
borrowck_capture_move =
|
|
||||||
capture is moved because of use here
|
|
||||||
|
|
||||||
borrowck_capture_mut =
|
|
||||||
capture is mutable because of use here
|
|
||||||
|
|
||||||
borrowck_closure_inferred_mut = inferred to be a `FnMut` closure
|
|
||||||
|
|
||||||
borrowck_closure_invoked_twice =
|
|
||||||
closure cannot be invoked more than once because it moves the variable `{$place_name}` out of its environment
|
|
||||||
|
|
||||||
borrowck_closure_moved_twice =
|
|
||||||
closure cannot be moved more than once as it is not `Copy` due to moving the variable `{$place_name}` out of its environment
|
|
||||||
|
|
||||||
borrowck_consider_borrow_type_contents =
|
|
||||||
help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
|
|
||||||
|
|
||||||
borrowck_could_not_normalize =
|
|
||||||
could not normalize `{$value}`
|
|
||||||
|
|
||||||
borrowck_could_not_prove =
|
|
||||||
could not prove `{$predicate}`
|
|
||||||
|
|
||||||
borrowck_dereference_suggestion =
|
|
||||||
dereference the return value
|
|
||||||
|
|
||||||
borrowck_func_take_self_moved_place =
|
|
||||||
`{$func}` takes ownership of the receiver `self`, which moves {$place_name}
|
|
||||||
|
|
||||||
borrowck_generic_does_not_live_long_enough =
|
|
||||||
`{$kind}` does not live long enough
|
|
||||||
|
|
||||||
borrowck_higher_ranked_lifetime_error =
|
|
||||||
higher-ranked lifetime error
|
|
||||||
|
|
||||||
borrowck_higher_ranked_subtype_error =
|
|
||||||
higher-ranked subtype error
|
|
||||||
|
|
||||||
borrowck_implicit_static =
|
|
||||||
this has an implicit `'static` lifetime requirement
|
|
||||||
|
|
||||||
borrowck_implicit_static_introduced =
|
|
||||||
calling this method introduces the `impl`'s `'static` requirement
|
|
||||||
|
|
||||||
borrowck_implicit_static_relax =
|
|
||||||
consider relaxing the implicit `'static` requirement
|
|
||||||
|
|
||||||
borrowck_lifetime_constraints_error =
|
|
||||||
lifetime may not live long enough
|
|
||||||
|
|
||||||
borrowck_limitations_implies_static =
|
|
||||||
due to a current limitation of the type system, this implies a `'static` lifetime
|
|
||||||
|
|
||||||
borrowck_move_closure_suggestion =
|
|
||||||
consider adding 'move' keyword before the nested closure
|
|
||||||
|
|
||||||
borrowck_move_out_place_here =
|
|
||||||
{$place} is moved here
|
|
||||||
|
|
||||||
borrowck_move_unsized =
|
|
||||||
cannot move a value of type `{$ty}`
|
|
||||||
.label = the size of `{$ty}` cannot be statically determined
|
|
||||||
|
|
||||||
borrowck_moved_a_fn_once_in_call =
|
|
||||||
this value implements `FnOnce`, which causes it to be moved when called
|
|
||||||
|
|
||||||
borrowck_moved_a_fn_once_in_call_call =
|
|
||||||
`FnOnce` closures can only be called once
|
|
||||||
|
|
||||||
borrowck_moved_a_fn_once_in_call_def =
|
|
||||||
`{$ty}` is made to be an `FnOnce` closure here
|
|
||||||
|
|
||||||
borrowck_moved_due_to_await =
|
|
||||||
{$place_name} {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to this {$is_loop_message ->
|
|
||||||
[true] await, in previous iteration of loop
|
|
||||||
*[false] await
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_moved_due_to_call =
|
|
||||||
{$place_name} {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to this {$is_loop_message ->
|
|
||||||
[true] call, in previous iteration of loop
|
|
||||||
*[false] call
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_moved_due_to_implicit_into_iter_call =
|
|
||||||
{$place_name} {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to this implicit call to {$is_loop_message ->
|
|
||||||
[true] `.into_iter()`, in previous iteration of loop
|
|
||||||
*[false] `.into_iter()`
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_moved_due_to_method_call =
|
|
||||||
{$place_name} {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to this method {$is_loop_message ->
|
|
||||||
[true] call, in previous iteration of loop
|
|
||||||
*[false] call
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_moved_due_to_usage_in_operator =
|
|
||||||
{$place_name} {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to usage in {$is_loop_message ->
|
|
||||||
[true] operator, in previous iteration of loop
|
|
||||||
*[false] operator
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_opaque_type_lifetime_mismatch =
|
|
||||||
opaque type used twice with different lifetimes
|
|
||||||
.label = lifetime `{$arg}` used here
|
|
||||||
.prev_lifetime_label = lifetime `{$prev}` previously used here
|
|
||||||
.note = if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types
|
|
||||||
|
|
||||||
borrowck_partial_var_move_by_use_in_closure =
|
|
||||||
variable {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to use in closure
|
|
||||||
|
|
||||||
borrowck_partial_var_move_by_use_in_coroutine =
|
|
||||||
variable {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_restrict_to_static =
|
|
||||||
consider restricting the type parameter to the `'static` lifetime
|
|
||||||
|
|
||||||
borrowck_returned_async_block_escaped =
|
|
||||||
returns an `async` block that contains a reference to a captured variable, which then escapes the closure body
|
|
||||||
|
|
||||||
borrowck_returned_closure_escaped =
|
|
||||||
returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
|
||||||
|
|
||||||
borrowck_returned_lifetime_short =
|
|
||||||
{$category_desc}requires that `{$free_region_name}` must outlive `{$outlived_fr_name}`
|
|
||||||
|
|
||||||
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_ref_escaped =
|
|
||||||
returns a reference to a captured variable which escapes the closure body
|
|
||||||
|
|
||||||
borrowck_simd_intrinsic_arg_const =
|
|
||||||
{$arg ->
|
|
||||||
[1] 1st
|
|
||||||
[2] 2nd
|
|
||||||
[3] 3rd
|
|
||||||
*[other] {$arg}th
|
|
||||||
} argument of `{$intrinsic}` is required to be a `const` item
|
|
||||||
|
|
||||||
borrowck_suggest_create_fresh_reborrow =
|
|
||||||
consider reborrowing the `Pin` instead of moving it
|
|
||||||
|
|
||||||
borrowck_suggest_iterate_over_slice =
|
|
||||||
consider iterating over a slice of the `{$ty}`'s content to avoid moving into the `for` loop
|
|
||||||
|
|
||||||
borrowck_tail_expr_drop_order = relative drop order changing in Rust 2024
|
|
||||||
.label = this temporary value will be dropped at the end of the block
|
|
||||||
.note = consider using a `let` binding to ensure the value will live long enough
|
|
||||||
|
|
||||||
borrowck_ty_no_impl_copy =
|
|
||||||
{$is_partial_move ->
|
|
||||||
[true] partial move
|
|
||||||
*[false] move
|
|
||||||
} occurs because {$place} has type `{$ty}`, which does not implement the `Copy` trait
|
|
||||||
|
|
||||||
borrowck_use_due_to_use_closure =
|
|
||||||
use occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_use_due_to_use_coroutine =
|
|
||||||
use occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_used_impl_require_static =
|
|
||||||
the used `impl` has a `'static` requirement
|
|
||||||
|
|
||||||
borrowck_value_capture_here =
|
|
||||||
value captured {$is_within ->
|
|
||||||
[true] here by coroutine
|
|
||||||
*[false] here
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_value_moved_here =
|
|
||||||
value {$is_partial ->
|
|
||||||
[true] partially moved
|
|
||||||
*[false] moved
|
|
||||||
} {$is_move_msg ->
|
|
||||||
[true] into closure here
|
|
||||||
*[false] here
|
|
||||||
}{$is_loop_message ->
|
|
||||||
[true] , in previous iteration of loop
|
|
||||||
*[false] {""}
|
|
||||||
}
|
|
||||||
|
|
||||||
borrowck_var_borrow_by_use_in_closure =
|
|
||||||
borrow occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_var_borrow_by_use_in_coroutine =
|
|
||||||
borrow occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_var_borrow_by_use_place_in_closure =
|
|
||||||
{$is_single_var ->
|
|
||||||
*[true] borrow occurs
|
|
||||||
[false] borrows occur
|
|
||||||
} due to use of {$place} in closure
|
|
||||||
|
|
||||||
borrowck_var_borrow_by_use_place_in_coroutine =
|
|
||||||
{$is_single_var ->
|
|
||||||
*[true] borrow occurs
|
|
||||||
[false] borrows occur
|
|
||||||
} due to use of {$place} in coroutine
|
|
||||||
|
|
||||||
borrowck_var_cannot_escape_closure =
|
|
||||||
captured variable cannot escape `FnMut` closure body
|
|
||||||
.note = `FnMut` closures only have access to their captured variables while they are executing...
|
|
||||||
.cannot_escape = ...therefore, they cannot allow references to captured variables to escape
|
|
||||||
|
|
||||||
borrowck_var_does_not_need_mut =
|
|
||||||
variable does not need to be mutable
|
|
||||||
.suggestion = remove this `mut`
|
|
||||||
|
|
||||||
borrowck_var_first_borrow_by_use_place_in_closure =
|
|
||||||
first borrow occurs due to use of {$place} in closure
|
|
||||||
|
|
||||||
borrowck_var_first_borrow_by_use_place_in_coroutine =
|
|
||||||
first borrow occurs due to use of {$place} in coroutine
|
|
||||||
|
|
||||||
borrowck_var_here_captured = variable captured here
|
|
||||||
|
|
||||||
borrowck_var_here_defined = variable defined here
|
|
||||||
|
|
||||||
borrowck_var_move_by_use_in_closure =
|
|
||||||
move occurs due to use in closure
|
|
||||||
|
|
||||||
borrowck_var_move_by_use_in_coroutine =
|
|
||||||
move occurs due to use in coroutine
|
|
||||||
|
|
||||||
borrowck_var_mutable_borrow_by_use_place_in_closure =
|
|
||||||
mutable borrow occurs due to use of {$place} in closure
|
|
||||||
|
|
||||||
borrowck_var_second_borrow_by_use_place_in_closure =
|
|
||||||
second borrow occurs due to use of {$place} in closure
|
|
||||||
|
|
||||||
borrowck_var_second_borrow_by_use_place_in_coroutine =
|
|
||||||
second borrow occurs due to use of {$place} in coroutine
|
|
||||||
|
|
@ -4,7 +4,9 @@ use std::collections::BTreeMap;
|
||||||
|
|
||||||
use rustc_abi::{FieldIdx, VariantIdx};
|
use rustc_abi::{FieldIdx, VariantIdx};
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
|
use rustc_errors::{
|
||||||
|
Applicability, Diag, DiagMessage, EmissionGuarantee, MultiSpan, inline_fluent, listify,
|
||||||
|
};
|
||||||
use rustc_hir::def::{CtorKind, Namespace};
|
use rustc_hir::def::{CtorKind, Namespace};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
self as hir, CoroutineKind, GenericBound, LangItem, WhereBoundPredicate, WherePredicateKind,
|
self as hir, CoroutineKind, GenericBound, LangItem, WhereBoundPredicate, WherePredicateKind,
|
||||||
|
|
@ -35,7 +37,6 @@ use tracing::debug;
|
||||||
use super::MirBorrowckCtxt;
|
use super::MirBorrowckCtxt;
|
||||||
use super::borrow_set::BorrowData;
|
use super::borrow_set::BorrowData;
|
||||||
use crate::constraints::OutlivesConstraint;
|
use crate::constraints::OutlivesConstraint;
|
||||||
use crate::fluent_generated as fluent;
|
|
||||||
use crate::nll::ConstraintDescription;
|
use crate::nll::ConstraintDescription;
|
||||||
use crate::session_diagnostics::{
|
use crate::session_diagnostics::{
|
||||||
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
|
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
|
||||||
|
|
@ -700,7 +701,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
|
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
diag.span_note(pred.span, fluent::borrowck_limitations_implies_static);
|
diag.span_note(pred.span, LIMITATION_NOTE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for bound in bounds.iter() {
|
for bound in bounds.iter() {
|
||||||
|
|
@ -711,7 +712,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
|
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
diag.span_note(bound.span, fluent::borrowck_limitations_implies_static);
|
diag.span_note(bound.span, LIMITATION_NOTE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1312,7 +1313,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
let mut span: MultiSpan = spans.clone().into();
|
let mut span: MultiSpan = spans.clone().into();
|
||||||
err.arg("ty", param_ty.to_string());
|
err.arg("ty", param_ty.to_string());
|
||||||
let msg = err.dcx.eagerly_translate_to_string(
|
let msg = err.dcx.eagerly_translate_to_string(
|
||||||
fluent::borrowck_moved_a_fn_once_in_call_def,
|
inline_fluent!("`{$ty}` is made to be an `FnOnce` closure here"),
|
||||||
err.args.iter(),
|
err.args.iter(),
|
||||||
);
|
);
|
||||||
err.remove_arg("ty");
|
err.remove_arg("ty");
|
||||||
|
|
@ -1321,9 +1322,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
span.push_span_label(
|
span.push_span_label(
|
||||||
fn_call_span,
|
fn_call_span,
|
||||||
fluent::borrowck_moved_a_fn_once_in_call,
|
inline_fluent!("this value implements `FnOnce`, which causes it to be moved when called"),
|
||||||
|
);
|
||||||
|
err.span_note(
|
||||||
|
span,
|
||||||
|
inline_fluent!("`FnOnce` closures can only be called once"),
|
||||||
);
|
);
|
||||||
err.span_note(span, fluent::borrowck_moved_a_fn_once_in_call_call);
|
|
||||||
} else {
|
} else {
|
||||||
err.subdiagnostic(CaptureReasonNote::FnOnceMoveInCall { var_span });
|
err.subdiagnostic(CaptureReasonNote::FnOnceMoveInCall { var_span });
|
||||||
}
|
}
|
||||||
|
|
@ -1568,3 +1572,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
self.local_name(index).is_none_or(|name| name.as_str().starts_with('_'))
|
self.local_name(index).is_none_or(|name| name.as_str().starts_with('_'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LIMITATION_NOTE: DiagMessage = inline_fluent!(
|
||||||
|
"due to a current limitation of the type system, this implies a `'static` lifetime"
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Error reporting machinery for lifetime errors.
|
//! Error reporting machinery for lifetime errors.
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, inline_fluent};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::GenericBound::Trait;
|
use rustc_hir::GenericBound::Trait;
|
||||||
use rustc_hir::QPath::Resolved;
|
use rustc_hir::QPath::Resolved;
|
||||||
|
|
@ -27,7 +27,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
|
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
|
||||||
use tracing::{debug, instrument, trace};
|
use tracing::{debug, instrument, trace};
|
||||||
|
|
||||||
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
|
use super::{LIMITATION_NOTE, OutlivesSuggestionBuilder, RegionName, RegionNameSource};
|
||||||
use crate::nll::ConstraintDescription;
|
use crate::nll::ConstraintDescription;
|
||||||
use crate::region_infer::values::RegionElement;
|
use crate::region_infer::values::RegionElement;
|
||||||
use crate::region_infer::{BlameConstraint, TypeTest};
|
use crate::region_infer::{BlameConstraint, TypeTest};
|
||||||
|
|
@ -36,7 +36,7 @@ use crate::session_diagnostics::{
|
||||||
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
|
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
|
||||||
};
|
};
|
||||||
use crate::universal_regions::DefiningTy;
|
use crate::universal_regions::DefiningTy;
|
||||||
use crate::{MirBorrowckCtxt, borrowck_errors, fluent_generated as fluent};
|
use crate::{MirBorrowckCtxt, borrowck_errors};
|
||||||
|
|
||||||
impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
||||||
fn description(&self) -> &'static str {
|
fn description(&self) -> &'static str {
|
||||||
|
|
@ -265,7 +265,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }) = bound else {
|
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }) = bound else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
diag.span_note(*trait_span, fluent::borrowck_limitations_implies_static);
|
diag.span_note(*trait_span, LIMITATION_NOTE);
|
||||||
let Some(generics_fn) = tcx.hir_get_generics(self.body.source.def_id().expect_local())
|
let Some(generics_fn) = tcx.hir_get_generics(self.body.source.def_id().expect_local())
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -298,7 +298,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
if suggestions.len() > 0 {
|
if suggestions.len() > 0 {
|
||||||
suggestions.dedup();
|
suggestions.dedup();
|
||||||
diag.multipart_suggestion_verbose(
|
diag.multipart_suggestion_verbose(
|
||||||
fluent::borrowck_restrict_to_static,
|
inline_fluent!("consider restricting the type parameter to the `'static` lifetime"),
|
||||||
suggestions,
|
suggestions,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
@ -966,12 +966,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
debug!("trait spans found: {:?}", traits);
|
debug!("trait spans found: {:?}", traits);
|
||||||
for span in &traits {
|
for span in &traits {
|
||||||
let mut multi_span: MultiSpan = vec![*span].into();
|
let mut multi_span: MultiSpan = vec![*span].into();
|
||||||
multi_span.push_span_label(*span, fluent::borrowck_implicit_static);
|
multi_span.push_span_label(
|
||||||
multi_span.push_span_label(ident.span, fluent::borrowck_implicit_static_introduced);
|
*span,
|
||||||
|
inline_fluent!("this has an implicit `'static` lifetime requirement"),
|
||||||
|
);
|
||||||
|
multi_span.push_span_label(
|
||||||
|
ident.span,
|
||||||
|
inline_fluent!(
|
||||||
|
"calling this method introduces the `impl`'s `'static` requirement"
|
||||||
|
),
|
||||||
|
);
|
||||||
err.subdiagnostic(RequireStaticErr::UsedImpl { multi_span });
|
err.subdiagnostic(RequireStaticErr::UsedImpl { multi_span });
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span.shrink_to_hi(),
|
span.shrink_to_hi(),
|
||||||
fluent::borrowck_implicit_static_relax,
|
inline_fluent!("consider relaxing the implicit `'static` requirement"),
|
||||||
" + '_",
|
" + '_",
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
@ -1134,7 +1142,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
if ocx.evaluate_obligations_error_on_ambiguity().is_empty() && count > 0 {
|
if ocx.evaluate_obligations_error_on_ambiguity().is_empty() && count > 0 {
|
||||||
diag.span_suggestion_verbose(
|
diag.span_suggestion_verbose(
|
||||||
tcx.hir_body(*body).value.peel_blocks().span.shrink_to_lo(),
|
tcx.hir_body(*body).value.peel_blocks().span.shrink_to_lo(),
|
||||||
fluent::borrowck_dereference_suggestion,
|
inline_fluent!("dereference the return value"),
|
||||||
"*".repeat(count),
|
"*".repeat(count),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
|
@ -1178,7 +1186,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
if let Some(closure_span) = closure_span {
|
if let Some(closure_span) = closure_span {
|
||||||
diag.span_suggestion_verbose(
|
diag.span_suggestion_verbose(
|
||||||
closure_span,
|
closure_span,
|
||||||
fluent::borrowck_move_closure_suggestion,
|
inline_fluent!("consider adding 'move' keyword before the nested closure"),
|
||||||
"move ",
|
"move ",
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,6 @@ mod used_muts;
|
||||||
/// A public API provided for the Rust compiler consumers.
|
/// A public API provided for the Rust compiler consumers.
|
||||||
pub mod consumers;
|
pub mod consumers;
|
||||||
|
|
||||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
|
||||||
|
|
||||||
/// Associate some local constants with the `'tcx` lifetime
|
/// Associate some local constants with the `'tcx` lifetime
|
||||||
struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
|
struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,16 @@ use rustc_span::Span;
|
||||||
use crate::diagnostics::RegionName;
|
use crate::diagnostics::RegionName;
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_move_unsized, code = E0161)]
|
#[diag("cannot move a value of type `{$ty}`", code = E0161)]
|
||||||
pub(crate) struct MoveUnsized<'tcx> {
|
pub(crate) struct MoveUnsized<'tcx> {
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label("the size of `{$ty}` cannot be statically determined")]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_higher_ranked_lifetime_error)]
|
#[diag("higher-ranked lifetime error")]
|
||||||
pub(crate) struct HigherRankedLifetimeError {
|
pub(crate) struct HigherRankedLifetimeError {
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub cause: Option<HigherRankedErrorCause>,
|
pub cause: Option<HigherRankedErrorCause>,
|
||||||
|
|
@ -26,21 +26,21 @@ pub(crate) struct HigherRankedLifetimeError {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum HigherRankedErrorCause {
|
pub(crate) enum HigherRankedErrorCause {
|
||||||
#[note(borrowck_could_not_prove)]
|
#[note("could not prove `{$predicate}`")]
|
||||||
CouldNotProve { predicate: String },
|
CouldNotProve { predicate: String },
|
||||||
#[note(borrowck_could_not_normalize)]
|
#[note("could not normalize `{$value}`")]
|
||||||
CouldNotNormalize { value: String },
|
CouldNotNormalize { value: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_higher_ranked_subtype_error)]
|
#[diag("higher-ranked subtype error")]
|
||||||
pub(crate) struct HigherRankedSubtypeError {
|
pub(crate) struct HigherRankedSubtypeError {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_generic_does_not_live_long_enough)]
|
#[diag("`{$kind}` does not live long enough")]
|
||||||
pub(crate) struct GenericDoesNotLiveLongEnough {
|
pub(crate) struct GenericDoesNotLiveLongEnough {
|
||||||
pub kind: String,
|
pub kind: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
@ -48,15 +48,20 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(borrowck_var_does_not_need_mut)]
|
#[diag("variable does not need to be mutable")]
|
||||||
pub(crate) struct VarNeedNotMut {
|
pub(crate) struct VarNeedNotMut {
|
||||||
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
|
#[suggestion(
|
||||||
|
"remove this `mut`",
|
||||||
|
style = "short",
|
||||||
|
applicability = "machine-applicable",
|
||||||
|
code = ""
|
||||||
|
)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_var_cannot_escape_closure)]
|
#[diag("captured variable cannot escape `FnMut` closure body")]
|
||||||
#[note]
|
#[note("`FnMut` closures only have access to their captured variables while they are executing...")]
|
||||||
#[note(borrowck_cannot_escape)]
|
#[note("...therefore, they cannot allow references to captured variables to escape")]
|
||||||
pub(crate) struct FnMutError {
|
pub(crate) struct FnMutError {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
@ -66,17 +71,17 @@ pub(crate) struct FnMutError {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum VarHereDenote {
|
pub(crate) enum VarHereDenote {
|
||||||
#[label(borrowck_var_here_captured)]
|
#[label("variable captured here")]
|
||||||
Captured {
|
Captured {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_here_defined)]
|
#[label("variable defined here")]
|
||||||
Defined {
|
Defined {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_closure_inferred_mut)]
|
#[label("inferred to be a `FnMut` closure")]
|
||||||
FnMutInferred {
|
FnMutInferred {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
@ -85,17 +90,21 @@ pub(crate) enum VarHereDenote {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum FnMutReturnTypeErr {
|
pub(crate) enum FnMutReturnTypeErr {
|
||||||
#[label(borrowck_returned_closure_escaped)]
|
#[label(
|
||||||
|
"returns a closure that contains a reference to a captured variable, which then escapes the closure body"
|
||||||
|
)]
|
||||||
ReturnClosure {
|
ReturnClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_returned_async_block_escaped)]
|
#[label(
|
||||||
|
"returns an `async` block that contains a reference to a captured variable, which then escapes the closure body"
|
||||||
|
)]
|
||||||
ReturnAsyncBlock {
|
ReturnAsyncBlock {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_returned_ref_escaped)]
|
#[label("returns a reference to a captured variable which escapes the closure body")]
|
||||||
ReturnRef {
|
ReturnRef {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
@ -103,7 +112,7 @@ pub(crate) enum FnMutReturnTypeErr {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_lifetime_constraints_error)]
|
#[diag("lifetime may not live long enough")]
|
||||||
pub(crate) struct LifetimeOutliveErr {
|
pub(crate) struct LifetimeOutliveErr {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
@ -111,7 +120,9 @@ pub(crate) struct LifetimeOutliveErr {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
||||||
#[label(borrowck_returned_lifetime_wrong)]
|
#[label(
|
||||||
|
"{$mir_def_name} was supposed to return data with lifetime `{$outlived_fr_name}` but it is returning data with lifetime `{$fr_name}`"
|
||||||
|
)]
|
||||||
WrongReturn {
|
WrongReturn {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
@ -119,7 +130,9 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
||||||
outlived_fr_name: RegionName,
|
outlived_fr_name: RegionName,
|
||||||
fr_name: &'a RegionName,
|
fr_name: &'a RegionName,
|
||||||
},
|
},
|
||||||
#[label(borrowck_returned_lifetime_short)]
|
#[label(
|
||||||
|
"{$category_desc}requires that `{$free_region_name}` must outlive `{$outlived_fr_name}`"
|
||||||
|
)]
|
||||||
ShortReturn {
|
ShortReturn {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
@ -131,7 +144,7 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum RequireStaticErr {
|
pub(crate) enum RequireStaticErr {
|
||||||
#[note(borrowck_used_impl_require_static)]
|
#[note("the used `impl` has a `'static` requirement")]
|
||||||
UsedImpl {
|
UsedImpl {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
multi_span: MultiSpan,
|
multi_span: MultiSpan,
|
||||||
|
|
@ -140,42 +153,42 @@ pub(crate) enum RequireStaticErr {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureVarPathUseCause {
|
pub(crate) enum CaptureVarPathUseCause {
|
||||||
#[label(borrowck_borrow_due_to_use_coroutine)]
|
#[label("borrow occurs due to use in coroutine")]
|
||||||
BorrowInCoroutine {
|
BorrowInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_use_due_to_use_coroutine)]
|
#[label("use occurs due to use in coroutine")]
|
||||||
UseInCoroutine {
|
UseInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_assign_due_to_use_coroutine)]
|
#[label("assign occurs due to use in coroutine")]
|
||||||
AssignInCoroutine {
|
AssignInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_assign_part_due_to_use_coroutine)]
|
#[label("assign to part occurs due to use in coroutine")]
|
||||||
AssignPartInCoroutine {
|
AssignPartInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_borrow_due_to_use_closure)]
|
#[label("borrow occurs due to use in closure")]
|
||||||
BorrowInClosure {
|
BorrowInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_use_due_to_use_closure)]
|
#[label("use occurs due to use in closure")]
|
||||||
UseInClosure {
|
UseInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_assign_due_to_use_closure)]
|
#[label("assignment occurs due to use in closure")]
|
||||||
AssignInClosure {
|
AssignInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_assign_part_due_to_use_closure)]
|
#[label("assignment to part occurs due to use in closure")]
|
||||||
AssignPartInClosure {
|
AssignPartInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
|
|
@ -184,17 +197,17 @@ pub(crate) enum CaptureVarPathUseCause {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureVarKind {
|
pub(crate) enum CaptureVarKind {
|
||||||
#[label(borrowck_capture_immute)]
|
#[label("capture is immutable because of use here")]
|
||||||
Immut {
|
Immut {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
kind_span: Span,
|
kind_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_capture_mut)]
|
#[label("capture is mutable because of use here")]
|
||||||
Mut {
|
Mut {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
kind_span: Span,
|
kind_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_capture_move)]
|
#[label("capture is moved because of use here")]
|
||||||
Move {
|
Move {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
kind_span: Span,
|
kind_span: Span,
|
||||||
|
|
@ -203,77 +216,97 @@ pub(crate) enum CaptureVarKind {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureVarCause {
|
pub(crate) enum CaptureVarCause {
|
||||||
#[label(borrowck_var_borrow_by_use_place_in_coroutine)]
|
#[label(
|
||||||
|
"{$is_single_var ->
|
||||||
|
*[true] borrow occurs
|
||||||
|
[false] borrows occur
|
||||||
|
} due to use of {$place} in coroutine"
|
||||||
|
)]
|
||||||
BorrowUsePlaceCoroutine {
|
BorrowUsePlaceCoroutine {
|
||||||
is_single_var: bool,
|
is_single_var: bool,
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_borrow_by_use_place_in_closure)]
|
#[label(
|
||||||
|
"{$is_single_var ->
|
||||||
|
*[true] borrow occurs
|
||||||
|
[false] borrows occur
|
||||||
|
} due to use of {$place} in closure"
|
||||||
|
)]
|
||||||
BorrowUsePlaceClosure {
|
BorrowUsePlaceClosure {
|
||||||
is_single_var: bool,
|
is_single_var: bool,
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_borrow_by_use_in_coroutine)]
|
#[label("borrow occurs due to use in coroutine")]
|
||||||
BorrowUseInCoroutine {
|
BorrowUseInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_borrow_by_use_in_closure)]
|
#[label("borrow occurs due to use in closure")]
|
||||||
BorrowUseInClosure {
|
BorrowUseInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_move_by_use_in_coroutine)]
|
#[label("move occurs due to use in coroutine")]
|
||||||
MoveUseInCoroutine {
|
MoveUseInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_move_by_use_in_closure)]
|
#[label("move occurs due to use in closure")]
|
||||||
MoveUseInClosure {
|
MoveUseInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_first_borrow_by_use_place_in_coroutine)]
|
#[label("first borrow occurs due to use of {$place} in coroutine")]
|
||||||
FirstBorrowUsePlaceCoroutine {
|
FirstBorrowUsePlaceCoroutine {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_first_borrow_by_use_place_in_closure)]
|
#[label("first borrow occurs due to use of {$place} in closure")]
|
||||||
FirstBorrowUsePlaceClosure {
|
FirstBorrowUsePlaceClosure {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_second_borrow_by_use_place_in_coroutine)]
|
#[label("second borrow occurs due to use of {$place} in coroutine")]
|
||||||
SecondBorrowUsePlaceCoroutine {
|
SecondBorrowUsePlaceCoroutine {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_second_borrow_by_use_place_in_closure)]
|
#[label("second borrow occurs due to use of {$place} in closure")]
|
||||||
SecondBorrowUsePlaceClosure {
|
SecondBorrowUsePlaceClosure {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_var_mutable_borrow_by_use_place_in_closure)]
|
#[label("mutable borrow occurs due to use of {$place} in closure")]
|
||||||
MutableBorrowUsePlaceClosure {
|
MutableBorrowUsePlaceClosure {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_partial_var_move_by_use_in_coroutine)]
|
#[label(
|
||||||
|
"variable {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to use in coroutine"
|
||||||
|
)]
|
||||||
PartialMoveUseInCoroutine {
|
PartialMoveUseInCoroutine {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_partial_var_move_by_use_in_closure)]
|
#[label(
|
||||||
|
"variable {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to use in closure"
|
||||||
|
)]
|
||||||
PartialMoveUseInClosure {
|
PartialMoveUseInClosure {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
|
|
@ -282,34 +315,57 @@ pub(crate) enum CaptureVarCause {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_cannot_move_when_borrowed, code = E0505)]
|
#[diag("cannot move out of {$place ->
|
||||||
|
[value] value
|
||||||
|
*[other] {$place}
|
||||||
|
} because it is borrowed", code = E0505)]
|
||||||
pub(crate) struct MoveBorrow<'a> {
|
pub(crate) struct MoveBorrow<'a> {
|
||||||
pub place: &'a str,
|
pub place: &'a str,
|
||||||
pub borrow_place: &'a str,
|
pub borrow_place: &'a str,
|
||||||
pub value_place: &'a str,
|
pub value_place: &'a str,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label(borrowck_move_label)]
|
#[label(
|
||||||
|
"move out of {$value_place ->
|
||||||
|
[value] value
|
||||||
|
*[other] {$value_place}
|
||||||
|
} occurs here"
|
||||||
|
)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[label]
|
#[label(
|
||||||
|
"borrow of {$borrow_place ->
|
||||||
|
[value] value
|
||||||
|
*[other] {$borrow_place}
|
||||||
|
} occurs here"
|
||||||
|
)]
|
||||||
pub borrow_span: Span,
|
pub borrow_span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_opaque_type_lifetime_mismatch)]
|
#[diag("opaque type used twice with different lifetimes")]
|
||||||
pub(crate) struct LifetimeMismatchOpaqueParam<'tcx> {
|
pub(crate) struct LifetimeMismatchOpaqueParam<'tcx> {
|
||||||
pub arg: GenericArg<'tcx>,
|
pub arg: GenericArg<'tcx>,
|
||||||
pub prev: GenericArg<'tcx>,
|
pub prev: GenericArg<'tcx>,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label("lifetime `{$arg}` used here")]
|
||||||
#[note]
|
#[note(
|
||||||
|
"if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types"
|
||||||
|
)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[label(borrowck_prev_lifetime_label)]
|
#[label("lifetime `{$prev}` previously used here")]
|
||||||
pub prev_span: Span,
|
pub prev_span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureReasonLabel<'a> {
|
pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
#[label(borrowck_moved_due_to_call)]
|
#[label(
|
||||||
|
"{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to this {$is_loop_message ->
|
||||||
|
[true] call, in previous iteration of loop
|
||||||
|
*[false] call
|
||||||
|
}"
|
||||||
|
)]
|
||||||
Call {
|
Call {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
fn_call_span: Span,
|
fn_call_span: Span,
|
||||||
|
|
@ -317,7 +373,15 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_moved_due_to_usage_in_operator)]
|
#[label(
|
||||||
|
"{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to usage in {$is_loop_message ->
|
||||||
|
[true] operator, in previous iteration of loop
|
||||||
|
*[false] operator
|
||||||
|
}"
|
||||||
|
)]
|
||||||
OperatorUse {
|
OperatorUse {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
fn_call_span: Span,
|
fn_call_span: Span,
|
||||||
|
|
@ -325,7 +389,15 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_moved_due_to_implicit_into_iter_call)]
|
#[label(
|
||||||
|
"{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to this implicit call to {$is_loop_message ->
|
||||||
|
[true] `.into_iter()`, in previous iteration of loop
|
||||||
|
*[false] `.into_iter()`
|
||||||
|
}"
|
||||||
|
)]
|
||||||
ImplicitCall {
|
ImplicitCall {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
fn_call_span: Span,
|
fn_call_span: Span,
|
||||||
|
|
@ -333,7 +405,15 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_moved_due_to_method_call)]
|
#[label(
|
||||||
|
"{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to this method {$is_loop_message ->
|
||||||
|
[true] call, in previous iteration of loop
|
||||||
|
*[false] call
|
||||||
|
}"
|
||||||
|
)]
|
||||||
MethodCall {
|
MethodCall {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
fn_call_span: Span,
|
fn_call_span: Span,
|
||||||
|
|
@ -341,7 +421,15 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_moved_due_to_await)]
|
#[label(
|
||||||
|
"{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to this {$is_loop_message ->
|
||||||
|
[true] await, in previous iteration of loop
|
||||||
|
*[false] await
|
||||||
|
}"
|
||||||
|
)]
|
||||||
Await {
|
Await {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
fn_call_span: Span,
|
fn_call_span: Span,
|
||||||
|
|
@ -349,7 +437,18 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_value_moved_here)]
|
#[label(
|
||||||
|
"value {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} {$is_move_msg ->
|
||||||
|
[true] into closure here
|
||||||
|
*[false] here
|
||||||
|
}{$is_loop_message ->
|
||||||
|
[true] , in previous iteration of loop
|
||||||
|
*[false] {\"\"}
|
||||||
|
}"
|
||||||
|
)]
|
||||||
MovedHere {
|
MovedHere {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
move_span: Span,
|
move_span: Span,
|
||||||
|
|
@ -357,7 +456,7 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_move_msg: bool,
|
is_move_msg: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
#[label(borrowck_consider_borrow_type_contents)]
|
#[label("help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents")]
|
||||||
BorrowContent {
|
BorrowContent {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
|
|
@ -366,22 +465,22 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureReasonNote {
|
pub(crate) enum CaptureReasonNote {
|
||||||
#[note(borrowck_moved_a_fn_once_in_call)]
|
#[note("this value implements `FnOnce`, which causes it to be moved when called")]
|
||||||
FnOnceMoveInCall {
|
FnOnceMoveInCall {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
var_span: Span,
|
var_span: Span,
|
||||||
},
|
},
|
||||||
#[note(borrowck_calling_operator_moves)]
|
#[note("calling this operator moves the value")]
|
||||||
UnOpMoveByOperator {
|
UnOpMoveByOperator {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[note(borrowck_calling_operator_moves_lhs)]
|
#[note("calling this operator moves the left-hand side")]
|
||||||
LhsMoveByOperator {
|
LhsMoveByOperator {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[note(borrowck_func_take_self_moved_place)]
|
#[note("`{$func}` takes ownership of the receiver `self`, which moves {$place_name}")]
|
||||||
FuncTakeSelf {
|
FuncTakeSelf {
|
||||||
func: String,
|
func: String,
|
||||||
place_name: String,
|
place_name: String,
|
||||||
|
|
@ -393,7 +492,7 @@ pub(crate) enum CaptureReasonNote {
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureReasonSuggest<'tcx> {
|
pub(crate) enum CaptureReasonSuggest<'tcx> {
|
||||||
#[suggestion(
|
#[suggestion(
|
||||||
borrowck_suggest_iterate_over_slice,
|
"consider iterating over a slice of the `{$ty}`'s content to avoid moving into the `for` loop",
|
||||||
applicability = "maybe-incorrect",
|
applicability = "maybe-incorrect",
|
||||||
code = "&",
|
code = "&",
|
||||||
style = "verbose"
|
style = "verbose"
|
||||||
|
|
@ -404,7 +503,7 @@ pub(crate) enum CaptureReasonSuggest<'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[suggestion(
|
#[suggestion(
|
||||||
borrowck_suggest_create_fresh_reborrow,
|
"consider reborrowing the `Pin` instead of moving it",
|
||||||
applicability = "maybe-incorrect",
|
applicability = "maybe-incorrect",
|
||||||
code = ".as_mut()",
|
code = ".as_mut()",
|
||||||
style = "verbose"
|
style = "verbose"
|
||||||
|
|
@ -417,13 +516,18 @@ pub(crate) enum CaptureReasonSuggest<'tcx> {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureArgLabel {
|
pub(crate) enum CaptureArgLabel {
|
||||||
#[label(borrowck_value_capture_here)]
|
#[label(
|
||||||
|
"value captured {$is_within ->
|
||||||
|
[true] here by coroutine
|
||||||
|
*[false] here
|
||||||
|
}"
|
||||||
|
)]
|
||||||
Capture {
|
Capture {
|
||||||
is_within: bool,
|
is_within: bool,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
args_span: Span,
|
args_span: Span,
|
||||||
},
|
},
|
||||||
#[label(borrowck_move_out_place_here)]
|
#[label("{$place} is moved here")]
|
||||||
MoveOutPlace {
|
MoveOutPlace {
|
||||||
place: String,
|
place: String,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
@ -433,13 +537,17 @@ pub(crate) enum CaptureArgLabel {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum OnClosureNote<'a> {
|
pub(crate) enum OnClosureNote<'a> {
|
||||||
#[note(borrowck_closure_invoked_twice)]
|
#[note(
|
||||||
|
"closure cannot be invoked more than once because it moves the variable `{$place_name}` out of its environment"
|
||||||
|
)]
|
||||||
InvokedTwice {
|
InvokedTwice {
|
||||||
place_name: &'a str,
|
place_name: &'a str,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[note(borrowck_closure_moved_twice)]
|
#[note(
|
||||||
|
"closure cannot be moved more than once as it is not `Copy` due to moving the variable `{$place_name}` out of its environment"
|
||||||
|
)]
|
||||||
MovedTwice {
|
MovedTwice {
|
||||||
place_name: &'a str,
|
place_name: &'a str,
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
@ -449,7 +557,12 @@ pub(crate) enum OnClosureNote<'a> {
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum TypeNoCopy<'a, 'tcx> {
|
pub(crate) enum TypeNoCopy<'a, 'tcx> {
|
||||||
#[label(borrowck_ty_no_impl_copy)]
|
#[label(
|
||||||
|
"{$is_partial_move ->
|
||||||
|
[true] partial move
|
||||||
|
*[false] move
|
||||||
|
} occurs because {$place} has type `{$ty}`, which does not implement the `Copy` trait"
|
||||||
|
)]
|
||||||
Label {
|
Label {
|
||||||
is_partial_move: bool,
|
is_partial_move: bool,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
|
@ -457,12 +570,24 @@ pub(crate) enum TypeNoCopy<'a, 'tcx> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
#[note(borrowck_ty_no_impl_copy)]
|
#[note(
|
||||||
|
"{$is_partial_move ->
|
||||||
|
[true] partial move
|
||||||
|
*[false] move
|
||||||
|
} occurs because {$place} has type `{$ty}`, which does not implement the `Copy` trait"
|
||||||
|
)]
|
||||||
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
|
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(borrowck_simd_intrinsic_arg_const)]
|
#[diag(
|
||||||
|
"{$arg ->
|
||||||
|
[1] 1st
|
||||||
|
[2] 2nd
|
||||||
|
[3] 3rd
|
||||||
|
*[other] {$arg}th
|
||||||
|
} argument of `{$intrinsic}` is required to be a `const` item"
|
||||||
|
)]
|
||||||
pub(crate) struct SimdIntrinsicArgConst {
|
pub(crate) struct SimdIntrinsicArgConst {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
@ -471,8 +596,8 @@ pub(crate) struct SimdIntrinsicArgConst {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(borrowck_tail_expr_drop_order)]
|
#[diag("relative drop order changing in Rust 2024")]
|
||||||
pub(crate) struct TailExprDropOrder {
|
pub(crate) struct TailExprDropOrder {
|
||||||
#[label]
|
#[label("this temporary value will be dropped at the end of the block")]
|
||||||
pub borrowed: Span,
|
pub borrowed: Span,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ jiff = { version = "0.2.5", default-features = false, features = ["std"] }
|
||||||
rustc_abi = { path = "../rustc_abi" }
|
rustc_abi = { path = "../rustc_abi" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
||||||
rustc_borrowck = { path = "../rustc_borrowck" }
|
|
||||||
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
|
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
|
||||||
rustc_const_eval = { path = "../rustc_const_eval" }
|
rustc_const_eval = { path = "../rustc_const_eval" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,6 @@ pub fn default_translator() -> Translator {
|
||||||
|
|
||||||
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
|
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
rustc_borrowck::DEFAULT_LOCALE_RESOURCE,
|
|
||||||
rustc_const_eval::DEFAULT_LOCALE_RESOURCE,
|
rustc_const_eval::DEFAULT_LOCALE_RESOURCE,
|
||||||
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
|
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
|
||||||
rustc_lint::DEFAULT_LOCALE_RESOURCE,
|
rustc_lint::DEFAULT_LOCALE_RESOURCE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue