Skip to content

Commit 336cf9d

Browse files
committed
Tweak the raw_identifiers lints in 2018
* Enable the `raw_identifiers` feature automatically in the 2018 preview * Only emit lint warnings if the `raw_identifiers` feature is activated cc rust-lang/cargo#5783
1 parent e842dea commit 336cf9d

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

src/librustc_lint/builtin.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1830,12 +1830,16 @@ impl Async2018 {
18301830
span,
18311831
"`async` is a keyword in the 2018 edition",
18321832
);
1833-
lint.span_suggestion_with_applicability(
1834-
span,
1835-
"you can use a raw identifier to stay compatible",
1836-
"r#async".to_string(),
1837-
Applicability::MachineApplicable,
1838-
);
1833+
1834+
// Don't suggest about raw identifiers if the feature isn't active
1835+
if cx.sess.features_untracked().raw_identifiers {
1836+
lint.span_suggestion_with_applicability(
1837+
span,
1838+
"you can use a raw identifier to stay compatible",
1839+
"r#async".to_string(),
1840+
Applicability::MachineApplicable,
1841+
);
1842+
}
18391843
lint.emit()
18401844
}
18411845
}

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ declare_features! (
409409
(active, underscore_imports, "1.26.0", Some(48216), None),
410410

411411
// Allows keywords to be escaped for use as identifiers
412-
(active, raw_identifiers, "1.26.0", Some(48589), None),
412+
(active, raw_identifiers, "1.26.0", Some(48589), Some(Edition::Edition2018)),
413413

414414
// Allows macro invocations in `extern {}` blocks
415415
(active, macros_in_extern, "1.27.0", Some(49476), None),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// compile-flags: --edition 2015
12+
13+
#![deny(rust_2018_compatibility)]
14+
15+
// Don't make a suggestion for a raw identifer replacement unless raw
16+
// identifiers are enabled.
17+
18+
fn main() {
19+
let async = 3; //~ ERROR: is a keyword
20+
//~^ WARN previously accepted
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: `async` is a keyword in the 2018 edition
2+
--> $DIR/async-ident-allowed.rs:19:9
3+
|
4+
LL | let async = 3; //~ ERROR: is a keyword
5+
| ^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/async-ident-allowed.rs:13:9
9+
|
10+
LL | #![deny(rust_2018_compatibility)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: #[deny(async_idents)] implied by #[deny(rust_2018_compatibility)]
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
14+
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
15+
16+
error: aborting due to previous error
17+

0 commit comments

Comments
 (0)