|
8 | 8 | //! The output types are defined in `rustc_session::config::ErrorOutputType`.
|
9 | 9 |
|
10 | 10 | use rustc_span::source_map::SourceMap;
|
11 |
| -use rustc_span::{FileLines, SourceFile, Span}; |
| 11 | +use rustc_span::{FileLines, FileName, SourceFile, Span}; |
12 | 12 |
|
13 | 13 | use crate::snippet::{
|
14 | 14 | Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
|
@@ -635,6 +635,7 @@ pub struct EmitterWriter {
|
635 | 635 | short_message: bool,
|
636 | 636 | teach: bool,
|
637 | 637 | ui_testing: bool,
|
| 638 | + ignored_directories_in_source_blocks: Vec<String>, |
638 | 639 | diagnostic_width: Option<usize>,
|
639 | 640 |
|
640 | 641 | macro_backtrace: bool,
|
@@ -664,6 +665,7 @@ impl EmitterWriter {
|
664 | 665 | short_message: false,
|
665 | 666 | teach: false,
|
666 | 667 | ui_testing: false,
|
| 668 | + ignored_directories_in_source_blocks: Vec::new(), |
667 | 669 | diagnostic_width: None,
|
668 | 670 | macro_backtrace: false,
|
669 | 671 | track_diagnostics: false,
|
@@ -1193,7 +1195,7 @@ impl EmitterWriter {
|
1193 | 1195 | let will_be_emitted = |span: Span| {
|
1194 | 1196 | !span.is_dummy() && {
|
1195 | 1197 | let file = sm.lookup_source_file(span.hi());
|
1196 |
| - sm.ensure_source_file_source_present(&file) |
| 1198 | + should_show_source_code(&self.ignored_directories_in_source_blocks, sm, &file) |
1197 | 1199 | }
|
1198 | 1200 | };
|
1199 | 1201 |
|
@@ -1388,7 +1390,11 @@ impl EmitterWriter {
|
1388 | 1390 | // Print out the annotate source lines that correspond with the error
|
1389 | 1391 | for annotated_file in annotated_files {
|
1390 | 1392 | // we can't annotate anything if the source is unavailable.
|
1391 |
| - if !sm.ensure_source_file_source_present(&annotated_file.file) { |
| 1393 | + if !should_show_source_code( |
| 1394 | + &self.ignored_directories_in_source_blocks, |
| 1395 | + sm, |
| 1396 | + &annotated_file.file, |
| 1397 | + ) { |
1392 | 1398 | if !self.short_message {
|
1393 | 1399 | // We'll just print an unannotated message.
|
1394 | 1400 | for (annotation_id, line) in annotated_file.lines.iter().enumerate() {
|
@@ -2737,3 +2743,18 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
|
2737 | 2743 | // bug, but be defensive against that here.
|
2738 | 2744 | && found != suggested
|
2739 | 2745 | }
|
| 2746 | + |
| 2747 | +pub(crate) fn should_show_source_code( |
| 2748 | + ignored_directories: &[String], |
| 2749 | + sm: &SourceMap, |
| 2750 | + file: &SourceFile, |
| 2751 | +) -> bool { |
| 2752 | + if !sm.ensure_source_file_source_present(file) { |
| 2753 | + return false; |
| 2754 | + } |
| 2755 | + |
| 2756 | + let FileName::Real(name) = &file.name else { return true }; |
| 2757 | + name.local_path() |
| 2758 | + .map(|path| ignored_directories.iter().all(|dir| !path.starts_with(dir))) |
| 2759 | + .unwrap_or(true) |
| 2760 | +} |
0 commit comments