diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-05-11 15:26:22 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-05-11 15:26:22 +0200 |
| commit | 644ce5e535f74be304a77dfadb9ff46c743554c7 (patch) | |
| tree | d00077c7ca7462f6162d2d008ba26a6c5721cae9 /src/librustc_errors/lib.rs | |
| parent | f859f2585b0167dfd9ef22d88d992ba6fe55e158 (diff) | |
| download | rust-644ce5e535f74be304a77dfadb9ff46c743554c7.tar.gz rust-644ce5e535f74be304a77dfadb9ff46c743554c7.zip | |
Address PR reviews
Diffstat (limited to 'src/librustc_errors/lib.rs')
| -rw-r--r-- | src/librustc_errors/lib.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 82d688d6ba6..e1ec23479ab 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -23,6 +23,7 @@ #![feature(staged_api)] #![feature(range_contains)] #![feature(libc)] +#![feature(conservative_impl_trait)] extern crate term; extern crate libc; @@ -83,10 +84,17 @@ pub struct CodeSuggestion { /// ``` /// vec![(0..7, vec!["a.b", "x.y"])] /// ``` - pub substitutes: Vec<(Span, Vec<String>)>, + pub substitution_parts: Vec<Substitution>, pub msg: String, } +#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] +/// See the docs on `CodeSuggestion::substitutions` +pub struct Substitution { + pub span: Span, + pub substitutions: Vec<String>, +} + pub trait CodeMapper { fn lookup_char_pos(&self, pos: BytePos) -> Loc; fn span_to_lines(&self, sp: Span) -> FileLinesResult; @@ -96,6 +104,16 @@ pub trait CodeMapper { } impl CodeSuggestion { + /// Returns the number of substitutions + fn substitutions(&self) -> usize { + self.substitution_parts[0].substitutions.len() + } + + /// Returns the number of substitutions + pub fn substitution_spans<'a>(&'a self) -> impl Iterator<Item = Span> + 'a { + self.substitution_parts.iter().map(|sub| sub.span) + } + /// Returns the assembled code suggestions. pub fn splice_lines(&self, cm: &CodeMapper) -> Vec<String> { use syntax_pos::{CharPos, Loc, Pos}; @@ -119,13 +137,13 @@ impl CodeSuggestion { } } - if self.substitutes.is_empty() { + if self.substitution_parts.is_empty() { return vec![String::new()]; } - let mut primary_spans: Vec<_> = self.substitutes + let mut primary_spans: Vec<_> = self.substitution_parts .iter() - .map(|&(sp, ref sub)| (sp, sub)) + .map(|sub| (sub.span, &sub.substitutions)) .collect(); // Assumption: all spans are in the same file, and all spans @@ -157,7 +175,7 @@ impl CodeSuggestion { prev_hi.col = CharPos::from_usize(0); let mut prev_line = fm.get_line(lines.lines[0].line_index); - let mut bufs = vec![String::new(); self.substitutes[0].1.len()]; + let mut bufs = vec![String::new(); self.substitutions()]; for (sp, substitutes) in primary_spans { let cur_lo = cm.lookup_char_pos(sp.lo); |
