Skip to content

Commit ecea94e

Browse files
committed
fix #104513, Use node_ty_opt to avoid ICE in visit_ty
1 parent bebd57a commit ecea94e

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,12 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
363363

364364
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) {
365365
intravisit::walk_ty(self, hir_ty);
366-
let ty = self.fcx.node_ty(hir_ty.hir_id);
367-
let ty = self.resolve(ty, &hir_ty.span);
368-
self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
366+
// If there are type checking errors, Type privacy pass will stop,
367+
// so we may not get the type from hid_id, see #104513
368+
if let Some(ty) = self.fcx.node_ty_opt(hir_ty.hir_id) {
369+
let ty = self.resolve(ty, &hir_ty.span);
370+
self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
371+
}
369372
}
370373

371374
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
+6
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() {}
+18
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)