From a1d181d740df13972533475b4b35d59678b3ab50 Mon Sep 17 00:00:00 2001 From: Lenko Donchev Date: Wed, 5 Jul 2023 20:19:14 -0500 Subject: [PATCH] Added additional visit steps to visit_generic_param() in order to avoid ICE on no bound vars. --- .../src/collect/resolve_bound_vars.rs | 31 +++++++++---------- tests/ui/closures/issue-112547.rs | 15 +++++++++ tests/ui/closures/issue-112547.stderr | 23 ++++++++++++++ 3 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 tests/ui/closures/issue-112547.rs create mode 100644 tests/ui/closures/issue-112547.stderr diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index a39cfd7b6e169..d9207f2de52c0 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -856,22 +856,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { let scope = Scope::TraitRefBoundary { s: self.scope }; self.with(scope, |this| { walk_list!(this, visit_generic_param, generics.params); - for param in generics.params { - match param.kind { - GenericParamKind::Lifetime { .. } => {} - GenericParamKind::Type { default, .. } => { - if let Some(ty) = default { - this.visit_ty(ty); - } - } - GenericParamKind::Const { ty, default } => { - this.visit_ty(ty); - if let Some(default) = default { - this.visit_body(this.tcx.hir().body(default.body)); - } - } - } - } walk_list!(this, visit_where_predicate, generics.predicates); }) } @@ -1000,6 +984,21 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { // like implicit `?Sized` or const-param-has-ty predicates. } } + + match p.kind { + GenericParamKind::Lifetime { .. } => {} + GenericParamKind::Type { default, .. } => { + if let Some(ty) = default { + self.visit_ty(ty); + } + } + GenericParamKind::Const { ty, default } => { + self.visit_ty(ty); + if let Some(default) = default { + self.visit_body(self.tcx.hir().body(default.body)); + } + } + } } } diff --git a/tests/ui/closures/issue-112547.rs b/tests/ui/closures/issue-112547.rs new file mode 100644 index 0000000000000..8ecb2abccd4f9 --- /dev/null +++ b/tests/ui/closures/issue-112547.rs @@ -0,0 +1,15 @@ +#![feature(non_lifetime_binders)] + //~^ WARNING the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + +pub fn bar() +where + for V: IntoIterator +//~^ ERROR cannot find type `V` in this scope [E0412] +{ +} + +fn main() { + bar(); +} diff --git a/tests/ui/closures/issue-112547.stderr b/tests/ui/closures/issue-112547.stderr new file mode 100644 index 0000000000000..d86b05dc6a7bf --- /dev/null +++ b/tests/ui/closures/issue-112547.stderr @@ -0,0 +1,23 @@ +error[E0412]: cannot find type `V` in this scope + --> $DIR/issue-112547.rs:8:4 + | +LL | }> V: IntoIterator + | ^ not found in this scope + | +help: you might be missing a type parameter + | +LL | pub fn bar() + | +++ + +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-112547.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0412`.