Skip to content

Remove left over dead code from suggestion diagnostic refactoring #46039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use CodeSuggestion;
use SubstitutionPart;
use Substitution;
use Level;
use RenderSpan;
use std::fmt;
use syntax_pos::{MultiSpan, Span};
use snippet::Style;
Expand Down Expand Up @@ -40,7 +39,7 @@ pub struct SubDiagnostic {
pub level: Level,
pub message: Vec<(String, Style)>,
pub span: MultiSpan,
pub render_span: Option<RenderSpan>,
pub render_span: Option<MultiSpan>,
}

#[derive(PartialEq, Eq)]
Expand Down Expand Up @@ -307,7 +306,7 @@ impl Diagnostic {
level: Level,
message: &str,
span: MultiSpan,
render_span: Option<RenderSpan>) {
render_span: Option<MultiSpan>) {
let sub = SubDiagnostic {
level,
message: vec![(message.to_owned(), Style::NoStyle)],
Expand All @@ -323,7 +322,7 @@ impl Diagnostic {
level: Level,
message: Vec<(String, Style)>,
span: MultiSpan,
render_span: Option<RenderSpan>) {
render_span: Option<MultiSpan>) {
let sub = SubDiagnostic {
level,
message,
Expand Down
65 changes: 23 additions & 42 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use self::Destination::*;
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};

use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
use RenderSpan::*;
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use styled_buffer::StyledBuffer;

Expand All @@ -35,6 +34,7 @@ impl Emitter for EmitterWriter {
fn emit(&mut self, db: &DiagnosticBuilder) {
let mut primary_span = db.span.clone();
let mut children = db.children.clone();
let mut suggestions: &[_] = &[];

if let Some((sugg, rest)) = db.suggestions.split_first() {
if rest.is_empty() &&
Expand All @@ -60,14 +60,7 @@ impl Emitter for EmitterWriter {
// to be consistent. We could try to figure out if we can
// make one (or the first one) inline, but that would give
// undue importance to a semi-random suggestion
for sugg in &db.suggestions {
children.push(SubDiagnostic {
level: Level::Help,
message: Vec::new(),
span: MultiSpan::new(),
render_span: Some(Suggestion(sugg.clone())),
});
}
suggestions = &db.suggestions;
}
}

Expand All @@ -76,7 +69,8 @@ impl Emitter for EmitterWriter {
&db.styled_message(),
&db.code,
&primary_span,
&children);
&children,
&suggestions);
}
}

Expand Down Expand Up @@ -1179,7 +1173,8 @@ impl EmitterWriter {
message: &Vec<(String, Style)>,
code: &Option<DiagnosticId>,
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_len = max_line_num.to_string().len();

Expand All @@ -1198,37 +1193,23 @@ impl EmitterWriter {
}
if !self.short_message {
for child in children {
match child.render_span {
Some(FullSpan(ref msp)) => {
match self.emit_message_default(msp,
&child.styled_message(),
&None,
&child.level,
max_line_num_len,
true) {
Err(e) => panic!("failed to emit error: {}", e),
_ => ()
}
}
Some(Suggestion(ref cs)) => {
match self.emit_suggestion_default(cs,
&child.level,
max_line_num_len) {
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),
_ => (),
}
}
let span = child.render_span.as_ref().unwrap_or(&child.span);
match self.emit_message_default(&span,
&child.styled_message(),
&None,
&child.level,
max_line_num_len,
true) {
Err(e) => panic!("failed to emit error: {}", e),
_ => ()
}
}
for sugg in suggestions {
match self.emit_suggestion_default(sugg,
&Level::Help,
max_line_num_len) {
Err(e) => panic!("failed to emit error: {}", e),
_ => ()
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ mod lock;

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)]
pub struct CodeSuggestion {
/// Each substitute can have multiple variants due to multiple
Expand Down
14 changes: 2 additions & 12 deletions src/libsyntax/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use codemap::{CodeMap, FilePathMapping};
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
use errors::registry::Registry;
use errors::{DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper};
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
use errors::DiagnosticId;
use errors::emitter::Emitter;

Expand Down Expand Up @@ -188,7 +188,7 @@ impl Diagnostic {
code: None,
level: db.level.to_str(),
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)),
children: vec![],
rendered: None,
Expand Down Expand Up @@ -300,16 +300,6 @@ impl DiagnosticSpan {
})
.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 {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/impl-trait/universal_wrong_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ error[E0405]: cannot find trait `Debug` in this scope
|
21 | fn wants_debug(g: impl Debug) { }
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
13 | use std::fmt::Debug;
Expand All @@ -20,7 +19,6 @@ error[E0405]: cannot find trait `Debug` in this scope
|
22 | fn wants_display(g: impl Debug) { }
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
13 | use std::fmt::Debug;
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/issue-22644.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
| ^ not interpreted as comparison
27 | 4);
| - interpreted as generic arguments
|
help: try comparing the casted value
|
23 | println!("{}", (a
Expand All @@ -65,7 +64,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
| ^ not interpreted as comparison
36 | 5);
| - interpreted as generic arguments
|
help: try comparing the casted value
|
28 | println!("{}", (a
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/issue-35675.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ error[E0425]: cannot find function `Apple` in this scope
|
23 | Apple(5)
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
12 | use Fruit::Apple;
Expand All @@ -32,7 +31,6 @@ error[E0425]: cannot find function `Apple` in this scope
|
31 | Apple(5)
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
12 | use Fruit::Apple;
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/resolve/enums-are-namespaced-xc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
|
15 | let _ = namespaced_enums::A;
| ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope
|
14 | use namespaced_enums::Foo::A;
Expand All @@ -14,7 +13,6 @@ error[E0425]: cannot find function `B` in module `namespaced_enums`
|
18 | let _ = namespaced_enums::B(10);
| ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope
|
14 | use namespaced_enums::Foo::B;
Expand All @@ -25,7 +23,6 @@ error[E0422]: cannot find struct, variant or union type `C` in module `namespace
|
21 | let _ = namespaced_enums::C { a: 10 };
| ^ not found in `namespaced_enums`
|
help: possible candidate is found in another module, you can import it into scope
|
14 | use namespaced_enums::Foo::C;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-16058.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
|
19 | Result {
| ^^^^^^ not a struct, variant or union type
|
help: possible better candidates are found in other modules, you can import them into scope
|
12 | use std::fmt::Result;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-17518.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
| ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
11 | use SomeEnum::E;
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/resolve/issue-21221-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0405]: cannot find trait `Mul` in this scope
|
53 | impl Mul for Foo {
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use mul1::Mul;
Expand All @@ -18,7 +17,6 @@ error[E0412]: cannot find type `Mul` in this scope
|
72 | fn getMul() -> Mul {
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use mul1::Mul;
Expand All @@ -42,7 +40,6 @@ error[E0405]: cannot find trait `Div` in this scope
|
88 | impl Div for Foo {
| ^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
11 | use std::ops::Div;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-21221-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
|
28 | impl T for Foo { }
| ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
11 | use foo::bar::T;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-21221-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
|
25 | impl OuterTrait for Foo {}
| ^^^^^^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
18 | use issue_21221_3::outer::OuterTrait;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-21221-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
|
20 | impl T for Foo {}
| ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
18 | use issue_21221_4::T;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/resolve/issue-3907.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0404]: 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
|
help: possible better candidate is found in another module, you can import it into scope
|
14 | use issue_3907::Foo;
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/resolve/privacy-struct-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ error[E0423]: expected value, found struct `Z`
| did you mean `S`?
| constructor is not visible here due to private fields
| did you mean `Z { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
22 | use m::n::Z;
Expand All @@ -21,7 +20,6 @@ error[E0423]: expected value, found struct `S`
| |
| constructor is not visible here due to private fields
| did you mean `S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
32 | use m::S;
Expand All @@ -35,7 +33,6 @@ error[E0423]: expected value, found struct `xcrate::S`
| |
| constructor is not visible here due to private fields
| did you mean `xcrate::S { /* fields */ }`?
|
help: possible better candidate is found in another module, you can import it into scope
|
32 | use m::S;
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/resolve/use_suggestion_placement.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0412]: cannot find type `Path` in this scope
|
25 | type Bar = Path;
| ^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
21 | use std::path::Path;
Expand All @@ -14,7 +13,6 @@ error[E0425]: cannot find value `A` in this scope
|
30 | let _ = A;
| ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
11 | use m::A;
Expand All @@ -25,7 +23,6 @@ error[E0412]: cannot find type `HashMap` in this scope
|
35 | type Dict<K, V> = HashMap<K, V>;
| ^^^^^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
|
11 | use std::collections::HashMap;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/span/issue-35987.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ error[E0404]: expected trait, found type parameter `Add`
|
15 | impl<T: Clone, Add> Add for Foo<T> {
| ^^^ not a trait
|
help: possible better candidate is found in another module, you can import it into scope
|
13 | use std::ops::Add;
Expand Down
Loading