diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index d102fb45a8cbc..e2f6b55b148a7 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -293,6 +293,17 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { intravisit::walk_expr(self, e); } + fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { + match &p.kind { + hir::GenericParamKind::Lifetime { .. } => { + // Nothing to write back here + } + hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => { + self.tcx().sess.delay_span_bug(p.span, format!("unexpected generic param: {p:?}")); + } + } + } + fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) { self.visit_node_id(b.span, b.hir_id); intravisit::walk_block(self, b); diff --git a/src/test/ui/closures/binder/disallow-const.rs b/src/test/ui/closures/binder/disallow-const.rs new file mode 100644 index 0000000000000..72ad6185d3761 --- /dev/null +++ b/src/test/ui/closures/binder/disallow-const.rs @@ -0,0 +1,6 @@ +#![feature(closure_lifetime_binder)] + +fn main() { + for || -> () {}; + //~^ ERROR only lifetime parameters can be used in this context +} diff --git a/src/test/ui/closures/binder/disallow-const.stderr b/src/test/ui/closures/binder/disallow-const.stderr new file mode 100644 index 0000000000000..3c3b43d8cf342 --- /dev/null +++ b/src/test/ui/closures/binder/disallow-const.stderr @@ -0,0 +1,8 @@ +error: only lifetime parameters can be used in this context + --> $DIR/disallow-const.rs:4:15 + | +LL | for || -> () {}; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/closures/binder/disallow-ty.rs b/src/test/ui/closures/binder/disallow-ty.rs new file mode 100644 index 0000000000000..bbe3d8488d982 --- /dev/null +++ b/src/test/ui/closures/binder/disallow-ty.rs @@ -0,0 +1,6 @@ +#![feature(closure_lifetime_binder)] + +fn main() { + for || -> () {}; + //~^ ERROR only lifetime parameters can be used in this context +} diff --git a/src/test/ui/closures/binder/disallow-ty.stderr b/src/test/ui/closures/binder/disallow-ty.stderr new file mode 100644 index 0000000000000..51b6773edea98 --- /dev/null +++ b/src/test/ui/closures/binder/disallow-ty.stderr @@ -0,0 +1,8 @@ +error: only lifetime parameters can be used in this context + --> $DIR/disallow-ty.rs:4:9 + | +LL | for || -> () {}; + | ^ + +error: aborting due to previous error +