diff options
| author | bors <bors@rust-lang.org> | 2024-09-21 22:09:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-09-21 22:09:47 +0000 |
| commit | 764e6aec81517cde60214ccd00a709a34eb0c07d (patch) | |
| tree | 098f6fe0dcc9a44cb5280b813bda474854d0a1e5 /compiler/rustc_resolve/src | |
| parent | 1d68e6dd1deef26c5aeb91aee554edbee8b6d5e2 (diff) | |
| parent | 52f146d363504d25b5e2fe468cadc2f50315da91 (diff) | |
| download | rust-764e6aec81517cde60214ccd00a709a34eb0c07d.tar.gz rust-764e6aec81517cde60214ccd00a709a34eb0c07d.zip | |
Auto merge of #130674 - compiler-errors:rollup-yu105fl, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #127766 (add `extern "C-cmse-nonsecure-entry" fn` ) - #129629 (Implement Return Type Notation (RTN)'s path form in where clauses) - #130408 (Avoid re-validating UTF-8 in `FromUtf8Error::into_utf8_lossy`) - #130651 (Add --enable-profiler to armhf dist) - #130653 (ABI compatibility: mention Result guarantee) - #130666 (Assert that `explicit_super_predicates_of` and `explicit_item_super_predicates` truly only contains bounds for the type itself) - #130667 (compiler: Accept "improper" ctypes in extern "rust-cold" fn) - #130673 (Parser: recover from `:::` to `::`) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ac03a3ac42c..f1d9028f88c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -404,6 +404,8 @@ pub(crate) enum PathSource<'a> { Delegation, /// An arg in a `use<'a, N>` precise-capturing bound. PreciseCapturingArg(Namespace), + // Paths that end with `(..)`, for return type notation. + ReturnTypeNotation, } impl<'a> PathSource<'a> { @@ -413,7 +415,8 @@ impl<'a> PathSource<'a> { PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct(..) - | PathSource::Delegation => ValueNS, + | PathSource::Delegation + | PathSource::ReturnTypeNotation => ValueNS, PathSource::TraitItem(ns) => ns, PathSource::PreciseCapturingArg(ns) => ns, } @@ -425,7 +428,8 @@ impl<'a> PathSource<'a> { | PathSource::Expr(..) | PathSource::Pat | PathSource::Struct - | PathSource::TupleStruct(..) => true, + | PathSource::TupleStruct(..) + | PathSource::ReturnTypeNotation => true, PathSource::Trait(_) | PathSource::TraitItem(..) | PathSource::Delegation @@ -471,7 +475,7 @@ impl<'a> PathSource<'a> { }, _ => "value", }, - PathSource::Delegation => "function", + PathSource::ReturnTypeNotation | PathSource::Delegation => "function", PathSource::PreciseCapturingArg(..) => "type or const parameter", } } @@ -540,6 +544,10 @@ impl<'a> PathSource<'a> { Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true, _ => false, }, + PathSource::ReturnTypeNotation => match res { + Res::Def(DefKind::AssocFn, _) => true, + _ => false, + }, PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)), PathSource::PreciseCapturingArg(ValueNS) => { matches!(res, Res::Def(DefKind::ConstParam, _)) @@ -565,8 +573,8 @@ impl<'a> PathSource<'a> { (PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425, (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532, (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531, - (PathSource::TraitItem(..), true) => E0575, - (PathSource::TraitItem(..), false) => E0576, + (PathSource::TraitItem(..), true) | (PathSource::ReturnTypeNotation, true) => E0575, + (PathSource::TraitItem(..), false) | (PathSource::ReturnTypeNotation, false) => E0576, (PathSource::PreciseCapturingArg(..), true) => E0799, (PathSource::PreciseCapturingArg(..), false) => E0800, } @@ -781,7 +789,20 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r } TyKind::Path(qself, path) => { self.diag_metadata.current_type_path = Some(ty); - self.smart_resolve_path(ty.id, qself, path, PathSource::Type); + + // If we have a path that ends with `(..)`, then it must be + // return type notation. Resolve that path in the *value* + // namespace. + 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. if qself.is_none() @@ -1920,7 +1941,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type - | PathSource::PreciseCapturingArg(..) => false, + | PathSource::PreciseCapturingArg(..) + | PathSource::ReturnTypeNotation => false, PathSource::Expr(..) | PathSource::Pat | PathSource::Struct |
