diff options
| author | Mark Mansi <markm@cs.wisc.edu> | 2018-11-28 15:05:36 -0600 |
|---|---|---|
| committer | Mark Mansi <markm@cs.wisc.edu> | 2019-10-27 08:47:22 -0500 |
| commit | 3a1847b07d552fff62be4ebf11e74f90b6a43fce (patch) | |
| tree | f78a7df11927b72879242fbab8b4aeb7917a7c54 /src/librustc_errors | |
| parent | b7176b44a203322c834302f3b515f8c10a54f2c1 (diff) | |
| download | rust-3a1847b07d552fff62be4ebf11e74f90b6a43fce.tar.gz rust-3a1847b07d552fff62be4ebf11e74f90b6a43fce.zip | |
implement outlive suggestions
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 1781f2e1650..3c4539b597b 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -6,7 +6,7 @@ use crate::Applicability; use crate::Level; use crate::snippet::Style; use std::fmt; -use syntax_pos::{MultiSpan, Span}; +use syntax_pos::{MultiSpan, Span, DUMMY_SP}; #[must_use] #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] @@ -17,6 +17,11 @@ pub struct Diagnostic { pub span: MultiSpan, pub children: Vec<SubDiagnostic>, pub suggestions: Vec<CodeSuggestion>, + + /// This is not used for highlighting or rendering any error message. Rather, it can be used + /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of + /// `span` if there is one. Otherwise, it is `DUMMY_SP`. + pub sort_span: Span, } #[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] @@ -87,6 +92,7 @@ impl Diagnostic { span: MultiSpan::new(), children: vec![], suggestions: vec![], + sort_span: DUMMY_SP, } } @@ -118,6 +124,11 @@ impl Diagnostic { self.level == Level::Cancelled } + /// Set the sorting span. + pub fn set_sort_span(&mut self, sp: Span) { + self.sort_span = sp; + } + /// Adds a span/label to be included in the resulting snippet. /// This label will be shown together with the original span/label used when creating the /// diagnostic, *not* a span added by one of the `span_*` methods. @@ -457,6 +468,9 @@ impl Diagnostic { pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self { self.span = sp.into(); + if let Some(span) = self.span.primary_span() { + self.sort_span = span; + } self } |
