Skip to content

Commit 80dc91c

Browse files
authored
Rollup merge of rust-lang#104514 - chenyukang:yukang/fix-104513-ice, r=petrochenkov
Use node_ty_opt to avoid ICE in visit_ty Fixes rust-lang#104513
2 parents 5dfb4b0 + ecea94e commit 80dc91c

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
@@ -361,9 +361,12 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
361361

362362
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) {
363363
intravisit::walk_ty(self, hir_ty);
364-
let ty = self.fcx.node_ty(hir_ty.hir_id);
365-
let ty = self.resolve(ty, &hir_ty.span);
366-
self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
364+
// If there are type checking errors, Type privacy pass will stop,
365+
// so we may not get the type from hid_id, see #104513
366+
if let Some(ty) = self.fcx.node_ty_opt(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);
369+
}
367370
}
368371

369372
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)