Skip to content

Commit 6920064

Browse files
committed
Don't look for late bound vars if the closure has no input.
1 parent b7bc6f8 commit 6920064

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_infer::infer::{InferOk, InferResult};
1212
use rustc_macros::{TypeFoldable, TypeVisitable};
1313
use rustc_middle::ty::subst::InternalSubsts;
1414
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
15-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
15+
use rustc_middle::ty::{self, List, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
1616
use rustc_span::def_id::LocalDefId;
1717
use rustc_span::source_map::Span;
1818
use rustc_span::sym;
@@ -622,7 +622,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
622622
debug!(?body.generator_kind);
623623

624624
let hir_id = self.tcx.hir().local_def_id_to_hir_id(expr_def_id);
625-
let bound_vars = self.tcx.late_bound_vars(hir_id);
625+
let bound_vars = match decl.inputs.len() {
626+
0 => List::empty(),
627+
_ => self.tcx.late_bound_vars(hir_id),
628+
};
626629

627630
// First, convert the types that the user supplied (if any).
628631
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));

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)