feat: Use annotate-snippets by default on nightly

This commit is contained in:
Scott Schafer 2025-10-14 19:19:46 -06:00
parent 9cb7deb0b5
commit 9243928c6c
No known key found for this signature in database
12 changed files with 113 additions and 71 deletions

View file

@ -2041,8 +2041,16 @@ impl JsonUnusedExterns {
///
/// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled.
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
let mut json_rendered = HumanReadableErrorType::Default { short: false };
pub fn parse_json(
early_dcx: &EarlyDiagCtxt,
matches: &getopts::Matches,
is_nightly_build: bool,
) -> JsonConfig {
let mut json_rendered = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
} else {
HumanReadableErrorType::Default { short: false }
};
let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false;
let mut json_unused_externs = JsonUnusedExterns::No;
@ -2059,7 +2067,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
for sub_option in option.split(',') {
match sub_option {
"diagnostic-short" => {
json_rendered = HumanReadableErrorType::Default { short: true }
json_rendered = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
} else {
HumanReadableErrorType::Default { short: true }
};
}
"diagnostic-unicode" => {
json_rendered =
@ -2093,14 +2105,22 @@ pub fn parse_error_format(
color_config: ColorConfig,
json_color: ColorConfig,
json_rendered: HumanReadableErrorType,
is_nightly_build: bool,
) -> ErrorOutputType {
let default_kind = if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
} else {
HumanReadableErrorType::Default { short: false }
};
// We need the `opts_present` check because the driver will send us Matches
// with only stable options if no unstable options are used. Since error-format
// is unstable, it will not be present. We have to use `opts_present` not
// `opt_present` because the latter will panic.
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
match matches.opt_str("error-format").as_deref() {
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
None | Some("human") => {
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
}
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false },
color_config,
@ -2112,7 +2132,11 @@ pub fn parse_error_format(
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
}
Some("short") => ErrorOutputType::HumanReadable {
kind: HumanReadableErrorType::Default { short: true },
kind: if is_nightly_build {
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
} else {
HumanReadableErrorType::Default { short: true }
},
color_config,
},
Some("human-unicode") => ErrorOutputType::HumanReadable {
@ -2120,7 +2144,10 @@ pub fn parse_error_format(
color_config,
},
Some(arg) => {
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
early_dcx.set_error_format(ErrorOutputType::HumanReadable {
color_config,
kind: default_kind,
});
early_dcx.early_fatal(format!(
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
@ -2128,7 +2155,7 @@ pub fn parse_error_format(
}
}
} else {
ErrorOutputType::HumanReadable { color_config, .. }
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
};
match error_format {
@ -2176,9 +2203,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
fn check_error_format_stability(
early_dcx: &EarlyDiagCtxt,
unstable_opts: &UnstableOptions,
is_nightly_build: bool,
format: ErrorOutputType,
) {
if unstable_opts.unstable_options {
if unstable_opts.unstable_options || is_nightly_build {
return;
}
let format = match format {
@ -2606,6 +2634,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
let edition = parse_crate_edition(early_dcx, matches);
let crate_name = matches.opt_str("crate-name");
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
let JsonConfig {
json_rendered,
json_color,
@ -2613,9 +2643,16 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
json_timings,
json_unused_externs,
json_future_incompat,
} = parse_json(early_dcx, matches);
} = parse_json(early_dcx, matches, unstable_features.is_nightly_build());
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);
let error_format = parse_error_format(
early_dcx,
matches,
color,
json_color,
json_rendered,
unstable_features.is_nightly_build(),
);
early_dcx.set_error_format(error_format);
@ -2636,7 +2673,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
early_dcx.early_fatal("--json=timings is unstable and requires using `-Zunstable-options`");
}
check_error_format_stability(early_dcx, &unstable_opts, error_format);
check_error_format_stability(
early_dcx,
&unstable_opts,
unstable_features.is_nightly_build(),
error_format,
);
let output_types = parse_output_types(early_dcx, &unstable_opts, matches);
@ -2823,8 +2865,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
)
}
let crate_name = matches.opt_str("crate-name");
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
// Parse any `-l` flags, which link to native libraries.
let libs = parse_native_libs(early_dcx, &unstable_opts, unstable_features, matches);

View file

@ -389,10 +389,19 @@ impl Options {
}
let color = config::parse_color(early_dcx, matches);
let crate_name = matches.opt_str("crate-name");
let unstable_features =
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
let config::JsonConfig { json_rendered, json_unused_externs, json_color, .. } =
config::parse_json(early_dcx, matches);
let error_format =
config::parse_error_format(early_dcx, matches, color, json_color, json_rendered);
config::parse_json(early_dcx, matches, unstable_features.is_nightly_build());
let error_format = config::parse_error_format(
early_dcx,
matches,
color,
json_color,
json_rendered,
unstable_features.is_nightly_build(),
);
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();
let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();
@ -753,7 +762,6 @@ impl Options {
}
};
let crate_name = matches.opt_str("crate-name");
let bin_crate = crate_types.contains(&CrateType::Executable);
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
let playground_url = matches.opt_str("playground-url");
@ -815,9 +823,6 @@ impl Options {
crate::scrape_examples::load_call_locations(with_examples, dcx, &mut loaded_paths);
let doctest_build_args = matches.opt_strs("doctest-build-arg");
let unstable_features =
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
let disable_minification = matches.opt_present("disable-minification");
let options = Options {

View file

@ -272,10 +272,8 @@ LL | assert_eq!(a!(), true);
|
help: replace it with `assert!(..)`
|
LL | true
...
LL |
LL ~ assert!(a!());
LL - assert_eq!(a!(), true);
LL + assert!(a!());
|
error: used `assert_eq!` with a literal bool
@ -286,10 +284,8 @@ LL | assert_eq!(true, b!());
|
help: replace it with `assert!(..)`
|
LL | true
...
LL |
LL ~ assert!(b!());
LL - assert_eq!(true, b!());
LL + assert!(b!());
|
error: used `debug_assert_eq!` with a literal bool

View file

@ -1,3 +1,4 @@
//@ needs-rustc-debug-assertions
//@ known-bug: #131762
// ignore-tidy-linelength

View file

@ -19,6 +19,7 @@ LL | println!();
error: macro expansion ignores `{` and any tokens following
--> $SRC_DIR/std/src/macros.rs:LL:COL
|
|
::: $DIR/main-alongside-macro-calls.rs:30:1
|
LL | println!();
@ -41,6 +42,7 @@ LL | println!();
error: macro expansion ignores `{` and any tokens following
--> $SRC_DIR/std/src/macros.rs:LL:COL
|
|
::: $DIR/main-alongside-macro-calls.rs:34:1
|
LL | println!();

View file

@ -1,11 +1,11 @@
error[E0369]: cannot add `&str` to `&str`
--> $DIR/non-1-width-unicode-multiline-label.rs:8:237
|
LL | ...👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
= note: string concatenation requires an owned `String` on the left
help: create an owned `String` from a string reference
@ -16,11 +16,11 @@ LL | let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
error[E0369]: cannot add `&str` to `&str`
--> $DIR/non-1-width-unicode-multiline-label.rs:10:384
|
LL | ...👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
= note: string concatenation requires an owned `String` on the left
help: create an owned `String` from a string reference
@ -31,11 +31,11 @@ LL | let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
error[E0369]: cannot add `&str` to `&str`
--> $DIR/non-1-width-unicode-multiline-label.rs:12:260
|
LL | ...࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
LL | ...࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
| -------------- ^ -------------- &str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
= note: string concatenation requires an owned `String` on the left
help: create an owned `String` from a string reference

View file

@ -1,10 +1,10 @@
error[E0308]: mismatched types
--> $DIR/non-whitespace-trimming-unicode.rs:5:415
|
LL | ...♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽ ...
| -- ^^ expected `()`, found integer
| |
| expected due to this
LL | ...♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42; let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓ ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳...
| -- ^^ expected `()`, found integer
| |
| expected due to this
error: aborting due to 1 previous error

View file

@ -1,20 +1,20 @@
error[E0408]: variable `v` is not bound in all patterns
--> $DIR/tabs-trimming.rs:9:16
|
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
| - ^ ^ pattern doesn't bind `v`
| | |
| | pattern doesn't bind `v`
| variable not in all patterns
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
| - ^ ^ pattern doesn't bind `v`
| | |
| | pattern doesn't bind `v`
| variable not in all patterns
error[E0381]: used binding `v` is possibly-uninitialized
--> $DIR/tabs-trimming.rs:9:67
|
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
| - ^ `v` used here but it is possibly-uninitialized
| |
| binding initialized here in some conditions
| binding declared here but left uninitialized
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
| - ^ `v` used here but it is possibly-uninitialized
| |
| binding initialized here in some conditions
| binding declared here but left uninitialized
error: aborting due to 2 previous errors

View file

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/file.txt:0:1
|
LL |
| ^ expected `&[u8]`, found `&str`
|
::: $DIR/mismatched-types.rs:2:12
|

View file

@ -17,14 +17,8 @@ LL | $(= $z:tt)*
error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fragments
--> $DIR/same-sequence-span.rs:20:1
|
LL | | // `proc_macro_sequence.rs`.
| |_____________________________^not allowed after `expr` fragments
...
LL | proc_macro_sequence::make_foo!();
| ^-------------------------------
| |
| _in this macro invocation
| |
LL | proc_macro_sequence::make_foo!();
| -------------------------------- in this macro invocation
|
= note: allowed there are: `=>`, `,` or `;`
= note: this error originates in the macro `proc_macro_sequence::make_foo` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -38,10 +38,10 @@ LL | field2: SafeEnum::Variant4("str".to_string()),
note: method `to_string` is not const because trait `ToString` is not const
--> $SRC_DIR/alloc/src/string.rs:LL:COL
|
= note: this trait is not const
= note: this method is not const
::: $SRC_DIR/alloc/src/string.rs:LL:COL
|
= note: this method is not const
= note: this trait is not const
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`

View file

@ -686,11 +686,12 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
|
note: method `filter` is not const because trait `Iterator` is not const
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this trait is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this method is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this trait is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:240:49: 240:52}>` in constants
@ -701,11 +702,12 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
|
note: method `map` is not const because trait `Iterator` is not const
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this trait is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this method is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this trait is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 83 previous errors