Rollup merge of #136018 - estebank:long-moved-type, r=jieyouxu
Use short ty string for move errors
```
error[E0382]: use of moved value: `x`
--> bay.rs:14:14
|
12 | fn foo(x: D) {
| - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
13 | let _a = x;
| - value moved here
14 | let _b = x; //~ ERROR use of moved value
| ^ value used here after move
|
= note: the full type name has been written to 'bay.long-type-14349227078439097973.txt'
= note: consider using `--verbose` to print the full type name to the console
help: consider cloning the value if the performance cost is acceptable
|
13 | let _a = x.clone();
| ++++++++
```
Address 4th case in #135919.
This commit is contained in:
@@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
if needs_note {
|
||||
let mut path = None;
|
||||
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
|
||||
if let Some(local) = place.as_local() {
|
||||
let span = self.body.local_decls[local].source_info.span;
|
||||
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
|
||||
@@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
place: ¬e_msg,
|
||||
});
|
||||
};
|
||||
if let Some(path) = path {
|
||||
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
|
||||
path: path.display().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let UseSpans::FnSelfUse {
|
||||
|
||||
@@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
self.suggest_cloning(err, place_ty, expr, None);
|
||||
}
|
||||
|
||||
let mut path = None;
|
||||
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
|
||||
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
|
||||
is_partial_move: false,
|
||||
ty: place_ty,
|
||||
ty,
|
||||
place: &place_desc,
|
||||
span,
|
||||
});
|
||||
if let Some(path) = path {
|
||||
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
|
||||
path: path.display().to_string(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
binds_to.sort();
|
||||
binds_to.dedup();
|
||||
@@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
|
||||
}
|
||||
|
||||
let mut path = None;
|
||||
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
|
||||
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
|
||||
is_partial_move: false,
|
||||
ty: place_ty,
|
||||
ty,
|
||||
place: &place_desc,
|
||||
span: use_span,
|
||||
});
|
||||
if let Some(path) = path {
|
||||
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
|
||||
path: path.display().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
use_spans.args_subdiag(err, |args_span| {
|
||||
crate::session_diagnostics::CaptureArgLabel::MoveOutPlace {
|
||||
@@ -831,12 +845,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||
self.suggest_cloning(err, bind_to.ty, expr, None);
|
||||
}
|
||||
|
||||
let mut path = None;
|
||||
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
|
||||
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
|
||||
is_partial_move: false,
|
||||
ty: bind_to.ty,
|
||||
ty,
|
||||
place: place_desc,
|
||||
span: binding_span,
|
||||
});
|
||||
if let Some(path) = path {
|
||||
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
|
||||
path: path.display().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user