diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-10-06 12:33:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-06 12:33:19 -0700 |
| commit | b01594051cdb7bcd2ccc9f3957fdd243c7d66ef8 (patch) | |
| tree | e3afc03853f17da880d84b9404a6d813f8b08c68 /compiler | |
| parent | b87a9a8a7c40484bc94515fd6d51e6e271ad4cb8 (diff) | |
| parent | 3c974adb4c4c6de497a36dec362af6c0928c7367 (diff) | |
| download | rust-b01594051cdb7bcd2ccc9f3957fdd243c7d66ef8.tar.gz rust-b01594051cdb7bcd2ccc9f3957fdd243c7d66ef8.zip | |
Rollup merge of #89501 - Aaron1011:escaping-name-regions, r=davidtwco
Note specific regions involved in 'borrowed data escapes' error Fixes #67007 Currently, a 'borrowed data escapes' error does not mention the specific lifetime involved (except indirectly through a suggestion about adding a lifetime bound). We now explain the specific lifetime relationship that failed to hold, which improves otherwise vague error messages.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/region_errors.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index d05cfebc5f0..11cdbe84acc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -498,6 +498,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from)); } + // Only show an extra note if we can find an 'error region' for both of the region + // variables. This avoids showing a noisy note that just mentions 'synthetic' regions + // that don't help the user understand the error. + if self.to_error_region(errci.fr).is_some() + && self.to_error_region(errci.outlived_fr).is_some() + { + let fr_region_name = self.give_region_a_name(errci.fr).unwrap(); + fr_region_name.highlight_region_name(&mut diag); + let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap(); + outlived_fr_region_name.highlight_region_name(&mut diag); + + diag.span_label( + *span, + format!( + "{}requires that `{}` must outlive `{}`", + category.description(), + fr_region_name, + outlived_fr_region_name, + ), + ); + } diag } |
