Skip to content

Commit

Permalink
Delay a span bug if we see ty/const generic params during writeback
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 22, 2022
1 parent 74f600b commit 01db8b6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/closures/binder/disallow-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(closure_lifetime_binder)]

fn main() {
for<const N: i32> || -> () {};
//~^ ERROR only lifetime parameters can be used in this context
}
8 changes: 8 additions & 0 deletions src/test/ui/closures/binder/disallow-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: only lifetime parameters can be used in this context
--> $DIR/disallow-const.rs:4:15
|
LL | for<const N: i32> || -> () {};
| ^

error: aborting due to previous error

6 changes: 6 additions & 0 deletions src/test/ui/closures/binder/disallow-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(closure_lifetime_binder)]

fn main() {
for<T> || -> () {};
//~^ ERROR only lifetime parameters can be used in this context
}
8 changes: 8 additions & 0 deletions src/test/ui/closures/binder/disallow-ty.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: only lifetime parameters can be used in this context
--> $DIR/disallow-ty.rs:4:9
|
LL | for<T> || -> () {};
| ^

error: aborting due to previous error

0 comments on commit 01db8b6

Please sign in to comment.