Skip to content

Commit

Permalink
Auto merge of #47413 - GuillaumeGomez:unstable-error-code, r=estebank
Browse files Browse the repository at this point in the history
Add error code for unstable feature errors

Fixes #47397.
  • Loading branch information
bors committed Jan 15, 2018
2 parents 57850e5 + c8a110e commit 79a521b
Show file tree
Hide file tree
Showing 121 changed files with 345 additions and 297 deletions.
25 changes: 25 additions & 0 deletions src/libsyntax/diagnostic_list.rs
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
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
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
@@ -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
@@ -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

0 comments on commit 79a521b

Please sign in to comment.