diff options
| author | Afnan Enayet <afnan@afnan.io> | 2019-09-13 06:48:47 -0700 |
|---|---|---|
| committer | Afnan Enayet <afnan@afnan.io> | 2019-09-16 22:30:59 -0700 |
| commit | 02c1b892c1dfa6d0f00254f9c058ce7595921d61 (patch) | |
| tree | a301925d6013e968a8cdfa95cc723c75720096b2 | |
| parent | 3287a65fc05028dce3b521765f4643384ebc4346 (diff) | |
| download | rust-02c1b892c1dfa6d0f00254f9c058ce7595921d61.tar.gz rust-02c1b892c1dfa6d0f00254f9c058ce7595921d61.zip | |
Fix failure note `to_str` implementation
* Serialize the level to something a little more useful for a failure note struct * Update tests accordingly
| -rw-r--r-- | src/librustc_errors/emitter.rs | 15 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/json-short.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/use_suggestion_json.stderr | 2 |
4 files changed, 12 insertions, 9 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 0ce69eecc6b..5214806c6ea 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1144,15 +1144,18 @@ impl EmitterWriter { buffer.prepend(0, " ", Style::NoStyle); } draw_note_separator(&mut buffer, 0, max_line_num_len + 1); - let level_str = level.to_string(); - if !level_str.is_empty() { - buffer.append(0, &level_str, Style::MainHeaderMsg); - buffer.append(0, ": ", Style::NoStyle); + if *level != Level::FailureNote { + let level_str = level.to_string(); + if !level_str.is_empty() { + buffer.append(0, &level_str, Style::MainHeaderMsg); + buffer.append(0, ": ", Style::NoStyle); + } } self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None); } else { let level_str = level.to_string(); - if !level_str.is_empty() { + // The failure note level itself does not provide any useful diagnostic information + if *level != Level::FailureNote && !level_str.is_empty() { buffer.append(0, &level_str, Style::Level(level.clone())); } // only render error codes, not lint codes @@ -1161,7 +1164,7 @@ impl EmitterWriter { buffer.append(0, &code, Style::Level(level.clone())); buffer.append(0, "]", Style::Level(level.clone())); } - if !level_str.is_empty() { + if *level != Level::FailureNote && !level_str.is_empty() { buffer.append(0, ": ", header_style); } for &(ref text, _) in msg.iter() { diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index c1fba416d64..8b543be6e64 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -833,7 +833,7 @@ impl Level { Warning => "warning", Note => "note", Help => "help", - FailureNote => "", + FailureNote => "failure-note", Cancelled => panic!("Shouldn't call on cancelled error"), } } diff --git a/src/test/ui/json-short.stderr b/src/test/ui/json-short.stderr index dffbdb7e480..549de0d2710 100644 --- a/src/test/ui/json-short.stderr +++ b/src/test/ui/json-short.stderr @@ -15,5 +15,5 @@ started: https://doc.rust-lang.org/book/ "} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error "} -{"message":"For more information about this error, try `rustc --explain E0601`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0601`. +{"message":"For more information about this error, try `rustc --explain E0601`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0601`. "} diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index c7c53abcf44..678c88849b5 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -412,7 +412,7 @@ mod foo { { "message": "For more information about this error, try `rustc --explain E0412`.", "code": null, - "level": "", + "level": "failure-note", "spans": [], "children": [], "rendered": "\u001b[0m\u001b[1mFor more information about this error, try `rustc --explain E0412`.\u001b[0m |
