提交 51e414ff 编写于 作者: A asquared31415

Combine spans into one error, deduplicate code

上级 ae8a1baf
......@@ -10,7 +10,7 @@
use rustc_session::lint::{self, BuiltinLintDiagnostics};
use rustc_span::symbol::Ident;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{InnerSpan, Span};
use rustc_span::{InnerSpan, MultiSpan, Span};
use rustc_target::asm::InlineAsmArch;
use smallvec::smallvec;
......@@ -523,26 +523,19 @@ fn expand_preparsed_asm(
if found_labels.len() > 0 {
let spans =
found_labels.into_iter().filter_map(find_label_span).collect::<Vec<Span>>();
if spans.len() > 0 {
for span in spans.into_iter() {
ecx.parse_sess().buffer_lint_with_diagnostic(
lint::builtin::NAMED_ASM_LABELS,
span,
ecx.current_expansion.lint_node_id,
"avoid using named labels in inline assembly",
BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
);
}
} else {
// If there were labels but we couldn't find a span, combine the warnings and use the template span
ecx.parse_sess().buffer_lint_with_diagnostic(
lint::builtin::NAMED_ASM_LABELS,
template_sp,
ecx.current_expansion.lint_node_id,
"avoid using named labels in inline assembly",
BuiltinLintDiagnostics::NamedAsmLabel("only local labels of the form `<number>:` should be used in inline asm".to_string()),
);
}
// If there were labels but we couldn't find a span, combine the warnings and use the template span
let target_spans: MultiSpan =
if spans.len() > 0 { spans.into() } else { template_sp.into() };
ecx.parse_sess().buffer_lint_with_diagnostic(
lint::builtin::NAMED_ASM_LABELS,
target_spans,
ecx.current_expansion.lint_node_id,
"avoid using named labels in inline assembly",
BuiltinLintDiagnostics::NamedAsmLabel(
"only local labels of the form `<number>:` should be used in inline asm"
.to_string(),
),
);
}
}
......
......@@ -16,13 +16,11 @@ fn main() {
// Multiple labels on one line
asm!("foo: bar1: nop");
//~^ ERROR avoid using named labels
//~| ERROR avoid using named labels
// Multiple lines
asm!("foo1: nop", "nop"); //~ ERROR avoid using named labels
asm!("foo2: foo3: nop", "nop");
//~^ ERROR avoid using named labels
//~| ERROR avoid using named labels
asm!("nop", "foo4: nop"); //~ ERROR avoid using named labels
asm!("foo5: nop", "foo6: nop");
//~^ ERROR avoid using named labels
......@@ -31,19 +29,16 @@ fn main() {
// Statement separator
asm!("foo7: nop; foo8: nop");
//~^ ERROR avoid using named labels
//~| ERROR avoid using named labels
asm!("foo9: nop; nop"); //~ ERROR avoid using named labels
asm!("nop; foo10: nop"); //~ ERROR avoid using named labels
// Escaped newline
asm!("bar2: nop\n bar3: nop");
//~^ ERROR avoid using named labels
//~| ERROR avoid using named labels
asm!("bar4: nop\n nop"); //~ ERROR avoid using named labels
asm!("nop\n bar5: nop"); //~ ERROR avoid using named labels
asm!("nop\n bar6: bar7: nop");
//~^ ERROR avoid using named labels
//~| ERROR avoid using named labels
// Raw strings
asm!(
......@@ -53,7 +48,7 @@ fn main() {
"
);
//~^^^^ ERROR avoid using named labels
//~^^^^ ERROR avoid using named labels
asm!(
r###"
nop
......
......@@ -21,22 +21,13 @@ error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:17:15
|
LL | asm!("foo: bar1: nop");
| ^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:17:20
|
LL | asm!("foo: bar1: nop");
| ^^^^
| ^^^ ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:22:15
--> $DIR/named-asm-labels.rs:21:15
|
LL | asm!("foo1: nop", "nop");
| ^^^^
......@@ -45,25 +36,16 @@ LL | asm!("foo1: nop", "nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:23:15
|
LL | asm!("foo2: foo3: nop", "nop");
| ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:23:21
--> $DIR/named-asm-labels.rs:22:15
|
LL | asm!("foo2: foo3: nop", "nop");
| ^^^^
| ^^^^ ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:26:22
--> $DIR/named-asm-labels.rs:24:22
|
LL | asm!("nop", "foo4: nop");
| ^^^^
......@@ -72,7 +54,7 @@ LL | asm!("nop", "foo4: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:27:15
--> $DIR/named-asm-labels.rs:25:15
|
LL | asm!("foo5: nop", "foo6: nop");
| ^^^^
......@@ -81,7 +63,7 @@ LL | asm!("foo5: nop", "foo6: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:27:28
--> $DIR/named-asm-labels.rs:25:28
|
LL | asm!("foo5: nop", "foo6: nop");
| ^^^^
......@@ -90,25 +72,16 @@ LL | asm!("foo5: nop", "foo6: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:32:15
|
LL | asm!("foo7: nop; foo8: nop");
| ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:32:26
--> $DIR/named-asm-labels.rs:30:15
|
LL | asm!("foo7: nop; foo8: nop");
| ^^^^
| ^^^^ ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:35:15
--> $DIR/named-asm-labels.rs:32:15
|
LL | asm!("foo9: nop; nop");
| ^^^^
......@@ -117,7 +90,7 @@ LL | asm!("foo9: nop; nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:36:20
--> $DIR/named-asm-labels.rs:33:20
|
LL | asm!("nop; foo10: nop");
| ^^^^^
......@@ -126,25 +99,16 @@ LL | asm!("nop; foo10: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:39:15
|
LL | asm!("bar2: nop\n bar3: nop");
| ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:39:27
--> $DIR/named-asm-labels.rs:36:15
|
LL | asm!("bar2: nop\n bar3: nop");
| ^^^^
| ^^^^ ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:42:15
--> $DIR/named-asm-labels.rs:38:15
|
LL | asm!("bar4: nop\n nop");
| ^^^^
......@@ -153,7 +117,7 @@ LL | asm!("bar4: nop\n nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:43:21
--> $DIR/named-asm-labels.rs:39:21
|
LL | asm!("nop\n bar5: nop");
| ^^^^
......@@ -162,35 +126,19 @@ LL | asm!("nop\n bar5: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:44:21
--> $DIR/named-asm-labels.rs:40:21
|
LL | asm!("nop\n bar6: bar7: nop");
| ^^^^
| ^^^^ ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:44:27
|
LL | asm!("nop\n bar6: bar7: nop");
| ^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:51:13
--> $DIR/named-asm-labels.rs:46:13
|
LL | blah2: nop
| ^^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:52:13
|
LL | blah3: nop
| ^^^^^
|
......@@ -198,7 +146,7 @@ LL | blah3: nop
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:60:19
--> $DIR/named-asm-labels.rs:55:19
|
LL | nop ; blah4: nop
| ^^^^^
......@@ -207,7 +155,7 @@ LL | nop ; blah4: nop
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:74:15
--> $DIR/named-asm-labels.rs:69:15
|
LL | asm!("blah1: 2bar: nop");
| ^^^^^
......@@ -216,7 +164,7 @@ LL | asm!("blah1: 2bar: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:77:15
--> $DIR/named-asm-labels.rs:72:15
|
LL | asm!("def: def: nop");
| ^^^
......@@ -225,7 +173,7 @@ LL | asm!("def: def: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:78:15
--> $DIR/named-asm-labels.rs:73:15
|
LL | asm!("def: nop\ndef: nop");
| ^^^
......@@ -234,7 +182,7 @@ LL | asm!("def: nop\ndef: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:79:15
--> $DIR/named-asm-labels.rs:74:15
|
LL | asm!("def: nop; def: nop");
| ^^^
......@@ -243,7 +191,7 @@ LL | asm!("def: nop; def: nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:87:15
--> $DIR/named-asm-labels.rs:82:15
|
LL | asm!("fooo\u{003A} nop");
| ^^^^^^^^^^^^^^^^
......@@ -252,7 +200,7 @@ LL | asm!("fooo\u{003A} nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:88:15
--> $DIR/named-asm-labels.rs:83:15
|
LL | asm!("foooo\x3A nop");
| ^^^^^^^^^^^^^
......@@ -261,7 +209,7 @@ LL | asm!("foooo\x3A nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:91:15
--> $DIR/named-asm-labels.rs:86:15
|
LL | asm!("fooooo:\u{000A} nop");
| ^^^^^^
......@@ -270,7 +218,7 @@ LL | asm!("fooooo:\u{000A} nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:92:15
--> $DIR/named-asm-labels.rs:87:15
|
LL | asm!("foooooo:\x0A nop");
| ^^^^^^^
......@@ -279,7 +227,7 @@ LL | asm!("foooooo:\x0A nop");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:96:14
--> $DIR/named-asm-labels.rs:91:14
|
LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -288,7 +236,7 @@ LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:107:13
--> $DIR/named-asm-labels.rs:102:13
|
LL | ab: nop // ab: does foo
| ^^
......@@ -297,7 +245,7 @@ LL | ab: nop // ab: does foo
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:119:14
--> $DIR/named-asm-labels.rs:114:14
|
LL | asm!(include_str!("named-asm-labels.s"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -306,18 +254,18 @@ LL | asm!(include_str!("named-asm-labels.s"));
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
warning: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:129:19
--> $DIR/named-asm-labels.rs:124:19
|
LL | asm!("warned: nop");
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/named-asm-labels.rs:127:16
--> $DIR/named-asm-labels.rs:122:16
|
LL | #[warn(named_asm_labels)]
| ^^^^^^^^^^^^^^^^
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
error: aborting due to 34 previous errors; 1 warning emitted
error: aborting due to 28 previous errors; 1 warning emitted
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册