Skip to content

Commit 5ed2b51

Browse files
committed
Auto merge of #52722 - alexcrichton:more-identifier-lints, r=oli-obk
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
2 parents 7bbcd00 + 336cf9d commit 5ed2b51

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
@@ -1891,12 +1891,16 @@ impl Async2018 {
18911891
span,
18921892
"`async` is a keyword in the 2018 edition",
18931893
);
1894-
lint.span_suggestion_with_applicability(
1895-
span,
1896-
"you can use a raw identifier to stay compatible",
1897-
"r#async".to_string(),
1898-
Applicability::MachineApplicable,
1899-
);
1894+
1895+
// Don't suggest about raw identifiers if the feature isn't active
1896+
if cx.sess.features_untracked().raw_identifiers {
1897+
lint.span_suggestion_with_applicability(
1898+
span,
1899+
"you can use a raw identifier to stay compatible",
1900+
"r#async".to_string(),
1901+
Applicability::MachineApplicable,
1902+
);
1903+
}
19001904
lint.emit()
19011905
}
19021906
}

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ declare_features! (
412412
(active, underscore_imports, "1.26.0", Some(48216), None),
413413

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

417417
// Allows macro invocations in `extern {}` blocks
418418
(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)