Skip to content

Commit 4d7f08b

Browse files
committed
rustc: improve E0669 span
E0669 refers to a constraint that cannot be coerced into a single LLVM value, unfortunately right now this uses the Span for the entire inline assembly statement, which is less than ideal. This commit preserves the Span from HIR, which lets us emit the error using the Span for the operand itself in MIR. Signed-off-by: Levente Kurusa <[email protected]>
1 parent 567557f commit 4d7f08b

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ pub enum StatementKind<'tcx> {
17131713
InlineAsm {
17141714
asm: Box<InlineAsm>,
17151715
outputs: Box<[Place<'tcx>]>,
1716-
inputs: Box<[Operand<'tcx>]>,
1716+
inputs: Box<[(Span, Operand<'tcx>)]>,
17171717
},
17181718

17191719
/// Assert the given places to be valid inhabitants of their type. These statements are

src/librustc/mir/visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ macro_rules! make_mir_visitor {
383383
for output in & $($mutability)* outputs[..] {
384384
self.visit_place(output, PlaceContext::AsmOutput, location);
385385
}
386-
for input in & $($mutability)* inputs[..] {
386+
for (span, input) in & $($mutability)* inputs[..] {
387+
self.visit_span(span);
387388
self.visit_operand(input, location);
388389
}
389390
}

src/librustc_codegen_llvm/mir/statement.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ impl FunctionCx<'a, 'll, 'tcx> {
8484
}).collect();
8585

8686
let input_vals = inputs.iter()
87-
.try_fold(Vec::with_capacity(inputs.len()), |mut acc, input| {
87+
.try_fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
8888
let op = self.codegen_operand(&bx, input);
8989
if let OperandValue::Immediate(_) = op.val {
9090
acc.push(op.immediate());
9191
Ok(acc)
9292
} else {
93-
Err(op)
93+
Err(span)
9494
}
9595
});
9696

97-
if input_vals.is_err() {
98-
span_err!(bx.sess(), statement.source_info.span, E0669,
97+
if let Err(span) = input_vals {
98+
span_err!(bx.sess(), span.to_owned(), E0669,
9999
"invalid value for constraint in inline assembly");
100100
} else {
101101
let input_vals = input_vals.unwrap();

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
565565
);
566566
}
567567
}
568-
for input in inputs.iter() {
568+
for (_, input) in inputs.iter() {
569569
self.consume_operand(context, (input, span), flow_state);
570570
}
571571
}

src/librustc_mir/borrow_check/nll/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
128128
);
129129
}
130130
}
131-
for input in inputs.iter() {
131+
for (_, input) in inputs.iter() {
132132
self.consume_operand(context, input);
133133
}
134134
}

src/librustc_mir/build/expr/stmt.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
167167
.into_boxed_slice();
168168
let inputs = inputs
169169
.into_iter()
170-
.map(|input| unpack!(block = this.as_local_operand(block, input)))
171-
.collect::<Vec<_>>()
170+
.map(|input| {
171+
(
172+
input.span(),
173+
unpack!(block = this.as_local_operand(block, input)),
174+
)
175+
}).collect::<Vec<_>>()
172176
.into_boxed_slice();
173177
this.cfg.push(
174178
block,

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
290290
self.gather_init(output, InitKind::Deep);
291291
}
292292
}
293-
for input in inputs.iter() {
293+
for (_, input) in inputs.iter() {
294294
self.gather_operand(input);
295295
}
296296
}

src/test/ui/inline-asm-bad-operand.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
error[E0669]: invalid value for constraint in inline assembly
2-
--> $DIR/inline-asm-bad-operand.rs:28:9
2+
--> $DIR/inline-asm-bad-operand.rs:28:24
33
|
44
LL | asm!("" :: "r"("")); //~ ERROR E0669
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^
66

77
error[E0669]: invalid value for constraint in inline assembly
8-
--> $DIR/inline-asm-bad-operand.rs:33:9
8+
--> $DIR/inline-asm-bad-operand.rs:33:32
99
|
1010
LL | asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^
1212

1313
error[E0669]: invalid value for constraint in inline assembly
14-
--> $DIR/inline-asm-bad-operand.rs:40:14
14+
--> $DIR/inline-asm-bad-operand.rs:40:29
1515
|
1616
LL | unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
17-
| ^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^
1818

1919
error[E0669]: invalid value for constraint in inline assembly
20-
--> $DIR/inline-asm-bad-operand.rs:48:9
20+
--> $DIR/inline-asm-bad-operand.rs:48:38
2121
|
2222
LL | asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
| ^^^
2424

2525
error[E0669]: invalid value for constraint in inline assembly
26-
--> $DIR/inline-asm-bad-operand.rs:55:9
26+
--> $DIR/inline-asm-bad-operand.rs:55:32
2727
|
2828
LL | asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
| ^^^^
3030

3131
error: aborting due to 5 previous errors
3232

0 commit comments

Comments
 (0)