Skip to content

Commit c19a893

Browse files
committed
Auto merge of #103116 - TaKO8Ki:fix-103053, r=lcnr
Fix `own_substs` ICE Fixes #103053
2 parents 1536ab1 + 0b6fa0d commit c19a893

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,18 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
902902
// impl is currently the `DefId` of `Output` in the trait definition
903903
// which makes this somewhat difficult and prevents us from just
904904
// using `self.path_inferred_subst_iter` here.
905-
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _) => {
906-
if let Some(ty) = self.opt_node_type(expr.hir_id) {
907-
if let ty::Adt(_, substs) = ty.kind() {
908-
return Box::new(self.resolved_path_inferred_subst_iter(path, substs));
909-
}
905+
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _)
906+
// FIXME(TaKO8Ki): Ideally we should support this. For that
907+
// we have to map back from the self type to the
908+
// type alias though. That's difficult.
909+
//
910+
// See the `need_type_info/issue-103053.rs` test for
911+
// a example.
912+
if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
913+
if let Some(ty) = self.opt_node_type(expr.hir_id)
914+
&& let ty::Adt(_, substs) = ty.kind()
915+
{
916+
return Box::new(self.resolved_path_inferred_subst_iter(path, substs));
910917
}
911918
}
912919
hir::ExprKind::MethodCall(segment, ..) => {

Diff for: src/test/ui/inference/need_type_info/issue-103053.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait TypeMapper {
2+
type MapType;
3+
}
4+
5+
type Mapped<T> = <T as TypeMapper>::MapType;
6+
7+
struct Test {}
8+
9+
impl TypeMapper for () {
10+
type MapType = Test;
11+
}
12+
13+
fn test() {
14+
Mapped::<()> {};
15+
None; //~ ERROR type annotations needed
16+
}
17+
18+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-103053.rs:15:5
3+
|
4+
LL | None;
5+
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | None::<T>;
10+
| +++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)