Skip to content

Commit 26478c8

Browse files
Don't show note if span is DUMMY_SP
1 parent bba2bac commit 26478c8

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

Diff for: compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::{
1313
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
1414
use rustc_span::source_map::DesugaringKind;
1515
use rustc_span::symbol::sym;
16-
use rustc_span::Span;
16+
use rustc_span::{Span, DUMMY_SP};
1717

1818
use crate::dataflow::drop_flag_effects;
1919
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
@@ -216,12 +216,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
216216
);
217217
}
218218
// Avoid pointing to the same function in multiple different
219-
// error messages
220-
if self.fn_self_span_reported.insert(self_arg.span) {
219+
// error messages.
220+
if span != DUMMY_SP && self.fn_self_span_reported.insert(self_arg.span)
221+
{
221222
err.span_note(
222-
self_arg.span,
223-
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
224-
);
223+
self_arg.span,
224+
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
225+
);
225226
}
226227
}
227228
// Deref::deref takes &self, which cannot cause a move

Diff for: src/test/ui/loops/issue-82916.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct S(i32);
2+
3+
fn foo(x: Vec<S>) {
4+
for y in x {
5+
6+
}
7+
let z = x; //~ ERROR use of moved value: `x`
8+
}
9+
10+
fn main() {}

Diff for: src/test/ui/loops/issue-82916.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0382]: use of moved value: `x`
2+
--> $DIR/issue-82916.rs:7:13
3+
|
4+
LL | fn foo(x: Vec<S>) {
5+
| - move occurs because `x` has type `Vec<S>`, which does not implement the `Copy` trait
6+
LL | for y in x {
7+
| -
8+
| |
9+
| `x` moved due to this implicit call to `.into_iter()`
10+
| help: consider borrowing to avoid moving into the for loop: `&x`
11+
...
12+
LL | let z = x;
13+
| ^ value used here after move
14+
|
15+
note: this function takes ownership of the receiver `self`, which moves `x`
16+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
17+
|
18+
LL | fn into_iter(self) -> Self::IntoIter;
19+
| ^^^^
20+
21+
error: aborting due to previous error
22+
23+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)