Skip to content

Commit 0257caa

Browse files
authored
Unrolled build for #150032
Rollup merge of #150032 - Kivooeo:annotate-snippets-stable, r=Muscraft Use annotate-snippet as default emitter on stable This is implementation of #149932 Now, after MCP was accepted, we can use annotate-snippet as default emitter for errors, that means that we not longer need of previous emitter, so this PR removed previous emitter and makes annotate-snippet new default one both on stable and nightly (this PR does not remove a code of previous emitter it just removes a `Default` option of `HumanReadableErrorType` enum, and keeping only `HumanReadableErrorType::AnnotateSnippet` as it now uses by default)
2 parents 31010ca + 84f2854 commit 0257caa

File tree

22 files changed

+45
-170
lines changed

22 files changed

+45
-170
lines changed

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,6 @@ impl AnnotateSnippetEmitter {
303303
}
304304
}
305305

306-
let suggestions_expected = suggestions
307-
.iter()
308-
.filter(|s| {
309-
matches!(
310-
s.style,
311-
SuggestionStyle::HideCodeInline
312-
| SuggestionStyle::ShowCode
313-
| SuggestionStyle::ShowAlways
314-
)
315-
})
316-
.count();
317306
for suggestion in suggestions {
318307
match suggestion.style {
319308
SuggestionStyle::CompletelyHidden => {
@@ -526,12 +515,6 @@ impl AnnotateSnippetEmitter {
526515
}
527516
}
528517

529-
// FIXME: This hack should be removed once annotate_snippets is the
530-
// default emitter.
531-
if suggestions_expected > 0 && report.is_empty() {
532-
group = group.element(Padding);
533-
}
534-
535518
if !group.is_empty() {
536519
report.push(group);
537520
}

compiler/rustc_errors/src/emitter.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ const DEFAULT_COLUMN_WIDTH: usize = 140;
4646

4747
/// Describes the way the content of the `rendered` field of the json output is generated
4848
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49-
pub enum HumanReadableErrorType {
50-
Default { short: bool },
51-
AnnotateSnippet { short: bool, unicode: bool },
49+
pub struct HumanReadableErrorType {
50+
pub short: bool,
51+
pub unicode: bool,
5252
}
5353

5454
impl HumanReadableErrorType {
5555
pub fn short(&self) -> bool {
56-
match self {
57-
HumanReadableErrorType::Default { short }
58-
| HumanReadableErrorType::AnnotateSnippet { short, .. } => *short,
59-
}
56+
self.short
6057
}
6158
}
6259

@@ -607,7 +604,7 @@ pub enum OutputTheme {
607604
Unicode,
608605
}
609606

610-
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
607+
/// Handles the writing of `HumanReadableErrorType`
611608
#[derive(Setters)]
612609
pub struct HumanEmitter {
613610
#[setters(skip)]

compiler/rustc_errors/src/json.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use serde::Serialize;
2828
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
2929
use crate::diagnostic::IsLint;
3030
use crate::emitter::{
31-
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
32-
TimingEvent, should_show_source_code,
31+
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
32+
should_show_source_code,
3333
};
3434
use crate::registry::Registry;
3535
use crate::timings::{TimingRecord, TimingSection};
@@ -378,38 +378,17 @@ impl Diagnostic {
378378
choice => choice,
379379
},
380380
);
381-
match je.json_rendered {
382-
HumanReadableErrorType::AnnotateSnippet { short, unicode } => {
383-
AnnotateSnippetEmitter::new(dst, je.translator.clone())
384-
.short_message(short)
385-
.sm(je.sm.clone())
386-
.diagnostic_width(je.diagnostic_width)
387-
.macro_backtrace(je.macro_backtrace)
388-
.track_diagnostics(je.track_diagnostics)
389-
.terminal_url(je.terminal_url)
390-
.ui_testing(je.ui_testing)
391-
.ignored_directories_in_source_blocks(
392-
je.ignored_directories_in_source_blocks.clone(),
393-
)
394-
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
395-
.emit_diagnostic(diag, registry)
396-
}
397-
HumanReadableErrorType::Default { short } => {
398-
HumanEmitter::new(dst, je.translator.clone())
399-
.short_message(short)
400-
.sm(je.sm.clone())
401-
.diagnostic_width(je.diagnostic_width)
402-
.macro_backtrace(je.macro_backtrace)
403-
.track_diagnostics(je.track_diagnostics)
404-
.terminal_url(je.terminal_url)
405-
.ui_testing(je.ui_testing)
406-
.ignored_directories_in_source_blocks(
407-
je.ignored_directories_in_source_blocks.clone(),
408-
)
409-
.theme(OutputTheme::Ascii)
410-
.emit_diagnostic(diag, registry)
411-
}
412-
}
381+
AnnotateSnippetEmitter::new(dst, je.translator.clone())
382+
.short_message(je.json_rendered.short)
383+
.sm(je.sm.clone())
384+
.diagnostic_width(je.diagnostic_width)
385+
.macro_backtrace(je.macro_backtrace)
386+
.track_diagnostics(je.track_diagnostics)
387+
.terminal_url(je.terminal_url)
388+
.ui_testing(je.ui_testing)
389+
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
390+
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
391+
.emit_diagnostic(diag, registry);
413392

414393
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
415394
let buf = String::from_utf8(buf).unwrap();

compiler/rustc_errors/src/json/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
5454
Some(sm),
5555
translator,
5656
true, // pretty
57-
HumanReadableErrorType::Default { short: true },
57+
HumanReadableErrorType { short: true, unicode: false },
5858
ColorConfig::Never,
5959
);
6060

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn test_search_paths_tracking_hash_different_order() {
321321
let early_dcx = EarlyDiagCtxt::new(JSON);
322322
const JSON: ErrorOutputType = ErrorOutputType::Json {
323323
pretty: false,
324-
json_rendered: HumanReadableErrorType::Default { short: false },
324+
json_rendered: HumanReadableErrorType { short: false, unicode: false },
325325
color_config: ColorConfig::Never,
326326
};
327327

compiler/rustc_session/src/config.rs

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ pub enum ErrorOutputType {
806806
/// Output meant for the consumption of humans.
807807
#[default]
808808
HumanReadable {
809-
kind: HumanReadableErrorType = HumanReadableErrorType::Default { short: false },
809+
kind: HumanReadableErrorType = HumanReadableErrorType { short: false, unicode: false },
810810
color_config: ColorConfig = ColorConfig::Auto,
811811
},
812812
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
@@ -1965,16 +1965,8 @@ impl JsonUnusedExterns {
19651965
///
19661966
/// The first value returned is how to render JSON diagnostics, and the second
19671967
/// is whether or not artifact notifications are enabled.
1968-
pub fn parse_json(
1969-
early_dcx: &EarlyDiagCtxt,
1970-
matches: &getopts::Matches,
1971-
is_nightly_build: bool,
1972-
) -> JsonConfig {
1973-
let mut json_rendered = if is_nightly_build {
1974-
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
1975-
} else {
1976-
HumanReadableErrorType::Default { short: false }
1977-
};
1968+
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
1969+
let mut json_rendered = HumanReadableErrorType { short: false, unicode: false };
19781970
let mut json_color = ColorConfig::Never;
19791971
let mut json_artifact_notifications = false;
19801972
let mut json_unused_externs = JsonUnusedExterns::No;
@@ -1991,15 +1983,10 @@ pub fn parse_json(
19911983
for sub_option in option.split(',') {
19921984
match sub_option {
19931985
"diagnostic-short" => {
1994-
json_rendered = if is_nightly_build {
1995-
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
1996-
} else {
1997-
HumanReadableErrorType::Default { short: true }
1998-
};
1986+
json_rendered = HumanReadableErrorType { short: true, unicode: false };
19991987
}
20001988
"diagnostic-unicode" => {
2001-
json_rendered =
2002-
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true };
1989+
json_rendered = HumanReadableErrorType { short: false, unicode: true };
20031990
}
20041991
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
20051992
"artifacts" => json_artifact_notifications = true,
@@ -2029,13 +2016,8 @@ pub fn parse_error_format(
20292016
color_config: ColorConfig,
20302017
json_color: ColorConfig,
20312018
json_rendered: HumanReadableErrorType,
2032-
is_nightly_build: bool,
20332019
) -> ErrorOutputType {
2034-
let default_kind = if is_nightly_build {
2035-
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
2036-
} else {
2037-
HumanReadableErrorType::Default { short: false }
2038-
};
2020+
let default_kind = HumanReadableErrorType { short: false, unicode: false };
20392021
// We need the `opts_present` check because the driver will send us Matches
20402022
// with only stable options if no unstable options are used. Since error-format
20412023
// is unstable, it will not be present. We have to use `opts_present` not
@@ -2045,26 +2027,18 @@ pub fn parse_error_format(
20452027
None | Some("human") => {
20462028
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
20472029
}
2048-
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
2049-
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false },
2050-
color_config,
2051-
},
20522030
Some("json") => {
20532031
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
20542032
}
20552033
Some("pretty-json") => {
20562034
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
20572035
}
20582036
Some("short") => ErrorOutputType::HumanReadable {
2059-
kind: if is_nightly_build {
2060-
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
2061-
} else {
2062-
HumanReadableErrorType::Default { short: true }
2063-
},
2037+
kind: HumanReadableErrorType { short: true, unicode: false },
20642038
color_config,
20652039
},
20662040
Some("human-unicode") => ErrorOutputType::HumanReadable {
2067-
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true },
2041+
kind: HumanReadableErrorType { short: false, unicode: true },
20682042
color_config,
20692043
},
20702044
Some(arg) => {
@@ -2073,8 +2047,8 @@ pub fn parse_error_format(
20732047
kind: default_kind,
20742048
});
20752049
early_dcx.early_fatal(format!(
2076-
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
2077-
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
2050+
"argument for `--error-format` must be `human`, `human-unicode`, \
2051+
`json`, `pretty-json` or `short` (instead was `{arg}`)"
20782052
))
20792053
}
20802054
}
@@ -2136,8 +2110,7 @@ fn check_error_format_stability(
21362110
let format = match format {
21372111
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
21382112
ErrorOutputType::HumanReadable { kind, .. } => match kind {
2139-
HumanReadableErrorType::AnnotateSnippet { unicode: false, .. } => "human-annotate-rs",
2140-
HumanReadableErrorType::AnnotateSnippet { unicode: true, .. } => "human-unicode",
2113+
HumanReadableErrorType { unicode: true, .. } => "human-unicode",
21412114
_ => return,
21422115
},
21432116
_ => return,
@@ -2465,16 +2438,9 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24652438
json_timings,
24662439
json_unused_externs,
24672440
json_future_incompat,
2468-
} = parse_json(early_dcx, matches, unstable_features.is_nightly_build());
2441+
} = parse_json(early_dcx, matches);
24692442

2470-
let error_format = parse_error_format(
2471-
early_dcx,
2472-
matches,
2473-
color,
2474-
json_color,
2475-
json_rendered,
2476-
unstable_features.is_nightly_build(),
2477-
);
2443+
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);
24782444

24792445
early_dcx.set_error_format(error_format);
24802446

compiler/rustc_session/src/session.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
1313
use rustc_data_structures::sync::{DynSend, DynSync, Lock, MappedReadGuard, ReadGuard, RwLock};
1414
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
1515
use rustc_errors::codes::*;
16-
use rustc_errors::emitter::{
17-
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
18-
};
16+
use rustc_errors::emitter::{DynEmitter, HumanReadableErrorType, OutputTheme, stderr_destination};
1917
use rustc_errors::json::JsonEmitter;
2018
use rustc_errors::timings::TimingSectionHandler;
2119
use rustc_errors::translation::Translator;
@@ -920,7 +918,7 @@ fn default_emitter(
920918

921919
match sopts.error_format {
922920
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
923-
HumanReadableErrorType::AnnotateSnippet { short, unicode } => {
921+
HumanReadableErrorType { short, unicode } => {
924922
let emitter =
925923
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
926924
.sm(source_map)
@@ -938,20 +936,6 @@ fn default_emitter(
938936
);
939937
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
940938
}
941-
HumanReadableErrorType::Default { short } => {
942-
let emitter = HumanEmitter::new(stderr_destination(color_config), translator)
943-
.sm(source_map)
944-
.short_message(short)
945-
.diagnostic_width(sopts.diagnostic_width)
946-
.macro_backtrace(macro_backtrace)
947-
.track_diagnostics(track_diagnostics)
948-
.terminal_url(terminal_url)
949-
.theme(OutputTheme::Ascii)
950-
.ignored_directories_in_source_blocks(
951-
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
952-
);
953-
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
954-
}
955939
},
956940
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => Box::new(
957941
JsonEmitter::new(
@@ -1460,16 +1444,11 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
14601444
Translator::with_fallback_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
14611445
let emitter: Box<DynEmitter> = match output {
14621446
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
1463-
HumanReadableErrorType::AnnotateSnippet { short, unicode } => Box::new(
1447+
HumanReadableErrorType { short, unicode } => Box::new(
14641448
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
14651449
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
14661450
.short_message(short),
14671451
),
1468-
HumanReadableErrorType::Default { short } => Box::new(
1469-
HumanEmitter::new(stderr_destination(color_config), translator)
1470-
.theme(OutputTheme::Ascii)
1471-
.short_message(short),
1472-
),
14731452
},
14741453
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {
14751454
Box::new(JsonEmitter::new(

src/librustdoc/config.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,9 @@ impl Options {
404404
let unstable_features =
405405
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
406406
let config::JsonConfig { json_rendered, json_unused_externs, json_color, .. } =
407-
config::parse_json(early_dcx, matches, unstable_features.is_nightly_build());
408-
let error_format = config::parse_error_format(
409-
early_dcx,
410-
matches,
411-
color,
412-
json_color,
413-
json_rendered,
414-
unstable_features.is_nightly_build(),
415-
);
407+
config::parse_json(early_dcx, matches);
408+
let error_format =
409+
config::parse_error_format(early_dcx, matches, color, json_color, json_rendered);
416410
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();
417411

418412
let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();

src/librustdoc/core.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_driver::USING_INTERNAL_FEATURES;
77
use rustc_errors::TerminalUrl;
88
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
99
use rustc_errors::codes::*;
10-
use rustc_errors::emitter::{
11-
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
12-
};
10+
use rustc_errors::emitter::{DynEmitter, HumanReadableErrorType, OutputTheme, stderr_destination};
1311
use rustc_errors::json::JsonEmitter;
1412
use rustc_feature::UnstableFeatures;
1513
use rustc_hir::def::Res;
@@ -162,7 +160,7 @@ pub(crate) fn new_dcx(
162160
let translator = rustc_driver::default_translator();
163161
let emitter: Box<DynEmitter> = match error_format {
164162
ErrorOutputType::HumanReadable { kind, color_config } => match kind {
165-
HumanReadableErrorType::AnnotateSnippet { short, unicode } => Box::new(
163+
HumanReadableErrorType { short, unicode } => Box::new(
166164
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
167165
.sm(source_map.map(|sm| sm as _))
168166
.short_message(short)
@@ -171,15 +169,6 @@ pub(crate) fn new_dcx(
171169
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
172170
.ui_testing(unstable_opts.ui_testing),
173171
),
174-
HumanReadableErrorType::Default { short } => Box::new(
175-
HumanEmitter::new(stderr_destination(color_config), translator)
176-
.sm(source_map.map(|sm| sm as _))
177-
.short_message(short)
178-
.diagnostic_width(diagnostic_width)
179-
.track_diagnostics(unstable_opts.track_diagnostics)
180-
.theme(OutputTheme::Ascii)
181-
.ui_testing(unstable_opts.ui_testing),
182-
),
183172
},
184173
ErrorOutputType::Json { pretty, json_rendered, color_config } => {
185174
let source_map = source_map.unwrap_or_else(|| {

src/librustdoc/doctest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ fn run_test(
625625
]);
626626
if let ErrorOutputType::HumanReadable { kind, color_config } = rustdoc_options.error_format {
627627
let short = kind.short();
628-
let unicode = kind == HumanReadableErrorType::AnnotateSnippet { unicode: true, short };
628+
let unicode = kind == HumanReadableErrorType { unicode: true, short };
629629

630630
if short {
631631
compiler_args.extend_from_slice(&["--error-format".to_owned(), "short".to_owned()]);

0 commit comments

Comments
 (0)