Skip to content

Commit 01db8b6

Browse files
Delay a span bug if we see ty/const generic params during writeback
1 parent 74f600b commit 01db8b6

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

compiler/rustc_typeck/src/check/writeback.rs

+11
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
293293
intravisit::walk_expr(self, e);
294294
}
295295

296+
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
297+
match &p.kind {
298+
hir::GenericParamKind::Lifetime { .. } => {
299+
// Nothing to write back here
300+
}
301+
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => {
302+
self.tcx().sess.delay_span_bug(p.span, format!("unexpected generic param: {p:?}"));
303+
}
304+
}
305+
}
306+
296307
fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
297308
self.visit_node_id(b.span, b.hir_id);
298309
intravisit::walk_block(self, b);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(closure_lifetime_binder)]
2+
3+
fn main() {
4+
for<const N: i32> || -> () {};
5+
//~^ ERROR only lifetime parameters can be used in this context
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: only lifetime parameters can be used in this context
2+
--> $DIR/disallow-const.rs:4:15
3+
|
4+
LL | for<const N: i32> || -> () {};
5+
| ^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(closure_lifetime_binder)]
2+
3+
fn main() {
4+
for<T> || -> () {};
5+
//~^ ERROR only lifetime parameters can be used in this context
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: only lifetime parameters can be used in this context
2+
--> $DIR/disallow-ty.rs:4:9
3+
|
4+
LL | for<T> || -> () {};
5+
| ^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)