Skip to content

Commit ca9f04e

Browse files
authored
Rollup merge of rust-lang#59862 - estebank:tweak-unstable-diag, r=petrochenkov
Tweak unstable diagnostic output
2 parents 2bc127d + 66ed5d9 commit ca9f04e

File tree

174 files changed

+857
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+857
-459
lines changed

src/libsyntax/feature_gate.rs

+44-23
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu
903903
("thread_local", Whitelisted, template!(Word), Gated(Stability::Unstable,
904904
"thread_local",
905905
"`#[thread_local]` is an experimental feature, and does \
906-
not currently handle destructors.",
906+
not currently handle destructors",
907907
cfg_fn!(thread_local))),
908908

909909
("rustc_on_unimplemented", Whitelisted, template!(List:
@@ -1438,42 +1438,61 @@ pub enum GateStrength {
14381438
Soft,
14391439
}
14401440

1441-
pub fn emit_feature_err(sess: &ParseSess, feature: &str, span: Span, issue: GateIssue,
1442-
explain: &str) {
1441+
pub fn emit_feature_err(
1442+
sess: &ParseSess,
1443+
feature: &str,
1444+
span: Span,
1445+
issue: GateIssue,
1446+
explain: &str,
1447+
) {
14431448
feature_err(sess, feature, span, issue, explain).emit();
14441449
}
14451450

1446-
pub fn feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: GateIssue,
1447-
explain: &str) -> DiagnosticBuilder<'a> {
1451+
pub fn feature_err<'a>(
1452+
sess: &'a ParseSess,
1453+
feature: &str,
1454+
span: Span,
1455+
issue: GateIssue,
1456+
explain: &str,
1457+
) -> DiagnosticBuilder<'a> {
14481458
leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard)
14491459
}
14501460

1451-
fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: GateIssue,
1452-
explain: &str, level: GateStrength) -> DiagnosticBuilder<'a> {
1461+
fn leveled_feature_err<'a>(
1462+
sess: &'a ParseSess,
1463+
feature: &str,
1464+
span: Span,
1465+
issue: GateIssue,
1466+
explain: &str,
1467+
level: GateStrength,
1468+
) -> DiagnosticBuilder<'a> {
14531469
let diag = &sess.span_diagnostic;
14541470

14551471
let issue = match issue {
14561472
GateIssue::Language => find_lang_feature_issue(feature),
14571473
GateIssue::Library(lib) => lib,
14581474
};
14591475

1460-
let explanation = match issue {
1461-
None | Some(0) => explain.to_owned(),
1462-
Some(n) => format!("{} (see issue #{})", explain, n)
1463-
};
1464-
14651476
let mut err = match level {
14661477
GateStrength::Hard => {
1467-
diag.struct_span_err_with_code(span, &explanation, stringify_error_code!(E0658))
1478+
diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658))
14681479
}
1469-
GateStrength::Soft => diag.struct_span_warn(span, &explanation),
1480+
GateStrength::Soft => diag.struct_span_warn(span, explain),
14701481
};
14711482

1483+
match issue {
1484+
None | Some(0) => {} // We still accept `0` as a stand-in for backwards compatibility
1485+
Some(n) => {
1486+
err.note(&format!(
1487+
"for more information, see https://github.com/rust-lang/rust/issues/{}",
1488+
n,
1489+
));
1490+
}
1491+
}
1492+
14721493
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
14731494
if sess.unstable_features.is_nightly_build() {
1474-
err.help(&format!("add #![feature({})] to the \
1475-
crate attributes to enable",
1476-
feature));
1495+
err.help(&format!("add #![feature({})] to the crate attributes to enable", feature));
14771496
}
14781497

14791498
// If we're on stable and only emitting a "soft" warning, add a note to
@@ -1488,10 +1507,10 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue
14881507
}
14891508

14901509
const EXPLAIN_BOX_SYNTAX: &str =
1491-
"box expression syntax is experimental; you can call `Box::new` instead.";
1510+
"box expression syntax is experimental; you can call `Box::new` instead";
14921511

14931512
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
1494-
"attributes on expressions are experimental.";
1513+
"attributes on expressions are experimental";
14951514

14961515
pub const EXPLAIN_ASM: &str =
14971516
"inline assembly is not stable enough for use and is subject to change";
@@ -1685,10 +1704,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16851704

16861705
fn visit_name(&mut self, sp: Span, name: ast::Name) {
16871706
if !name.as_str().is_ascii() {
1688-
gate_feature_post!(&self,
1689-
non_ascii_idents,
1690-
self.context.parse_sess.source_map().def_span(sp),
1691-
"non-ascii idents are not fully supported.");
1707+
gate_feature_post!(
1708+
&self,
1709+
non_ascii_idents,
1710+
self.context.parse_sess.source_map().def_span(sp),
1711+
"non-ascii idents are not fully supported"
1712+
);
16921713
}
16931714
}
16941715

src/libsyntax/json.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,17 @@ impl DiagnosticSpanLine {
348348
/// `span` within the line.
349349
fn from_span(span: Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
350350
je.sm.span_to_lines(span)
351-
.map(|lines| {
352-
let fm = &*lines.file;
353-
lines.lines
354-
.iter()
355-
.map(|line| {
356-
DiagnosticSpanLine::line_from_source_file(fm,
357-
line.line_index,
358-
line.start_col.0 + 1,
359-
line.end_col.0 + 1)
360-
})
361-
.collect()
362-
})
363-
.unwrap_or_else(|_| vec![])
351+
.map(|lines| {
352+
let fm = &*lines.file;
353+
lines.lines
354+
.iter()
355+
.map(|line| DiagnosticSpanLine::line_from_source_file(
356+
fm,
357+
line.line_index,
358+
line.start_col.0 + 1,
359+
line.end_col.0 + 1,
360+
)).collect()
361+
}).unwrap_or_else(|_| vec![])
364362
}
365363
}
366364

src/test/ui-fulldeps/gated-plugin.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
1+
error[E0658]: compiler plugins are experimental and possibly buggy
22
--> $DIR/gated-plugin.rs:3:1
33
|
44
LL | #![plugin(attr_plugin_test)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/29597
78
= help: add #![feature(plugin)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui-fulldeps/hash-stable-is-unstable.stderr

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,49 @@ error[E0601]: `main` function not found in crate `hash_stable_is_unstable`
22
|
33
= note: consider adding a `main` function to `$DIR/hash-stable-is-unstable.rs`
44

5-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
5+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
66
--> $DIR/hash-stable-is-unstable.rs:3:1
77
|
88
LL | extern crate rustc_data_structures;
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1010
|
11+
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
1112
= help: add #![feature(rustc_private)] to the crate attributes to enable
1213

13-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
14+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
1415
--> $DIR/hash-stable-is-unstable.rs:5:1
1516
|
1617
LL | extern crate rustc;
1718
| ^^^^^^^^^^^^^^^^^^^
1819
|
20+
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
1921
= help: add #![feature(rustc_private)] to the crate attributes to enable
2022

21-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
23+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2224
--> $DIR/hash-stable-is-unstable.rs:7:1
2325
|
2426
LL | extern crate rustc_macros;
2527
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2628
|
29+
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
2730
= help: add #![feature(rustc_private)] to the crate attributes to enable
2831

29-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
32+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
3033
--> $DIR/hash-stable-is-unstable.rs:10:5
3134
|
3235
LL | use rustc_macros::HashStable;
3336
| ^^^^^^^^^^^^^^^^^^^^^^^^
3437
|
38+
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
3539
= help: add #![feature(rustc_private)] to the crate attributes to enable
3640

37-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
41+
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
3842
--> $DIR/hash-stable-is-unstable.rs:13:10
3943
|
4044
LL | #[derive(HashStable)]
4145
| ^^^^^^^^^^
4246
|
47+
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
4348
= help: add #![feature(rustc_private)] to the crate attributes to enable
4449

4550
error: aborting due to 6 previous errors

src/test/ui/cast/cast-ptr-to-int-const.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
error[E0658]: casting pointers to integers in constants is unstable (see issue #51910)
1+
error[E0658]: casting pointers to integers in constants is unstable
22
--> $DIR/cast-ptr-to-int-const.rs:5:9
33
|
44
LL | main as u32
55
| ^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
78
= help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable
89

9-
error[E0658]: casting pointers to integers in constants is unstable (see issue #51910)
10+
error[E0658]: casting pointers to integers in constants is unstable
1011
--> $DIR/cast-ptr-to-int-const.rs:9:9
1112
|
1213
LL | &Y as *const u32 as u32
1314
| ^^^^^^^^^^^^^^^^^^^^^^^
1415
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
1517
= help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable
1618

1719
error: aborting due to 2 previous errors

src/test/ui/conditional-compilation/cfg-attr-crate-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: no_core is experimental (see issue #29639)
1+
error[E0658]: no_core is experimental
22
--> $DIR/cfg-attr-crate-2.rs:6:21
33
|
44
LL | #![cfg_attr(broken, no_core)]
55
| ^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/29639
78
= help: add #![feature(no_core)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: no_core is experimental (see issue #29639)
1+
error[E0658]: no_core is experimental
22
--> $DIR/cfg-attr-multi-invalid-1.rs:4:21
33
|
44
LL | #![cfg_attr(broken, no_core, no_std)]
55
| ^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/29639
78
= help: add #![feature(no_core)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: no_core is experimental (see issue #29639)
1+
error[E0658]: no_core is experimental
22
--> $DIR/cfg-attr-multi-invalid-2.rs:4:29
33
|
44
LL | #![cfg_attr(broken, no_std, no_core)]
55
| ^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/29639
78
= help: add #![feature(no_core)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
1+
error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
22
--> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:27
33
|
44
LL | #[cfg_attr(all(), unknown)]
@@ -7,6 +7,7 @@ LL | #[cfg_attr(all(), unknown)]
77
LL | foo!();
88
| ------- in this macro invocation
99
|
10+
= note: for more information, see https://github.com/rust-lang/rust/issues/29642
1011
= help: add #![feature(custom_attribute)] to the crate attributes to enable
1112

1213
error: aborting due to previous error

src/test/ui/consts/const-deref-ptr.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: dereferencing raw pointers in statics is unstable (see issue #51911)
1+
error[E0658]: dereferencing raw pointers in statics is unstable
22
--> $DIR/const-deref-ptr.rs:4:29
33
|
44
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51911
78
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/consts/const-eval/feature-gate-const_fn_union.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0658]: unions in const fn are unstable (see issue #51909)
1+
error[E0658]: unions in const fn are unstable
22
--> $DIR/feature-gate-const_fn_union.rs:11:5
33
|
44
LL | Foo { u }.i
55
| ^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51909
78
= help: add #![feature(const_fn_union)] to the crate attributes to enable
89

910
error: aborting due to previous error

src/test/ui/consts/const-eval/feature-gate-const_panic.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
error[E0658]: panicking in constants is unstable (see issue #51999)
1+
error[E0658]: panicking in constants is unstable
22
--> $DIR/feature-gate-const_panic.rs:3:15
33
|
44
LL | const Z: () = panic!("cheese");
55
| ^^^^^^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
78
= help: add #![feature(const_panic)] to the crate attributes to enable
89
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
910

10-
error[E0658]: panicking in constants is unstable (see issue #51999)
11+
error[E0658]: panicking in constants is unstable
1112
--> $DIR/feature-gate-const_panic.rs:9:15
1213
|
1314
LL | const X: () = unimplemented!();
1415
| ^^^^^^^^^^^^^^^^
1516
|
17+
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
1618
= help: add #![feature(const_panic)] to the crate attributes to enable
1719
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1820

19-
error[E0658]: panicking in constants is unstable (see issue #51999)
21+
error[E0658]: panicking in constants is unstable
2022
--> $DIR/feature-gate-const_panic.rs:6:15
2123
|
2224
LL | const Y: () = unreachable!();
2325
| ^^^^^^^^^^^^^^
2426
|
27+
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
2528
= help: add #![feature(const_panic)] to the crate attributes to enable
2629
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
2730

src/test/ui/consts/const-eval/match-test-ptr-null.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ fn main() {
33
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
44
// bytes.
55
let _: [u8; 0] = [4; {
6-
match &1 as *const i32 as usize { //~ ERROR casting pointers to integers in constants
6+
match &1 as *const i32 as usize {
7+
//~^ ERROR casting pointers to integers in constants
8+
//~| NOTE for more information, see
79
0 => 42, //~ ERROR constant contains unimplemented expression type
810
//~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed
911
//~| ERROR evaluation of constant value failed

src/test/ui/consts/const-eval/match-test-ptr-null.stderr

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
error[E0658]: casting pointers to integers in constants is unstable (see issue #51910)
1+
error[E0658]: casting pointers to integers in constants is unstable
22
--> $DIR/match-test-ptr-null.rs:6:15
33
|
44
LL | match &1 as *const i32 as usize {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
78
= help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable
89

910
error[E0019]: constant contains unimplemented expression type
10-
--> $DIR/match-test-ptr-null.rs:7:13
11+
--> $DIR/match-test-ptr-null.rs:9:13
1112
|
1213
LL | 0 => 42,
1314
| ^
1415

1516
error[E0080]: evaluation of constant value failed
16-
--> $DIR/match-test-ptr-null.rs:7:13
17+
--> $DIR/match-test-ptr-null.rs:9:13
1718
|
1819
LL | 0 => 42,
1920
| ^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants

0 commit comments

Comments
 (0)