Skip to content

Commit 43a1ca5

Browse files
authored
Rollup merge of rust-lang#129277 - Xiretza:update-annotate-snippets, r=fee1-dead
Update annotate-snippets to 0.11
2 parents d502b1c + c864238 commit 43a1ca5

File tree

5 files changed

+42
-75
lines changed

5 files changed

+42
-75
lines changed

Cargo.lock

+2-12
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ dependencies = [
9494
"yansi-term",
9595
]
9696

97-
[[package]]
98-
name = "annotate-snippets"
99-
version = "0.10.2"
100-
source = "registry+https://github.com/rust-lang/crates.io-index"
101-
checksum = "6d9b665789884a7e8fb06c84b295e923b03ca51edbb7d08f91a6a50322ecbfe6"
102-
dependencies = [
103-
"anstyle",
104-
"unicode-width",
105-
]
106-
10797
[[package]]
10898
name = "annotate-snippets"
10999
version = "0.11.4"
@@ -3642,7 +3632,7 @@ dependencies = [
36423632
name = "rustc_errors"
36433633
version = "0.0.0"
36443634
dependencies = [
3645-
"annotate-snippets 0.10.2",
3635+
"annotate-snippets 0.11.4",
36463636
"derive_setters",
36473637
"rustc_ast",
36483638
"rustc_ast_pretty",
@@ -3702,7 +3692,7 @@ dependencies = [
37023692
name = "rustc_fluent_macro"
37033693
version = "0.0.0"
37043694
dependencies = [
3705-
"annotate-snippets 0.10.2",
3695+
"annotate-snippets 0.11.4",
37063696
"fluent-bundle",
37073697
"fluent-syntax",
37083698
"proc-macro2",

compiler/rustc_errors/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
annotate-snippets = "0.10"
8+
annotate-snippets = "0.11"
99
derive_setters = "0.1.6"
1010
rustc_ast = { path = "../rustc_ast" }
1111
rustc_ast_pretty = { path = "../rustc_ast_pretty" }

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+29-40
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/
77
8-
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
8+
use annotate_snippets::{Renderer, Snippet};
99
use rustc_data_structures::sync::Lrc;
1010
use rustc_error_messages::FluentArgs;
1111
use rustc_span::source_map::SourceMap;
@@ -83,15 +83,17 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8383
file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or_default()
8484
}
8585

86-
/// Maps `diagnostic::Level` to `snippet::AnnotationType`
87-
fn annotation_type_for_level(level: Level) -> AnnotationType {
86+
/// Maps [`crate::Level`] to [`annotate_snippets::Level`]
87+
fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
8888
match level {
89-
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => AnnotationType::Error,
90-
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
91-
Level::Note | Level::OnceNote => AnnotationType::Note,
92-
Level::Help | Level::OnceHelp => AnnotationType::Help,
89+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
90+
annotate_snippets::Level::Error
91+
}
92+
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
93+
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
94+
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
9395
// FIXME(#59346): Not sure how to map this level
94-
Level::FailureNote => AnnotationType::Error,
96+
Level::FailureNote => annotate_snippets::Level::Error,
9597
Level::Allow => panic!("Should not call with Allow"),
9698
Level::Expect(_) => panic!("Should not call with Expect"),
9799
}
@@ -180,42 +182,29 @@ impl AnnotateSnippetEmitter {
180182
})
181183
.collect();
182184
let code = code.map(|code| code.to_string());
183-
let snippet = Snippet {
184-
title: Some(Annotation {
185-
label: Some(&message),
186-
id: code.as_deref(),
187-
annotation_type: annotation_type_for_level(*level),
188-
}),
189-
footer: vec![],
190-
slices: annotated_files
191-
.iter()
192-
.map(|(file_name, source, line_index, annotations)| {
193-
Slice {
194-
source,
195-
line_start: *line_index,
196-
origin: Some(file_name),
197-
// FIXME(#59346): Not really sure when `fold` should be true or false
198-
fold: false,
199-
annotations: annotations
200-
.iter()
201-
.map(|annotation| SourceAnnotation {
202-
range: (
203-
annotation.start_col.display,
204-
annotation.end_col.display,
205-
),
206-
label: annotation.label.as_deref().unwrap_or_default(),
207-
annotation_type: annotation_type_for_level(*level),
208-
})
209-
.collect(),
210-
}
211-
})
212-
.collect(),
213-
};
185+
186+
let snippets =
187+
annotated_files.iter().map(|(file_name, source, line_index, annotations)| {
188+
Snippet::source(source)
189+
.line_start(*line_index)
190+
.origin(file_name)
191+
// FIXME(#59346): Not really sure when `fold` should be true or false
192+
.fold(false)
193+
.annotations(annotations.iter().map(|annotation| {
194+
annotation_level_for_level(*level)
195+
.span(annotation.start_col.display..annotation.end_col.display)
196+
.label(annotation.label.as_deref().unwrap_or_default())
197+
}))
198+
});
199+
let mut message = annotation_level_for_level(*level).title(&message).snippets(snippets);
200+
if let Some(code) = code.as_deref() {
201+
message = message.id(code)
202+
}
214203
// FIXME(#59346): Figure out if we can _always_ print to stderr or not.
215204
// `emitter.rs` has the `Destination` enum that lists various possible output
216205
// destinations.
217206
let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing);
218-
eprintln!("{}", renderer.render(snippet))
207+
eprintln!("{}", renderer.render(message))
219208
}
220209
// FIXME(#59346): Is it ok to return None if there's no source_map?
221210
}

compiler/rustc_fluent_macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ proc-macro = true
88

99
[dependencies]
1010
# tidy-alphabetical-start
11-
annotate-snippets = "0.10"
11+
annotate-snippets = "0.11"
1212
fluent-bundle = "0.15.2"
1313
fluent-syntax = "0.11"
1414
proc-macro2 = "1"

compiler/rustc_fluent_macro/src/fluent.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
22
use std::fs::read_to_string;
33
use std::path::{Path, PathBuf};
44

5-
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
5+
use annotate_snippets::{Renderer, Snippet};
66
use fluent_bundle::{FluentBundle, FluentError, FluentResource};
77
use fluent_syntax::ast::{
88
Attribute, Entry, Expression, Identifier, InlineExpression, Message, Pattern, PatternElement,
@@ -154,27 +154,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
154154
.unwrap()
155155
.0;
156156

157-
let snippet = Snippet {
158-
title: Some(Annotation {
159-
label: Some(&err),
160-
id: None,
161-
annotation_type: AnnotationType::Error,
162-
}),
163-
footer: vec![],
164-
slices: vec![Slice {
165-
source: this.source(),
166-
line_start,
167-
origin: Some(&relative_ftl_path),
168-
fold: true,
169-
annotations: vec![SourceAnnotation {
170-
label: "",
171-
annotation_type: AnnotationType::Error,
172-
range: (pos.start, pos.end - 1),
173-
}],
174-
}],
175-
};
157+
let message = annotate_snippets::Level::Error.title(&err).snippet(
158+
Snippet::source(this.source())
159+
.line_start(line_start)
160+
.origin(&relative_ftl_path)
161+
.fold(true)
162+
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),
163+
);
176164
let renderer = Renderer::plain();
177-
eprintln!("{}\n", renderer.render(snippet));
165+
eprintln!("{}\n", renderer.render(message));
178166
}
179167

180168
return failed(&crate_name);

0 commit comments

Comments
 (0)