]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53413 - eddyb:featured-in-the-latest-edition, r=varkor
authorCorey Farwell <coreyf@rwell.org>
Fri, 17 Aug 2018 15:23:44 +0000 (08:23 -0700)
committerGitHub <noreply@github.com>
Fri, 17 Aug 2018 15:23:44 +0000 (08:23 -0700)
Warn that `#![feature(rust_2018_preview)]` is implied when the edition is set to Rust 2018.

cc @varkor @petrochenkov @joshtriplett

29 files changed:
src/libsyntax/feature_gate.rs
src/test/run-pass/macro-at-most-once-rep.rs
src/test/rustdoc/async-fn.rs
src/test/ui-fulldeps/rust-2018/suggestions-not-always-applicable.fixed
src/test/ui-fulldeps/rust-2018/suggestions-not-always-applicable.rs
src/test/ui-fulldeps/unnecessary-extern-crate.rs
src/test/ui/E0705.rs
src/test/ui/E0705.stderr
src/test/ui/borrowck/borrowck-feature-nll-overrides-migrate.rs
src/test/ui/borrowck/borrowck-migrate-to-nll.rs
src/test/ui/borrowck/issue-52967-edition-2018-needs-two-phase-borrows.rs
src/test/ui/editions/edition-extern-crate-allowed.rs
src/test/ui/editions/edition-feature-ok.rs
src/test/ui/editions/edition-feature-redundant.rs [new file with mode: 0644]
src/test/ui/editions/edition-feature-redundant.stderr [new file with mode: 0644]
src/test/ui/in-band-lifetimes/elided-lifetimes.fixed
src/test/ui/in-band-lifetimes/elided-lifetimes.rs
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep-feature-flag.rs
src/test/ui/macros/macro-at-most-once-rep-2015-ques-rep.rs
src/test/ui/macros/macro-at-most-once-rep-2015-ques-sep.rs
src/test/ui/macros/macro-at-most-once-rep-2018-feature-gate.rs
src/test/ui/macros/macro-at-most-once-rep-2018.rs
src/test/ui/removing-extern-crate.fixed
src/test/ui/removing-extern-crate.rs
src/test/ui/rust-2018/async-ident-allowed.rs
src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed
src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs
src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr
src/test/ui/rust-2018/issue-52202-use-suggestions.rs

index 395e5c98652326091ed5ce6f79d573698426722c..7a8a7b073185a6477dfeb8fdbb73dec1995d1202 100644 (file)
@@ -1930,7 +1930,15 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
     let mut features = Features::new();
     let mut edition_enabled_features = FxHashMap();
 
-    for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
+    for &edition in ALL_EDITIONS {
+        if edition <= crate_edition {
+            // The `crate_edition` implies its respective umbrella feature-gate
+            // (i.e. `#![feature(rust_20XX_preview)]` isn't needed on edition 20XX).
+            edition_enabled_features.insert(Symbol::intern(edition.feature_name()), edition);
+        }
+    }
+
+    for &(name, .., f_edition, set) in ACTIVE_FEATURES {
         if let Some(f_edition) = f_edition {
             if f_edition <= crate_edition {
                 set(&mut features, DUMMY_SP);
@@ -1939,6 +1947,8 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
         }
     }
 
+    // Process the edition umbrella feature-gates first, to ensure
+    // `edition_enabled_features` is completed before it's queried.
     for attr in krate_attrs {
         if !attr.check_name("feature") {
             continue
@@ -1946,19 +1956,13 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
 
         let list = match attr.meta_item_list() {
             Some(list) => list,
-            None => {
-                span_err!(span_handler, attr.span, E0555,
-                          "malformed feature attribute, expected #![feature(...)]");
-                continue
-            }
+            None => continue,
         };
 
         for mi in list {
             let name = if let Some(word) = mi.word() {
                 word.name()
             } else {
-                span_err!(span_handler, mi.span, E0556,
-                          "malformed feature, expected just one word");
                 continue
             };
 
@@ -1974,10 +1978,10 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
 
             if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
                 if *edition <= crate_edition {
-                    continue
+                    continue;
                 }
 
-                for &(name, .., f_edition, set) in ACTIVE_FEATURES.iter() {
+                for &(name, .., f_edition, set) in ACTIVE_FEATURES {
                     if let Some(f_edition) = f_edition {
                         if f_edition <= *edition {
                             // FIXME(Manishearth) there is currently no way to set
@@ -1987,24 +1991,53 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
                         }
                     }
                 }
+            }
+        }
+    }
+
+    for attr in krate_attrs {
+        if !attr.check_name("feature") {
+            continue
+        }
+
+        let list = match attr.meta_item_list() {
+            Some(list) => list,
+            None => {
+                span_err!(span_handler, attr.span, E0555,
+                          "malformed feature attribute, expected #![feature(...)]");
+                continue
+            }
+        };
 
+        for mi in list {
+            let name = if let Some(word) = mi.word() {
+                word.name()
+            } else {
+                span_err!(span_handler, mi.span, E0556,
+                          "malformed feature, expected just one word");
                 continue
+            };
+
+            if let Some(edition) = edition_enabled_features.get(&name) {
+                struct_span_warn!(
+                    span_handler,
+                    mi.span,
+                    E0705,
+                    "the feature `{}` is included in the Rust {} edition",
+                    name,
+                    edition,
+                ).emit();
+                continue;
+            }
+
+            if ALL_EDITIONS.iter().any(|e| name == e.feature_name()) {
+                // Handled in the separate loop above.
+                continue;
             }
 
             if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
-                if let Some(edition) = edition_enabled_features.get(&name) {
-                    struct_span_warn!(
-                        span_handler,
-                        mi.span,
-                        E0705,
-                        "the feature `{}` is included in the Rust {} edition",
-                        name,
-                        edition,
-                    ).emit();
-                } else {
-                    set(&mut features, mi.span);
-                    features.declared_lang_features.push((name, mi.span, None));
-                }
+                set(&mut features, mi.span);
+                features.declared_lang_features.push((name, mi.span, None));
                 continue
             }
 
index dcf2222ba6dea18a012768b49d4f0db05957bc97..61c3e781c08676fe99413024987c9f8f37d18196 100644 (file)
@@ -18,7 +18,7 @@
 //
 // This test focuses on non-error cases and making sure the correct number of repetitions happen.
 
-// compile-flags: --edition=2018
+// edition:2018
 
 #![feature(macro_at_most_once_rep)]
 
index 21ad5159946fd701d89b9e30617664b95b92b0fb..f3d39deef173083939609268aff7177579709c79 100644 (file)
@@ -13,7 +13,7 @@
 
 // FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive
 
-#![feature(rust_2018_preview, async_await, futures_api)]
+#![feature(async_await, futures_api)]
 
 // @has async_fn/struct.S.html
 // @has - '//code' 'pub async fn f()'
index e5b47c70863e5371b0d0d640cf5ba182b3bb7fbc..b64ebed030588fae9cccd48b4f963f1d580c0aa5 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // aux-build:suggestions-not-always-applicable.rs
-// compile-flags: --edition 2015
+// edition:2015
 // run-rustfix
 // rustfix-only-machine-applicable
 // compile-pass
index e5b47c70863e5371b0d0d640cf5ba182b3bb7fbc..b64ebed030588fae9cccd48b4f963f1d580c0aa5 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // aux-build:suggestions-not-always-applicable.rs
-// compile-flags: --edition 2015
+// edition:2015
 // run-rustfix
 // rustfix-only-machine-applicable
 // compile-pass
index 0811c79b0a4b9d5d50a4abd343c8756934c855d5..ea3e0587958b10a8c86c0713333508606628e145 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: --edition 2018
+// edition:2018
 
 #![deny(unused_extern_crates)]
 #![feature(alloc, test, libc)]
index a0ce95e3e02c1ad1f4f45395cccc41b135902144..b5fd3cf35f28bedd306e13813b6ed3a1a1a2a261 100644 (file)
@@ -10,9 +10,9 @@
 
 // compile-pass
 
-#![feature(rust_2018_preview)]
 #![feature(raw_identifiers)]
 //~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition
+#![feature(rust_2018_preview)]
 
 fn main() {
     let foo = 0;
index ebb8dd4975d6f101aa15f8b23f111fce301e49d6..2aa3077e48c2dad6ffa3d56be088b875f2f4492e 100644 (file)
@@ -1,5 +1,5 @@
 warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition
-  --> $DIR/E0705.rs:14:12
+  --> $DIR/E0705.rs:13:12
    |
 LL | #![feature(raw_identifiers)]
    |            ^^^^^^^^^^^^^^^
index 72043938f53511f0e441e6c2b8bd6e1045d376a3..104c0886311d0bda3cea464539a338336fdb6288 100644 (file)
@@ -20,7 +20,7 @@
 
 // revisions: zflag edition
 // [zflag]compile-flags: -Z borrowck=migrate
-// [edition]compile-flags: --edition 2018
+// [edition]edition:2018
 
 #![feature(nll)]
 
index e7f2bfbfedba79bd74840fe89c9c01ea140e4a09..bb6b29072e257fc6fe317d8f726912d0acdca55b 100644 (file)
@@ -23,7 +23,7 @@
 
 // revisions: zflag edition
 //[zflag]compile-flags: -Z borrowck=migrate
-//[edition]compile-flags: --edition 2018
+//[edition]edition:2018
 //[zflag] run-pass
 //[edition] run-pass
 
index c39fff2644dfd3325127c39b059fcda63da60c26..3b53fb9fc42831f7bf77da554c3a76bf1df29799 100644 (file)
@@ -14,7 +14,7 @@
 
 // revisions: ast zflags edition
 //[zflags]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
-//[edition]compile-flags: --edition 2018
+//[edition]edition:2018
 
 // run-pass
 
index 7368564e250d1b7a7e9a8c487f417e6ca125196f..75761a0b5b9716849883878868ca2cbfddad7fbe 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // aux-build:edition-extern-crate-allowed.rs
-// compile-flags: --edition 2015
+// edition:2015
 // compile-pass
 
 #![warn(rust_2018_idioms)]
index 3a3a6ff95f97e9a73943244423eb261ba49a16ab..5896e9a07159164c923153fb375b54b25c0663f4 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags:--edition 2018
 // compile-pass
 
 #![feature(rust_2018_preview)]
diff --git a/src/test/ui/editions/edition-feature-redundant.rs b/src/test/ui/editions/edition-feature-redundant.rs
new file mode 100644 (file)
index 0000000..d20873f
--- /dev/null
@@ -0,0 +1,17 @@
+// 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.
+
+// edition:2018
+// compile-pass
+
+#![feature(rust_2018_preview)]
+//~^ WARN the feature `rust_2018_preview` is included in the Rust 2018 edition
+
+fn main() {}
diff --git a/src/test/ui/editions/edition-feature-redundant.stderr b/src/test/ui/editions/edition-feature-redundant.stderr
new file mode 100644 (file)
index 0000000..ccf7b21
--- /dev/null
@@ -0,0 +1,6 @@
+warning[E0705]: the feature `rust_2018_preview` is included in the Rust 2018 edition
+  --> $DIR/edition-feature-redundant.rs:14:12
+   |
+LL | #![feature(rust_2018_preview)]
+   |            ^^^^^^^^^^^^^^^^^
+
index c9381e6350f2bc64926c69a4df33f4676eacc4be..153e5003746887eff17f558297ac82f585d9e2a0 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // run-rustfix
-// compile-flags: --edition 2018
+// edition:2018
 
 #![allow(unused)]
 #![deny(elided_lifetimes_in_paths)]
index 8151dd01a98d8d8108d81ab6f0e0a4eb77764882..41aa7e1a7b7b9b4524b9c311559c88f3bef64801 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // run-rustfix
-// compile-flags: --edition 2018
+// edition:2018
 
 #![allow(unused)]
 #![deny(elided_lifetimes_in_paths)]
index fd7925ea3eeeb07bf1821fa8d6ae55396f80892b..63a4ef16a2581cef6a2a03fdc27dff2ad29402b4 100644 (file)
@@ -12,7 +12,7 @@
 // with the feature flag.
 
 // gate-test-macro_at_most_once_rep
-// compile-flags: --edition=2015
+// edition:2015
 
 #![feature(macro_at_most_once_rep)]
 
index 90bc19739b8724b279891854f02352afa8a24fe9..64848d050cb1e90bbe242628a1ceddb7266017c8 100644 (file)
@@ -10,7 +10,7 @@
 
 // Test behavior of `?` macro _kleene op_ under the 2015 edition. Namely, it doesn't exist.
 
-// compile-flags: --edition=2015
+// edition:2015
 
 macro_rules! bar {
     ($(a)?) => {} //~ERROR expected `*` or `+`
index 2e06b4bd5c2405819a29fe8efbe2822d5c48257b..a7857991079feefec88b41726b3e71cc68fe90e5 100644 (file)
@@ -11,7 +11,7 @@
 // Test behavior of `?` macro _separator_ under the 2015 edition. Namely, `?` can be used as a
 // separator, but you get a migration warning for the edition.
 
-// compile-flags: --edition=2015
+// edition:2015
 // compile-pass
 
 #![warn(rust_2018_compatibility)]
index f3107d4f1e4f6382942cfef5bea134988755bea8..ffabf9bcdf68557dad795f6135ed646380c87d74 100644 (file)
@@ -11,7 +11,7 @@
 // Feature gate test for macro_at_most_once_rep under 2018 edition.
 
 // gate-test-macro_at_most_once_rep
-// compile-flags: --edition=2018
+// edition:2018
 
 macro_rules! foo {
     ($(a)?) => {}
index 958a7e0cdf444beed41e76010c0f8ebe5580420c..5dabe8d95280100932a910c7b92344c23dbb1fde 100644 (file)
@@ -10,7 +10,7 @@
 
 // Tests that `?` is a Kleene op and not a macro separator in the 2018 edition.
 
-// compile-flags: --edition=2018
+// edition:2018
 
 #![feature(macro_at_most_once_rep)]
 
index 83b35cec80956847ff2141afc27d63697b8b209f..90427b061b652f16a6ab7575314416f286689ec3 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: --edition 2018
+// edition:2018
 // aux-build:removing-extern-crate.rs
 // run-rustfix
 // compile-pass
index 29479086460e6cca9095f4ec5ebc646b7dd091c9..3905d285becb55a5cf42ac18915b8bf469a09079 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: --edition 2018
+// edition:2018
 // aux-build:removing-extern-crate.rs
 // run-rustfix
 // compile-pass
index fd4eae1f9b54c33d7ea0d4273e2d9069184e0c26..3bc468483bda2a1487ceeff1cd3119864fb4f761 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: --edition 2015
+// edition:2015
 
 #![deny(rust_2018_compatibility)]
 
index 4f99c1240f8f49a65baf52352a6e6ee8e91ca146..fc81ab08f624d480ee5491354e3cfb911653f98a 100644 (file)
 
 // aux-build:edition-lint-paths.rs
 // run-rustfix
-// compile-flags:--edition 2018
+// edition:2018
 
 // The "normal case". Ideally we would remove the `extern crate` here,
 // but we don't.
 
-#![feature(rust_2018_preview)]
 #![deny(rust_2018_idioms)]
 #![allow(dead_code)]
 
index 9c1235a296799cdd238f5a55705e3c7e18cd28fe..72751f2080cc9b2d28f31ab179189438679dc9a1 100644 (file)
 
 // aux-build:edition-lint-paths.rs
 // run-rustfix
-// compile-flags:--edition 2018
+// edition:2018
 
 // The "normal case". Ideally we would remove the `extern crate` here,
 // but we don't.
 
-#![feature(rust_2018_preview)]
 #![deny(rust_2018_idioms)]
 #![allow(dead_code)]
 
index b3afa2bd1d59289bb9c7ffd23a23829793436a7b..0ecfd4e4a2ca3076523bffe3ebf6a840dd5fcda9 100644 (file)
@@ -1,18 +1,18 @@
 error: unused extern crate
-  --> $DIR/extern-crate-idiomatic-in-2018.rs:22:1
+  --> $DIR/extern-crate-idiomatic-in-2018.rs:21:1
    |
 LL | extern crate edition_lint_paths;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
    |
 note: lint level defined here
-  --> $DIR/extern-crate-idiomatic-in-2018.rs:19:9
+  --> $DIR/extern-crate-idiomatic-in-2018.rs:18:9
    |
 LL | #![deny(rust_2018_idioms)]
    |         ^^^^^^^^^^^^^^^^
    = note: #[deny(unused_extern_crates)] implied by #[deny(rust_2018_idioms)]
 
 error: `extern crate` is not idiomatic in the new edition
-  --> $DIR/extern-crate-idiomatic-in-2018.rs:25:1
+  --> $DIR/extern-crate-idiomatic-in-2018.rs:24:1
    |
 LL | extern crate edition_lint_paths as bar;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`
index 5acd19c2471e68169c0c92d3a2fcab8286d41112..deb80411bbf6405ed809afe2c6c113fbb737ca9c 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags: --edition 2018
+// edition:2018
 
 // The local `use` suggestion should start with `crate::` (but the
 // standard-library suggestions should not, obviously).