mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Auto merge of #95127 - notriddle:notriddle/option-content-move-from-tuple-match, r=estebank
diagnostics: do not give Option::as_ref suggestion for complex match Fixes #82528
This commit is contained in:
commit
2d15732f6e
@ -218,18 +218,29 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
fn report(&mut self, error: GroupedMoveError<'tcx>) {
|
fn report(&mut self, error: GroupedMoveError<'tcx>) {
|
||||||
let (mut err, err_span) = {
|
let (mut err, err_span) = {
|
||||||
let (span, use_spans, original_path, kind): (
|
let (span, use_spans, original_path, kind, has_complex_bindings): (
|
||||||
Span,
|
Span,
|
||||||
Option<UseSpans<'tcx>>,
|
Option<UseSpans<'tcx>>,
|
||||||
Place<'tcx>,
|
Place<'tcx>,
|
||||||
&IllegalMoveOriginKind<'_>,
|
&IllegalMoveOriginKind<'_>,
|
||||||
|
bool,
|
||||||
) = match error {
|
) = match error {
|
||||||
GroupedMoveError::MovesFromPlace { span, original_path, ref kind, .. }
|
GroupedMoveError::MovesFromPlace {
|
||||||
| GroupedMoveError::MovesFromValue { span, original_path, ref kind, .. } => {
|
span,
|
||||||
(span, None, original_path, kind)
|
original_path,
|
||||||
|
ref kind,
|
||||||
|
ref binds_to,
|
||||||
|
..
|
||||||
}
|
}
|
||||||
|
| GroupedMoveError::MovesFromValue {
|
||||||
|
span,
|
||||||
|
original_path,
|
||||||
|
ref kind,
|
||||||
|
ref binds_to,
|
||||||
|
..
|
||||||
|
} => (span, None, original_path, kind, !binds_to.is_empty()),
|
||||||
GroupedMoveError::OtherIllegalMove { use_spans, original_path, ref kind } => {
|
GroupedMoveError::OtherIllegalMove { use_spans, original_path, ref kind } => {
|
||||||
(use_spans.args_or_use(), Some(use_spans), original_path, kind)
|
(use_spans.args_or_use(), Some(use_spans), original_path, kind, false)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!(
|
debug!(
|
||||||
@ -248,6 +259,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
target_place,
|
target_place,
|
||||||
span,
|
span,
|
||||||
use_spans,
|
use_spans,
|
||||||
|
has_complex_bindings,
|
||||||
),
|
),
|
||||||
&IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => {
|
&IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => {
|
||||||
self.cannot_move_out_of_interior_of_drop(span, ty)
|
self.cannot_move_out_of_interior_of_drop(span, ty)
|
||||||
@ -290,6 +302,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
deref_target_place: Place<'tcx>,
|
deref_target_place: Place<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
use_spans: Option<UseSpans<'tcx>>,
|
use_spans: Option<UseSpans<'tcx>>,
|
||||||
|
has_complex_bindings: bool,
|
||||||
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
// Inspect the type of the content behind the
|
// Inspect the type of the content behind the
|
||||||
// borrow to provide feedback about why this
|
// borrow to provide feedback about why this
|
||||||
@ -399,6 +412,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
let diag_name = self.infcx.tcx.get_diagnostic_name(def_id);
|
let diag_name = self.infcx.tcx.get_diagnostic_name(def_id);
|
||||||
if matches!(diag_name, Some(sym::Option | sym::Result))
|
if matches!(diag_name, Some(sym::Option | sym::Result))
|
||||||
&& use_spans.map_or(true, |v| !v.for_closure())
|
&& use_spans.map_or(true, |v| !v.for_closure())
|
||||||
|
&& !has_complex_bindings
|
||||||
{
|
{
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span.shrink_to_hi(),
|
span.shrink_to_hi(),
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
fn foo(a: &Option<String>, b: &Option<String>) {
|
||||||
|
match (a, b) {
|
||||||
|
//~^ ERROR cannot move out of a shared reference
|
||||||
|
(None, &c) => &c.unwrap(),
|
||||||
|
(&Some(ref c), _) => c,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,15 @@
|
|||||||
|
error[E0507]: cannot move out of a shared reference
|
||||||
|
--> $DIR/option-content-move-from-tuple-match.rs:2:11
|
||||||
|
|
|
||||||
|
LL | match (a, b) {
|
||||||
|
| ^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | (None, &c) => &c.unwrap(),
|
||||||
|
| -
|
||||||
|
| |
|
||||||
|
| data moved here
|
||||||
|
| move occurs because `c` has type `Option<String>`, which does not implement the `Copy` trait
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0507`.
|
Loading…
Reference in New Issue
Block a user