2022-08-26 02:32:59 +00:00
|
|
|
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
|
2022-09-18 15:47:31 +00:00
|
|
|
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
2022-06-23 04:43:01 +00:00
|
|
|
use rustc_middle::ty::Ty;
|
|
|
|
use rustc_span::Span;
|
|
|
|
|
2022-08-26 02:32:59 +00:00
|
|
|
use crate::diagnostics::RegionName;
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_move_unsized, code = "E0161")]
|
2022-06-23 04:43:01 +00:00
|
|
|
pub(crate) struct MoveUnsized<'tcx> {
|
|
|
|
pub ty: Ty<'tcx>,
|
|
|
|
#[primary_span]
|
|
|
|
#[label]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_higher_ranked_lifetime_error)]
|
2022-06-23 04:43:01 +00:00
|
|
|
pub(crate) struct HigherRankedLifetimeError {
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub cause: Option<HigherRankedErrorCause>,
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-06-23 04:43:01 +00:00
|
|
|
pub(crate) enum HigherRankedErrorCause {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[note(borrowck_could_not_prove)]
|
2022-06-23 04:43:01 +00:00
|
|
|
CouldNotProve { predicate: String },
|
2022-10-22 09:07:54 +00:00
|
|
|
#[note(borrowck_could_not_normalize)]
|
2022-06-23 04:43:01 +00:00
|
|
|
CouldNotNormalize { value: String },
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_higher_ranked_subtype_error)]
|
2022-06-23 04:43:01 +00:00
|
|
|
pub(crate) struct HigherRankedSubtypeError {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_generic_does_not_live_long_enough)]
|
2022-06-23 04:43:01 +00:00
|
|
|
pub(crate) struct GenericDoesNotLiveLongEnough {
|
|
|
|
pub kind: String,
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-08-26 02:32:59 +00:00
|
|
|
|
|
|
|
#[derive(LintDiagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_var_does_not_need_mut)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) struct VarNeedNotMut {
|
2022-10-22 13:48:55 +00:00
|
|
|
#[suggestion(style = "short", applicability = "machine-applicable", code = "")]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub span: Span,
|
|
|
|
}
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_var_cannot_escape_closure)]
|
2022-08-26 02:32:59 +00:00
|
|
|
#[note]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[note(cannot_escape)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) struct FnMutError {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
#[subdiagnostic]
|
|
|
|
pub ty_err: FnMutReturnTypeErr,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) enum VarHereDenote {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_var_here_captured)]
|
2022-08-26 02:32:59 +00:00
|
|
|
Captured {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_var_here_defined)]
|
2022-08-26 02:32:59 +00:00
|
|
|
Defined {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_closure_inferred_mut)]
|
2022-08-26 02:32:59 +00:00
|
|
|
FnMutInferred {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) enum FnMutReturnTypeErr {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_returned_closure_escaped)]
|
2022-08-26 02:32:59 +00:00
|
|
|
ReturnClosure {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_returned_async_block_escaped)]
|
2022-08-26 02:32:59 +00:00
|
|
|
ReturnAsyncBlock {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_returned_ref_escaped)]
|
2022-08-26 02:32:59 +00:00
|
|
|
ReturnRef {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:46:56 +00:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 09:07:54 +00:00
|
|
|
#[diag(borrowck_lifetime_constraints_error)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) struct LifetimeOutliveErr {
|
|
|
|
#[primary_span]
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) enum LifetimeReturnCategoryErr<'a> {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_returned_lifetime_wrong)]
|
2022-08-26 02:32:59 +00:00
|
|
|
WrongReturn {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
mir_def_name: &'a str,
|
|
|
|
outlived_fr_name: RegionName,
|
|
|
|
fr_name: &'a RegionName,
|
|
|
|
},
|
2022-10-22 09:07:54 +00:00
|
|
|
#[label(borrowck_returned_lifetime_short)]
|
2022-08-26 02:32:59 +00:00
|
|
|
ShortReturn {
|
|
|
|
#[primary_span]
|
|
|
|
span: Span,
|
|
|
|
category_desc: &'static str,
|
|
|
|
free_region_name: &'a RegionName,
|
|
|
|
outlived_fr_name: RegionName,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagnosticArg for &RegionName {
|
|
|
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
|
|
|
format!("{}", self).into_diagnostic_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoDiagnosticArg for RegionName {
|
|
|
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
|
|
|
format!("{}", self).into_diagnostic_arg()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 15:47:31 +00:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-26 02:32:59 +00:00
|
|
|
pub(crate) enum RequireStaticErr {
|
2022-10-22 09:07:54 +00:00
|
|
|
#[note(borrowck_used_impl_require_static)]
|
2022-08-26 02:32:59 +00:00
|
|
|
UsedImpl {
|
|
|
|
#[primary_span]
|
|
|
|
multi_span: MultiSpan,
|
|
|
|
},
|
|
|
|
}
|