Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
55082ce4
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,发现更多精彩内容 >>
未验证
提交
55082ce4
编写于
8月 21, 2020
作者:
A
Aaron Hill
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attach `TokenStream` to `ast::Path`
上级
3815e91c
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
41 addition
and
21 deletion
+41
-21
compiler/rustc_ast/src/ast.rs
compiler/rustc_ast/src/ast.rs
+3
-2
compiler/rustc_ast/src/attr/mod.rs
compiler/rustc_ast/src/attr/mod.rs
+1
-1
compiler/rustc_ast/src/mut_visit.rs
compiler/rustc_ast/src/mut_visit.rs
+1
-1
compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_ast_lowering/src/item.rs
+8
-5
compiler/rustc_expand/src/build.rs
compiler/rustc_expand/src/build.rs
+1
-1
compiler/rustc_expand/src/placeholders.rs
compiler/rustc_expand/src/placeholders.rs
+1
-1
compiler/rustc_parse/src/lib.rs
compiler/rustc_parse/src/lib.rs
+1
-0
compiler/rustc_parse/src/parser/diagnostics.rs
compiler/rustc_parse/src/parser/diagnostics.rs
+1
-1
compiler/rustc_parse/src/parser/item.rs
compiler/rustc_parse/src/parser/item.rs
+1
-1
compiler/rustc_parse/src/parser/nonterminal.rs
compiler/rustc_parse/src/parser/nonterminal.rs
+9
-1
compiler/rustc_parse/src/parser/path.rs
compiler/rustc_parse/src/parser/path.rs
+6
-3
compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_resolve/src/diagnostics.rs
+1
-1
compiler/rustc_resolve/src/late.rs
compiler/rustc_resolve/src/late.rs
+1
-1
compiler/rustc_resolve/src/late/diagnostics.rs
compiler/rustc_resolve/src/late/diagnostics.rs
+4
-2
compiler/rustc_resolve/src/lib.rs
compiler/rustc_resolve/src/lib.rs
+2
-0
未找到文件。
compiler/rustc_ast/src/ast.rs
浏览文件 @
55082ce4
...
...
@@ -96,6 +96,7 @@ pub struct Path {
/// The segments in the path: the things separated by `::`.
/// Global paths begin with `kw::PathRoot`.
pub
segments
:
Vec
<
PathSegment
>
,
pub
tokens
:
Option
<
TokenStream
>
,
}
impl
PartialEq
<
Symbol
>
for
Path
{
...
...
@@ -117,7 +118,7 @@ impl Path {
// Convert a span and an identifier to the corresponding
// one-segment path.
pub
fn
from_ident
(
ident
:
Ident
)
->
Path
{
Path
{
segments
:
vec!
[
PathSegment
::
from_ident
(
ident
)],
span
:
ident
.span
}
Path
{
segments
:
vec!
[
PathSegment
::
from_ident
(
ident
)],
span
:
ident
.span
,
tokens
:
None
}
}
pub
fn
is_global
(
&
self
)
->
bool
{
...
...
@@ -1069,7 +1070,7 @@ pub struct Expr {
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch
=
"x86_64"
)]
rustc_data_structures
::
static_assert_size!
(
Expr
,
1
04
);
rustc_data_structures
::
static_assert_size!
(
Expr
,
1
12
);
impl
Expr
{
/// Returns `true` if this expression would be valid somewhere that expects a value;
...
...
compiler/rustc_ast/src/attr/mod.rs
浏览文件 @
55082ce4
...
...
@@ -415,7 +415,7 @@ fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem>
}
}
let
span
=
span
.with_hi
(
segments
.last
()
.unwrap
()
.ident.span
.hi
());
Path
{
span
,
segments
}
Path
{
span
,
segments
,
tokens
:
None
}
}
Some
(
TokenTree
::
Token
(
Token
{
kind
:
token
::
Interpolated
(
nt
),
..
}))
=>
match
*
nt
{
token
::
Nonterminal
::
NtMeta
(
ref
item
)
=>
return
item
.meta
(
item
.path.span
),
...
...
compiler/rustc_ast/src/mut_visit.rs
浏览文件 @
55082ce4
...
...
@@ -513,7 +513,7 @@ pub fn noop_visit_ident<T: MutVisitor>(Ident { name: _, span }: &mut Ident, vis:
vis
.visit_span
(
span
);
}
pub
fn
noop_visit_path
<
T
:
MutVisitor
>
(
Path
{
segments
,
span
}:
&
mut
Path
,
vis
:
&
mut
T
)
{
pub
fn
noop_visit_path
<
T
:
MutVisitor
>
(
Path
{
segments
,
span
,
tokens
:
_
}:
&
mut
Path
,
vis
:
&
mut
T
)
{
vis
.visit_span
(
span
);
for
PathSegment
{
ident
,
id
,
args
}
in
segments
{
vis
.visit_ident
(
ident
);
...
...
compiler/rustc_ast_lowering/src/item.rs
浏览文件 @
55082ce4
...
...
@@ -251,7 +251,7 @@ fn lower_item_kind(
ItemKind
::
ExternCrate
(
orig_name
)
=>
hir
::
ItemKind
::
ExternCrate
(
orig_name
),
ItemKind
::
Use
(
ref
use_tree
)
=>
{
// Start with an empty prefix.
let
prefix
=
Path
{
segments
:
vec!
[],
span
:
use_tree
.span
};
let
prefix
=
Path
{
segments
:
vec!
[],
span
:
use_tree
.span
,
tokens
:
None
};
self
.lower_use_tree
(
use_tree
,
&
prefix
,
id
,
vis
,
ident
,
attrs
)
}
...
...
@@ -488,7 +488,7 @@ fn lower_use_tree(
*
ident
=
tree
.ident
();
// First, apply the prefix to the path.
let
mut
path
=
Path
{
segments
,
span
:
path
.span
};
let
mut
path
=
Path
{
segments
,
span
:
path
.span
,
tokens
:
None
};
// Correctly resolve `self` imports.
if
path
.segments
.len
()
>
1
...
...
@@ -540,8 +540,11 @@ fn lower_use_tree(
hir
::
ItemKind
::
Use
(
path
,
hir
::
UseKind
::
Single
)
}
UseTreeKind
::
Glob
=>
{
let
path
=
self
.lower_path
(
id
,
&
Path
{
segments
,
span
:
path
.span
},
ParamMode
::
Explicit
);
let
path
=
self
.lower_path
(
id
,
&
Path
{
segments
,
span
:
path
.span
,
tokens
:
None
},
ParamMode
::
Explicit
,
);
hir
::
ItemKind
::
Use
(
path
,
hir
::
UseKind
::
Glob
)
}
UseTreeKind
::
Nested
(
ref
trees
)
=>
{
...
...
@@ -569,7 +572,7 @@ fn lower_use_tree(
// for that we return the `{}` import (called the
// `ListStem`).
let
prefix
=
Path
{
segments
,
span
:
prefix
.span
.to
(
path
.span
)
};
let
prefix
=
Path
{
segments
,
span
:
prefix
.span
.to
(
path
.span
)
,
tokens
:
None
};
// Add all the nested `PathListItem`s to the HIR.
for
&
(
ref
use_tree
,
id
)
in
trees
{
...
...
compiler/rustc_expand/src/build.rs
浏览文件 @
55082ce4
...
...
@@ -46,7 +46,7 @@ pub fn path_all(
id
:
ast
::
DUMMY_NODE_ID
,
args
,
});
ast
::
Path
{
span
,
segments
}
ast
::
Path
{
span
,
segments
,
tokens
:
None
}
}
pub
fn
ty_mt
(
&
self
,
ty
:
P
<
ast
::
Ty
>
,
mutbl
:
ast
::
Mutability
)
->
ast
::
MutTy
{
...
...
compiler/rustc_expand/src/placeholders.rs
浏览文件 @
55082ce4
...
...
@@ -18,7 +18,7 @@ pub fn placeholder(
)
->
AstFragment
{
fn
mac_placeholder
()
->
ast
::
MacCall
{
ast
::
MacCall
{
path
:
ast
::
Path
{
span
:
DUMMY_SP
,
segments
:
Vec
::
new
()
},
path
:
ast
::
Path
{
span
:
DUMMY_SP
,
segments
:
Vec
::
new
()
,
tokens
:
None
},
args
:
P
(
ast
::
MacArgs
::
Empty
),
prior_type_ascription
:
None
,
}
...
...
compiler/rustc_parse/src/lib.rs
浏览文件 @
55082ce4
...
...
@@ -278,6 +278,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
Some
(
tokenstream
::
TokenTree
::
token
(
token
::
Lifetime
(
ident
.name
),
ident
.span
)
.into
())
}
Nonterminal
::
NtMeta
(
ref
attr
)
=>
attr
.tokens
.clone
(),
Nonterminal
::
NtPath
(
ref
path
)
=>
path
.tokens
.clone
(),
Nonterminal
::
NtTT
(
ref
tt
)
=>
Some
(
tt
.clone
()
.into
()),
Nonterminal
::
NtExpr
(
ref
expr
)
|
Nonterminal
::
NtLiteral
(
ref
expr
)
=>
{
if
expr
.tokens
.is_none
()
{
...
...
compiler/rustc_parse/src/parser/diagnostics.rs
浏览文件 @
55082ce4
...
...
@@ -901,7 +901,7 @@ pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
)
->
PResult
<
'a
,
P
<
T
>>
{
self
.expect
(
&
token
::
ModSep
)
?
;
let
mut
path
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
DUMMY_SP
};
let
mut
path
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
DUMMY_SP
,
tokens
:
None
};
self
.parse_path_segments
(
&
mut
path
.segments
,
T
::
PATH_STYLE
)
?
;
path
.span
=
ty_span
.to
(
self
.prev_token.span
);
...
...
compiler/rustc_parse/src/parser/item.rs
浏览文件 @
55082ce4
...
...
@@ -787,7 +787,7 @@ fn parse_type_alias(&mut self, def: Defaultness) -> PResult<'a, ItemInfo> {
fn
parse_use_tree
(
&
mut
self
)
->
PResult
<
'a
,
UseTree
>
{
let
lo
=
self
.token.span
;
let
mut
prefix
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
lo
.shrink_to_lo
()
};
let
mut
prefix
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
lo
.shrink_to_lo
()
,
tokens
:
None
};
let
kind
=
if
self
.check
(
&
token
::
OpenDelim
(
token
::
Brace
))
||
self
.check
(
&
token
::
BinOp
(
token
::
Star
))
||
self
.is_import_coupler
()
...
...
compiler/rustc_parse/src/parser/nonterminal.rs
浏览文件 @
55082ce4
...
...
@@ -168,7 +168,15 @@ pub fn parse_nonterminal(&mut self, kind: NonterminalKind) -> PResult<'a, Nonter
return
Err
(
self
.struct_span_err
(
self
.token.span
,
msg
));
}
}
NonterminalKind
::
Path
=>
token
::
NtPath
(
self
.parse_path
(
PathStyle
::
Type
)
?
),
NonterminalKind
::
Path
=>
{
let
(
mut
path
,
tokens
)
=
self
.collect_tokens
(|
this
|
this
.parse_path
(
PathStyle
::
Type
))
?
;
// We have have eaten an NtPath, which could already have tokens
if
path
.tokens
.is_none
()
{
path
.tokens
=
Some
(
tokens
);
}
token
::
NtPath
(
path
)
}
NonterminalKind
::
Meta
=>
{
let
(
mut
attr
,
tokens
)
=
self
.collect_tokens
(|
this
|
this
.parse_attr_item
())
?
;
// We may have eaten a nonterminal, which could already have tokens
...
...
compiler/rustc_parse/src/parser/path.rs
浏览文件 @
55082ce4
...
...
@@ -64,7 +64,7 @@ pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (QSelf, Pa
path_span
=
path_lo
.to
(
self
.prev_token.span
);
}
else
{
path_span
=
self
.token.span
.to
(
self
.token.span
);
path
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
path_span
};
path
=
ast
::
Path
{
segments
:
Vec
::
new
(),
span
:
path_span
,
tokens
:
None
};
}
// See doc comment for `unmatched_angle_bracket_count`.
...
...
@@ -81,7 +81,10 @@ pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (QSelf, Pa
let
qself
=
QSelf
{
ty
,
path_span
,
position
:
path
.segments
.len
()
};
self
.parse_path_segments
(
&
mut
path
.segments
,
style
)
?
;
Ok
((
qself
,
Path
{
segments
:
path
.segments
,
span
:
lo
.to
(
self
.prev_token.span
)
}))
Ok
((
qself
,
Path
{
segments
:
path
.segments
,
span
:
lo
.to
(
self
.prev_token.span
),
tokens
:
None
},
))
}
/// Recover from an invalid single colon, when the user likely meant a qualified path.
...
...
@@ -144,7 +147,7 @@ pub(super) fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path> {
}
self
.parse_path_segments
(
&
mut
segments
,
style
)
?
;
Ok
(
Path
{
segments
,
span
:
lo
.to
(
self
.prev_token.span
)
})
Ok
(
Path
{
segments
,
span
:
lo
.to
(
self
.prev_token.span
)
,
tokens
:
None
})
}
pub
(
super
)
fn
parse_path_segments
(
...
...
compiler/rustc_resolve/src/diagnostics.rs
浏览文件 @
55082ce4
...
...
@@ -794,7 +794,7 @@ fn lookup_import_candidates_from_module<FilterFn>(
}
segms
.push
(
ast
::
PathSegment
::
from_ident
(
ident
));
let
path
=
Path
{
span
:
name_binding
.span
,
segments
:
segms
};
let
path
=
Path
{
span
:
name_binding
.span
,
segments
:
segms
,
tokens
:
None
};
let
did
=
match
res
{
Res
::
Def
(
DefKind
::
Ctor
(
..
),
did
)
=>
this
.parent
(
did
),
_
=>
res
.opt_def_id
(),
...
...
compiler/rustc_resolve/src/late.rs
浏览文件 @
55082ce4
...
...
@@ -1967,7 +1967,7 @@ fn resolve_qpath_anywhere(
if
qself
.is_none
()
{
let
path_seg
=
|
seg
:
&
Segment
|
PathSegment
::
from_ident
(
seg
.ident
);
let
path
=
Path
{
segments
:
path
.iter
()
.map
(
path_seg
)
.collect
(),
span
};
let
path
=
Path
{
segments
:
path
.iter
()
.map
(
path_seg
)
.collect
(),
span
,
tokens
:
None
};
if
let
Ok
((
_
,
res
))
=
self
.r
.resolve_macro_path
(
&
path
,
None
,
&
self
.parent_scope
,
false
,
false
)
{
...
...
compiler/rustc_resolve/src/late/diagnostics.rs
浏览文件 @
55082ce4
...
...
@@ -83,6 +83,7 @@ fn import_candidate_to_enum_paths(suggestion: &ImportSuggestion) -> (String, Str
let
enum_path
=
ast
::
Path
{
span
:
suggestion
.path.span
,
segments
:
suggestion
.path.segments
[
0
..
path_len
-
1
]
.to_vec
(),
tokens
:
None
,
};
let
enum_path_string
=
path_names_to_string
(
&
enum_path
);
...
...
@@ -1065,7 +1066,8 @@ fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion
path_segments
.push
(
ast
::
PathSegment
::
from_ident
(
ident
));
let
module_def_id
=
module
.def_id
()
.unwrap
();
if
module_def_id
==
def_id
{
let
path
=
Path
{
span
:
name_binding
.span
,
segments
:
path_segments
};
let
path
=
Path
{
span
:
name_binding
.span
,
segments
:
path_segments
,
tokens
:
None
};
result
=
Some
((
module
,
ImportSuggestion
{
...
...
@@ -1095,7 +1097,7 @@ fn collect_enum_variants(&mut self, def_id: DefId) -> Option<Vec<Path>> {
if
let
Res
::
Def
(
DefKind
::
Variant
,
_
)
=
name_binding
.res
()
{
let
mut
segms
=
enum_import_suggestion
.path.segments
.clone
();
segms
.push
(
ast
::
PathSegment
::
from_ident
(
ident
));
variants
.push
(
Path
{
span
:
name_binding
.span
,
segments
:
segms
});
variants
.push
(
Path
{
span
:
name_binding
.span
,
segments
:
segms
,
tokens
:
None
});
}
});
variants
...
...
compiler/rustc_resolve/src/lib.rs
浏览文件 @
55082ce4
...
...
@@ -3189,6 +3189,7 @@ pub fn resolve_str_path_error(
.chain
(
path_str
.split
(
"::"
)
.skip
(
1
)
.map
(
Ident
::
from_str
))
.map
(|
i
|
self
.new_ast_path_segment
(
i
))
.collect
(),
tokens
:
None
,
}
}
else
{
ast
::
Path
{
...
...
@@ -3198,6 +3199,7 @@ pub fn resolve_str_path_error(
.map
(
Ident
::
from_str
)
.map
(|
i
|
self
.new_ast_path_segment
(
i
))
.collect
(),
tokens
:
None
,
}
};
let
module
=
self
.get_module
(
module_id
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录