From 5b153b52a25dfe4c9592dd6c9f47582018b4fa61 Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 30 Dec 2023 18:11:41 +0300 Subject: [PATCH 1/2] annotate-snippets: update to 0.10 --- Cargo.lock | 22 ++++++++++++++----- compiler/rustc_errors/Cargo.toml | 2 +- .../src/annotate_snippet_emitter_writer.rs | 11 +++------- compiler/rustc_fluent_macro/Cargo.toml | 2 +- compiler/rustc_fluent_macro/src/fluent.rs | 10 +++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8192e333fe91..6ceadaa09a450 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,16 @@ dependencies = [ "yansi-term", ] +[[package]] +name = "annotate-snippets" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a433302f833baa830c0092100c481c7ea768c5981a3c36f549517a502f246dd" +dependencies = [ + "anstyle", + "unicode-width", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -3770,7 +3780,7 @@ dependencies = [ name = "rustc_errors" version = "0.0.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.10.1", "derive_setters", "rustc_ast", "rustc_ast_pretty", @@ -3831,7 +3841,7 @@ dependencies = [ name = "rustc_fluent_macro" version = "0.0.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.10.1", "fluent-bundle", "fluent-syntax", "proc-macro2", @@ -4736,7 +4746,7 @@ dependencies = [ name = "rustfmt-nightly" version = "1.7.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.9.1", "anyhow", "bytecount", "cargo_metadata 0.15.4", @@ -5726,7 +5736,7 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf4bf7c184b8dfc7a4d3b90df789b1eb992ee42811cd115f32a7a1eb781058d" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.9.1", "anyhow", "bstr", "cargo-platform", @@ -5857,9 +5867,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index fc3ff835a8136..0c1fcecb57173 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -annotate-snippets = "0.9" +annotate-snippets = "0.10" derive_setters = "0.1.6" rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 5c0e210f1472b..e59188b3a9386 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -12,8 +12,7 @@ use crate::{ CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage, Emitter, FluentBundle, LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic, }; -use annotate_snippets::display_list::{DisplayList, FormatOptions}; -use annotate_snippets::snippet::*; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use rustc_data_structures::sync::Lrc; use rustc_error_messages::FluentArgs; use rustc_span::source_map::SourceMap; @@ -190,11 +189,6 @@ impl AnnotateSnippetEmitter { annotation_type: annotation_type_for_level(*level), }), footer: vec![], - opt: FormatOptions { - color: true, - anonymized_line_numbers: self.ui_testing, - margin: None, - }, slices: annotated_files .iter() .map(|(file_name, source, line_index, annotations)| { @@ -222,7 +216,8 @@ impl AnnotateSnippetEmitter { // FIXME(#59346): Figure out if we can _always_ print to stderr or not. // `emitter.rs` has the `Destination` enum that lists various possible output // destinations. - eprintln!("{}", DisplayList::from(snippet)) + let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing); + eprintln!("{}", renderer.render(snippet)) } // FIXME(#59346): Is it ok to return None if there's no source_map? } diff --git a/compiler/rustc_fluent_macro/Cargo.toml b/compiler/rustc_fluent_macro/Cargo.toml index 872dd29a7a8ac..c5a53ae831355 100644 --- a/compiler/rustc_fluent_macro/Cargo.toml +++ b/compiler/rustc_fluent_macro/Cargo.toml @@ -8,7 +8,7 @@ proc-macro = true [dependencies] # tidy-alphabetical-start -annotate-snippets = "0.9" +annotate-snippets = "0.10" fluent-bundle = "0.15.2" fluent-syntax = "0.11" proc-macro2 = "1" diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs index 3b1b63455eddd..520a64aaf5e23 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -1,7 +1,4 @@ -use annotate_snippets::{ - display_list::DisplayList, - snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}, -}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use fluent_bundle::{FluentBundle, FluentError, FluentResource}; use fluent_syntax::{ ast::{ @@ -179,10 +176,9 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok range: (pos.start, pos.end - 1), }], }], - opt: Default::default(), }; - let dl = DisplayList::from(snippet); - eprintln!("{dl}\n"); + let renderer = Renderer::plain(); + eprintln!("{}\n", renderer.render(snippet)); } return failed(&crate_name); From 46cf55ac6fa8d0e45e1d4f47cc9d9dd467da90d4 Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 30 Dec 2023 20:13:25 +0300 Subject: [PATCH 2/2] tidy: add\remove deps --- src/tools/tidy/src/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 3c00027b9fdc9..f6769877a19aa 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -194,6 +194,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "aho-corasick", "allocator-api2", // FIXME: only appears in Cargo.lock due to https://github.com/rust-lang/cargo/issues/10801 "annotate-snippets", + "anstyle", "ar_archive_writer", "arrayvec", "autocfg", @@ -390,7 +391,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "windows_x86_64_gnullvm", "windows_x86_64_msvc", "writeable", - "yansi-term", // this is a false-positive: it's only used by rustfmt, but because it's enabled through a feature, tidy thinks it's used by rustc as well. "yoke", "yoke-derive", "zerocopy",