Skip to content

Commit 9243928

Browse files
committed
feat: Use annotate-snippets by default on nightly
1 parent 9cb7deb commit 9243928

File tree

12 files changed

+113
-71
lines changed

12 files changed

+113
-71
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,16 @@ impl JsonUnusedExterns {
20412041
///
20422042
/// The first value returned is how to render JSON diagnostics, and the second
20432043
/// is whether or not artifact notifications are enabled.
2044-
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
2045-
let mut json_rendered = HumanReadableErrorType::Default { short: false };
2044+
pub fn parse_json(
2045+
early_dcx: &EarlyDiagCtxt,
2046+
matches: &getopts::Matches,
2047+
is_nightly_build: bool,
2048+
) -> JsonConfig {
2049+
let mut json_rendered = if is_nightly_build {
2050+
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
2051+
} else {
2052+
HumanReadableErrorType::Default { short: false }
2053+
};
20462054
let mut json_color = ColorConfig::Never;
20472055
let mut json_artifact_notifications = false;
20482056
let mut json_unused_externs = JsonUnusedExterns::No;
@@ -2059,7 +2067,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20592067
for sub_option in option.split(',') {
20602068
match sub_option {
20612069
"diagnostic-short" => {
2062-
json_rendered = HumanReadableErrorType::Default { short: true }
2070+
json_rendered = if is_nightly_build {
2071+
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
2072+
} else {
2073+
HumanReadableErrorType::Default { short: true }
2074+
};
20632075
}
20642076
"diagnostic-unicode" => {
20652077
json_rendered =
@@ -2093,14 +2105,22 @@ pub fn parse_error_format(
20932105
color_config: ColorConfig,
20942106
json_color: ColorConfig,
20952107
json_rendered: HumanReadableErrorType,
2108+
is_nightly_build: bool,
20962109
) -> ErrorOutputType {
2110+
let default_kind = if is_nightly_build {
2111+
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
2112+
} else {
2113+
HumanReadableErrorType::Default { short: false }
2114+
};
20972115
// We need the `opts_present` check because the driver will send us Matches
20982116
// with only stable options if no unstable options are used. Since error-format
20992117
// is unstable, it will not be present. We have to use `opts_present` not
21002118
// `opt_present` because the latter will panic.
21012119
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
21022120
match matches.opt_str("error-format").as_deref() {
2103-
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
2121+
None | Some("human") => {
2122+
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
2123+
}
21042124
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
21052125
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false },
21062126
color_config,
@@ -2112,23 +2132,30 @@ pub fn parse_error_format(
21122132
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
21132133
}
21142134
Some("short") => ErrorOutputType::HumanReadable {
2115-
kind: HumanReadableErrorType::Default { short: true },
2135+
kind: if is_nightly_build {
2136+
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
2137+
} else {
2138+
HumanReadableErrorType::Default { short: true }
2139+
},
21162140
color_config,
21172141
},
21182142
Some("human-unicode") => ErrorOutputType::HumanReadable {
21192143
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true },
21202144
color_config,
21212145
},
21222146
Some(arg) => {
2123-
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
2147+
early_dcx.set_error_format(ErrorOutputType::HumanReadable {
2148+
color_config,
2149+
kind: default_kind,
2150+
});
21242151
early_dcx.early_fatal(format!(
21252152
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
21262153
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21272154
))
21282155
}
21292156
}
21302157
} else {
2131-
ErrorOutputType::HumanReadable { color_config, .. }
2158+
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
21322159
};
21332160

21342161
match error_format {
@@ -2176,9 +2203,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21762203
fn check_error_format_stability(
21772204
early_dcx: &EarlyDiagCtxt,
21782205
unstable_opts: &UnstableOptions,
2206+
is_nightly_build: bool,
21792207
format: ErrorOutputType,
21802208
) {
2181-
if unstable_opts.unstable_options {
2209+
if unstable_opts.unstable_options || is_nightly_build {
21822210
return;
21832211
}
21842212
let format = match format {
@@ -2606,16 +2634,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26062634

26072635
let edition = parse_crate_edition(early_dcx, matches);
26082636

2637+
let crate_name = matches.opt_str("crate-name");
2638+
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
26092639
let JsonConfig {
26102640
json_rendered,
26112641
json_color,
26122642
json_artifact_notifications,
26132643
json_timings,
26142644
json_unused_externs,
26152645
json_future_incompat,
2616-
} = parse_json(early_dcx, matches);
2646+
} = parse_json(early_dcx, matches, unstable_features.is_nightly_build());
26172647

2618-
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);
2648+
let error_format = parse_error_format(
2649+
early_dcx,
2650+
matches,
2651+
color,
2652+
json_color,
2653+
json_rendered,
2654+
unstable_features.is_nightly_build(),
2655+
);
26192656

26202657
early_dcx.set_error_format(error_format);
26212658

@@ -2636,7 +2673,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26362673
early_dcx.early_fatal("--json=timings is unstable and requires using `-Zunstable-options`");
26372674
}
26382675

2639-
check_error_format_stability(early_dcx, &unstable_opts, error_format);
2676+
check_error_format_stability(
2677+
early_dcx,
2678+
&unstable_opts,
2679+
unstable_features.is_nightly_build(),
2680+
error_format,
2681+
);
26402682

26412683
let output_types = parse_output_types(early_dcx, &unstable_opts, matches);
26422684

@@ -2823,8 +2865,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28232865
)
28242866
}
28252867

2826-
let crate_name = matches.opt_str("crate-name");
2827-
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
28282868
// Parse any `-l` flags, which link to native libraries.
28292869
let libs = parse_native_libs(early_dcx, &unstable_opts, unstable_features, matches);
28302870

src/librustdoc/config.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,19 @@ impl Options {
389389
}
390390

391391
let color = config::parse_color(early_dcx, matches);
392+
let crate_name = matches.opt_str("crate-name");
393+
let unstable_features =
394+
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
392395
let config::JsonConfig { json_rendered, json_unused_externs, json_color, .. } =
393-
config::parse_json(early_dcx, matches);
394-
let error_format =
395-
config::parse_error_format(early_dcx, matches, color, json_color, json_rendered);
396+
config::parse_json(early_dcx, matches, unstable_features.is_nightly_build());
397+
let error_format = config::parse_error_format(
398+
early_dcx,
399+
matches,
400+
color,
401+
json_color,
402+
json_rendered,
403+
unstable_features.is_nightly_build(),
404+
);
396405
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default();
397406

398407
let mut target_modifiers = BTreeMap::<OptionsTargetModifiers, String>::new();
@@ -753,7 +762,6 @@ impl Options {
753762
}
754763
};
755764

756-
let crate_name = matches.opt_str("crate-name");
757765
let bin_crate = crate_types.contains(&CrateType::Executable);
758766
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
759767
let playground_url = matches.opt_str("playground-url");
@@ -815,9 +823,6 @@ impl Options {
815823
crate::scrape_examples::load_call_locations(with_examples, dcx, &mut loaded_paths);
816824
let doctest_build_args = matches.opt_strs("doctest-build-arg");
817825

818-
let unstable_features =
819-
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
820-
821826
let disable_minification = matches.opt_present("disable-minification");
822827

823828
let options = Options {

src/tools/clippy/tests/ui/bool_assert_comparison.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,8 @@ LL | assert_eq!(a!(), true);
272272
|
273273
help: replace it with `assert!(..)`
274274
|
275-
LL | true
276-
...
277-
LL |
278-
LL ~ assert!(a!());
275+
LL - assert_eq!(a!(), true);
276+
LL + assert!(a!());
279277
|
280278

281279
error: used `assert_eq!` with a literal bool
@@ -286,10 +284,8 @@ LL | assert_eq!(true, b!());
286284
|
287285
help: replace it with `assert!(..)`
288286
|
289-
LL | true
290-
...
291-
LL |
292-
LL ~ assert!(b!());
287+
LL - assert_eq!(true, b!());
288+
LL + assert!(b!());
293289
|
294290

295291
error: used `debug_assert_eq!` with a literal bool

tests/crashes/131762.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ needs-rustc-debug-assertions
12
//@ known-bug: #131762
23
// ignore-tidy-linelength
34

tests/rustdoc-ui/doctest/main-alongside-macro-calls.fail.stdout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ LL | println!();
1919
error: macro expansion ignores `{` and any tokens following
2020
--> $SRC_DIR/std/src/macros.rs:LL:COL
2121
|
22+
|
2223
::: $DIR/main-alongside-macro-calls.rs:30:1
2324
|
2425
LL | println!();
@@ -41,6 +42,7 @@ LL | println!();
4142
error: macro expansion ignores `{` and any tokens following
4243
--> $SRC_DIR/std/src/macros.rs:LL:COL
4344
|
45+
|
4446
::: $DIR/main-alongside-macro-calls.rs:34:1
4547
|
4648
LL | println!();

tests/ui/diagnostic-width/non-1-width-unicode-multiline-label.ascii.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0369]: cannot add `&str` to `&str`
22
--> $DIR/non-1-width-unicode-multiline-label.rs:8:237
33
|
4-
LL | ...👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
5-
| -------------- ^ -------------- &str
6-
| | |
7-
| | `+` cannot be used to concatenate two `&str` strings
8-
| &str
4+
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
5+
| -------------- ^ -------------- &str
6+
| | |
7+
| | `+` cannot be used to concatenate two `&str` strings
8+
| &str
99
|
1010
= note: string concatenation requires an owned `String` on the left
1111
help: create an owned `String` from a string reference
@@ -16,11 +16,11 @@ LL | let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
1616
error[E0369]: cannot add `&str` to `&str`
1717
--> $DIR/non-1-width-unicode-multiline-label.rs:10:384
1818
|
19-
LL | ...👧👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
20-
| -------------- ^ -------------- &str
21-
| | |
22-
| | `+` cannot be used to concatenate two `&str` strings
23-
| &str
19+
LL | ... 👦👨👩👧👦👨👩👧👦"; let _a = unicode_is_fun + " really fun!";
20+
| -------------- ^ -------------- &str
21+
| | |
22+
| | `+` cannot be used to concatenate two `&str` strings
23+
| &str
2424
|
2525
= note: string concatenation requires an owned `String` on the left
2626
help: create an owned `String` from a string reference
@@ -31,11 +31,11 @@ LL | let _ = "👨👩👧👦👨👩👧👦👨👩👧👦👨👩👧
3131
error[E0369]: cannot add `&str` to `&str`
3232
--> $DIR/non-1-width-unicode-multiline-label.rs:12:260
3333
|
34-
LL | ...࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
35-
| -------------- ^ -------------- &str
36-
| | |
37-
| | `+` cannot be used to concatenate two `&str` strings
38-
| &str
34+
LL | ...࿇࿈࿉࿊࿋࿌࿍࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚"; let _a = unicode_is_fun + " really fun!";
35+
| -------------- ^ -------------- &str
36+
| | |
37+
| | `+` cannot be used to concatenate two `&str` strings
38+
| &str
3939
|
4040
= note: string concatenation requires an owned `String` on the left
4141
help: create an owned `String` from a string reference

tests/ui/diagnostic-width/non-whitespace-trimming-unicode.stderr

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

99
error: aborting due to 1 previous error
1010

tests/ui/diagnostic-width/tabs-trimming.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0408]: variable `v` is not bound in all patterns
22
--> $DIR/tabs-trimming.rs:9:16
33
|
4-
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
5-
| - ^ ^ pattern doesn't bind `v`
6-
| | |
7-
| | pattern doesn't bind `v`
8-
| variable not in all patterns
4+
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
5+
| - ^ ^ pattern doesn't bind `v`
6+
| | |
7+
| | pattern doesn't bind `v`
8+
| variable not in all patterns
99

1010
error[E0381]: used binding `v` is possibly-uninitialized
1111
--> $DIR/tabs-trimming.rs:9:67
1212
|
13-
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
14-
| - ^ `v` used here but it is possibly-uninitialized
15-
| |
16-
| binding initialized here in some conditions
17-
| binding declared here but left uninitialized
13+
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
14+
| - ^ `v` used here but it is possibly-uninitialized
15+
| |
16+
| binding initialized here in some conditions
17+
| binding declared here but left uninitialized
1818

1919
error: aborting due to 2 previous errors
2020

tests/ui/include-macros/mismatched-types.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/file.txt:0:1
33
|
4+
LL |
5+
| ^ expected `&[u8]`, found `&str`
46
|
57
::: $DIR/mismatched-types.rs:2:12
68
|

tests/ui/macros/same-sequence-span.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ LL | $(= $z:tt)*
1717
error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fragments
1818
--> $DIR/same-sequence-span.rs:20:1
1919
|
20-
LL | | // `proc_macro_sequence.rs`.
21-
| |_____________________________^not allowed after `expr` fragments
22-
...
23-
LL | proc_macro_sequence::make_foo!();
24-
| ^-------------------------------
25-
| |
26-
| _in this macro invocation
27-
| |
20+
LL | proc_macro_sequence::make_foo!();
21+
| -------------------------------- in this macro invocation
2822
|
2923
= note: allowed there are: `=>`, `,` or `;`
3024
= note: this error originates in the macro `proc_macro_sequence::make_foo` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)