1
Fork 0

Note when a a move/borrow error is caused by a deref coercion

Fixes #73268

When a deref coercion occurs, we may end up with a move error if the
base value has been partially moved out of. However, we do not indicate
anywhere that a deref coercion is occuring, resulting in an error
message with a confusing span.

This PR adds an explicit note to move errors when a deref coercion is
involved. We mention the name of the type that the deref-coercion
resolved to, as well as the `Deref::Target` associated type being used.
This commit is contained in:
Aaron Hill 2020-07-25 07:04:13 -04:00
parent a1947b3f9e
commit d18b4bb7a7
No known key found for this signature in database
GPG key ID: B4087E510E98B164
23 changed files with 250 additions and 54 deletions

View file

@ -4,6 +4,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_macros::HashStable;
use rustc_span::Span;
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub enum PointerCast {
@ -113,6 +114,9 @@ pub enum Adjust<'tcx> {
pub struct OverloadedDeref<'tcx> {
pub region: ty::Region<'tcx>,
pub mutbl: hir::Mutability,
/// The `Span` associated with the field access or method call
/// that triggered this overloaded deref.
pub span: Span,
}
impl<'tcx> OverloadedDeref<'tcx> {

View file

@ -606,8 +606,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.region)
.map(|region| ty::adjustment::OverloadedDeref { region, mutbl: self.mutbl })
tcx.lift(&self.region).map(|region| ty::adjustment::OverloadedDeref {
region,
mutbl: self.mutbl,
span: self.span,
})
}
}