Skip to content

Commit 241c75f

Browse files
committed
Visit generic parameters in where predicate in order to prevent ICE due to not bound vars.
1 parent 91958e0 commit 241c75f

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+18
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,24 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
897897
})
898898
.unzip();
899899
self.record_late_bound_vars(hir_id, binders.clone());
900+
901+
for param in bound_generic_params {
902+
match param.kind {
903+
GenericParamKind::Lifetime { .. } => {}
904+
GenericParamKind::Type { default, .. } => {
905+
if let Some(ty) = default {
906+
self.visit_ty(ty);
907+
}
908+
}
909+
GenericParamKind::Const { ty, default } => {
910+
self.visit_ty(ty);
911+
if let Some(default) = default {
912+
self.visit_body(self.tcx.hir().body(default.body));
913+
}
914+
}
915+
}
916+
}
917+
900918
// Even if there are no lifetimes defined here, we still wrap it in a binder
901919
// scope. If there happens to be a nested poly trait ref (an error), that
902920
// will be `Concatenating` anyways, so we don't have to worry about the depth

tests/ui/closures/issue-112547.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(non_lifetime_binders)]
2+
//~^ WARNING the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
3+
4+
pub fn bar()
5+
where
6+
for<const N: usize = {
7+
(||1usize)()
8+
}> V: IntoIterator
9+
//~^ ERROR cannot find type `V` in this scope [E0412]
10+
{
11+
}
12+
13+
fn main() {
14+
bar();
15+
}

tests/ui/closures/issue-112547.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0412]: cannot find type `V` in this scope
2+
--> $DIR/issue-112547.rs:8:4
3+
|
4+
LL | }> V: IntoIterator
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | pub fn bar<V>()
10+
| +++
11+
12+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
13+
--> $DIR/issue-112547.rs:1:12
14+
|
15+
LL | #![feature(non_lifetime_binders)]
16+
| ^^^^^^^^^^^^^^^^^^^^
17+
|
18+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
19+
= note: `#[warn(incomplete_features)]` on by default
20+
21+
error: aborting due to previous error; 1 warning emitted
22+
23+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)