Rollup merge of #114018 - Enselic:multi-annotation, r=b-naber

Make `--error-format human-annotate-rs` handle multiple files

Closes #64205 which is E-help-wanted
This commit is contained in:
Matthias Krüger 2023-07-30 14:25:09 +02:00 committed by GitHub
commit 427f3d3266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 7 deletions

View File

@ -157,10 +157,8 @@ fn emit_messages_default(
{ {
annotated_files.swap(0, pos); annotated_files.swap(0, pos);
} }
// owned: line source, line index, annotations // owned: file name, line source, line index, annotations
type Owned = (String, usize, Vec<crate::snippet::Annotation>); type Owned = (String, String, usize, Vec<crate::snippet::Annotation>);
let filename = source_map.filename_for_diagnostics(&primary_lo.file.name);
let origin = filename.to_string_lossy();
let annotated_files: Vec<Owned> = annotated_files let annotated_files: Vec<Owned> = annotated_files
.into_iter() .into_iter()
.flat_map(|annotated_file| { .flat_map(|annotated_file| {
@ -169,7 +167,15 @@ fn emit_messages_default(
.lines .lines
.into_iter() .into_iter()
.map(|line| { .map(|line| {
(source_string(file.clone(), &line), line.line_index, line.annotations) // Ensure the source file is present before we try
// to load a string from it.
source_map.ensure_source_file_source_present(file.clone());
(
format!("{}", source_map.filename_for_diagnostics(&file.name)),
source_string(file.clone(), &line),
line.line_index,
line.annotations,
)
}) })
.collect::<Vec<Owned>>() .collect::<Vec<Owned>>()
}) })
@ -192,11 +198,11 @@ fn emit_messages_default(
}, },
slices: annotated_files slices: annotated_files
.iter() .iter()
.map(|(source, line_index, annotations)| { .map(|(file_name, source, line_index, annotations)| {
Slice { Slice {
source, source,
line_start: *line_index, line_start: *line_index,
origin: Some(&origin), origin: Some(&file_name),
// FIXME(#59346): Not really sure when `fold` should be true or false // FIXME(#59346): Not really sure when `fold` should be true or false
fold: false, fold: false,
annotations: annotations annotations: annotations

View File

@ -0,0 +1,6 @@
pub struct WithPrivateMethod;
impl WithPrivateMethod {
/// Private to get an error involving two files
fn private_method(&self) {}
}

View File

@ -0,0 +1,8 @@
// aux-build:other_file.rs
// compile-flags: --error-format human-annotate-rs -Z unstable-options
extern crate other_file;
fn main() {
other_file::WithPrivateMethod.private_method();
}

View File

@ -0,0 +1,11 @@
error[E0624]: method `private_method` is private
--> $DIR/multiple-files.rs:7:35
|
LL | other_file::WithPrivateMethod.private_method();
| ^^^^^^^^^^^^^^ private method
|
::: $DIR/auxiliary/other_file.rs:5:5
|
LL | fn private_method(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ private method defined here
|