-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #103171 - jackh726:gen-interior-hrtb-error, r=cjgillot
Better error for HRTB error from generator interior cc #100013 This is just a first pass at an error. It could be better, and shouldn't really be emitted in the first place. But this is better than what was being emitted before.
- Loading branch information
Showing
23 changed files
with
344 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use crate::infer::{ | ||
error_reporting::nice_region_error::NiceRegionError, RegionResolutionError, SubregionOrigin, | ||
}; | ||
use rustc_data_structures::intern::Interned; | ||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; | ||
use rustc_middle::ty::{self, RePlaceholder, Region}; | ||
|
||
impl<'tcx> NiceRegionError<'_, 'tcx> { | ||
/// Emitted wwhen given a `ConcreteFailure` when relating two placeholders. | ||
pub(super) fn try_report_placeholder_relation( | ||
&self, | ||
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> { | ||
match &self.error { | ||
Some(RegionResolutionError::ConcreteFailure( | ||
SubregionOrigin::RelateRegionParamBound(span), | ||
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)), | ||
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)), | ||
)) => { | ||
let msg = "lifetime bound not satisfied"; | ||
let mut err = self.tcx().sess.struct_span_err(*span, msg); | ||
let (sub_span, sub_symbol) = match sub_name { | ||
ty::BrNamed(def_id, symbol) => { | ||
(Some(self.tcx().def_span(def_id)), Some(symbol)) | ||
} | ||
ty::BrAnon(_, span) => (*span, None), | ||
ty::BrEnv => (None, None), | ||
}; | ||
let (sup_span, sup_symbol) = match sup_name { | ||
ty::BrNamed(def_id, symbol) => { | ||
(Some(self.tcx().def_span(def_id)), Some(symbol)) | ||
} | ||
ty::BrAnon(_, span) => (*span, None), | ||
ty::BrEnv => (None, None), | ||
}; | ||
match (sub_span, sup_span, sub_symbol, sup_symbol) { | ||
(Some(sub_span), Some(sup_span), Some(sub_symbol), Some(sup_symbol)) => { | ||
err.span_note( | ||
sub_span, | ||
format!("the lifetime `{sub_symbol}` defined here..."), | ||
); | ||
err.span_note( | ||
sup_span, | ||
format!("...must outlive the lifetime `{sup_symbol}` defined here"), | ||
); | ||
} | ||
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => { | ||
err.span_note(sub_span, format!("the lifetime defined here...")); | ||
err.span_note( | ||
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, | ||
format!("the lifetime `{sub_symbol}` defined here..."), | ||
); | ||
err.span_note( | ||
sup_span, | ||
format!("...must outlive the lifetime defined here"), | ||
); | ||
} | ||
(Some(sub_span), Some(sup_span), _, _) => { | ||
err.span_note(sub_span, format!("the lifetime defined here...")); | ||
err.span_note( | ||
sup_span, | ||
format!("...must outlive the lifetime defined here"), | ||
); | ||
} | ||
_ => {} | ||
} | ||
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(err) | ||
} | ||
|
||
_ => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.