Remove left over dead code from suggestion diagnostic refactoring

This commit is contained in:
Oliver Schneider 2017-11-16 16:36:49 +01:00
parent c81f201d48
commit 47c7e430d3
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
20 changed files with 28 additions and 102 deletions

View File

@ -12,7 +12,6 @@ use CodeSuggestion;
use SubstitutionPart; use SubstitutionPart;
use Substitution; use Substitution;
use Level; use Level;
use RenderSpan;
use std::fmt; use std::fmt;
use syntax_pos::{MultiSpan, Span}; use syntax_pos::{MultiSpan, Span};
use snippet::Style; use snippet::Style;
@ -40,7 +39,7 @@ pub struct SubDiagnostic {
pub level: Level, pub level: Level,
pub message: Vec<(String, Style)>, pub message: Vec<(String, Style)>,
pub span: MultiSpan, pub span: MultiSpan,
pub render_span: Option<RenderSpan>, pub render_span: Option<MultiSpan>,
} }
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@ -307,7 +306,7 @@ impl Diagnostic {
level: Level, level: Level,
message: &str, message: &str,
span: MultiSpan, span: MultiSpan,
render_span: Option<RenderSpan>) { render_span: Option<MultiSpan>) {
let sub = SubDiagnostic { let sub = SubDiagnostic {
level, level,
message: vec![(message.to_owned(), Style::NoStyle)], message: vec![(message.to_owned(), Style::NoStyle)],
@ -323,7 +322,7 @@ impl Diagnostic {
level: Level, level: Level,
message: Vec<(String, Style)>, message: Vec<(String, Style)>,
span: MultiSpan, span: MultiSpan,
render_span: Option<RenderSpan>) { render_span: Option<MultiSpan>) {
let sub = SubDiagnostic { let sub = SubDiagnostic {
level, level,
message, message,

View File

@ -13,7 +13,6 @@ use self::Destination::*;
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan}; use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId}; use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
use RenderSpan::*;
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use styled_buffer::StyledBuffer; use styled_buffer::StyledBuffer;
@ -35,6 +34,7 @@ impl Emitter for EmitterWriter {
fn emit(&mut self, db: &DiagnosticBuilder) { fn emit(&mut self, db: &DiagnosticBuilder) {
let mut primary_span = db.span.clone(); let mut primary_span = db.span.clone();
let mut children = db.children.clone(); let mut children = db.children.clone();
let mut suggestions: &[_] = &[];
if let Some((sugg, rest)) = db.suggestions.split_first() { if let Some((sugg, rest)) = db.suggestions.split_first() {
if rest.is_empty() && if rest.is_empty() &&
@ -60,14 +60,7 @@ impl Emitter for EmitterWriter {
// to be consistent. We could try to figure out if we can // to be consistent. We could try to figure out if we can
// make one (or the first one) inline, but that would give // make one (or the first one) inline, but that would give
// undue importance to a semi-random suggestion // undue importance to a semi-random suggestion
for sugg in &db.suggestions { suggestions = &db.suggestions;
children.push(SubDiagnostic {
level: Level::Help,
message: Vec::new(),
span: MultiSpan::new(),
render_span: Some(Suggestion(sugg.clone())),
});
}
} }
} }
@ -76,7 +69,8 @@ impl Emitter for EmitterWriter {
&db.styled_message(), &db.styled_message(),
&db.code, &db.code,
&primary_span, &primary_span,
&children); &children,
&suggestions);
} }
} }
@ -1179,7 +1173,8 @@ impl EmitterWriter {
message: &Vec<(String, Style)>, message: &Vec<(String, Style)>,
code: &Option<DiagnosticId>, code: &Option<DiagnosticId>,
span: &MultiSpan, span: &MultiSpan,
children: &Vec<SubDiagnostic>) { children: &Vec<SubDiagnostic>,
suggestions: &[CodeSuggestion]) {
let max_line_num = self.get_max_line_num(span, children); let max_line_num = self.get_max_line_num(span, children);
let max_line_num_len = max_line_num.to_string().len(); let max_line_num_len = max_line_num.to_string().len();
@ -1198,37 +1193,23 @@ impl EmitterWriter {
} }
if !self.short_message { if !self.short_message {
for child in children { for child in children {
match child.render_span { let span = child.render_span.as_ref().unwrap_or(&child.span);
Some(FullSpan(ref msp)) => { match self.emit_message_default(&span,
match self.emit_message_default(msp, &child.styled_message(),
&child.styled_message(), &None,
&None, &child.level,
&child.level, max_line_num_len,
max_line_num_len, true) {
true) { Err(e) => panic!("failed to emit error: {}", e),
Err(e) => panic!("failed to emit error: {}", e), _ => ()
_ => () }
} }
} for sugg in suggestions {
Some(Suggestion(ref cs)) => { match self.emit_suggestion_default(sugg,
match self.emit_suggestion_default(cs, &Level::Help,
&child.level, max_line_num_len) {
max_line_num_len) { Err(e) => panic!("failed to emit error: {}", e),
Err(e) => panic!("failed to emit error: {}", e), _ => ()
_ => ()
}
}
None => {
match self.emit_message_default(&child.span,
&child.styled_message(),
&None,
&child.level,
max_line_num_len,
true) {
Err(e) => panic!("failed to emit error: {}", e),
_ => (),
}
}
} }
} }
} }

View File

@ -52,20 +52,6 @@ mod lock;
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION}; use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
pub enum RenderSpan {
/// A FullSpan renders with both with an initial line for the
/// message, prefixed by file:linenum, followed by a summary of
/// the source code covered by the span.
FullSpan(MultiSpan),
/// A suggestion renders with both with an initial line for the
/// message, prefixed by file:linenum, followed by a summary
/// of hypothetical source code, where each `String` is spliced
/// into the lines in place of the code covered by each span.
Suggestion(CodeSuggestion),
}
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
pub struct CodeSuggestion { pub struct CodeSuggestion {
/// Each substitute can have multiple variants due to multiple /// Each substitute can have multiple variants due to multiple

View File

@ -22,7 +22,7 @@
use codemap::{CodeMap, FilePathMapping}; use codemap::{CodeMap, FilePathMapping};
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan}; use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
use errors::registry::Registry; use errors::registry::Registry;
use errors::{DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper}; use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
use errors::DiagnosticId; use errors::DiagnosticId;
use errors::emitter::Emitter; use errors::emitter::Emitter;
@ -188,7 +188,7 @@ impl Diagnostic {
code: None, code: None,
level: db.level.to_str(), level: db.level.to_str(),
spans: db.render_span.as_ref() spans: db.render_span.as_ref()
.map(|sp| DiagnosticSpan::from_render_span(sp, je)) .map(|sp| DiagnosticSpan::from_multispan(sp, je))
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&db.span, je)), .unwrap_or_else(|| DiagnosticSpan::from_multispan(&db.span, je)),
children: vec![], children: vec![],
rendered: None, rendered: None,
@ -300,16 +300,6 @@ impl DiagnosticSpan {
}) })
.collect() .collect()
} }
fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
match *rsp {
RenderSpan::FullSpan(ref msp) =>
DiagnosticSpan::from_multispan(msp, je),
// regular diagnostics don't produce this anymore
// FIXME(oli_obk): remove it entirely
RenderSpan::Suggestion(_) => unreachable!(),
}
}
} }
impl DiagnosticSpanLine { impl DiagnosticSpanLine {

View File

@ -9,7 +9,6 @@ error[E0405]: cannot find trait `Debug` in this scope
| |
21 | fn wants_debug(g: impl Debug) { } 21 | fn wants_debug(g: impl Debug) { }
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
13 | use std::fmt::Debug; 13 | use std::fmt::Debug;
@ -20,7 +19,6 @@ error[E0405]: cannot find trait `Debug` in this scope
| |
22 | fn wants_display(g: impl Debug) { } 22 | fn wants_display(g: impl Debug) { }
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
13 | use std::fmt::Debug; 13 | use std::fmt::Debug;

View File

@ -50,7 +50,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
| ^ not interpreted as comparison | ^ not interpreted as comparison
27 | 4); 27 | 4);
| - interpreted as generic arguments | - interpreted as generic arguments
|
help: try comparing the casted value help: try comparing the casted value
| |
23 | println!("{}", (a 23 | println!("{}", (a
@ -65,7 +64,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
| ^ not interpreted as comparison | ^ not interpreted as comparison
36 | 5); 36 | 5);
| - interpreted as generic arguments | - interpreted as generic arguments
|
help: try comparing the casted value help: try comparing the casted value
| |
28 | println!("{}", (a 28 | println!("{}", (a

View File

@ -12,7 +12,6 @@ error[E0425]: cannot find function `Apple` in this scope
| |
23 | Apple(5) 23 | Apple(5)
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
12 | use Fruit::Apple; 12 | use Fruit::Apple;
@ -32,7 +31,6 @@ error[E0425]: cannot find function `Apple` in this scope
| |
31 | Apple(5) 31 | Apple(5)
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
12 | use Fruit::Apple; 12 | use Fruit::Apple;

View File

@ -3,7 +3,6 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
| |
15 | let _ = namespaced_enums::A; 15 | let _ = namespaced_enums::A;
| ^ not found in `namespaced_enums` | ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
14 | use namespaced_enums::Foo::A; 14 | use namespaced_enums::Foo::A;
@ -14,7 +13,6 @@ error[E0425]: cannot find function `B` in module `namespaced_enums`
| |
18 | let _ = namespaced_enums::B(10); 18 | let _ = namespaced_enums::B(10);
| ^ not found in `namespaced_enums` | ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
14 | use namespaced_enums::Foo::B; 14 | use namespaced_enums::Foo::B;
@ -25,7 +23,6 @@ error[E0422]: cannot find struct, variant or union type `C` in module `namespace
| |
21 | let _ = namespaced_enums::C { a: 10 }; 21 | let _ = namespaced_enums::C { a: 10 };
| ^ not found in `namespaced_enums` | ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
14 | use namespaced_enums::Foo::C; 14 | use namespaced_enums::Foo::C;

View File

@ -3,7 +3,6 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
| |
19 | Result { 19 | Result {
| ^^^^^^ not a struct, variant or union type | ^^^^^^ not a struct, variant or union type
|
help: possible better candidates are found in other modules, you can import them into scope help: possible better candidates are found in other modules, you can import them into scope
| |
12 | use std::fmt::Result; 12 | use std::fmt::Result;

View File

@ -3,7 +3,6 @@ error[E0422]: cannot find struct, variant or union type `E` in this scope
| |
16 | E { name: "foobar" }; //~ ERROR unresolved struct, variant or union type `E` 16 | E { name: "foobar" }; //~ ERROR unresolved struct, variant or union type `E`
| ^ not found in this scope | ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
11 | use SomeEnum::E; 11 | use SomeEnum::E;

View File

@ -3,7 +3,6 @@ error[E0405]: cannot find trait `Mul` in this scope
| |
53 | impl Mul for Foo { 53 | impl Mul for Foo {
| ^^^ not found in this scope | ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope help: possible candidates are found in other modules, you can import them into scope
| |
11 | use mul1::Mul; 11 | use mul1::Mul;
@ -18,7 +17,6 @@ error[E0412]: cannot find type `Mul` in this scope
| |
72 | fn getMul() -> Mul { 72 | fn getMul() -> Mul {
| ^^^ not found in this scope | ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope help: possible candidates are found in other modules, you can import them into scope
| |
11 | use mul1::Mul; 11 | use mul1::Mul;
@ -42,7 +40,6 @@ error[E0405]: cannot find trait `Div` in this scope
| |
88 | impl Div for Foo { 88 | impl Div for Foo {
| ^^^ not found in this scope | ^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
11 | use std::ops::Div; 11 | use std::ops::Div;

View File

@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
| |
28 | impl T for Foo { } 28 | impl T for Foo { }
| ^ not found in this scope | ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
11 | use foo::bar::T; 11 | use foo::bar::T;

View File

@ -3,7 +3,6 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
| |
25 | impl OuterTrait for Foo {} 25 | impl OuterTrait for Foo {}
| ^^^^^^^^^^ not found in this scope | ^^^^^^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
18 | use issue_21221_3::outer::OuterTrait; 18 | use issue_21221_3::outer::OuterTrait;

View File

@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
| |
20 | impl T for Foo {} 20 | impl T for Foo {}
| ^ not found in this scope | ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
18 | use issue_21221_4::T; 18 | use issue_21221_4::T;

View File

@ -3,7 +3,6 @@ error[E0404]: expected trait, found type alias `Foo`
| |
20 | impl Foo for S { //~ ERROR expected trait, found type alias `Foo` 20 | impl Foo for S { //~ ERROR expected trait, found type alias `Foo`
| ^^^ type aliases cannot be used for traits | ^^^ type aliases cannot be used for traits
|
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
14 | use issue_3907::Foo; 14 | use issue_3907::Foo;

View File

@ -7,7 +7,6 @@ error[E0423]: expected value, found struct `Z`
| did you mean `S`? | did you mean `S`?
| constructor is not visible here due to private fields | constructor is not visible here due to private fields
| did you mean `Z { /* fields */ }`? | did you mean `Z { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
22 | use m::n::Z; 22 | use m::n::Z;
@ -21,7 +20,6 @@ error[E0423]: expected value, found struct `S`
| | | |
| constructor is not visible here due to private fields | constructor is not visible here due to private fields
| did you mean `S { /* fields */ }`? | did you mean `S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
32 | use m::S; 32 | use m::S;
@ -35,7 +33,6 @@ error[E0423]: expected value, found struct `xcrate::S`
| | | |
| constructor is not visible here due to private fields | constructor is not visible here due to private fields
| did you mean `xcrate::S { /* fields */ }`? | did you mean `xcrate::S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
32 | use m::S; 32 | use m::S;

View File

@ -3,7 +3,6 @@ error[E0412]: cannot find type `Path` in this scope
| |
25 | type Bar = Path; 25 | type Bar = Path;
| ^^^^ not found in this scope | ^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
21 | use std::path::Path; 21 | use std::path::Path;
@ -14,7 +13,6 @@ error[E0425]: cannot find value `A` in this scope
| |
30 | let _ = A; 30 | let _ = A;
| ^ not found in this scope | ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope help: possible candidate is found in another module, you can import it into scope
| |
11 | use m::A; 11 | use m::A;
@ -25,7 +23,6 @@ error[E0412]: cannot find type `HashMap` in this scope
| |
35 | type Dict<K, V> = HashMap<K, V>; 35 | type Dict<K, V> = HashMap<K, V>;
| ^^^^^^^ not found in this scope | ^^^^^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope help: possible candidates are found in other modules, you can import them into scope
| |
11 | use std::collections::HashMap; 11 | use std::collections::HashMap;

View File

@ -3,7 +3,6 @@ error[E0404]: expected trait, found type parameter `Add`
| |
15 | impl<T: Clone, Add> Add for Foo<T> { 15 | impl<T: Clone, Add> Add for Foo<T> {
| ^^^ not a trait | ^^^ not a trait
|
help: possible better candidate is found in another module, you can import it into scope help: possible better candidate is found in another module, you can import it into scope
| |
13 | use std::ops::Add; 13 | use std::ops::Add;

View File

@ -3,7 +3,6 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
| |
12 | let x = "Hello " + "World!"; 12 | let x = "Hello " + "World!";
| ^^^^^^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings | ^^^^^^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
|
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
| |
12 | let x = "Hello ".to_owned() + "World!"; 12 | let x = "Hello ".to_owned() + "World!";

View File

@ -3,7 +3,6 @@ error[E0061]: this function takes 1 parameter but 0 parameters were supplied
| |
21 | let _: Result<(), String> = Ok(); 21 | let _: Result<(), String> = Ok();
| ^^^^ | ^^^^
|
help: expected the unit value `()`; create it with empty parentheses help: expected the unit value `()`; create it with empty parentheses
| |
21 | let _: Result<(), String> = Ok(()); 21 | let _: Result<(), String> = Ok(());
@ -35,7 +34,6 @@ error[E0061]: this function takes 1 parameter but 0 parameters were supplied
... ...
24 | bar(); 24 | bar();
| ^^^^^ | ^^^^^
|
help: expected the unit value `()`; create it with empty parentheses help: expected the unit value `()`; create it with empty parentheses
| |
24 | bar(()); 24 | bar(());
@ -49,7 +47,6 @@ error[E0061]: this function takes 1 parameter but 0 parameters were supplied
... ...
25 | S.baz(); 25 | S.baz();
| ^^^ | ^^^
|
help: expected the unit value `()`; create it with empty parentheses help: expected the unit value `()`; create it with empty parentheses
| |
25 | S.baz(()); 25 | S.baz(());
@ -63,7 +60,6 @@ error[E0061]: this function takes 1 parameter but 0 parameters were supplied
... ...
26 | S.generic::<()>(); 26 | S.generic::<()>();
| ^^^^^^^ | ^^^^^^^
|
help: expected the unit value `()`; create it with empty parentheses help: expected the unit value `()`; create it with empty parentheses
| |
26 | S.generic::<()>(()); 26 | S.generic::<()>(());