diff options
| author | bors <bors@rust-lang.org> | 2018-01-15 15:36:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-15 15:36:54 +0000 |
| commit | 79a521bb9a8ace1a6663578a4c409906adde620d (patch) | |
| tree | 73990bc3ee1c7d1a5511a37c8b2a52b9d934cd5e /src/libsyntax | |
| parent | 57850e53602bfc1f66a12d20299c938925c1986a (diff) | |
| parent | c8a110ed6329022850fd9d473ec987ba1459a64f (diff) | |
| download | rust-79a521bb9a8ace1a6663578a4c409906adde620d.tar.gz rust-79a521bb9a8ace1a6663578a4c409906adde620d.zip | |
Auto merge of #47413 - GuillaumeGomez:unstable-error-code, r=estebank
Add error code for unstable feature errors Fixes #47397.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostic_list.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/diagnostics/macros.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 4 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index c3cf4747835..d841281e485 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -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! { diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index c01836b6194..61f3e7046f1 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -106,6 +106,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)*) => ({ if $typ.references_error() { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index c3bf5dbff5c..196fadcc997 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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), }; |
