Skip to content

Commit 0d8882c

Browse files
committed
feat: Use annotate-snippets by default on nightly
1 parent 26e1b1e commit 0d8882c

File tree

11 files changed

+105
-68
lines changed

11 files changed

+105
-68
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,8 +2052,16 @@ impl JsonUnusedExterns {
20522052
///
20532053
/// The first value returned is how to render JSON diagnostics, and the second
20542054
/// is whether or not artifact notifications are enabled.
2055-
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
2056-
let mut json_rendered = HumanReadableErrorType::Default { short: false };
2055+
pub fn parse_json(
2056+
early_dcx: &EarlyDiagCtxt,
2057+
matches: &getopts::Matches,
2058+
is_nightly_build: bool,
2059+
) -> JsonConfig {
2060+
let mut json_rendered = if is_nightly_build {
2061+
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
2062+
} else {
2063+
HumanReadableErrorType::Default { short: false }
2064+
};
20572065
let mut json_color = ColorConfig::Never;
20582066
let mut json_artifact_notifications = false;
20592067
let mut json_unused_externs = JsonUnusedExterns::No;
@@ -2070,7 +2078,11 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
20702078
for sub_option in option.split(',') {
20712079
match sub_option {
20722080
"diagnostic-short" => {
2073-
json_rendered = HumanReadableErrorType::Default { short: true }
2081+
json_rendered = if is_nightly_build {
2082+
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
2083+
} else {
2084+
HumanReadableErrorType::Default { short: true }
2085+
};
20742086
}
20752087
"diagnostic-unicode" => {
20762088
json_rendered =
@@ -2104,14 +2116,22 @@ pub fn parse_error_format(
21042116
color_config: ColorConfig,
21052117
json_color: ColorConfig,
21062118
json_rendered: HumanReadableErrorType,
2119+
is_nightly_build: bool,
21072120
) -> ErrorOutputType {
2121+
let default_kind = if is_nightly_build {
2122+
HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false }
2123+
} else {
2124+
HumanReadableErrorType::Default { short: false }
2125+
};
21082126
// We need the `opts_present` check because the driver will send us Matches
21092127
// with only stable options if no unstable options are used. Since error-format
21102128
// is unstable, it will not be present. We have to use `opts_present` not
21112129
// `opt_present` because the latter will panic.
21122130
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
21132131
match matches.opt_str("error-format").as_deref() {
2114-
None | Some("human") => ErrorOutputType::HumanReadable { color_config, .. },
2132+
None | Some("human") => {
2133+
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
2134+
}
21152135
Some("human-annotate-rs") => ErrorOutputType::HumanReadable {
21162136
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: false },
21172137
color_config,
@@ -2123,23 +2143,30 @@ pub fn parse_error_format(
21232143
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
21242144
}
21252145
Some("short") => ErrorOutputType::HumanReadable {
2126-
kind: HumanReadableErrorType::Default { short: true },
2146+
kind: if is_nightly_build {
2147+
HumanReadableErrorType::AnnotateSnippet { short: true, unicode: false }
2148+
} else {
2149+
HumanReadableErrorType::Default { short: true }
2150+
},
21272151
color_config,
21282152
},
21292153
Some("human-unicode") => ErrorOutputType::HumanReadable {
21302154
kind: HumanReadableErrorType::AnnotateSnippet { short: false, unicode: true },
21312155
color_config,
21322156
},
21332157
Some(arg) => {
2134-
early_dcx.set_error_format(ErrorOutputType::HumanReadable { color_config, .. });
2158+
early_dcx.set_error_format(ErrorOutputType::HumanReadable {
2159+
color_config,
2160+
kind: default_kind,
2161+
});
21352162
early_dcx.early_fatal(format!(
21362163
"argument for `--error-format` must be `human`, `human-annotate-rs`, \
21372164
`human-unicode`, `json`, `pretty-json` or `short` (instead was `{arg}`)"
21382165
))
21392166
}
21402167
}
21412168
} else {
2142-
ErrorOutputType::HumanReadable { color_config, .. }
2169+
ErrorOutputType::HumanReadable { color_config, kind: default_kind }
21432170
};
21442171

21452172
match error_format {
@@ -2187,9 +2214,10 @@ pub fn parse_crate_edition(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches
21872214
fn check_error_format_stability(
21882215
early_dcx: &EarlyDiagCtxt,
21892216
unstable_opts: &UnstableOptions,
2217+
is_nightly_build: bool,
21902218
format: ErrorOutputType,
21912219
) {
2192-
if unstable_opts.unstable_options {
2220+
if unstable_opts.unstable_options || is_nightly_build {
21932221
return;
21942222
}
21952223
let format = match format {
@@ -2617,16 +2645,25 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26172645

26182646
let edition = parse_crate_edition(early_dcx, matches);
26192647

2648+
let crate_name = matches.opt_str("crate-name");
2649+
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
26202650
let JsonConfig {
26212651
json_rendered,
26222652
json_color,
26232653
json_artifact_notifications,
26242654
json_timings,
26252655
json_unused_externs,
26262656
json_future_incompat,
2627-
} = parse_json(early_dcx, matches);
2657+
} = parse_json(early_dcx, matches, unstable_features.is_nightly_build());
26282658

2629-
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);
2659+
let error_format = parse_error_format(
2660+
early_dcx,
2661+
matches,
2662+
color,
2663+
json_color,
2664+
json_rendered,
2665+
unstable_features.is_nightly_build(),
2666+
);
26302667

26312668
early_dcx.set_error_format(error_format);
26322669

@@ -2647,7 +2684,12 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26472684
early_dcx.early_fatal("--json=timings is unstable and requires using `-Zunstable-options`");
26482685
}
26492686

2650-
check_error_format_stability(early_dcx, &unstable_opts, error_format);
2687+
check_error_format_stability(
2688+
early_dcx,
2689+
&unstable_opts,
2690+
unstable_features.is_nightly_build(),
2691+
error_format,
2692+
);
26512693

26522694
let output_types = parse_output_types(early_dcx, &unstable_opts, matches);
26532695

@@ -2834,8 +2876,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28342876
)
28352877
}
28362878

2837-
let crate_name = matches.opt_str("crate-name");
2838-
let unstable_features = UnstableFeatures::from_environment(crate_name.as_deref());
28392879
// Parse any `-l` flags, which link to native libraries.
28402880
let libs = parse_native_libs(early_dcx, &unstable_opts, unstable_features, matches);
28412881

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

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ LL + fn default() -> Self {
191191
LL + Self::new()
192192
LL + }
193193
LL + }
194-
LL | impl NewWithCfg {
195194
|
196195

197196
error: you should consider adding a `Default` implementation for `NewWith2Cfgs`
@@ -212,7 +211,6 @@ LL + fn default() -> Self {
212211
LL + Self::new()
213212
LL + }
214213
LL + }
215-
LL | impl NewWith2Cfgs {
216214
|
217215

218216
error: you should consider adding a `Default` implementation for `NewWithExtraneous`
@@ -250,7 +248,6 @@ LL + fn default() -> Self {
250248
LL + Self::new()
251249
LL + }
252250
LL + }
253-
LL | impl NewWithCfgAndExtraneous {
254251
|
255252

256253
error: aborting due to 13 previous errors

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
|

0 commit comments

Comments
 (0)