Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cfcd449c
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,发现更多精彩内容 >>
提交
cfcd449c
编写于
7月 31, 2015
作者:
S
Sean McArthur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: rename multiple imports in a list
上级
d0345618
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
169 addition
and
33 deletion
+169
-33
src/grammar/parser-lalr.y
src/grammar/parser-lalr.y
+1
-0
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+2
-2
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+7
-6
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+6
-3
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+7
-2
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+18
-3
src/libsyntax/ext/build.rs
src/libsyntax/ext/build.rs
+1
-1
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+7
-3
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+14
-6
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+16
-4
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+9
-2
src/test/compile-fail/unresolved-import.rs
src/test/compile-fail/unresolved-import.rs
+15
-1
src/test/pretty/import-renames.rs
src/test/pretty/import-renames.rs
+14
-0
src/test/run-pass/import-rename.rs
src/test/run-pass/import-rename.rs
+21
-0
src/test/run-pass/use.rs
src/test/run-pass/use.rs
+3
-0
src/test/rustdoc/viewpath-rename.rs
src/test/rustdoc/viewpath-rename.rs
+28
-0
未找到文件。
src/grammar/parser-lalr.y
浏览文件 @
cfcd449c
...
...
@@ -472,6 +472,7 @@ visibility
idents_or_self
: ident_or_self { $$ = mk_node("IdentsOrSelf", 1, $1); }
| ident_or_self AS ident { $$ = mk_node("IdentsOrSelf", 2, $1, $3); }
| idents_or_self ',' ident_or_self { $$ = ext_node($1, 1, $3); }
;
...
...
src/librustc_privacy/lib.rs
浏览文件 @
cfcd449c
...
...
@@ -862,11 +862,11 @@ fn visit_item(&mut self, item: &ast::Item) {
if
let
ast
::
ViewPathList
(
ref
prefix
,
ref
list
)
=
vpath
.node
{
for
pid
in
list
{
match
pid
.node
{
ast
::
PathListIdent
{
id
,
name
}
=>
{
ast
::
PathListIdent
{
id
,
name
,
..
}
=>
{
debug!
(
"privacy - ident item {}"
,
id
);
self
.check_path
(
pid
.span
,
id
,
name
.name
);
}
ast
::
PathListMod
{
id
}
=>
{
ast
::
PathListMod
{
id
,
..
}
=>
{
debug!
(
"privacy - mod item {}"
,
id
);
let
name
=
prefix
.segments
.last
()
.unwrap
()
.identifier.name
;
self
.check_path
(
pid
.span
,
id
,
name
);
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
cfcd449c
...
...
@@ -341,10 +341,10 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
}
for
source_item
in
source_items
{
let
(
module_path
,
name
)
=
match
source_item
.node
{
PathListIdent
{
name
,
..
}
=>
(
module_path
.clone
(),
name
.name
),
PathListMod
{
..
}
=>
{
let
(
module_path
,
name
,
rename
)
=
match
source_item
.node
{
PathListIdent
{
name
,
rename
,
..
}
=>
(
module_path
.clone
(),
name
.name
,
rename
.unwrap_or
(
name
)
.name
),
PathListMod
{
rename
,
..
}
=>
{
let
name
=
match
module_path
.last
()
{
Some
(
name
)
=>
*
name
,
None
=>
{
...
...
@@ -358,13 +358,14 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: &Rc<Module>) ->
}
};
let
module_path
=
module_path
.split_last
()
.unwrap
()
.1
;
(
module_path
.to_vec
(),
name
)
let
rename
=
rename
.map
(|
n
|
n
.name
)
.unwrap_or
(
name
);
(
module_path
.to_vec
(),
name
,
rename
)
}
};
self
.build_import_directive
(
&**
parent
,
module_path
,
SingleImport
(
name
,
name
),
SingleImport
(
re
name
,
name
),
source_item
.span
,
source_item
.node
.id
(),
is_public
,
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
cfcd449c
...
...
@@ -2362,7 +2362,7 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
let
remaining
=
if
!
denied
{
let
mut
remaining
=
vec!
[];
for
path
in
list
{
match
inline
::
try_inline
(
cx
,
path
.node
.id
(),
None
)
{
match
inline
::
try_inline
(
cx
,
path
.node
.id
(),
path
.node
.rename
()
)
{
Some
(
items
)
=>
{
ret
.extend
(
items
);
}
...
...
@@ -2424,18 +2424,21 @@ pub struct ImportSource {
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
pub
struct
ViewListIdent
{
pub
name
:
String
,
pub
rename
:
Option
<
String
>
,
pub
source
:
Option
<
ast
::
DefId
>
,
}
impl
Clean
<
ViewListIdent
>
for
ast
::
PathListItem
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
ViewListIdent
{
match
self
.node
{
ast
::
PathListIdent
{
id
,
name
}
=>
ViewListIdent
{
ast
::
PathListIdent
{
id
,
name
,
rename
}
=>
ViewListIdent
{
name
:
name
.clean
(
cx
),
rename
:
rename
.map
(|
r
|
r
.clean
(
cx
)),
source
:
resolve_def
(
cx
,
id
)
},
ast
::
PathListMod
{
id
}
=>
ViewListIdent
{
ast
::
PathListMod
{
id
,
rename
}
=>
ViewListIdent
{
name
:
"self"
.to_string
(),
rename
:
rename
.map
(|
r
|
r
.clean
(
cx
)),
source
:
resolve_def
(
cx
,
id
)
}
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
cfcd449c
...
...
@@ -687,10 +687,15 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match
self
.source
{
Some
(
did
)
=>
{
let
path
=
clean
::
Path
::
singleton
(
self
.name
.clone
());
resolved_path
(
f
,
did
,
&
path
,
false
)
try!
(
resolved_path
(
f
,
did
,
&
path
,
false
));
}
_
=>
write!
(
f
,
"{}"
,
self
.name
),
_
=>
try!
(
write!
(
f
,
"{}"
,
self
.name
)),
}
if
let
Some
(
ref
name
)
=
self
.rename
{
try!
(
write!
(
f
,
" as {}"
,
name
));
}
Ok
(())
}
}
...
...
src/libsyntax/ast.rs
浏览文件 @
cfcd449c
...
...
@@ -1656,14 +1656,29 @@ pub struct Variant_ {
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug,
Copy)]
pub
enum
PathListItem_
{
PathListIdent
{
name
:
Ident
,
id
:
NodeId
},
PathListMod
{
id
:
NodeId
}
PathListIdent
{
name
:
Ident
,
/// renamed in list, eg `use foo::{bar as baz};`
rename
:
Option
<
Ident
>
,
id
:
NodeId
},
PathListMod
{
/// renamed in list, eg `use foo::{self as baz};`
rename
:
Option
<
Ident
>
,
id
:
NodeId
}
}
impl
PathListItem_
{
pub
fn
id
(
&
self
)
->
NodeId
{
match
*
self
{
PathListIdent
{
id
,
..
}
|
PathListMod
{
id
}
=>
id
PathListIdent
{
id
,
..
}
|
PathListMod
{
id
,
..
}
=>
id
}
}
pub
fn
rename
(
&
self
)
->
Option
<
Ident
>
{
match
*
self
{
PathListIdent
{
rename
,
..
}
|
PathListMod
{
rename
,
..
}
=>
rename
}
}
}
...
...
src/libsyntax/ext/build.rs
浏览文件 @
cfcd449c
...
...
@@ -1141,7 +1141,7 @@ fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
fn
item_use_list
(
&
self
,
sp
:
Span
,
vis
:
ast
::
Visibility
,
path
:
Vec
<
ast
::
Ident
>
,
imports
:
&
[
ast
::
Ident
])
->
P
<
ast
::
Item
>
{
let
imports
=
imports
.iter
()
.map
(|
id
|
{
respan
(
sp
,
ast
::
PathListIdent
{
name
:
*
id
,
id
:
ast
::
DUMMY_NODE_ID
})
respan
(
sp
,
ast
::
PathListIdent
{
name
:
*
id
,
rename
:
None
,
id
:
ast
::
DUMMY_NODE_ID
})
})
.collect
();
self
.item_use
(
sp
,
vis
,
...
...
src/libsyntax/fold.rs
浏览文件 @
cfcd449c
...
...
@@ -335,13 +335,17 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
path_list_idents
.move_map
(|
path_list_ident
|
{
Spanned
{
node
:
match
path_list_ident
.node
{
PathListIdent
{
id
,
name
}
=>
PathListIdent
{
id
,
name
,
rename
}
=>
PathListIdent
{
id
:
fld
.new_id
(
id
),
rename
:
rename
,
name
:
name
},
PathListMod
{
id
}
=>
PathListMod
{
id
:
fld
.new_id
(
id
)
}
PathListMod
{
id
,
rename
}
=>
PathListMod
{
id
:
fld
.new_id
(
id
),
rename
:
rename
}
},
span
:
fld
.new_span
(
path_list_ident
.span
)
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
cfcd449c
...
...
@@ -573,10 +573,12 @@ pub fn parse_ident_or_self_type(&mut self) -> PResult<ast::Ident> {
pub
fn
parse_path_list_item
(
&
mut
self
)
->
PResult
<
ast
::
PathListItem
>
{
let
lo
=
self
.span.lo
;
let
node
=
if
try!
(
self
.eat_keyword
(
keywords
::
SelfValue
))
{
ast
::
PathListMod
{
id
:
ast
::
DUMMY_NODE_ID
}
let
rename
=
try!
(
self
.parse_rename
());
ast
::
PathListMod
{
id
:
ast
::
DUMMY_NODE_ID
,
rename
:
rename
}
}
else
{
let
ident
=
try!
(
self
.parse_ident
());
ast
::
PathListIdent
{
name
:
ident
,
id
:
ast
::
DUMMY_NODE_ID
}
let
rename
=
try!
(
self
.parse_rename
());
ast
::
PathListIdent
{
name
:
ident
,
rename
:
rename
,
id
:
ast
::
DUMMY_NODE_ID
}
};
let
hi
=
self
.last_span.hi
;
Ok
(
spanned
(
lo
,
hi
,
node
))
...
...
@@ -5104,8 +5106,8 @@ fn parse_item_extern_crate(&mut self,
->
PResult
<
P
<
Item
>>
{
let
crate_name
=
try!
(
self
.parse_ident
());
let
(
maybe_path
,
ident
)
=
if
try!
(
self
.eat_keyword
(
keywords
::
As
))
{
(
Some
(
crate_name
.name
),
try!
(
self
.parse_ident
())
)
let
(
maybe_path
,
ident
)
=
if
let
Some
(
ident
)
=
try!
(
self
.parse_rename
(
))
{
(
Some
(
crate_name
.name
),
ident
)
}
else
{
(
None
,
crate_name
)
};
...
...
@@ -5766,10 +5768,16 @@ fn parse_view_path(&mut self) -> PResult<P<ViewPath>> {
}
})
.collect
()
};
rename_to
=
try!
(
self
.parse_rename
())
.unwrap_or
(
rename_to
);
Ok
(
P
(
spanned
(
lo
,
self
.last_span.hi
,
ViewPathSimple
(
rename_to
,
path
))))
}
fn
parse_rename
(
&
mut
self
)
->
PResult
<
Option
<
Ident
>>
{
if
try!
(
self
.eat_keyword
(
keywords
::
As
))
{
rename_to
=
try!
(
self
.parse_ident
())
self
.parse_ident
()
.map
(
Some
)
}
else
{
Ok
(
None
)
}
Ok
(
P
(
spanned
(
lo
,
self
.last_span.hi
,
ViewPathSimple
(
rename_to
,
path
))))
}
/// Parses a source module as a crate. This is the main
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
cfcd449c
...
...
@@ -2643,11 +2643,23 @@ pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> io::Result<()> {
}
try!
(
self
.commasep
(
Inconsistent
,
&
idents
[
..
],
|
s
,
w
|
{
match
w
.node
{
ast
::
PathListIdent
{
name
,
..
}
=>
{
s
.print_ident
(
name
)
ast
::
PathListIdent
{
name
,
rename
,
..
}
=>
{
try!
(
s
.print_ident
(
name
));
if
let
Some
(
ident
)
=
rename
{
try!
(
space
(
&
mut
s
.s
));
try!
(
s
.word_space
(
"as"
));
try!
(
s
.print_ident
(
ident
));
}
Ok
(())
},
ast
::
PathListMod
{
..
}
=>
{
word
(
&
mut
s
.s
,
"self"
)
ast
::
PathListMod
{
rename
,
..
}
=>
{
try!
(
word
(
&
mut
s
.s
,
"self"
));
if
let
Some
(
ident
)
=
rename
{
try!
(
space
(
&
mut
s
.s
));
try!
(
s
.word_space
(
"as"
));
try!
(
s
.print_ident
(
ident
));
}
Ok
(())
}
}
}));
...
...
src/libsyntax/visit.rs
浏览文件 @
cfcd449c
...
...
@@ -233,10 +233,17 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
ViewPathList
(
ref
prefix
,
ref
list
)
=>
{
for
id
in
list
{
match
id
.node
{
PathListIdent
{
name
,
..
}
=>
{
PathListIdent
{
name
,
rename
,
..
}
=>
{
visitor
.visit_ident
(
id
.span
,
name
);
if
let
Some
(
ident
)
=
rename
{
visitor
.visit_ident
(
id
.span
,
ident
);
}
}
PathListMod
{
rename
,
..
}
=>
{
if
let
Some
(
ident
)
=
rename
{
visitor
.visit_ident
(
id
.span
,
ident
);
}
}
PathListMod
{
..
}
=>
()
}
}
...
...
src/test/compile-fail/unresolved-import.rs
浏览文件 @
cfcd449c
// Copyright 2013-201
4
The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-201
5
The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
...
...
@@ -12,6 +12,20 @@
use
bar
::
baz
as
x
;
//~ ERROR unresolved import `bar::baz`. There is no `baz` in `bar`
use
food
::
baz
;
//~ ERROR unresolved import `food::baz`. There is no `baz` in `food`
use
food
::{
quux
as
beans
};
//~ ERROR unresolved import `food::quux`. There is no `quux` in `food`
mod
bar
{
struct
bar
;
}
mod
food
{
pub
use
self
::
zug
::
baz
::{
self
as
bag
,
quux
as
beans
};
mod
zug
{
pub
mod
baz
{
pub
struct
quux
;
}
}
}
src/test/pretty/import-renames.rs
0 → 100644
浏览文件 @
cfcd449c
// Copyright 2015 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.
// pp-exact
use
std
::
io
::{
self
,
Error
as
IoError
};
use
std
::
net
::{
self
as
stdnet
,
TcpStream
};
src/test/run-pass/import-rename.rs
0 → 100644
浏览文件 @
cfcd449c
// Copyright 2015 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.
use
foo
::{
x
,
y
as
fooy
};
use
Maybe
::{
Yes
as
MaybeYes
};
pub
enum
Maybe
{
Yes
,
No
}
mod
foo
{
use
super
::
Maybe
::{
self
as
MaybeFoo
};
pub
fn
x
(
a
:
MaybeFoo
)
{}
pub
fn
y
(
a
:
i32
)
{
println!
(
"{}"
,
a
);
}
}
pub
fn
main
()
{
x
(
MaybeYes
);
fooy
(
10
);
}
src/test/run-pass/use.rs
浏览文件 @
cfcd449c
...
...
@@ -19,6 +19,9 @@
use
std
::
str
;
use
zed
::
str
as
x
;
use
std
::
io
::{
self
,
Error
as
IoError
,
Result
as
IoResult
};
use
std
::
error
::{
self
as
foo
};
mod
baz
{
pub
use
std
::
str
as
x
;
}
...
...
src/test/rustdoc/viewpath-rename.rs
0 → 100644
浏览文件 @
cfcd449c
// Copyright 2015 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.
#![crate_name
=
"foo"
]
pub
mod
io
{
pub
trait
Reader
{
fn
dummy
(
&
self
)
{
}
}
}
pub
enum
Maybe
<
A
>
{
Just
(
A
),
Nothing
}
// @has foo/prelude/index.html
pub
mod
prelude
{
// @has foo/prelude/index.html '//code' 'pub use io::{self as FooIo, Reader as FooReader}'
#[doc(no_inline)]
pub
use
io
::{
self
as
FooIo
,
Reader
as
FooReader
};
// @has foo/prelude/index.html '//code' 'pub use Maybe::{self, Just as MaybeJust, Nothing}'
#[doc(no_inline)]
pub
use
Maybe
::{
self
,
Just
as
MaybeJust
,
Nothing
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录