Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
01f0814a
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
01f0814a
编写于
2月 01, 2018
作者:
P
Pietro Albini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stabilize use_nested_groups
上级
07ea2604
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
4 addition
and
181 deletion
+4
-181
src/doc/unstable-book/src/language-features/use-nested-groups.md
.../unstable-book/src/language-features/use-nested-groups.md
+0
-90
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+2
-26
src/test/compile-fail/absolute-paths-in-nested-use-groups.rs
src/test/compile-fail/absolute-paths-in-nested-use-groups.rs
+0
-1
src/test/run-pass/issue-47673.rs
src/test/run-pass/issue-47673.rs
+0
-1
src/test/run-pass/use-nested-groups.rs
src/test/run-pass/use-nested-groups.rs
+0
-2
src/test/ui/feature-gate-use_nested_groups.rs
src/test/ui/feature-gate-use_nested_groups.rs
+0
-31
src/test/ui/feature-gate-use_nested_groups.stderr
src/test/ui/feature-gate-use_nested_groups.stderr
+0
-26
src/test/ui/use-nested-groups-error.rs
src/test/ui/use-nested-groups-error.rs
+0
-2
src/test/ui/use-nested-groups-error.stderr
src/test/ui/use-nested-groups-error.stderr
+2
-2
未找到文件。
src/doc/unstable-book/src/language-features/use-nested-groups.md
已删除
100644 → 0
浏览文件 @
07ea2604
# `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}};`
src/libsyntax/feature_gate.rs
浏览文件 @
01f0814a
...
...
@@ -423,9 +423,6 @@ pub fn new() -> 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 @@ pub fn new() -> 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 @@ fn visit_path(&mut self, path: &'a ast::Path, _id: NodeId) {
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
,
...
...
src/test/compile-fail/absolute-paths-in-nested-use-groups.rs
浏览文件 @
01f0814a
...
...
@@ -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
{}
...
...
src/test/run-pass/issue-47673.rs
浏览文件 @
01f0814a
...
...
@@ -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
{{},
{}};
...
...
src/test/run-pass/use-nested-groups.rs
浏览文件 @
01f0814a
...
...
@@ -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
{}
...
...
src/test/ui/feature-gate-use_nested_groups.rs
已删除
100644 → 0
浏览文件 @
07ea2604
// 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 <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.
#![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
()
{}
src/test/ui/feature-gate-use_nested_groups.stderr
已删除
100644 → 0
浏览文件 @
07ea2604
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
src/test/ui/use-nested-groups-error.rs
浏览文件 @
01f0814a
...
...
@@ -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
{}
...
...
src/test/ui/use-nested-groups-error.stderr
浏览文件 @
01f0814a
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录