mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Port PlaceholderRelationLfNotSatisfied diagnostic
This commit is contained in:
parent
fdbec623c4
commit
5c7afde6f2
@ -338,4 +338,10 @@ infer_srs_add_one = consider returning one of these bindings
|
|||||||
|
|
||||||
infer_await_both_futures = consider `await`ing on both `Future`s
|
infer_await_both_futures = consider `await`ing on both `Future`s
|
||||||
infer_await_future = consider `await`ing on the `Future`
|
infer_await_future = consider `await`ing on the `Future`
|
||||||
infer_await_note = calling an async function returns a future
|
infer_await_note = calling an async function returns a future
|
||||||
|
|
||||||
|
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
|
||||||
|
infer_prlf_defined_without_sub = the lifetime defined here...
|
||||||
|
infer_prlf_must_oultive_with_sup = ...must outlive the lifetime `{$sup_symbol}` defined here
|
||||||
|
infer_prlf_must_oultive_without_sup = ...must outlive the lifetime defined here
|
||||||
|
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
|
||||||
|
@ -1093,3 +1093,62 @@ pub enum ConsiderAddingAwait {
|
|||||||
spans: Vec<Span>,
|
spans: Vec<Span>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
pub enum PlaceholderRelationLfNotSatisfied {
|
||||||
|
#[diag(infer_lf_bound_not_satisfied)]
|
||||||
|
HasBoth {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
#[note(infer_prlf_defined_with_sub)]
|
||||||
|
sub_span: Span,
|
||||||
|
#[note(infer_prlf_must_oultive_with_sup)]
|
||||||
|
sup_span: Span,
|
||||||
|
sub_symbol: Symbol,
|
||||||
|
sup_symbol: Symbol,
|
||||||
|
#[note(infer_prlf_known_limitation)]
|
||||||
|
note: (),
|
||||||
|
},
|
||||||
|
#[diag(infer_lf_bound_not_satisfied)]
|
||||||
|
HasSub {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
#[note(infer_prlf_defined_with_sub)]
|
||||||
|
sub_span: Span,
|
||||||
|
#[note(infer_prlf_must_oultive_without_sup)]
|
||||||
|
sup_span: Span,
|
||||||
|
sub_symbol: Symbol,
|
||||||
|
#[note(infer_prlf_known_limitation)]
|
||||||
|
note: (),
|
||||||
|
},
|
||||||
|
#[diag(infer_lf_bound_not_satisfied)]
|
||||||
|
HasSup {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
#[note(infer_prlf_defined_without_sub)]
|
||||||
|
sub_span: Span,
|
||||||
|
#[note(infer_prlf_must_oultive_with_sup)]
|
||||||
|
sup_span: Span,
|
||||||
|
sup_symbol: Symbol,
|
||||||
|
#[note(infer_prlf_known_limitation)]
|
||||||
|
note: (),
|
||||||
|
},
|
||||||
|
#[diag(infer_lf_bound_not_satisfied)]
|
||||||
|
HasNone {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
#[note(infer_prlf_defined_without_sub)]
|
||||||
|
sub_span: Span,
|
||||||
|
#[note(infer_prlf_must_oultive_without_sup)]
|
||||||
|
sup_span: Span,
|
||||||
|
#[note(infer_prlf_known_limitation)]
|
||||||
|
note: (),
|
||||||
|
},
|
||||||
|
#[diag(infer_lf_bound_not_satisfied)]
|
||||||
|
OnlyPrimarySpan {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
#[note(infer_prlf_known_limitation)]
|
||||||
|
note: (),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use crate::infer::{
|
use crate::{
|
||||||
error_reporting::nice_region_error::NiceRegionError, RegionResolutionError, SubregionOrigin,
|
errors::PlaceholderRelationLfNotSatisfied,
|
||||||
|
infer::{
|
||||||
|
error_reporting::nice_region_error::NiceRegionError, RegionResolutionError, SubregionOrigin,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use rustc_data_structures::intern::Interned;
|
use rustc_data_structures::intern::Interned;
|
||||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||||
@ -16,8 +19,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)),
|
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)),
|
||||||
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)),
|
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)),
|
||||||
)) => {
|
)) => {
|
||||||
let msg = "lifetime bound not satisfied";
|
let span = *span;
|
||||||
let mut err = self.tcx().sess.struct_span_err(*span, msg);
|
|
||||||
let (sub_span, sub_symbol) = match sub_name {
|
let (sub_span, sub_symbol) = match sub_name {
|
||||||
ty::BrNamed(def_id, symbol) => {
|
ty::BrNamed(def_id, symbol) => {
|
||||||
(Some(self.tcx().def_span(def_id)), Some(symbol))
|
(Some(self.tcx().def_span(def_id)), Some(symbol))
|
||||||
@ -32,41 +34,47 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
ty::BrAnon(_, span) => (*span, None),
|
ty::BrAnon(_, span) => (*span, None),
|
||||||
ty::BrEnv => (None, None),
|
ty::BrEnv => (None, None),
|
||||||
};
|
};
|
||||||
match (sub_span, sup_span, sub_symbol, sup_symbol) {
|
let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {
|
||||||
(Some(sub_span), Some(sup_span), Some(sub_symbol), Some(sup_symbol)) => {
|
(Some(sub_span), Some(sup_span), Some(&sub_symbol), Some(&sup_symbol)) => {
|
||||||
err.span_note(
|
PlaceholderRelationLfNotSatisfied::HasBoth {
|
||||||
|
span,
|
||||||
sub_span,
|
sub_span,
|
||||||
format!("the lifetime `{sub_symbol}` defined here..."),
|
|
||||||
);
|
|
||||||
err.span_note(
|
|
||||||
sup_span,
|
sup_span,
|
||||||
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
|
sub_symbol,
|
||||||
);
|
sup_symbol,
|
||||||
|
note: (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => {
|
(Some(sub_span), Some(sup_span), _, Some(&sup_symbol)) => {
|
||||||
err.span_note(sub_span, "the lifetime defined here...");
|
PlaceholderRelationLfNotSatisfied::HasSup {
|
||||||
err.span_note(
|
span,
|
||||||
sup_span,
|
|
||||||
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
(Some(sub_span), Some(sup_span), Some(sub_symbol), _) => {
|
|
||||||
err.span_note(
|
|
||||||
sub_span,
|
sub_span,
|
||||||
format!("the lifetime `{sub_symbol}` defined here..."),
|
sup_span,
|
||||||
);
|
sup_symbol,
|
||||||
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
note: (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Some(sub_span), Some(sup_span), Some(&sub_symbol), _) => {
|
||||||
|
PlaceholderRelationLfNotSatisfied::HasSub {
|
||||||
|
span,
|
||||||
|
sub_span,
|
||||||
|
sup_span,
|
||||||
|
sub_symbol,
|
||||||
|
note: (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Some(sub_span), Some(sup_span), _, _) => {
|
(Some(sub_span), Some(sup_span), _, _) => {
|
||||||
err.span_note(sub_span, "the lifetime defined here...");
|
PlaceholderRelationLfNotSatisfied::HasNone {
|
||||||
err.span_note(sup_span, "...must outlive the lifetime defined here");
|
span,
|
||||||
|
sub_span,
|
||||||
|
sup_span,
|
||||||
|
note: (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan { span, note: () },
|
||||||
}
|
};
|
||||||
err.note("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)");
|
Some(self.tcx().sess.create_err(diag))
|
||||||
Some(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user