diff options
| author | Michael Goulet <michael@errs.io> | 2024-04-04 20:23:52 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-04-15 16:45:26 -0400 |
| commit | 52c6b101ea18ed6f09367bf459ac55ffe473cd9c (patch) | |
| tree | 4bd7b7084b701a4c3e9deb299db09c209b5a7dbc /compiler/rustc_resolve/src | |
| parent | ce8961039e244b1e4e0fa02fc10d59a22abc9ea3 (diff) | |
| download | rust-52c6b101ea18ed6f09367bf459ac55ffe473cd9c.tar.gz rust-52c6b101ea18ed6f09367bf459ac55ffe473cd9c.zip | |
Use a path instead of an ident (and stop manually resolving)
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 66 |
1 files changed, 12 insertions, 54 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 7203adab135..64434412886 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1056,64 +1056,22 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, match arg { // Lower the lifetime regularly; we'll resolve the lifetime and check // it's a parameter later on in HIR lowering. - PreciseCapturingArg::Lifetime(_) => visit::walk_precise_capturing_arg(self, arg), + PreciseCapturingArg::Lifetime(_) => {} - PreciseCapturingArg::Arg(ident, node_id) => { - let ident = ident.normalize_to_macros_2_0(); - 'found: { - for (rib_t, rib_v) in - std::iter::zip(&self.ribs.type_ns, &self.ribs.value_ns).rev() - { - if let Some(res) = rib_t.bindings.get(&ident).or(rib_v.bindings.get(&ident)) - { - self.r.record_partial_res(*node_id, PartialRes::new(*res)); - - // Validate that this is a parameter - match res { - Res::Def(DefKind::TyParam | DefKind::ConstParam, _) - | Res::SelfTyParam { .. } => {} - Res::SelfTyAlias { .. } => { - self.report_error( - ident.span, - ResolutionError::FailedToResolve { - segment: Some(ident.name), - label: "`Self` cannot be captured because it is not a type parameter".to_string(), - suggestion: None, - module: None, - }, - ); - } - _ => { - self.report_error( - ident.span, - ResolutionError::FailedToResolve { - segment: Some(ident.name), - label: format!( - "expected type or const parameter, found {}", - res.descr() - ), - suggestion: None, - module: None, - }, - ); - } - } - - break 'found; - } - } - self.report_error( - ident.span, - ResolutionError::FailedToResolve { - segment: Some(ident.name), - label: "could not find type or const parameter".to_string(), - suggestion: None, - module: None, - }, - ); + PreciseCapturingArg::Arg(path, id) => { + let mut check_ns = |ns| { + self.maybe_resolve_ident_in_lexical_scope(path.segments[0].ident, ns).is_some() + }; + // Like `Ty::Param`, we try resolving this as both a const and a type. + if !check_ns(TypeNS) && check_ns(ValueNS) { + self.smart_resolve_path(*id, &None, path, PathSource::Expr(None)); + } else { + self.smart_resolve_path(*id, &None, path, PathSource::Type); } } } + + visit::walk_precise_capturing_arg(self, arg) } fn visit_generics(&mut self, generics: &'ast Generics) { |
