Skip to content

incorrect resolutions for type dependent paths in struct expression #98711

Open
@lcnr

Description

@lcnr
trait Foo: Sized {
    type Output;

    fn func() -> Self;
}

struct Type<T> { value: T }

impl<T: Default> Foo for Type<T> {
    type Output = Self;

    fn func() -> Self {
        Self::Output { value: Default::default() }
    }
}

stores the following resolution for Self::Output via fn write_resolution:

Ok((AssocTy, DefId(0:4 ~ test1[f74d]::Foo::Output)))

the node_substs for Self::Output are however empty. This makes the stored resolution completely useless as there isn't really a way to go from Foo::Output to Type<T>::Output which is what we actually need.

We should probably store <Foo as Type<T>>::Output instead. This happens here

QPath::TypeRelative(ref qself, ref segment) => {
let ty = self.to_ty(qself);
let result = <dyn AstConv<'_>>::associated_path_to_ty(
self, hir_id, path_span, ty, qself, segment, true,
);
let ty = result.map(|(ty, _, _)| ty).unwrap_or_else(|_| self.tcx().ty_error());
let result = result.map(|(_, kind, def_id)| (kind, def_id));
// Write back the new resolution.
self.write_resolution(hir_id, result);
(result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)), ty)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions