Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak unstable diagnostic output #59862

Merged
merged 3 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 44 additions & 23 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu
("thread_local", Whitelisted, template!(Word), Gated(Stability::Unstable,
"thread_local",
"`#[thread_local]` is an experimental feature, and does \
not currently handle destructors.",
not currently handle destructors",
cfg_fn!(thread_local))),

("rustc_on_unimplemented", Whitelisted, template!(List:
Expand Down Expand Up @@ -1438,42 +1438,61 @@ pub enum GateStrength {
Soft,
}

pub fn emit_feature_err(sess: &ParseSess, feature: &str, span: Span, issue: GateIssue,
explain: &str) {
pub fn emit_feature_err(
sess: &ParseSess,
feature: &str,
span: Span,
issue: GateIssue,
explain: &str,
) {
feature_err(sess, feature, span, issue, explain).emit();
}

pub fn feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: GateIssue,
explain: &str) -> DiagnosticBuilder<'a> {
pub fn feature_err<'a>(
sess: &'a ParseSess,
feature: &str,
span: Span,
issue: GateIssue,
explain: &str,
) -> DiagnosticBuilder<'a> {
leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard)
}

fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: GateIssue,
explain: &str, level: GateStrength) -> DiagnosticBuilder<'a> {
fn leveled_feature_err<'a>(
sess: &'a ParseSess,
feature: &str,
span: Span,
issue: GateIssue,
explain: &str,
level: GateStrength,
) -> DiagnosticBuilder<'a> {
let diag = &sess.span_diagnostic;

let issue = match issue {
GateIssue::Language => find_lang_feature_issue(feature),
GateIssue::Library(lib) => lib,
};

let explanation = match issue {
None | Some(0) => explain.to_owned(),
Some(n) => format!("{} (see issue #{})", explain, n)
};

let mut err = match level {
GateStrength::Hard => {
diag.struct_span_err_with_code(span, &explanation, stringify_error_code!(E0658))
diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658))
}
GateStrength::Soft => diag.struct_span_warn(span, &explanation),
GateStrength::Soft => diag.struct_span_warn(span, explain),
};

match issue {
None | Some(0) => {} // We still accept `0` as a stand-in for backwards compatibility
Some(n) => {
err.note(&format!(
"for more information, see https://github.com/rust-lang/rust/issues/{}",
n,
));
}
}

// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
if sess.unstable_features.is_nightly_build() {
err.help(&format!("add #![feature({})] to the \
crate attributes to enable",
feature));
err.help(&format!("add #![feature({})] to the crate attributes to enable", feature));
}

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

const EXPLAIN_BOX_SYNTAX: &str =
"box expression syntax is experimental; you can call `Box::new` instead.";
"box expression syntax is experimental; you can call `Box::new` instead";

pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
"attributes on expressions are experimental.";
"attributes on expressions are experimental";

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

fn visit_name(&mut self, sp: Span, name: ast::Name) {
if !name.as_str().is_ascii() {
gate_feature_post!(&self,
non_ascii_idents,
self.context.parse_sess.source_map().def_span(sp),
"non-ascii idents are not fully supported.");
gate_feature_post!(
&self,
non_ascii_idents,
self.context.parse_sess.source_map().def_span(sp),
"non-ascii idents are not fully supported"
);
}
}

Expand Down
24 changes: 11 additions & 13 deletions src/libsyntax/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,17 @@ impl DiagnosticSpanLine {
/// `span` within the line.
fn from_span(span: Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
je.sm.span_to_lines(span)
.map(|lines| {
let fm = &*lines.file;
lines.lines
.iter()
.map(|line| {
DiagnosticSpanLine::line_from_source_file(fm,
line.line_index,
line.start_col.0 + 1,
line.end_col.0 + 1)
})
.collect()
})
.unwrap_or_else(|_| vec![])
.map(|lines| {
let fm = &*lines.file;
lines.lines
.iter()
.map(|line| DiagnosticSpanLine::line_from_source_file(
fm,
line.line_index,
line.start_col.0 + 1,
line.end_col.0 + 1,
)).collect()
}).unwrap_or_else(|_| vec![])
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui-fulldeps/gated-plugin.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597)
error[E0658]: compiler plugins are experimental and possibly buggy
--> $DIR/gated-plugin.rs:3:1
|
LL | #![plugin(attr_plugin_test)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/29597
= help: add #![feature(plugin)] to the crate attributes to enable

error: aborting due to previous error
Expand Down
15 changes: 10 additions & 5 deletions src/test/ui-fulldeps/hash-stable-is-unstable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,49 @@ error[E0601]: `main` function not found in crate `hash_stable_is_unstable`
|
= note: consider adding a `main` function to `$DIR/hash-stable-is-unstable.rs`

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)
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?
--> $DIR/hash-stable-is-unstable.rs:3:1
|
LL | extern crate rustc_data_structures;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

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)
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?
--> $DIR/hash-stable-is-unstable.rs:5:1
|
LL | extern crate rustc;
| ^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

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)
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?
--> $DIR/hash-stable-is-unstable.rs:7:1
|
LL | extern crate rustc_macros;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

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)
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?
--> $DIR/hash-stable-is-unstable.rs:10:5
|
LL | use rustc_macros::HashStable;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

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)
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?
--> $DIR/hash-stable-is-unstable.rs:13:10
|
LL | #[derive(HashStable)]
| ^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/27812
= help: add #![feature(rustc_private)] to the crate attributes to enable

error: aborting due to 6 previous errors
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/cast/cast-ptr-to-int-const.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
error[E0658]: casting pointers to integers in constants is unstable (see issue #51910)
error[E0658]: casting pointers to integers in constants is unstable
--> $DIR/cast-ptr-to-int-const.rs:5:9
|
LL | main as u32
| ^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
= help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable

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

error: aborting due to 2 previous errors
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/conditional-compilation/cfg-attr-crate-2.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0658]: no_core is experimental (see issue #29639)
error[E0658]: no_core is experimental
--> $DIR/cfg-attr-crate-2.rs:6:21
|
LL | #![cfg_attr(broken, no_core)]
| ^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/29639
= help: add #![feature(no_core)] to the crate attributes to enable

error: aborting due to previous error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0658]: no_core is experimental (see issue #29639)
error[E0658]: no_core is experimental
--> $DIR/cfg-attr-multi-invalid-1.rs:4:21
|
LL | #![cfg_attr(broken, no_core, no_std)]
| ^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/29639
= help: add #![feature(no_core)] to the crate attributes to enable

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

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

error: aborting due to previous error
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/consts/const-deref-ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0658]: dereferencing raw pointers in statics is unstable (see issue #51911)
error[E0658]: dereferencing raw pointers in statics is unstable
--> $DIR/const-deref-ptr.rs:4:29
|
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51911
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable

error: aborting due to previous error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0658]: unions in const fn are unstable (see issue #51909)
error[E0658]: unions in const fn are unstable
--> $DIR/feature-gate-const_fn_union.rs:11:5
|
LL | Foo { u }.i
| ^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51909
= help: add #![feature(const_fn_union)] to the crate attributes to enable

error: aborting due to previous error
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/consts/const-eval/feature-gate-const_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
error[E0658]: panicking in constants is unstable (see issue #51999)
error[E0658]: panicking in constants is unstable
--> $DIR/feature-gate-const_panic.rs:3:15
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51999
= help: add #![feature(const_panic)] to the crate attributes to enable
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

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

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

Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/consts/const-eval/match-test-ptr-null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ fn main() {
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
// bytes.
let _: [u8; 0] = [4; {
match &1 as *const i32 as usize { //~ ERROR casting pointers to integers in constants
match &1 as *const i32 as usize {
//~^ ERROR casting pointers to integers in constants
//~| NOTE for more information, see
0 => 42, //~ ERROR constant contains unimplemented expression type
//~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed
//~| ERROR evaluation of constant value failed
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/consts/const-eval/match-test-ptr-null.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
error[E0658]: casting pointers to integers in constants is unstable (see issue #51910)
error[E0658]: casting pointers to integers in constants is unstable
--> $DIR/match-test-ptr-null.rs:6:15
|
LL | match &1 as *const i32 as usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51910
= help: add #![feature(const_raw_ptr_to_usize_cast)] to the crate attributes to enable

error[E0019]: constant contains unimplemented expression type
--> $DIR/match-test-ptr-null.rs:7:13
--> $DIR/match-test-ptr-null.rs:9:13
|
LL | 0 => 42,
| ^

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