diff options
| author | bors <bors@rust-lang.org> | 2022-10-17 08:04:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-17 08:04:52 +0000 |
| commit | c19a893f87e70fc1c9bab193c3f9c83d9a9d71d3 (patch) | |
| tree | 1f964256ae3b424fc1a095b4183e9b9487782bf6 | |
| parent | 1536ab1b383f21b38f8d49230a2aecc51daffa3d (diff) | |
| parent | 0b6fa0d418f8de754c32459c333a64b08b5ed863 (diff) | |
| download | rust-c19a893f87e70fc1c9bab193c3f9c83d9a9d71d3.tar.gz rust-c19a893f87e70fc1c9bab193c3f9c83d9a9d71d3.zip | |
Auto merge of #103116 - TaKO8Ki:fix-103053, r=lcnr
Fix `own_substs` ICE Fixes #103053
3 files changed, 44 insertions, 5 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index f4b3ded53b0..7b3178e610f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -902,11 +902,18 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { // impl is currently the `DefId` of `Output` in the trait definition // which makes this somewhat difficult and prevents us from just // using `self.path_inferred_subst_iter` here. - hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _) => { - if let Some(ty) = self.opt_node_type(expr.hir_id) { - if let ty::Adt(_, substs) = ty.kind() { - return Box::new(self.resolved_path_inferred_subst_iter(path, substs)); - } + hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _) + // FIXME(TaKO8Ki): Ideally we should support this. For that + // we have to map back from the self type to the + // type alias though. That's difficult. + // + // See the `need_type_info/issue-103053.rs` test for + // a example. + if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => { + if let Some(ty) = self.opt_node_type(expr.hir_id) + && let ty::Adt(_, substs) = ty.kind() + { + return Box::new(self.resolved_path_inferred_subst_iter(path, substs)); } } hir::ExprKind::MethodCall(segment, ..) => { diff --git a/src/test/ui/inference/need_type_info/issue-103053.rs b/src/test/ui/inference/need_type_info/issue-103053.rs new file mode 100644 index 00000000000..05169666f83 --- /dev/null +++ b/src/test/ui/inference/need_type_info/issue-103053.rs @@ -0,0 +1,18 @@ +trait TypeMapper { + type MapType; +} + +type Mapped<T> = <T as TypeMapper>::MapType; + +struct Test {} + +impl TypeMapper for () { + type MapType = Test; +} + +fn test() { + Mapped::<()> {}; + None; //~ ERROR type annotations needed +} + +fn main() {} diff --git a/src/test/ui/inference/need_type_info/issue-103053.stderr b/src/test/ui/inference/need_type_info/issue-103053.stderr new file mode 100644 index 00000000000..84f0475d8cd --- /dev/null +++ b/src/test/ui/inference/need_type_info/issue-103053.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/issue-103053.rs:15:5 + | +LL | None; + | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` + | +help: consider specifying the generic argument + | +LL | None::<T>; + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. |
