1
Fork 0

Resolve RTN for TyKind::Path ending in (..)

This commit is contained in:
Michael Goulet 2024-08-22 21:51:00 -04:00
parent c0838c8ebe
commit 6d788a18c5

View file

@ -404,6 +404,8 @@ pub(crate) enum PathSource<'a> {
Delegation, Delegation,
/// An arg in a `use<'a, N>` precise-capturing bound. /// An arg in a `use<'a, N>` precise-capturing bound.
PreciseCapturingArg(Namespace), PreciseCapturingArg(Namespace),
// Paths that end with `(..)`, for return type notation.
ReturnTypeNotation,
} }
impl<'a> PathSource<'a> { impl<'a> PathSource<'a> {
@ -413,7 +415,8 @@ impl<'a> PathSource<'a> {
PathSource::Expr(..) PathSource::Expr(..)
| PathSource::Pat | PathSource::Pat
| PathSource::TupleStruct(..) | PathSource::TupleStruct(..)
| PathSource::Delegation => ValueNS, | PathSource::Delegation
| PathSource::ReturnTypeNotation => ValueNS,
PathSource::TraitItem(ns) => ns, PathSource::TraitItem(ns) => ns,
PathSource::PreciseCapturingArg(ns) => ns, PathSource::PreciseCapturingArg(ns) => ns,
} }
@ -425,7 +428,8 @@ impl<'a> PathSource<'a> {
| PathSource::Expr(..) | PathSource::Expr(..)
| PathSource::Pat | PathSource::Pat
| PathSource::Struct | PathSource::Struct
| PathSource::TupleStruct(..) => true, | PathSource::TupleStruct(..)
| PathSource::ReturnTypeNotation => true,
PathSource::Trait(_) PathSource::Trait(_)
| PathSource::TraitItem(..) | PathSource::TraitItem(..)
| PathSource::Delegation | PathSource::Delegation
@ -471,7 +475,7 @@ impl<'a> PathSource<'a> {
}, },
_ => "value", _ => "value",
}, },
PathSource::Delegation => "function", PathSource::ReturnTypeNotation | PathSource::Delegation => "function",
PathSource::PreciseCapturingArg(..) => "type or const parameter", PathSource::PreciseCapturingArg(..) => "type or const parameter",
} }
} }
@ -540,6 +544,10 @@ impl<'a> PathSource<'a> {
Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true, Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
_ => false, _ => false,
}, },
PathSource::ReturnTypeNotation => match res {
Res::Def(DefKind::AssocFn, _) => true,
_ => false,
},
PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)), PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)),
PathSource::PreciseCapturingArg(ValueNS) => { PathSource::PreciseCapturingArg(ValueNS) => {
matches!(res, Res::Def(DefKind::ConstParam, _)) matches!(res, Res::Def(DefKind::ConstParam, _))
@ -565,8 +573,8 @@ impl<'a> PathSource<'a> {
(PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425, (PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425,
(PathSource::Pat | PathSource::TupleStruct(..), true) => E0532, (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532,
(PathSource::Pat | PathSource::TupleStruct(..), false) => E0531, (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
(PathSource::TraitItem(..), true) => E0575, (PathSource::TraitItem(..), true) | (PathSource::ReturnTypeNotation, true) => E0575,
(PathSource::TraitItem(..), false) => E0576, (PathSource::TraitItem(..), false) | (PathSource::ReturnTypeNotation, false) => E0576,
(PathSource::PreciseCapturingArg(..), true) => E0799, (PathSource::PreciseCapturingArg(..), true) => E0799,
(PathSource::PreciseCapturingArg(..), false) => E0800, (PathSource::PreciseCapturingArg(..), false) => E0800,
} }
@ -781,7 +789,17 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
} }
TyKind::Path(qself, path) => { TyKind::Path(qself, path) => {
self.diag_metadata.current_type_path = Some(ty); self.diag_metadata.current_type_path = Some(ty);
self.smart_resolve_path(ty.id, qself, path, PathSource::Type);
let source = if let Some(seg) = path.segments.last()
&& let Some(args) = &seg.args
&& matches!(**args, GenericArgs::ParenthesizedElided(..))
{
PathSource::ReturnTypeNotation
} else {
PathSource::Type
};
self.smart_resolve_path(ty.id, qself, path, source);
// Check whether we should interpret this as a bare trait object. // Check whether we should interpret this as a bare trait object.
if qself.is_none() if qself.is_none()
@ -1920,7 +1938,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
PathSource::Trait(..) PathSource::Trait(..)
| PathSource::TraitItem(..) | PathSource::TraitItem(..)
| PathSource::Type | PathSource::Type
| PathSource::PreciseCapturingArg(..) => false, | PathSource::PreciseCapturingArg(..)
| PathSource::ReturnTypeNotation => false,
PathSource::Expr(..) PathSource::Expr(..)
| PathSource::Pat | PathSource::Pat
| PathSource::Struct | PathSource::Struct