From 01f0814a2a7db7d93b4cb90b74242b082861e674 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 1 Feb 2018 22:55:20 +0100 Subject: [PATCH] Stabilize use_nested_groups --- .../language-features/use-nested-groups.md | 90 ------------------- src/libsyntax/feature_gate.rs | 28 +----- .../absolute-paths-in-nested-use-groups.rs | 1 - src/test/run-pass/issue-47673.rs | 1 - src/test/run-pass/use-nested-groups.rs | 2 - src/test/ui/feature-gate-use_nested_groups.rs | 31 ------- .../ui/feature-gate-use_nested_groups.stderr | 26 ------ src/test/ui/use-nested-groups-error.rs | 2 - src/test/ui/use-nested-groups-error.stderr | 4 +- 9 files changed, 4 insertions(+), 181 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/use-nested-groups.md delete mode 100644 src/test/ui/feature-gate-use_nested_groups.rs delete mode 100644 src/test/ui/feature-gate-use_nested_groups.stderr diff --git a/src/doc/unstable-book/src/language-features/use-nested-groups.md b/src/doc/unstable-book/src/language-features/use-nested-groups.md deleted file mode 100644 index 47b635bad736f..0000000000000 --- a/src/doc/unstable-book/src/language-features/use-nested-groups.md +++ /dev/null @@ -1,90 +0,0 @@ -# `use_nested_groups` - -The tracking issue for this feature is: [#44494] - -[#44494]: https://github.com/rust-lang/rust/issues/44494 - ------------------------- - -The `use_nested_groups` feature allows you to import multiple items from a -complex module tree easily, by nesting different imports in the same -declaration. For example: - -```rust -#![feature(use_nested_groups)] -# #![allow(unused_imports, dead_code)] -# -# mod foo { -# pub mod bar { -# pub type Foo = (); -# } -# pub mod baz { -# pub mod quux { -# pub type Bar = (); -# } -# } -# } - -use foo::{ - bar::{self, Foo}, - baz::{*, quux::Bar}, -}; -# -# fn main() {} -``` - -## Snippet for the book's new features appendix - -When stabilizing, add this to -`src/doc/book/second-edition/src/appendix-07-newest-features.md`: - -### Nested groups in `use` declarations - -If you have a complex module tree with many different submodules and you need -to import a few items from each one, it might be useful to group all the -imports in the same declaration to keep your code clean and avoid repeating the -base modules' name. - -The `use` declaration supports nesting to help you in those cases, both with -simple imports and glob ones. For example this snippets imports `bar`, `Foo`, -all the items in `baz` and `Bar`: - -```rust -# #![feature(use_nested_groups)] -# #![allow(unused_imports, dead_code)] -# -# mod foo { -# pub mod bar { -# pub type Foo = (); -# } -# pub mod baz { -# pub mod quux { -# pub type Bar = (); -# } -# } -# } -# -use foo::{ - bar::{self, Foo}, - baz::{*, quux::Bar}, -}; -# -# fn main() {} -``` - -## Updated reference - -When stabilizing, replace the shortcut list in -`src/doc/reference/src/items/use-declarations.md` with this updated one: - -* Simultaneously binding a list of paths with a common prefix, using the - glob-like brace syntax `use a::b::{c, d, e::f, g::h::i};` -* Simultaneously binding a list of paths with a common prefix and their common - parent module, using the `self` keyword, such as `use a::b::{self, c, d::e};` -* Rebinding the target name as a new local name, using the syntax `use p::q::r - as x;`. This can also be used with the last two features: - `use a::b::{self as ab, c as abc}`. -* Binding all paths matching a given prefix, using the asterisk wildcard syntax - `use a::b::*;`. -* Nesting groups of the previous features multiple times, such as - `use a::b::{self as ab, c d::{*, e::f}};` diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 3e858c3b923a1..9c6520cd874a8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -423,9 +423,6 @@ declare_features! ( // In-band lifetime bindings (e.g. `fn foo(x: &'a u8) -> &'a u8`) (active, in_band_lifetimes, "1.23.0", Some(44524)), - // Nested groups in `use` (RFC 2128) - (active, use_nested_groups, "1.23.0", Some(44494)), - // generic associated types (RFC 1598) (active, generic_associated_types, "1.23.0", Some(44265)), @@ -544,6 +541,8 @@ declare_features! ( (accepted, repr_align, "1.24.0", Some(33626)), // allow '|' at beginning of match arms (RFC 1925) (accepted, match_beginning_vert, "1.25.0", Some(44101)), + // Nested groups in `use` (RFC 2128) + (accepted, use_nested_groups, "1.25.0", Some(44494)), ); // If you change this, please modify src/doc/unstable-book as well. You must @@ -1805,29 +1804,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_path(self, path); } - fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: NodeId, nested: bool) { - if nested { - match use_tree.kind { - ast::UseTreeKind::Simple(_) => { - if use_tree.prefix.segments.len() != 1 { - gate_feature_post!(&self, use_nested_groups, use_tree.span, - "paths in `use` groups are experimental"); - } - } - ast::UseTreeKind::Glob => { - gate_feature_post!(&self, use_nested_groups, use_tree.span, - "glob imports in `use` groups are experimental"); - } - ast::UseTreeKind::Nested(_) => { - gate_feature_post!(&self, use_nested_groups, use_tree.span, - "nested groups in `use` are experimental"); - } - } - } - - visit::walk_use_tree(self, use_tree, id); - } - fn visit_vis(&mut self, vis: &'a ast::Visibility) { if let ast::Visibility::Crate(span, ast::CrateSugar::JustCrate) = *vis { gate_feature_post!(&self, crate_visibility_modifier, span, diff --git a/src/test/compile-fail/absolute-paths-in-nested-use-groups.rs b/src/test/compile-fail/absolute-paths-in-nested-use-groups.rs index 8e5ba489c565e..fe052f2f47ffd 100644 --- a/src/test/compile-fail/absolute-paths-in-nested-use-groups.rs +++ b/src/test/compile-fail/absolute-paths-in-nested-use-groups.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(use_nested_groups)] #![allow(unused_imports)] mod foo {} diff --git a/src/test/run-pass/issue-47673.rs b/src/test/run-pass/issue-47673.rs index 92f54a44f63c9..22f7f169e2988 100644 --- a/src/test/run-pass/issue-47673.rs +++ b/src/test/run-pass/issue-47673.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(use_nested_groups)] #![allow(unused_import)] use {{}, {}}; diff --git a/src/test/run-pass/use-nested-groups.rs b/src/test/run-pass/use-nested-groups.rs index a28f8da9ff882..be06e463e3b37 100644 --- a/src/test/run-pass/use-nested-groups.rs +++ b/src/test/run-pass/use-nested-groups.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(use_nested_groups)] - mod a { pub enum B {} diff --git a/src/test/ui/feature-gate-use_nested_groups.rs b/src/test/ui/feature-gate-use_nested_groups.rs deleted file mode 100644 index 56413a999d7f7..0000000000000 --- a/src/test/ui/feature-gate-use_nested_groups.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unused_imports, dead_code)] - -mod a { - pub enum B {} - pub enum C {} - - pub mod d { - pub enum E {} - pub enum F {} - - pub mod g { - pub enum H {} - } - } -} - -use a::{B, d::{*, g::H}}; //~ ERROR glob imports in `use` groups are experimental - //~^ ERROR nested groups in `use` are experimental - //~^^ ERROR paths in `use` groups are experimental - -fn main() {} diff --git a/src/test/ui/feature-gate-use_nested_groups.stderr b/src/test/ui/feature-gate-use_nested_groups.stderr deleted file mode 100644 index 6ae691c384be8..0000000000000 --- a/src/test/ui/feature-gate-use_nested_groups.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error[E0658]: nested groups in `use` are experimental (see issue #44494) - --> $DIR/feature-gate-use_nested_groups.rs:27:12 - | -27 | use a::{B, d::{*, g::H}}; //~ ERROR glob imports in `use` groups are experimental - | ^^^^^^^^^^^^ - | - = help: add #![feature(use_nested_groups)] to the crate attributes to enable - -error[E0658]: glob imports in `use` groups are experimental (see issue #44494) - --> $DIR/feature-gate-use_nested_groups.rs:27:16 - | -27 | use a::{B, d::{*, g::H}}; //~ ERROR glob imports in `use` groups are experimental - | ^ - | - = help: add #![feature(use_nested_groups)] to the crate attributes to enable - -error[E0658]: paths in `use` groups are experimental (see issue #44494) - --> $DIR/feature-gate-use_nested_groups.rs:27:19 - | -27 | use a::{B, d::{*, g::H}}; //~ ERROR glob imports in `use` groups are experimental - | ^^^^ - | - = help: add #![feature(use_nested_groups)] to the crate attributes to enable - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/use-nested-groups-error.rs b/src/test/ui/use-nested-groups-error.rs index a9b6b3ee70d57..0a68d34ade9fa 100644 --- a/src/test/ui/use-nested-groups-error.rs +++ b/src/test/ui/use-nested-groups-error.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(use_nested_groups)] - mod a { pub mod b1 { pub enum C2 {} diff --git a/src/test/ui/use-nested-groups-error.stderr b/src/test/ui/use-nested-groups-error.stderr index cae34684c8e38..c4edb626be0bb 100644 --- a/src/test/ui/use-nested-groups-error.stderr +++ b/src/test/ui/use-nested-groups-error.stderr @@ -1,7 +1,7 @@ error[E0432]: unresolved import `a::b1::C1` - --> $DIR/use-nested-groups-error.rs:21:14 + --> $DIR/use-nested-groups-error.rs:19:14 | -21 | use a::{b1::{C1, C2}, B2}; +19 | use a::{b1::{C1, C2}, B2}; | ^^ no `C1` in `a::b1`. Did you mean to use `C2`? error: aborting due to previous error