Skip to content

Commit 75915e8

Browse files
committed
fix rust-lang#104513, Delay a span bug if we see generic params with err during writeback
1 parent bebd57a commit 75915e8

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
325325
}
326326
}
327327

328+
fn visit_generic_arg(&mut self, arg: &'tcx hir::GenericArg<'tcx>) {
329+
match arg {
330+
hir::GenericArg::Type(ty) if let hir::TyKind::Err = ty.kind => {
331+
// An generic argument with an error type will be reported
332+
// We don't want to ICE here
333+
self.tcx().sess.delay_span_bug(ty.span, format!("unexpected generic argument: {arg:?}"));
334+
}
335+
hir::GenericArg::Type(t) => self.visit_ty(t),
336+
_ => {
337+
// Nothing to write back here
338+
}
339+
}
340+
}
341+
328342
fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
329343
self.visit_node_id(b.span, b.hir_id);
330344
intravisit::walk_block(self, b);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct S;
2+
fn f() {
3+
let _: S<impl Oops> = S; //~ ERROR cannot find trait `Oops` in this scope
4+
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
5+
}
6+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0405]: cannot find trait `Oops` in this scope
2+
--> $DIR/issue-104513-ice.rs:3:19
3+
|
4+
LL | fn f() {
5+
| - help: you might be missing a type parameter: `<Oops>`
6+
LL | let _: S<impl Oops> = S;
7+
| ^^^^ not found in this scope
8+
9+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
10+
--> $DIR/issue-104513-ice.rs:3:14
11+
|
12+
LL | let _: S<impl Oops> = S;
13+
| ^^^^^^^^^
14+
15+
error: aborting due to 2 previous errors
16+
17+
Some errors have detailed explanations: E0405, E0562.
18+
For more information about an error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)