Skip to content

Commit 2c1ceea

Browse files
committed
Auto merge of rust-lang#147207 - Muscraft:anstyle-anstream, r=davidtwco
refactor: Move to anstream + anstyle for styling `rustc` uses [`termcolor`](https://crates.io/crates/termcolor) for styling and writing, while `annotate-snippets` uses [`anstyle`](https://crates.io/crates/anstyle) for styling and currently writes directly to a `String`. When rendering directly to a terminal, there isn't/shouldn't be any differences. Still, there are differences in the escape sequences, which leads to slightly different output in JSON and SVG tests. As part of my work to have `rustc` use `annotate-snippets`, and to reduce the test differences between the two, I switched `rustc` to use `anstlye` and [`anstream`](https://crates.io/crates/anstream) for styling and writing. The first commit migrates to `anstyle` and `anstream` and notably does not change the output. This is because it includes extra formatting to ensure that `anstyle` + `anstream` match the current output exactly. Most of this code is unnecessary, as it adds redundant resets or uses 256-color (8-bit) when it could be using 4-bit color. The subsequent commits remove this extra formatting while maintaining the correct output when rendered. [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/annotate-snippets.20hurdles)
2 parents 960c01f + b5c3ed0 commit 2c1ceea

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::doc::{NEEDLESS_DOCTEST_MAIN, TEST_ATTR_IN_DOCTEST};
66
use clippy_utils::diagnostics::span_lint;
77
use rustc_ast::{CoroutineKind, Fn, FnRetTy, Item, ItemKind};
88
use rustc_errors::emitter::HumanEmitter;
9-
use rustc_errors::{Diag, DiagCtxt};
9+
use rustc_errors::{AutoStream, Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
1111
use rustc_parse::lexer::StripTokens;
1212
use rustc_parse::new_parser_from_source_str;
@@ -44,7 +44,7 @@ pub fn check(
4444
let filename = FileName::anon_source_code(&code);
4545

4646
let translator = rustc_driver::default_translator();
47-
let emitter = HumanEmitter::new(Box::new(io::sink()), translator);
47+
let emitter = HumanEmitter::new(AutoStream::never(Box::new(io::sink())), translator);
4848
let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings();
4949
#[expect(clippy::arc_with_non_send_sync)] // `Arc` is expected by with_dcx
5050
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));

0 commit comments

Comments
 (0)