Skip to content

Commit

Permalink
Don't show note if span is DUMMY_SP
Browse files Browse the repository at this point in the history
  • Loading branch information
henryboisdequin committed Mar 12, 2021
1 parent bba2bac commit 26478c8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Expand Up @@ -13,7 +13,7 @@ use rustc_middle::mir::{
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};

use crate::dataflow::drop_flag_effects;
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
Expand Down Expand Up @@ -216,12 +216,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
}
// Avoid pointing to the same function in multiple different
// error messages
if self.fn_self_span_reported.insert(self_arg.span) {
// error messages.
if span != DUMMY_SP && self.fn_self_span_reported.insert(self_arg.span)
{
err.span_note(
self_arg.span,
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
);
self_arg.span,
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
);
}
}
// Deref::deref takes &self, which cannot cause a move
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/loops/issue-82916.rs
@@ -0,0 +1,10 @@
struct S(i32);

fn foo(x: Vec<S>) {
for y in x {

}
let z = x; //~ ERROR use of moved value: `x`
}

fn main() {}
23 changes: 23 additions & 0 deletions src/test/ui/loops/issue-82916.stderr
@@ -0,0 +1,23 @@
error[E0382]: use of moved value: `x`
--> $DIR/issue-82916.rs:7:13
|
LL | fn foo(x: Vec<S>) {
| - move occurs because `x` has type `Vec<S>`, which does not implement the `Copy` trait
LL | for y in x {
| -
| |
| `x` moved due to this implicit call to `.into_iter()`
| help: consider borrowing to avoid moving into the for loop: `&x`
...
LL | let z = x;
| ^ value used here after move
|
note: this function takes ownership of the receiver `self`, which moves `x`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
LL | fn into_iter(self) -> Self::IntoIter;
| ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.

0 comments on commit 26478c8

Please sign in to comment.