diff options
Diffstat (limited to 'compiler/rustc_errors/src/emitter.rs')
-rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0cae06881..d322cbe9d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -8,7 +8,7 @@ //! The output types are defined in `rustc_session::config::ErrorOutputType`. use rustc_span::source_map::SourceMap; -use rustc_span::{FileLines, SourceFile, Span}; +use rustc_span::{FileLines, FileName, SourceFile, Span}; use crate::snippet::{ Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString, @@ -24,7 +24,7 @@ use rustc_lint_defs::pluralize; use derive_setters::Setters; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; -use rustc_data_structures::sync::Lrc; +use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc}; use rustc_error_messages::{FluentArgs, SpanLabel}; use rustc_span::hygiene::{ExpnKind, MacroKind}; use std::borrow::Cow; @@ -188,6 +188,8 @@ impl Margin { const ANONYMIZED_LINE_NUM: &str = "LL"; +pub type DynEmitter = dyn Emitter + DynSend; + /// Emitter trait for emitting errors. pub trait Emitter: Translate { /// Emit a structured diagnostic. @@ -625,7 +627,7 @@ impl ColorConfig { #[derive(Setters)] pub struct EmitterWriter { #[setters(skip)] - dst: Destination, + dst: IntoDynSyncSend<Destination>, sm: Option<Lrc<SourceMap>>, fluent_bundle: Option<Lrc<FluentBundle>>, #[setters(skip)] @@ -633,6 +635,7 @@ pub struct EmitterWriter { short_message: bool, teach: bool, ui_testing: bool, + ignored_directories_in_source_blocks: Vec<String>, diagnostic_width: Option<usize>, macro_backtrace: bool, @@ -655,13 +658,14 @@ impl EmitterWriter { fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> EmitterWriter { EmitterWriter { - dst, + dst: IntoDynSyncSend(dst), sm: None, fluent_bundle: None, fallback_bundle, short_message: false, teach: false, ui_testing: false, + ignored_directories_in_source_blocks: Vec::new(), diagnostic_width: None, macro_backtrace: false, track_diagnostics: false, @@ -1191,7 +1195,7 @@ impl EmitterWriter { let will_be_emitted = |span: Span| { !span.is_dummy() && { let file = sm.lookup_source_file(span.hi()); - sm.ensure_source_file_source_present(file) + should_show_source_code(&self.ignored_directories_in_source_blocks, sm, &file) } }; @@ -1386,7 +1390,11 @@ impl EmitterWriter { // Print out the annotate source lines that correspond with the error for annotated_file in annotated_files { // we can't annotate anything if the source is unavailable. - if !sm.ensure_source_file_source_present(annotated_file.file.clone()) { + if !should_show_source_code( + &self.ignored_directories_in_source_blocks, + sm, + &annotated_file.file, + ) { if !self.short_message { // We'll just print an unannotated message. for (annotation_id, line) in annotated_file.lines.iter().enumerate() { @@ -2346,7 +2354,13 @@ impl FileWithAnnotatedLines { } let label = label.as_ref().map(|m| { - emitter.translate_message(m, args).map_err(Report::new).unwrap().to_string() + normalize_whitespace( + &emitter + .translate_message(m, &args) + .map_err(Report::new) + .unwrap() + .to_string(), + ) }); if lo.line != hi.line { @@ -2729,3 +2743,18 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool { // bug, but be defensive against that here. && found != suggested } + +pub(crate) fn should_show_source_code( + ignored_directories: &[String], + sm: &SourceMap, + file: &SourceFile, +) -> bool { + if !sm.ensure_source_file_source_present(file) { + return false; + } + + let FileName::Real(name) = &file.name else { return true }; + name.local_path() + .map(|path| ignored_directories.iter().all(|dir| !path.starts_with(dir))) + .unwrap_or(true) +} |