Skip to content

Commit

Permalink
Visit generic parameters in where predicate in order to prevent ICE d…
Browse files Browse the repository at this point in the history
…ue to not bound vars.
  • Loading branch information
lenko-d committed Sep 25, 2023
1 parent 91958e0 commit 241c75f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,24 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
})
.unzip();
self.record_late_bound_vars(hir_id, binders.clone());

for param in bound_generic_params {
match param.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));
}
}
}
}

// Even if there are no lifetimes defined here, we still wrap it in a binder
// scope. If there happens to be a nested poly trait ref (an error), that
// will be `Concatenating` anyways, so we don't have to worry about the depth
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/closures/issue-112547.rs
Original file line number Diff line number Diff line change
@@ -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<const N: usize = {
(||1usize)()
}> V: IntoIterator
//~^ ERROR cannot find type `V` in this scope [E0412]
{
}

fn main() {
bar();
}
23 changes: 23 additions & 0 deletions tests/ui/closures/issue-112547.stderr
Original file line number Diff line number Diff line change
@@ -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<V>()
| +++

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 <https://github.com/rust-lang/rust/issues/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`.

0 comments on commit 241c75f

Please sign in to comment.