Skip to content

Commit 6160040

Browse files
committed
Auto merge of #46039 - oli-obk:test_suggestions, r=petrochenkov
Remove left over dead code from suggestion diagnostic refactoring More cleanups after #41876 and #45741
2 parents b1409af + 47c7e43 commit 6160040

20 files changed

+28
-102
lines changed

src/librustc_errors/diagnostic.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use CodeSuggestion;
1212
use SubstitutionPart;
1313
use Substitution;
1414
use Level;
15-
use RenderSpan;
1615
use std::fmt;
1716
use syntax_pos::{MultiSpan, Span};
1817
use snippet::Style;
@@ -40,7 +39,7 @@ pub struct SubDiagnostic {
4039
pub level: Level,
4140
pub message: Vec<(String, Style)>,
4241
pub span: MultiSpan,
43-
pub render_span: Option<RenderSpan>,
42+
pub render_span: Option<MultiSpan>,
4443
}
4544

4645
#[derive(PartialEq, Eq)]
@@ -307,7 +306,7 @@ impl Diagnostic {
307306
level: Level,
308307
message: &str,
309308
span: MultiSpan,
310-
render_span: Option<RenderSpan>) {
309+
render_span: Option<MultiSpan>) {
311310
let sub = SubDiagnostic {
312311
level,
313312
message: vec![(message.to_owned(), Style::NoStyle)],
@@ -323,7 +322,7 @@ impl Diagnostic {
323322
level: Level,
324323
message: Vec<(String, Style)>,
325324
span: MultiSpan,
326-
render_span: Option<RenderSpan>) {
325+
render_span: Option<MultiSpan>) {
327326
let sub = SubDiagnostic {
328327
level,
329328
message,

src/librustc_errors/emitter.rs

+23-42
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use self::Destination::*;
1313
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan};
1414

1515
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
16-
use RenderSpan::*;
1716
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
1817
use styled_buffer::StyledBuffer;
1918

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

3939
if let Some((sugg, rest)) = db.suggestions.split_first() {
4040
if rest.is_empty() &&
@@ -60,14 +60,7 @@ impl Emitter for EmitterWriter {
6060
// to be consistent. We could try to figure out if we can
6161
// make one (or the first one) inline, but that would give
6262
// undue importance to a semi-random suggestion
63-
for sugg in &db.suggestions {
64-
children.push(SubDiagnostic {
65-
level: Level::Help,
66-
message: Vec::new(),
67-
span: MultiSpan::new(),
68-
render_span: Some(Suggestion(sugg.clone())),
69-
});
70-
}
63+
suggestions = &db.suggestions;
7164
}
7265
}
7366

@@ -76,7 +69,8 @@ impl Emitter for EmitterWriter {
7669
&db.styled_message(),
7770
&db.code,
7871
&primary_span,
79-
&children);
72+
&children,
73+
&suggestions);
8074
}
8175
}
8276

@@ -1179,7 +1173,8 @@ impl EmitterWriter {
11791173
message: &Vec<(String, Style)>,
11801174
code: &Option<DiagnosticId>,
11811175
span: &MultiSpan,
1182-
children: &Vec<SubDiagnostic>) {
1176+
children: &Vec<SubDiagnostic>,
1177+
suggestions: &[CodeSuggestion]) {
11831178
let max_line_num = self.get_max_line_num(span, children);
11841179
let max_line_num_len = max_line_num.to_string().len();
11851180

@@ -1198,37 +1193,23 @@ impl EmitterWriter {
11981193
}
11991194
if !self.short_message {
12001195
for child in children {
1201-
match child.render_span {
1202-
Some(FullSpan(ref msp)) => {
1203-
match self.emit_message_default(msp,
1204-
&child.styled_message(),
1205-
&None,
1206-
&child.level,
1207-
max_line_num_len,
1208-
true) {
1209-
Err(e) => panic!("failed to emit error: {}", e),
1210-
_ => ()
1211-
}
1212-
}
1213-
Some(Suggestion(ref cs)) => {
1214-
match self.emit_suggestion_default(cs,
1215-
&child.level,
1216-
max_line_num_len) {
1217-
Err(e) => panic!("failed to emit error: {}", e),
1218-
_ => ()
1219-
}
1220-
}
1221-
None => {
1222-
match self.emit_message_default(&child.span,
1223-
&child.styled_message(),
1224-
&None,
1225-
&child.level,
1226-
max_line_num_len,
1227-
true) {
1228-
Err(e) => panic!("failed to emit error: {}", e),
1229-
_ => (),
1230-
}
1231-
}
1196+
let span = child.render_span.as_ref().unwrap_or(&child.span);
1197+
match self.emit_message_default(&span,
1198+
&child.styled_message(),
1199+
&None,
1200+
&child.level,
1201+
max_line_num_len,
1202+
true) {
1203+
Err(e) => panic!("failed to emit error: {}", e),
1204+
_ => ()
1205+
}
1206+
}
1207+
for sugg in suggestions {
1208+
match self.emit_suggestion_default(sugg,
1209+
&Level::Help,
1210+
max_line_num_len) {
1211+
Err(e) => panic!("failed to emit error: {}", e),
1212+
_ => ()
12321213
}
12331214
}
12341215
}

src/librustc_errors/lib.rs

-14
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ mod lock;
5252

5353
use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
5454

55-
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
56-
pub enum RenderSpan {
57-
/// A FullSpan renders with both with an initial line for the
58-
/// message, prefixed by file:linenum, followed by a summary of
59-
/// the source code covered by the span.
60-
FullSpan(MultiSpan),
61-
62-
/// A suggestion renders with both with an initial line for the
63-
/// message, prefixed by file:linenum, followed by a summary
64-
/// of hypothetical source code, where each `String` is spliced
65-
/// into the lines in place of the code covered by each span.
66-
Suggestion(CodeSuggestion),
67-
}
68-
6955
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
7056
pub struct CodeSuggestion {
7157
/// Each substitute can have multiple variants due to multiple

src/libsyntax/json.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use codemap::{CodeMap, FilePathMapping};
2323
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
2424
use errors::registry::Registry;
25-
use errors::{DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper};
25+
use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper};
2626
use errors::DiagnosticId;
2727
use errors::emitter::Emitter;
2828

@@ -188,7 +188,7 @@ impl Diagnostic {
188188
code: None,
189189
level: db.level.to_str(),
190190
spans: db.render_span.as_ref()
191-
.map(|sp| DiagnosticSpan::from_render_span(sp, je))
191+
.map(|sp| DiagnosticSpan::from_multispan(sp, je))
192192
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&db.span, je)),
193193
children: vec![],
194194
rendered: None,
@@ -300,16 +300,6 @@ impl DiagnosticSpan {
300300
})
301301
.collect()
302302
}
303-
304-
fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
305-
match *rsp {
306-
RenderSpan::FullSpan(ref msp) =>
307-
DiagnosticSpan::from_multispan(msp, je),
308-
// regular diagnostics don't produce this anymore
309-
// FIXME(oli_obk): remove it entirely
310-
RenderSpan::Suggestion(_) => unreachable!(),
311-
}
312-
}
313303
}
314304

315305
impl DiagnosticSpanLine {

src/test/ui/impl-trait/universal_wrong_bounds.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ error[E0405]: cannot find trait `Debug` in this scope
99
|
1010
21 | fn wants_debug(g: impl Debug) { }
1111
| ^^^^^ not found in this scope
12-
|
1312
help: possible candidate is found in another module, you can import it into scope
1413
|
1514
13 | use std::fmt::Debug;
@@ -20,7 +19,6 @@ error[E0405]: cannot find trait `Debug` in this scope
2019
|
2120
22 | fn wants_display(g: impl Debug) { }
2221
| ^^^^^ not found in this scope
23-
|
2422
help: possible candidate is found in another module, you can import it into scope
2523
|
2624
13 | use std::fmt::Debug;

src/test/ui/issue-22644.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
5050
| ^ not interpreted as comparison
5151
27 | 4);
5252
| - interpreted as generic arguments
53-
|
5453
help: try comparing the casted value
5554
|
5655
23 | println!("{}", (a
@@ -65,7 +64,6 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
6564
| ^ not interpreted as comparison
6665
36 | 5);
6766
| - interpreted as generic arguments
68-
|
6967
help: try comparing the casted value
7068
|
7169
28 | println!("{}", (a

src/test/ui/issue-35675.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ error[E0425]: cannot find function `Apple` in this scope
1212
|
1313
23 | Apple(5)
1414
| ^^^^^ not found in this scope
15-
|
1615
help: possible candidate is found in another module, you can import it into scope
1716
|
1817
12 | use Fruit::Apple;
@@ -32,7 +31,6 @@ error[E0425]: cannot find function `Apple` in this scope
3231
|
3332
31 | Apple(5)
3433
| ^^^^^ not found in this scope
35-
|
3634
help: possible candidate is found in another module, you can import it into scope
3735
|
3836
12 | use Fruit::Apple;

src/test/ui/resolve/enums-are-namespaced-xc.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
33
|
44
15 | let _ = namespaced_enums::A;
55
| ^ not found in `namespaced_enums`
6-
|
76
help: possible candidate is found in another module, you can import it into scope
87
|
98
14 | use namespaced_enums::Foo::A;
@@ -14,7 +13,6 @@ error[E0425]: cannot find function `B` in module `namespaced_enums`
1413
|
1514
18 | let _ = namespaced_enums::B(10);
1615
| ^ not found in `namespaced_enums`
17-
|
1816
help: possible candidate is found in another module, you can import it into scope
1917
|
2018
14 | use namespaced_enums::Foo::B;
@@ -25,7 +23,6 @@ error[E0422]: cannot find struct, variant or union type `C` in module `namespace
2523
|
2624
21 | let _ = namespaced_enums::C { a: 10 };
2725
| ^ not found in `namespaced_enums`
28-
|
2926
help: possible candidate is found in another module, you can import it into scope
3027
|
3128
14 | use namespaced_enums::Foo::C;

src/test/ui/resolve/issue-16058.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
33
|
44
19 | Result {
55
| ^^^^^^ not a struct, variant or union type
6-
|
76
help: possible better candidates are found in other modules, you can import them into scope
87
|
98
12 | use std::fmt::Result;

src/test/ui/resolve/issue-17518.stderr

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

src/test/ui/resolve/issue-21221-1.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0405]: cannot find trait `Mul` in this scope
33
|
44
53 | impl Mul for Foo {
55
| ^^^ not found in this scope
6-
|
76
help: possible candidates are found in other modules, you can import them into scope
87
|
98
11 | use mul1::Mul;
@@ -18,7 +17,6 @@ error[E0412]: cannot find type `Mul` in this scope
1817
|
1918
72 | fn getMul() -> Mul {
2019
| ^^^ not found in this scope
21-
|
2220
help: possible candidates are found in other modules, you can import them into scope
2321
|
2422
11 | use mul1::Mul;
@@ -42,7 +40,6 @@ error[E0405]: cannot find trait `Div` in this scope
4240
|
4341
88 | impl Div for Foo {
4442
| ^^^ not found in this scope
45-
|
4643
help: possible candidate is found in another module, you can import it into scope
4744
|
4845
11 | use std::ops::Div;

src/test/ui/resolve/issue-21221-2.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
33
|
44
28 | impl T for Foo { }
55
| ^ not found in this scope
6-
|
76
help: possible candidate is found in another module, you can import it into scope
87
|
98
11 | use foo::bar::T;

src/test/ui/resolve/issue-21221-3.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
33
|
44
25 | impl OuterTrait for Foo {}
55
| ^^^^^^^^^^ not found in this scope
6-
|
76
help: possible candidate is found in another module, you can import it into scope
87
|
98
18 | use issue_21221_3::outer::OuterTrait;

src/test/ui/resolve/issue-21221-4.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0405]: cannot find trait `T` in this scope
33
|
44
20 | impl T for Foo {}
55
| ^ not found in this scope
6-
|
76
help: possible candidate is found in another module, you can import it into scope
87
|
98
18 | use issue_21221_4::T;

src/test/ui/resolve/issue-3907.stderr

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

src/test/ui/resolve/privacy-struct-ctor.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ error[E0423]: expected value, found struct `Z`
77
| did you mean `S`?
88
| constructor is not visible here due to private fields
99
| did you mean `Z { /* fields */ }`?
10-
|
1110
help: possible better candidate is found in another module, you can import it into scope
1211
|
1312
22 | use m::n::Z;
@@ -21,7 +20,6 @@ error[E0423]: expected value, found struct `S`
2120
| |
2221
| constructor is not visible here due to private fields
2322
| did you mean `S { /* fields */ }`?
24-
|
2523
help: possible better candidate is found in another module, you can import it into scope
2624
|
2725
32 | use m::S;
@@ -35,7 +33,6 @@ error[E0423]: expected value, found struct `xcrate::S`
3533
| |
3634
| constructor is not visible here due to private fields
3735
| did you mean `xcrate::S { /* fields */ }`?
38-
|
3936
help: possible better candidate is found in another module, you can import it into scope
4037
|
4138
32 | use m::S;

src/test/ui/resolve/use_suggestion_placement.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0412]: cannot find type `Path` in this scope
33
|
44
25 | type Bar = Path;
55
| ^^^^ not found in this scope
6-
|
76
help: possible candidate is found in another module, you can import it into scope
87
|
98
21 | use std::path::Path;
@@ -14,7 +13,6 @@ error[E0425]: cannot find value `A` in this scope
1413
|
1514
30 | let _ = A;
1615
| ^ not found in this scope
17-
|
1816
help: possible candidate is found in another module, you can import it into scope
1917
|
2018
11 | use m::A;
@@ -25,7 +23,6 @@ error[E0412]: cannot find type `HashMap` in this scope
2523
|
2624
35 | type Dict<K, V> = HashMap<K, V>;
2725
| ^^^^^^^ not found in this scope
28-
|
2926
help: possible candidates are found in other modules, you can import them into scope
3027
|
3128
11 | use std::collections::HashMap;

src/test/ui/span/issue-35987.stderr

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

0 commit comments

Comments
 (0)