Address some comments
This commit is contained in:
parent
e0e9b21c78
commit
3190522294
5 changed files with 66 additions and 78 deletions
|
@ -1,6 +1,6 @@
|
|||
use hir::GenericParamKind;
|
||||
use rustc_errors::{
|
||||
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString,
|
||||
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::{FnRetTy, Ty};
|
||||
|
@ -273,8 +273,8 @@ pub enum LifetimeMismatchLabels {
|
|||
ty_sup: Span,
|
||||
ty_sub: Span,
|
||||
span: Span,
|
||||
label_var1: Option<Ident>,
|
||||
label_var2: Option<Ident>,
|
||||
sup: Option<Ident>,
|
||||
sub: Option<Ident>,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -293,8 +293,8 @@ impl AddSubdiagnostic for LifetimeMismatchLabels {
|
|||
ty_sup,
|
||||
ty_sub,
|
||||
span,
|
||||
label_var1,
|
||||
label_var2,
|
||||
sup: label_var1,
|
||||
sub: label_var2,
|
||||
} => {
|
||||
if hir_equal {
|
||||
diag.span_label(ty_sup, fluent::infer::declared_multiple);
|
||||
|
@ -422,68 +422,57 @@ pub struct LifetimeMismatch<'a> {
|
|||
pub suggestion: AddLifetimeParamsSuggestion<'a>,
|
||||
}
|
||||
|
||||
pub mod mismatched_static_lifetime {
|
||||
use rustc_errors::{self, fluent, AddSubdiagnostic, MultiSpan};
|
||||
use rustc_span::Span;
|
||||
pub struct IntroducesStaticBecauseUnmetLifetimeReq {
|
||||
pub unmet_requirements: MultiSpan,
|
||||
pub binding_span: Span,
|
||||
}
|
||||
|
||||
use super::note_and_explain;
|
||||
|
||||
pub struct LabeledMultiSpan {
|
||||
pub multi_span: MultiSpan,
|
||||
pub binding_span: Span,
|
||||
}
|
||||
|
||||
impl AddSubdiagnostic for LabeledMultiSpan {
|
||||
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
|
||||
self.multi_span
|
||||
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
|
||||
diag.span_note(self.multi_span, fluent::infer::msl_unmet_req);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ImplNote {
|
||||
pub impl_span: Option<Span>,
|
||||
}
|
||||
|
||||
impl AddSubdiagnostic for ImplNote {
|
||||
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
|
||||
match self.impl_span {
|
||||
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
|
||||
None => diag.note(fluent::infer::msl_impl_note),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub enum TraitSubdiag {
|
||||
#[note(infer::msl_trait_note)]
|
||||
Note {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion_verbose(
|
||||
infer::msl_trait_sugg,
|
||||
code = " + '_",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
Sugg {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(infer::mismatched_static_lifetime)]
|
||||
pub struct MismatchedStaticLifetime<'a> {
|
||||
#[primary_span]
|
||||
pub cause_span: Span,
|
||||
#[subdiagnostic]
|
||||
pub multispan_subdiag: LabeledMultiSpan,
|
||||
#[subdiagnostic]
|
||||
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
|
||||
#[subdiagnostic]
|
||||
pub impl_note: ImplNote,
|
||||
#[subdiagnostic]
|
||||
pub trait_subdiags: Vec<TraitSubdiag>,
|
||||
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
|
||||
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
|
||||
self.unmet_requirements
|
||||
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
|
||||
diag.span_note(self.unmet_requirements, fluent::infer::msl_unmet_req);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ImplNote {
|
||||
pub impl_span: Option<Span>,
|
||||
}
|
||||
|
||||
impl AddSubdiagnostic for ImplNote {
|
||||
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
|
||||
match self.impl_span {
|
||||
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
|
||||
None => diag.note(fluent::infer::msl_impl_note),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
pub enum TraitSubdiag {
|
||||
#[note(infer::msl_trait_note)]
|
||||
Note {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion_verbose(infer::msl_trait_sugg, code = " + '_", applicability = "maybe-incorrect")]
|
||||
Sugg {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(infer::mismatched_static_lifetime)]
|
||||
pub struct MismatchedStaticLifetime<'a> {
|
||||
#[primary_span]
|
||||
pub cause_span: Span,
|
||||
#[subdiagnostic]
|
||||
pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
|
||||
#[subdiagnostic]
|
||||
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
|
||||
#[subdiagnostic]
|
||||
pub impl_note: ImplNote,
|
||||
#[subdiagnostic]
|
||||
pub trait_subdiags: Vec<TraitSubdiag>,
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
me.kind = "as_defined_anon";
|
||||
} else {
|
||||
me.kind = "as_defined";
|
||||
me.arg = name.to_string();
|
||||
me.arg = name.to_string();
|
||||
};
|
||||
me.span = Some(sp);
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
ty_sup: ty_sup.span,
|
||||
ty_sub: ty_sub.span,
|
||||
span,
|
||||
label_var1: anon_param_sup.pat.simple_ident(),
|
||||
label_var2: anon_param_sub.pat.simple_ident(),
|
||||
sup: anon_param_sup.pat.simple_ident(),
|
||||
sub: anon_param_sub.pat.simple_ident(),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//! Error Reporting for when the lifetime for a type doesn't match the `impl` selected for a predicate
|
||||
//! to hold.
|
||||
|
||||
use crate::errors::mismatched_static_lifetime::{ImplNote, MismatchedStaticLifetime, TraitSubdiag};
|
||||
use crate::errors::{mismatched_static_lifetime::LabeledMultiSpan, note_and_explain};
|
||||
use crate::errors::{note_and_explain, IntroducesStaticBecauseUnmetLifetimeReq};
|
||||
use crate::errors::{ImplNote, MismatchedStaticLifetime, TraitSubdiag};
|
||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||
|
@ -43,7 +43,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
|
||||
// FIXME: we should point at the lifetime
|
||||
let multi_span: MultiSpan = vec![binding_span].into();
|
||||
let multispan_subdiag = LabeledMultiSpan { multi_span, binding_span };
|
||||
let multispan_subdiag = IntroducesStaticBecauseUnmetLifetimeReq {
|
||||
unmet_requirements: multi_span,
|
||||
binding_span,
|
||||
};
|
||||
|
||||
let expl = note_and_explain::RegionExplanation::new(
|
||||
self.tcx(),
|
||||
|
@ -100,7 +103,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
}
|
||||
let err = MismatchedStaticLifetime {
|
||||
cause_span: cause.span,
|
||||
multispan_subdiag,
|
||||
unmet_lifetime_reqs: multispan_subdiag,
|
||||
expl,
|
||||
impl_note: ImplNote { impl_span },
|
||||
trait_subdiags,
|
||||
|
|
|
@ -36,9 +36,5 @@ extern crate tracing;
|
|||
extern crate rustc_middle;
|
||||
|
||||
mod errors;
|
||||
pub mod public_errors {
|
||||
// Probably would be useful in rustc_borrowck
|
||||
pub use super::errors::AddLifetimeParamsSuggestion;
|
||||
}
|
||||
pub mod infer;
|
||||
pub mod traits;
|
||||
|
|
Loading…
Add table
Reference in a new issue