Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e99d309c
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,发现更多精彩内容 >>
提交
e99d309c
编写于
7月 19, 2017
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the macro structure spans instead of the invocation
上级
cc800531
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
105 addition
and
11 deletion
+105
-11
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+1
-0
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/ext/tt/macro_rules.rs
+14
-1
src/libsyntax/ext/tt/quoted.rs
src/libsyntax/ext/tt/quoted.rs
+1
-1
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+3
-5
src/libsyntax/tokenstream.rs
src/libsyntax/tokenstream.rs
+32
-0
src/libsyntax_pos/lib.rs
src/libsyntax_pos/lib.rs
+24
-4
src/test/ui/span/macro-span-replacement.rs
src/test/ui/span/macro-span-replacement.rs
+19
-0
src/test/ui/span/macro-span-replacement.stderr
src/test/ui/span/macro-span-replacement.stderr
+11
-0
未找到文件。
src/libsyntax/ext/expand.rs
浏览文件 @
e99d309c
...
...
@@ -1046,6 +1046,7 @@ fn enable_compile_error = compile_error,
}
// A Marker adds the given mark to the syntax context.
#[derive(Debug)]
pub
struct
Marker
(
pub
Mark
);
impl
Folder
for
Marker
{
...
...
src/libsyntax/ext/tt/macro_rules.rs
浏览文件 @
e99d309c
...
...
@@ -119,8 +119,21 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
quoted
::
TokenTree
::
Delimited
(
_
,
ref
delimed
)
=>
delimed
.tts
.clone
(),
_
=>
cx
.span_bug
(
sp
,
"malformed macro rhs"
),
};
// rhs has holes ( `$id` and `$(...)` that need filled)
let
tts
=
transcribe
(
cx
,
Some
(
named_matches
),
rhs
);
let
mut
tts
=
transcribe
(
cx
,
Some
(
named_matches
),
rhs
.clone
());
// Replace all the tokens for the corresponding positions in the macro, to maintain
// proper positions in error reporting, while maintaining the macro_backtrace.
if
rhs
.len
()
==
tts
.len
()
{
tts
=
tts
.map_pos
(|
i
,
tt
|
{
let
mut
tt
=
tt
.clone
();
let
mut
sp
=
rhs
[
i
]
.span
();
sp
.ctxt
=
tt
.span
()
.ctxt
;
tt
.set_span
(
sp
);
tt
});
}
if
cx
.trace_macros
()
{
trace_macros_note
(
cx
,
sp
,
format!
(
"to `{}`"
,
tts
));
...
...
src/libsyntax/ext/tt/quoted.rs
浏览文件 @
e99d309c
...
...
@@ -128,7 +128,7 @@ pub fn get_tt(&self, index: usize) -> TokenTree {
}
}
/// Retrieve the
TokenTree
's span.
/// Retrieve the
`TokenTree`
's span.
pub
fn
span
(
&
self
)
->
Span
{
match
*
self
{
TokenTree
::
Token
(
sp
,
_
)
|
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
e99d309c
...
...
@@ -150,7 +150,7 @@ fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
lhs
}
#[derive(Clone,
Copy,
PartialEq)]
#[derive(
Debug,
Clone,
Copy,
PartialEq)]
enum
PrevTokenKind
{
DocComment
,
Comma
,
...
...
@@ -6090,8 +6090,7 @@ fn parse_macro_use_or_failure(
let
(
delim
,
tts
)
=
self
.expect_delimited_token_tree
()
?
;
if
delim
!=
token
::
Brace
{
if
!
self
.eat
(
&
token
::
Semi
)
{
let
prev_span
=
self
.prev_span
;
self
.span_err
(
prev_span
,
self
.span_err
(
self
.prev_span
,
"macros that expand to items must either
\
be surrounded with braces or followed by
\
a semicolon"
);
...
...
@@ -6108,8 +6107,7 @@ fn parse_macro_use_or_failure(
match
visibility
{
Visibility
::
Inherited
=>
{}
_
=>
{
let
prev_span
=
self
.prev_span
;
return
Err
(
self
.span_fatal
(
prev_span
,
"unmatched visibility `pub`"
));
return
Err
(
self
.span_fatal
(
self
.prev_span
,
"unmatched visibility `pub`"
));
}
}
...
...
src/libsyntax/tokenstream.rs
浏览文件 @
e99d309c
...
...
@@ -131,6 +131,15 @@ pub fn span(&self) -> Span {
}
}
/// Modify the `TokenTree`'s span inplace.
pub
fn
set_span
(
&
mut
self
,
span
:
Span
)
{
match
*
self
{
TokenTree
::
Token
(
ref
mut
sp
,
_
)
|
TokenTree
::
Delimited
(
ref
mut
sp
,
_
)
=>
{
*
sp
=
span
;
}
}
}
/// Indicates if the stream is a token that is equal to the provided token.
pub
fn
eq_token
(
&
self
,
t
:
Token
)
->
bool
{
match
*
self
{
...
...
@@ -190,6 +199,14 @@ fn eq(&self, other: &TokenStream) -> bool {
}
impl
TokenStream
{
pub
fn
len
(
&
self
)
->
usize
{
if
let
TokenStreamKind
::
Stream
(
ref
slice
)
=
self
.kind
{
slice
.len
()
}
else
{
0
}
}
pub
fn
empty
()
->
TokenStream
{
TokenStream
{
kind
:
TokenStreamKind
::
Empty
}
}
...
...
@@ -241,6 +258,21 @@ pub fn as_tree(self) -> (TokenTree, bool /* joint? */) {
}
}
pub
fn
map_pos
<
F
:
FnMut
(
usize
,
TokenTree
)
->
TokenTree
>
(
self
,
mut
f
:
F
)
->
TokenStream
{
let
mut
trees
=
self
.into_trees
();
let
mut
result
=
Vec
::
new
();
let
mut
i
=
0
;
while
let
Some
(
stream
)
=
trees
.next_as_stream
()
{
result
.push
(
match
stream
.kind
{
TokenStreamKind
::
Tree
(
tree
)
=>
f
(
i
,
tree
)
.into
(),
TokenStreamKind
::
JointTree
(
tree
)
=>
f
(
i
,
tree
)
.joint
(),
_
=>
unreachable!
()
});
i
+=
1
;
}
TokenStream
::
concat
(
result
)
}
pub
fn
map
<
F
:
FnMut
(
TokenTree
)
->
TokenTree
>
(
self
,
mut
f
:
F
)
->
TokenStream
{
let
mut
trees
=
self
.into_trees
();
let
mut
result
=
Vec
::
new
();
...
...
src/libsyntax_pos/lib.rs
浏览文件 @
e99d309c
...
...
@@ -100,6 +100,7 @@ pub fn substitute_dummy(self, other: Span) -> Span {
if
self
.source_equal
(
&
DUMMY_SP
)
{
other
}
else
{
self
}
}
/// Return true if `self` fully encloses `other`.
pub
fn
contains
(
self
,
other
:
Span
)
->
bool
{
self
.lo
<=
other
.lo
&&
other
.hi
<=
self
.hi
}
...
...
@@ -184,15 +185,32 @@ pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
result
}
pub
fn
empty_ctxt
(
&
self
)
->
bool
{
self
.ctxt
==
SyntaxContext
::
empty
()
}
/// Return a `Span` that would enclose both `self` and `end`.
pub
fn
to
(
self
,
end
:
Span
)
->
Span
{
let
lo
=
if
self
.lo
<
end
.lo
{
self
.lo
}
else
{
end
.lo
};
let
hi
=
if
self
.hi
>
end
.hi
{
self
.hi
}
else
{
end
.hi
};
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
if
self
.ctxt
==
SyntaxContext
::
empty
()
{
Span
{
lo
:
self
.lo
,
..
end
}
let
ctxt
=
if
self
.ctxt
==
SyntaxContext
::
empty
()
{
end
.ctxt
}
else
{
Span
{
hi
:
end
.hi
,
..
self
}
}
self
.ctxt
};
Span
{
lo
,
hi
,
ctxt
}
}
/// Return a `Span` between the end of `self` to the beginning of `end`.
pub
fn
between
(
self
,
end
:
Span
)
->
Span
{
Span
{
lo
:
self
.hi
,
...
...
@@ -205,6 +223,7 @@ pub fn between(self, end: Span) -> Span {
}
}
/// Return a `Span` between the beginning of `self` to the beginning of `end`.
pub
fn
until
(
self
,
end
:
Span
)
->
Span
{
Span
{
lo
:
self
.lo
,
...
...
@@ -852,6 +871,7 @@ pub struct FileLines {
thread_local!
(
pub
static
SPAN_DEBUG
:
Cell
<
fn
(
Span
,
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
>
=
Cell
::
new
(
default_span_debug
));
#[derive(Debug)]
pub
struct
MacroBacktrace
{
/// span where macro was applied to generate this code
pub
call_site
:
Span
,
...
...
src/test/ui/span/macro-span-replacement.rs
0 → 100644
浏览文件 @
e99d309c
// 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.
macro_rules!
m
{
(
$a:tt
$b:tt
)
=>
{
$b
$a
;
}
}
fn
main
()
{
m!
(
S
struct
);
}
src/test/ui/span/macro-span-replacement.stderr
0 → 100644
浏览文件 @
e99d309c
warning: struct is never used: `S`
--> $DIR/macro-span-replacement.rs:13:9
|
13 | $b $a;
| ^^^^^^
...
18 | m!(S struct);
| ------------- in this macro invocation
|
= note: #[warn(dead_code)] on by default
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录