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

Add error code for unstable feature errors #47413

Merged
merged 1 commit into from
Jan 15, 2018
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
25 changes: 25 additions & 0 deletions src/libsyntax/diagnostic_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,31 @@ fn main() {
```
"##,

E0658: r##"
An unstable feature was used.

Erroneous code example:

```compile_fail,E658
let x = ::std::u128::MAX; // error: use of unstable library feature 'i128'
```

If you're using a stable or a beta version of rustc, you won't be able to use
any unstable features. In order to do so, please switch to a nightly version of
rustc (by using rustup).

If you're using a nightly version of rustc, just add the corresponding feature
to be able to use it:

```
#![feature(i128)]

fn main() {
let x = ::std::u128::MAX; // ok!
}
```
"##,

}

register_diagnostics! {
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/diagnostics/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ macro_rules! struct_span_err {
})
}

#[macro_export]
macro_rules! stringify_error_code {
($code:ident) => ({
__diagnostic_used!($code);
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned())
})
}

#[macro_export]
macro_rules! type_error_struct {
($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,9 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue
};

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

Expand Down
13 changes: 13 additions & 0 deletions src/test/compile-fail/E0658.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let _ = ::std::u128::MAX; //~ ERROR E0658
}
2 changes: 1 addition & 1 deletion src/test/ui/feature-gate-abi-msp430-interrupt.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: msp430-interrupt ABI is experimental and subject to change (see issue #38487)
error[E0658]: msp430-interrupt ABI is experimental and subject to change (see issue #38487)
--> $DIR/feature-gate-abi-msp430-interrupt.rs:14:1
|
14 | extern "msp430-interrupt" fn foo() {}
Expand Down
Loading