Skip to content
Open
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
17 changes: 0 additions & 17 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,6 @@ impl AnnotateSnippetEmitter {
}
}

let suggestions_expected = suggestions
.iter()
.filter(|s| {
matches!(
s.style,
SuggestionStyle::HideCodeInline
| SuggestionStyle::ShowCode
| SuggestionStyle::ShowAlways
)
})
.count();
for suggestion in suggestions {
match suggestion.style {
SuggestionStyle::CompletelyHidden => {
Expand Down Expand Up @@ -526,12 +515,6 @@ impl AnnotateSnippetEmitter {
}
}

// FIXME: This hack should be removed once annotate_snippets is the
// default emitter.
if suggestions_expected > 0 && report.is_empty() {
group = group.element(Padding);
}

if !group.is_empty() {
report.push(group);
}
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ const DEFAULT_COLUMN_WIDTH: usize = 140;

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

impl HumanReadableErrorType {
pub fn short(&self) -> bool {
match self {
HumanReadableErrorType::Default { short }
| HumanReadableErrorType::AnnotateSnippet { short, .. } => *short,
}
self.short
}
}

Expand Down Expand Up @@ -607,7 +604,7 @@ pub enum OutputTheme {
Unicode,
}

/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
/// Handles the writing of `HumanReadableErrorType`
#[derive(Setters)]
pub struct HumanEmitter {
#[setters(skip)]
Expand Down
47 changes: 13 additions & 34 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use serde::Serialize;
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
use crate::diagnostic::IsLint;
use crate::emitter::{
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
TimingEvent, should_show_source_code,
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
should_show_source_code,
};
use crate::registry::Registry;
use crate::timings::{TimingRecord, TimingSection};
Expand Down Expand Up @@ -378,38 +378,17 @@ impl Diagnostic {
choice => choice,
},
);
match je.json_rendered {
HumanReadableErrorType::AnnotateSnippet { short, unicode } => {
AnnotateSnippetEmitter::new(dst, je.translator.clone())
.short_message(short)
.sm(je.sm.clone())
.diagnostic_width(je.diagnostic_width)
.macro_backtrace(je.macro_backtrace)
.track_diagnostics(je.track_diagnostics)
.terminal_url(je.terminal_url)
.ui_testing(je.ui_testing)
.ignored_directories_in_source_blocks(
je.ignored_directories_in_source_blocks.clone(),
)
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.emit_diagnostic(diag, registry)
}
HumanReadableErrorType::Default { short } => {
HumanEmitter::new(dst, je.translator.clone())
.short_message(short)
.sm(je.sm.clone())
.diagnostic_width(je.diagnostic_width)
.macro_backtrace(je.macro_backtrace)
.track_diagnostics(je.track_diagnostics)
.terminal_url(je.terminal_url)
.ui_testing(je.ui_testing)
.ignored_directories_in_source_blocks(
je.ignored_directories_in_source_blocks.clone(),
)
.theme(OutputTheme::Ascii)
.emit_diagnostic(diag, registry)
}
}
AnnotateSnippetEmitter::new(dst, je.translator.clone())
.short_message(je.json_rendered.short)
.sm(je.sm.clone())
.diagnostic_width(je.diagnostic_width)
.macro_backtrace(je.macro_backtrace)
.track_diagnostics(je.track_diagnostics)
.terminal_url(je.terminal_url)
.ui_testing(je.ui_testing)
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.emit_diagnostic(diag, registry);

let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
let buf = String::from_utf8(buf).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
Some(sm),
translator,
true, // pretty
HumanReadableErrorType::Default { short: true },
HumanReadableErrorType { short: true, unicode: false },
ColorConfig::Never,
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn test_search_paths_tracking_hash_different_order() {
let early_dcx = EarlyDiagCtxt::new(JSON);
const JSON: ErrorOutputType = ErrorOutputType::Json {
pretty: false,
json_rendered: HumanReadableErrorType::Default { short: false },
json_rendered: HumanReadableErrorType { short: false, unicode: false },
color_config: ColorConfig::Never,
};

Expand Down
60 changes: 13 additions & 47 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ pub enum ErrorOutputType {
/// Output meant for the consumption of humans.
#[default]
HumanReadable {
kind: HumanReadableErrorType = HumanReadableErrorType::Default { short: false },
kind: HumanReadableErrorType = HumanReadableErrorType { short: false, unicode: false },
color_config: ColorConfig = ColorConfig::Auto,
},
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
Expand Down Expand Up @@ -1965,16 +1965,8 @@ impl JsonUnusedExterns {
///
/// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled.
pub fn parse_json(
early_dcx: &EarlyDiagCtxt,
matches: &getopts::Matches,
is_nightly_build: bool,
) -> JsonConfig {
let mut json_rendered = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
} else {
HumanReadableErrorType::Default { short: false }
};
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
let mut json_rendered = HumanReadableErrorType { short: false, unicode: false };
let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false;
let mut json_unused_externs = JsonUnusedExterns::No;
Expand All @@ -1991,15 +1983,10 @@ pub fn parse_json(
for sub_option in option.split(',') {
match sub_option {
"diagnostic-short" => {
json_rendered = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
} else {
HumanReadableErrorType::Default { short: true }
};
json_rendered = HumanReadableErrorType { short: true, unicode: false };
}
"diagnostic-unicode" => {
json_rendered =
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true };
json_rendered = HumanReadableErrorType { short: false, unicode: true };
}
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true,
Expand Down Expand Up @@ -2029,13 +2016,8 @@ pub fn parse_error_format(
color_config: ColorConfig,
json_color: ColorConfig,
json_rendered: HumanReadableErrorType,
is_nightly_build: bool,
) -> ErrorOutputType {
let default_kind = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
} else {
HumanReadableErrorType::Default { short: false }
};
let default_kind = HumanReadableErrorType { short: false, unicode: false };
// We need the `opts_present` check because the driver will send us Matches
// with only stable options if no unstable options are used. Since error-format
// is unstable, it will not be present. We have to use `opts_present` not
Expand All @@ -2045,26 +2027,18 @@ pub fn parse_error_format(
None | Some("human") => {
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
}
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false },
color_config,
},
Some("json") => {
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
}
Some("pretty-json") => {
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
}
Some("short") => ErrorOutputType::HumanReadable {
kind: if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
} else {
HumanReadableErrorType::Default { short: true }
},
kind: HumanReadableErrorType { short: true, unicode: false },
color_config,
},
Some("human-unicode") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true },
kind: HumanReadableErrorType { short: false, unicode: true },
color_config,
},
Some(arg) => {
Expand All @@ -2073,8 +2047,8 @@ pub fn parse_error_format(
kind: default_kind,
});
early_dcx.early_fatal(format!(
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
"argument for `--error-format` must be `human`, `human-unicode`, \
`json`, `pretty-json` or `short` (instead was `{arg}`)"
))
}
}
Expand Down Expand Up @@ -2136,8 +2110,7 @@ fn check_error_format_stability(
let format = match format {
ErrorOutputType::Json { pretty: true, .. } => "pretty-json",
ErrorOutputType::HumanReadable { kind, .. } => match kind {
HumanReadableErrorType::AnnotateSnippet { unicode: false, .. } => "human-annotate-rs",
HumanReadableErrorType::AnnotateSnippet { unicode: true, .. } => "human-unicode",
HumanReadableErrorType { unicode: true, .. } => "human-unicode",
_ => return,
},
_ => return,
Expand Down Expand Up @@ -2465,16 +2438,9 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
json_timings,
json_unused_externs,
json_future_incompat,
} = parse_json(early_dcx, matches, unstable_features.is_nightly_build());
} = parse_json(early_dcx, matches);

let error_format = parse_error_format(
early_dcx,
matches,
color,
json_color,
json_rendered,
unstable_features.is_nightly_build(),
);
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);

early_dcx.set_error_format(error_format);

Expand Down
27 changes: 3 additions & 24 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
use rustc_data_structures::sync::{DynSend, DynSync, Lock, MappedReadGuard, ReadGuard, RwLock};
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
use rustc_errors::codes::*;
use rustc_errors::emitter::{
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
};
use rustc_errors::emitter::{DynEmitter, HumanReadableErrorType, OutputTheme, stderr_destination};
use rustc_errors::json::JsonEmitter;
use rustc_errors::timings::TimingSectionHandler;
use rustc_errors::translation::Translator;
Expand Down Expand Up @@ -920,7 +918,7 @@ fn default_emitter(

match sopts.error_format {
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType::AnnotateSnippet { short, unicode } => {
HumanReadableErrorType { short, unicode } => {
let emitter =
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
.sm(source_map)
Expand All @@ -938,20 +936,6 @@ fn default_emitter(
);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
}
HumanReadableErrorType::Default { short } => {
let emitter = HumanEmitter::new(stderr_destination(color_config), translator)
.sm(source_map)
.short_message(short)
.diagnostic_width(sopts.diagnostic_width)
.macro_backtrace(macro_backtrace)
.track_diagnostics(track_diagnostics)
.terminal_url(terminal_url)
.theme(OutputTheme::Ascii)
.ignored_directories_in_source_blocks(
sopts.unstable_opts.ignore_directory_in_diagnostics_source_blocks.clone(),
);
Box::new(emitter.ui_testing(sopts.unstable_opts.ui_testing))
}
},
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => Box::new(
JsonEmitter::new(
Expand Down Expand Up @@ -1460,16 +1444,11 @@ fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
Translator::with_fallback_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false);
let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType::AnnotateSnippet { short, unicode } => Box::new(
HumanReadableErrorType { short, unicode } => Box::new(
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.short_message(short),
),
HumanReadableErrorType::Default { short } => Box::new(
HumanEmitter::new(stderr_destination(color_config), translator)
.theme(OutputTheme::Ascii)
.short_message(short),
),
},
config::ErrorOutputType::Json { pretty, json_rendered, color_config } => {
Box::new(JsonEmitter::new(
Expand Down
12 changes: 3 additions & 9 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,9 @@ impl Options {
let unstable_features =
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
let config::JsonConfig { json_rendered, json_unused_externs, json_color, .. } =
config::parse_json(early_dcx, matches, unstable_features.is_nightly_build());
let error_format = config::parse_error_format(
early_dcx,
matches,
color,
json_color,
json_rendered,
unstable_features.is_nightly_build(),
);
config::parse_json(early_dcx, matches);
let error_format =
config::parse_error_format(early_dcx, matches, color, json_color, json_rendered);
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();

let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();
Expand Down
15 changes: 2 additions & 13 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use rustc_driver::USING_INTERNAL_FEATURES;
use rustc_errors::TerminalUrl;
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
use rustc_errors::codes::*;
use rustc_errors::emitter::{
DynEmitter, HumanEmitter, HumanReadableErrorType, OutputTheme, stderr_destination,
};
use rustc_errors::emitter::{DynEmitter, HumanReadableErrorType, OutputTheme, stderr_destination};
use rustc_errors::json::JsonEmitter;
use rustc_feature::UnstableFeatures;
use rustc_hir::def::Res;
Expand Down Expand Up @@ -162,7 +160,7 @@ pub(crate) fn new_dcx(
let translator = rustc_driver::default_translator();
let emitter: Box<DynEmitter> = match error_format {
ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType::AnnotateSnippet { short, unicode } => Box::new(
HumanReadableErrorType { short, unicode } => Box::new(
AnnotateSnippetEmitter::new(stderr_destination(color_config), translator)
.sm(source_map.map(|sm| sm as _))
.short_message(short)
Expand All @@ -171,15 +169,6 @@ pub(crate) fn new_dcx(
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
.ui_testing(unstable_opts.ui_testing),
),
HumanReadableErrorType::Default { short } => Box::new(
HumanEmitter::new(stderr_destination(color_config), translator)
.sm(source_map.map(|sm| sm as _))
.short_message(short)
.diagnostic_width(diagnostic_width)
.track_diagnostics(unstable_opts.track_diagnostics)
.theme(OutputTheme::Ascii)
.ui_testing(unstable_opts.ui_testing),
),
},
ErrorOutputType::Json { pretty, json_rendered, color_config } => {
let source_map = source_map.unwrap_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn run_test(
]);
if let ErrorOutputType::HumanReadable { kind, color_config } = rustdoc_options.error_format {
let short = kind.short();
let unicode = kind == HumanReadableErrorType::AnnotateSnippet { unicode: true, short };
let unicode = kind == HumanReadableErrorType { unicode: true, short };

if short {
compiler_args.extend_from_slice(&["--error-format".to_owned(), "short".to_owned()]);
Expand Down
Loading
Loading