Address some comments

This commit is contained in:
Nikita Tomashevich 2022-08-31 15:02:11 +03:00
parent e0e9b21c78
commit 3190522294
No known key found for this signature in database
GPG key ID: B29791D4D878E345
5 changed files with 66 additions and 78 deletions

View file

@ -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,22 +422,16 @@ pub struct LifetimeMismatch<'a> {
pub suggestion: AddLifetimeParamsSuggestion<'a>,
}
pub mod mismatched_static_lifetime {
use rustc_errors::{self, fluent, AddSubdiagnostic, MultiSpan};
use rustc_span::Span;
use super::note_and_explain;
pub struct LabeledMultiSpan {
pub multi_span: MultiSpan,
pub struct IntroducesStaticBecauseUnmetLifetimeReq {
pub unmet_requirements: MultiSpan,
pub binding_span: Span,
}
impl AddSubdiagnostic for LabeledMultiSpan {
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
self.multi_span
self.unmet_requirements
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
diag.span_note(self.multi_span, fluent::infer::msl_unmet_req);
diag.span_note(self.unmet_requirements, fluent::infer::msl_unmet_req);
}
}
@ -461,11 +455,7 @@ pub mod mismatched_static_lifetime {
#[primary_span]
span: Span,
},
#[suggestion_verbose(
infer::msl_trait_sugg,
code = " + '_",
applicability = "maybe-incorrect"
)]
#[suggestion_verbose(infer::msl_trait_sugg, code = " + '_", applicability = "maybe-incorrect")]
Sugg {
#[primary_span]
span: Span,
@ -478,7 +468,7 @@ pub mod mismatched_static_lifetime {
#[primary_span]
pub cause_span: Span,
#[subdiagnostic]
pub multispan_subdiag: LabeledMultiSpan,
pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
#[subdiagnostic]
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
#[subdiagnostic]
@ -486,4 +476,3 @@ pub mod mismatched_static_lifetime {
#[subdiagnostic]
pub trait_subdiags: Vec<TraitSubdiag>,
}
}

View file

@ -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(),
},
};

View file

@ -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,

View file

@ -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;