Skip to content

Commit 6d788a1

Browse files
Resolve RTN for TyKind::Path ending in (..)
1 parent c0838c8 commit 6d788a1

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ pub(crate) enum PathSource<'a> {
404404
Delegation,
405405
/// An arg in a `use<'a, N>` precise-capturing bound.
406406
PreciseCapturingArg(Namespace),
407+
// Paths that end with `(..)`, for return type notation.
408+
ReturnTypeNotation,
407409
}
408410

409411
impl<'a> PathSource<'a> {
@@ -413,7 +415,8 @@ impl<'a> PathSource<'a> {
413415
PathSource::Expr(..)
414416
| PathSource::Pat
415417
| PathSource::TupleStruct(..)
416-
| PathSource::Delegation => ValueNS,
418+
| PathSource::Delegation
419+
| PathSource::ReturnTypeNotation => ValueNS,
417420
PathSource::TraitItem(ns) => ns,
418421
PathSource::PreciseCapturingArg(ns) => ns,
419422
}
@@ -425,7 +428,8 @@ impl<'a> PathSource<'a> {
425428
| PathSource::Expr(..)
426429
| PathSource::Pat
427430
| PathSource::Struct
428-
| PathSource::TupleStruct(..) => true,
431+
| PathSource::TupleStruct(..)
432+
| PathSource::ReturnTypeNotation => true,
429433
PathSource::Trait(_)
430434
| PathSource::TraitItem(..)
431435
| PathSource::Delegation
@@ -471,7 +475,7 @@ impl<'a> PathSource<'a> {
471475
},
472476
_ => "value",
473477
},
474-
PathSource::Delegation => "function",
478+
PathSource::ReturnTypeNotation | PathSource::Delegation => "function",
475479
PathSource::PreciseCapturingArg(..) => "type or const parameter",
476480
}
477481
}
@@ -540,6 +544,10 @@ impl<'a> PathSource<'a> {
540544
Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
541545
_ => false,
542546
},
547+
PathSource::ReturnTypeNotation => match res {
548+
Res::Def(DefKind::AssocFn, _) => true,
549+
_ => false,
550+
},
543551
PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)),
544552
PathSource::PreciseCapturingArg(ValueNS) => {
545553
matches!(res, Res::Def(DefKind::ConstParam, _))
@@ -565,8 +573,8 @@ impl<'a> PathSource<'a> {
565573
(PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425,
566574
(PathSource::Pat | PathSource::TupleStruct(..), true) => E0532,
567575
(PathSource::Pat | PathSource::TupleStruct(..), false) => E0531,
568-
(PathSource::TraitItem(..), true) => E0575,
569-
(PathSource::TraitItem(..), false) => E0576,
576+
(PathSource::TraitItem(..), true) | (PathSource::ReturnTypeNotation, true) => E0575,
577+
(PathSource::TraitItem(..), false) | (PathSource::ReturnTypeNotation, false) => E0576,
570578
(PathSource::PreciseCapturingArg(..), true) => E0799,
571579
(PathSource::PreciseCapturingArg(..), false) => E0800,
572580
}
@@ -781,7 +789,17 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
781789
}
782790
TyKind::Path(qself, path) => {
783791
self.diag_metadata.current_type_path = Some(ty);
784-
self.smart_resolve_path(ty.id, qself, path, PathSource::Type);
792+
793+
let source = if let Some(seg) = path.segments.last()
794+
&& let Some(args) = &seg.args
795+
&& matches!(**args, GenericArgs::ParenthesizedElided(..))
796+
{
797+
PathSource::ReturnTypeNotation
798+
} else {
799+
PathSource::Type
800+
};
801+
802+
self.smart_resolve_path(ty.id, qself, path, source);
785803

786804
// Check whether we should interpret this as a bare trait object.
787805
if qself.is_none()
@@ -1920,7 +1938,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
19201938
PathSource::Trait(..)
19211939
| PathSource::TraitItem(..)
19221940
| PathSource::Type
1923-
| PathSource::PreciseCapturingArg(..) => false,
1941+
| PathSource::PreciseCapturingArg(..)
1942+
| PathSource::ReturnTypeNotation => false,
19241943
PathSource::Expr(..)
19251944
| PathSource::Pat
19261945
| PathSource::Struct

0 commit comments

Comments
 (0)