Skip to content

Commit 3190522

Browse files
committed
Address some comments
1 parent e0e9b21 commit 3190522

File tree

5 files changed

+61
-73
lines changed

5 files changed

+61
-73
lines changed

compiler/rustc_infer/src/errors/mod.rs

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::GenericParamKind;
22
use rustc_errors::{
3-
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString,
3+
fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
44
};
55
use rustc_hir as hir;
66
use rustc_hir::{FnRetTy, Ty};
@@ -273,8 +273,8 @@ pub enum LifetimeMismatchLabels {
273273
ty_sup: Span,
274274
ty_sub: Span,
275275
span: Span,
276-
label_var1: Option<Ident>,
277-
label_var2: Option<Ident>,
276+
sup: Option<Ident>,
277+
sub: Option<Ident>,
278278
},
279279
}
280280

@@ -293,8 +293,8 @@ impl AddSubdiagnostic for LifetimeMismatchLabels {
293293
ty_sup,
294294
ty_sub,
295295
span,
296-
label_var1,
297-
label_var2,
296+
sup: label_var1,
297+
sub: label_var2,
298298
} => {
299299
if hir_equal {
300300
diag.span_label(ty_sup, fluent::infer::declared_multiple);
@@ -422,68 +422,57 @@ pub struct LifetimeMismatch<'a> {
422422
pub suggestion: AddLifetimeParamsSuggestion<'a>,
423423
}
424424

425-
pub mod mismatched_static_lifetime {
426-
use rustc_errors::{self, fluent, AddSubdiagnostic, MultiSpan};
427-
use rustc_span::Span;
428-
429-
use super::note_and_explain;
430-
431-
pub struct LabeledMultiSpan {
432-
pub multi_span: MultiSpan,
433-
pub binding_span: Span,
434-
}
435-
436-
impl AddSubdiagnostic for LabeledMultiSpan {
437-
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
438-
self.multi_span
439-
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
440-
diag.span_note(self.multi_span, fluent::infer::msl_unmet_req);
441-
}
442-
}
425+
pub struct IntroducesStaticBecauseUnmetLifetimeReq {
426+
pub unmet_requirements: MultiSpan,
427+
pub binding_span: Span,
428+
}
443429

444-
pub struct ImplNote {
445-
pub impl_span: Option<Span>,
430+
impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
431+
fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) {
432+
self.unmet_requirements
433+
.push_span_label(self.binding_span, fluent::infer::msl_introduces_static);
434+
diag.span_note(self.unmet_requirements, fluent::infer::msl_unmet_req);
446435
}
436+
}
447437

448-
impl AddSubdiagnostic for ImplNote {
449-
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
450-
match self.impl_span {
451-
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
452-
None => diag.note(fluent::infer::msl_impl_note),
453-
};
454-
}
455-
}
438+
pub struct ImplNote {
439+
pub impl_span: Option<Span>,
440+
}
456441

457-
#[derive(SessionSubdiagnostic)]
458-
pub enum TraitSubdiag {
459-
#[note(infer::msl_trait_note)]
460-
Note {
461-
#[primary_span]
462-
span: Span,
463-
},
464-
#[suggestion_verbose(
465-
infer::msl_trait_sugg,
466-
code = " + '_",
467-
applicability = "maybe-incorrect"
468-
)]
469-
Sugg {
470-
#[primary_span]
471-
span: Span,
472-
},
442+
impl AddSubdiagnostic for ImplNote {
443+
fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
444+
match self.impl_span {
445+
Some(span) => diag.span_note(span, fluent::infer::msl_impl_note),
446+
None => diag.note(fluent::infer::msl_impl_note),
447+
};
473448
}
449+
}
474450

475-
#[derive(SessionDiagnostic)]
476-
#[diag(infer::mismatched_static_lifetime)]
477-
pub struct MismatchedStaticLifetime<'a> {
451+
#[derive(SessionSubdiagnostic)]
452+
pub enum TraitSubdiag {
453+
#[note(infer::msl_trait_note)]
454+
Note {
478455
#[primary_span]
479-
pub cause_span: Span,
480-
#[subdiagnostic]
481-
pub multispan_subdiag: LabeledMultiSpan,
482-
#[subdiagnostic]
483-
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
484-
#[subdiagnostic]
485-
pub impl_note: ImplNote,
486-
#[subdiagnostic]
487-
pub trait_subdiags: Vec<TraitSubdiag>,
488-
}
456+
span: Span,
457+
},
458+
#[suggestion_verbose(infer::msl_trait_sugg, code = " + '_", applicability = "maybe-incorrect")]
459+
Sugg {
460+
#[primary_span]
461+
span: Span,
462+
},
463+
}
464+
465+
#[derive(SessionDiagnostic)]
466+
#[diag(infer::mismatched_static_lifetime)]
467+
pub struct MismatchedStaticLifetime<'a> {
468+
#[primary_span]
469+
pub cause_span: Span,
470+
#[subdiagnostic]
471+
pub unmet_lifetime_reqs: IntroducesStaticBecauseUnmetLifetimeReq,
472+
#[subdiagnostic]
473+
pub expl: Option<note_and_explain::RegionExplanation<'a>>,
474+
#[subdiagnostic]
475+
pub impl_note: ImplNote,
476+
#[subdiagnostic]
477+
pub trait_subdiags: Vec<TraitSubdiag>,
489478
}

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a> DescriptionCtx<'a> {
9191
me.kind = "as_defined_anon";
9292
} else {
9393
me.kind = "as_defined";
94-
me.arg = name.to_string();
94+
me.arg = name.to_string();
9595
};
9696
me.span = Some(sp);
9797
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
122122
ty_sup: ty_sup.span,
123123
ty_sub: ty_sub.span,
124124
span,
125-
label_var1: anon_param_sup.pat.simple_ident(),
126-
label_var2: anon_param_sub.pat.simple_ident(),
125+
sup: anon_param_sup.pat.simple_ident(),
126+
sub: anon_param_sub.pat.simple_ident(),
127127
},
128128
};
129129

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Error Reporting for when the lifetime for a type doesn't match the `impl` selected for a predicate
22
//! to hold.
33
4-
use crate::errors::mismatched_static_lifetime::{ImplNote, MismatchedStaticLifetime, TraitSubdiag};
5-
use crate::errors::{mismatched_static_lifetime::LabeledMultiSpan, note_and_explain};
4+
use crate::errors::{note_and_explain, IntroducesStaticBecauseUnmetLifetimeReq};
5+
use crate::errors::{ImplNote, MismatchedStaticLifetime, TraitSubdiag};
66
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
77
use crate::infer::lexical_region_resolve::RegionResolutionError;
88
use crate::infer::{SubregionOrigin, TypeTrace};
@@ -43,7 +43,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4343

4444
// FIXME: we should point at the lifetime
4545
let multi_span: MultiSpan = vec![binding_span].into();
46-
let multispan_subdiag = LabeledMultiSpan { multi_span, binding_span };
46+
let multispan_subdiag = IntroducesStaticBecauseUnmetLifetimeReq {
47+
unmet_requirements: multi_span,
48+
binding_span,
49+
};
4750

4851
let expl = note_and_explain::RegionExplanation::new(
4952
self.tcx(),
@@ -100,7 +103,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
100103
}
101104
let err = MismatchedStaticLifetime {
102105
cause_span: cause.span,
103-
multispan_subdiag,
106+
unmet_lifetime_reqs: multispan_subdiag,
104107
expl,
105108
impl_note: ImplNote { impl_span },
106109
trait_subdiags,

compiler/rustc_infer/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,5 @@ extern crate tracing;
3636
extern crate rustc_middle;
3737

3838
mod errors;
39-
pub mod public_errors {
40-
// Probably would be useful in rustc_borrowck
41-
pub use super::errors::AddLifetimeParamsSuggestion;
42-
}
4339
pub mod infer;
4440
pub mod traits;

0 commit comments

Comments
 (0)