Skip to content

Commit 2c99ace

Browse files
Add error code for unstable feature errors
1 parent 3f92e8d commit 2c99ace

File tree

121 files changed

+346
-297
lines changed

Some content is hidden

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

121 files changed

+346
-297
lines changed

src/libsyntax/diagnostic_list.rs

+25
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,31 @@ fn main() {
317317
```
318318
"##,
319319

320+
E0658: r##"
321+
An unstable feature was used.
322+
323+
Erroneous code example:
324+
325+
```compile_fail,E658
326+
let x = ::std::u128::MAX; // error: use of unstable library feature 'i128'
327+
```
328+
329+
If you're using a stable or a beta version of rustc, you won't be able to use
330+
any unstable features. In order to do so, please switch to a nightly version of
331+
rustc (by using rustup).
332+
333+
If you're using a nightly version of rustc, just add the corresponding feature
334+
to be able to use it:
335+
336+
```
337+
#![feature(i128)]
338+
339+
fn main() {
340+
let x = ::std::u128::MAX; // ok!
341+
}
342+
```
343+
"##,
344+
320345
}
321346

322347
register_diagnostics! {

src/libsyntax/diagnostics/macros.rs

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ macro_rules! struct_span_err {
105105
})
106106
}
107107

108+
#[macro_export]
109+
macro_rules! stringify_error_code {
110+
($code:ident) => ({
111+
__diagnostic_used!($code);
112+
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned())
113+
})
114+
}
115+
108116
#[macro_export]
109117
macro_rules! type_error_struct {
110118
($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({

src/libsyntax/feature_gate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,9 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue
11791179
};
11801180

11811181
let mut err = match level {
1182-
GateStrength::Hard => diag.struct_span_err(span, &explanation),
1182+
GateStrength::Hard => {
1183+
diag.struct_span_err_with_code(span, &explanation, stringify_error_code!(E0658))
1184+
}
11831185
GateStrength::Soft => diag.struct_span_warn(span, &explanation),
11841186
};
11851187

src/test/compile-fail/E0658.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let _ = ::std::u128::MAX; //~ ERROR E0658
13+
}

src/test/ui/feature-gate-abi-msp430-interrupt.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: msp430-interrupt ABI is experimental and subject to change (see issue #38487)
1+
error[E0658]: msp430-interrupt ABI is experimental and subject to change (see issue #38487)
22
--> $DIR/feature-gate-abi-msp430-interrupt.rs:14:1
33
|
44
14 | extern "msp430-interrupt" fn foo() {}

0 commit comments

Comments
 (0)