Skip to content

Fix own_substs ICE #103116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ..) => {
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/inference/need_type_info/issue-103053.rs
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 14 additions & 0 deletions src/test/ui/inference/need_type_info/issue-103053.stderr
Original file line number Diff line number Diff line change
@@ -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`.