Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ddacc671
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,发现更多精彩内容 >>
提交
ddacc671
编写于
6月 11, 2020
作者:
A
Amanieu d'Antras
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a suggestion to use unused asm arguments in comments
上级
34bb6d04
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
19 deletion
+50
-19
src/librustc_builtin_macros/asm.rs
src/librustc_builtin_macros/asm.rs
+29
-18
src/test/ui/asm/bad-template.rs
src/test/ui/asm/bad-template.rs
+2
-0
src/test/ui/asm/bad-template.stderr
src/test/ui/asm/bad-template.stderr
+17
-1
src/test/ui/asm/parse-error.stderr
src/test/ui/asm/parse-error.stderr
+2
-0
未找到文件。
src/librustc_builtin_macros/asm.rs
浏览文件 @
ddacc671
...
...
@@ -391,7 +391,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
used
[
*
pos
]
=
true
;
}
let
named_pos
:
FxHashSet
<
usize
>
=
args
.named_args
.values
()
.cloned
()
.collect
();
let
named_pos
:
FxHashMap
<
usize
,
Symbol
>
=
args
.named_args
.iter
()
.map
(|(
&
sym
,
&
idx
)|
(
idx
,
sym
))
.collect
();
let
mut
arg_spans
=
parser
.arg_places
.iter
()
.map
(|
span
|
template_span
.from_inner
(
*
span
));
let
mut
template
=
vec!
[];
for
piece
in
unverified_pieces
{
...
...
@@ -405,7 +406,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
let
operand_idx
=
match
arg
.position
{
parse
::
ArgumentIs
(
idx
)
|
parse
::
ArgumentImplicitlyIs
(
idx
)
=>
{
if
idx
>=
args
.operands
.len
()
||
named_pos
.contains
(
&
idx
)
||
named_pos
.contains
_key
(
&
idx
)
||
args
.reg_args
.contains
(
&
idx
)
{
let
msg
=
format!
(
"invalid reference to argument at index {}"
,
idx
);
...
...
@@ -426,7 +427,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
};
err
.note
(
&
msg
);
if
named_pos
.contains
(
&
idx
)
{
if
named_pos
.contains
_key
(
&
idx
)
{
err
.span_label
(
args
.operands
[
idx
]
.1
,
"named argument"
);
err
.span_note
(
args
.operands
[
idx
]
.1
,
...
...
@@ -480,27 +481,31 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
}
}
let
operands
=
args
.operands
;
let
unused_operands
:
Vec
<
_
>
=
used
.into_iter
()
.enumerate
()
.filter
(|
&
(
_
,
used
)|
!
used
)
.map
(|(
idx
,
_
)|
{
if
named_pos
.contains
(
&
idx
)
{
// named argument
(
operands
[
idx
]
.1
,
"named argument never used"
)
let
mut
unused_operands
=
vec!
[];
let
mut
help_str
=
String
::
new
();
for
(
idx
,
used
)
in
used
.into_iter
()
.enumerate
()
{
if
!
used
{
let
msg
=
if
let
Some
(
sym
)
=
named_pos
.get
(
&
idx
)
{
help_str
.push_str
(
&
format!
(
" {{{}}}"
,
sym
));
"named argument never used"
}
else
{
// positional argument
(
operands
[
idx
]
.1
,
"argument never used"
)
}
})
.collect
();
help_str
.push_str
(
&
format!
(
" {{{}}}"
,
idx
));
"argument never used"
};
unused_operands
.push
((
args
.operands
[
idx
]
.1
,
msg
));
}
}
match
unused_operands
.len
()
{
0
=>
{}
1
=>
{
let
(
sp
,
msg
)
=
unused_operands
.into_iter
()
.next
()
.unwrap
();
let
mut
err
=
ecx
.struct_span_err
(
sp
,
msg
);
err
.span_label
(
sp
,
msg
);
err
.help
(
&
format!
(
"if this argument is intentionally unused,
\
consider using it in an asm comment: `
\"
/*{} */
\"
`"
,
help_str
));
err
.emit
();
}
_
=>
{
...
...
@@ -511,6 +516,11 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
for
(
sp
,
msg
)
in
unused_operands
{
err
.span_label
(
sp
,
msg
);
}
err
.help
(
&
format!
(
"if these arguments are intentionally unused,
\
consider using them in an asm comment: `
\"
/*{} */
\"
`"
,
help_str
));
err
.emit
();
}
}
...
...
@@ -521,7 +531,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
parser
.line_spans
.iter
()
.map
(|
span
|
template_span
.from_inner
(
*
span
))
.collect
()
};
let
inline_asm
=
ast
::
InlineAsm
{
template
,
operands
,
options
:
args
.options
,
line_spans
};
let
inline_asm
=
ast
::
InlineAsm
{
template
,
operands
:
args
.operands
,
options
:
args
.options
,
line_spans
};
P
(
ast
::
Expr
{
id
:
ast
::
DUMMY_NODE_ID
,
kind
:
ast
::
ExprKind
::
InlineAsm
(
P
(
inline_asm
)),
...
...
src/test/ui/asm/bad-template.rs
浏览文件 @
ddacc671
...
...
@@ -22,5 +22,7 @@ fn main() {
//~^ ERROR invalid reference to argument at index 0
asm!
(
"{:foo}"
,
in
(
reg
)
foo
);
//~^ ERROR asm template modifier must be a single character
asm!
(
""
,
in
(
reg
)
0
,
in
(
reg
)
1
);
//~^ ERROR multiple unused asm arguments
}
}
src/test/ui/asm/bad-template.stderr
浏览文件 @
ddacc671
...
...
@@ -19,6 +19,8 @@ error: argument never used
|
LL | asm!("{1}", in(reg) foo);
| ^^^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:13:15
...
...
@@ -46,6 +48,8 @@ error: named argument never used
|
LL | asm!("{}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:18:15
...
...
@@ -60,6 +64,8 @@ error: named argument never used
|
LL | asm!("{1}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:21:15
...
...
@@ -82,5 +88,15 @@ error: asm template modifier must be a single character
LL | asm!("{:foo}", in(reg) foo);
| ^^^
error: aborting due to 10 previous errors
error: multiple unused asm arguments
--> $DIR/bad-template.rs:25:18
|
LL | asm!("", in(reg) 0, in(reg) 1);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
| |
| argument never used
|
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`
error: aborting due to 11 previous errors
src/test/ui/asm/parse-error.stderr
浏览文件 @
ddacc671
...
...
@@ -127,6 +127,8 @@ error: argument never used
|
LL | asm!("{a}", a = const foo, a = const bar);
| ^^^^^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
error: explicit register arguments cannot have names
--> $DIR/parse-error.rs:47:18
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录