mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 21:42:44 +00:00
Auto merge of #82935 - henryboisdequin:diagnostic-cleanups, r=estebank
Diagnostic cleanups Follow up to #81503 Helps with #82916 (don't show note if `span` is `DUMMY_SP`)
This commit is contained in:
commit
0cc64a34e9
@ -13,7 +13,7 @@ use rustc_middle::mir::{
|
|||||||
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
|
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty, TypeFoldable};
|
||||||
use rustc_span::source_map::DesugaringKind;
|
use rustc_span::source_map::DesugaringKind;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use crate::dataflow::drop_flag_effects;
|
use crate::dataflow::drop_flag_effects;
|
||||||
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
|
use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex};
|
||||||
@ -216,12 +216,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Avoid pointing to the same function in multiple different
|
// Avoid pointing to the same function in multiple different
|
||||||
// error messages
|
// error messages.
|
||||||
if self.fn_self_span_reported.insert(self_arg.span) {
|
if span != DUMMY_SP && self.fn_self_span_reported.insert(self_arg.span)
|
||||||
|
{
|
||||||
err.span_note(
|
err.span_note(
|
||||||
self_arg.span,
|
self_arg.span,
|
||||||
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
|
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deref::deref takes &self, which cannot cause a move
|
// Deref::deref takes &self, which cannot cause a move
|
||||||
|
@ -1908,7 +1908,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
if is_const_fn {
|
if is_const_fn {
|
||||||
err.help(
|
err.help(
|
||||||
"consider creating a new `const` item and initializing with the result \
|
"consider creating a new `const` item and initializing it with the result \
|
||||||
of the function call to be used in the repeat position, like \
|
of the function call to be used in the repeat position, like \
|
||||||
`const VAL: Type = const_fn();` and `let x = [VAL; 42];`",
|
`const VAL: Type = const_fn();` and `let x = [VAL; 42];`",
|
||||||
);
|
);
|
||||||
@ -1916,7 +1916,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
if self.tcx.sess.is_nightly_build() && is_const_fn {
|
if self.tcx.sess.is_nightly_build() && is_const_fn {
|
||||||
err.help(
|
err.help(
|
||||||
"create an inline `const` block, see PR \
|
"create an inline `const` block, see RFC \
|
||||||
#2920 <https://github.com/rust-lang/rfcs/pull/2920> \
|
#2920 <https://github.com/rust-lang/rfcs/pull/2920> \
|
||||||
for more information",
|
for more information",
|
||||||
);
|
);
|
||||||
|
@ -7,8 +7,8 @@ LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
|
|||||||
= help: the following implementations were found:
|
= help: the following implementations were found:
|
||||||
<Option<T> as Copy>
|
<Option<T> as Copy>
|
||||||
= note: the `Copy` trait is required because the repeated element will be copied
|
= note: the `Copy` trait is required because the repeated element will be copied
|
||||||
= help: consider creating a new `const` item and initializing with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];`
|
= help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];`
|
||||||
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
|
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ LL | let strings: [String; 5] = [String::new(); 5];
|
|||||||
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||||
|
|
|
|
||||||
= note: the `Copy` trait is required because the repeated element will be copied
|
= note: the `Copy` trait is required because the repeated element will be copied
|
||||||
= help: consider creating a new `const` item and initializing with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];`
|
= help: consider creating a new `const` item and initializing it with the result of the function call to be used in the repeat position, like `const VAL: Type = const_fn();` and `let x = [VAL; 42];`
|
||||||
= help: create an inline `const` block, see PR #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
|
= help: create an inline `const` block, see RFC #2920 <https://github.com/rust-lang/rfcs/pull/2920> for more information
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
10
src/test/ui/loops/issue-82916.rs
Normal file
10
src/test/ui/loops/issue-82916.rs
Normal file
@ -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
src/test/ui/loops/issue-82916.stderr
Normal file
23
src/test/ui/loops/issue-82916.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user