Skip to content

Inherent associated types defined on non-ADTs don't resolve successfully #106719

Open
@fmease

Description

@fmease
Member

Inherent associated types where the self type isn't an ADT (e.g. a trait object type or a primitive type like bool or i32) are currently not resolved successfully.

On Trait Object Types

I expected to see the following code compile successfully:

#![feature(inherent_associated_types)]

trait Tr {}

impl dyn Tr {
    type Pr = ();
}

const _: <dyn Tr>::Pr = ();

Instead, the following error was emitted:

error[E0223]: ambiguous associated type
  --> src/lib.rs:10:10
   |
10 | const _: <dyn Tr>::Pr = ();
   |          ^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn Tr + 'static) as Trait>::Pr`

For comparison, the analogous code involving inherent associated constants works flawlessly.

On Primitive Types

I expected to see the following code compile successfully (#![no_core] is representative for the core crate)

#![feature(inherent_associated_types, no_core)]
#![allow(incomplete_features)]
#![no_core]

impl bool {
    type Pr = ();
}

const _: bool::Pr = ();

Instead, the following error was emitted:

error[E0223]: ambiguous associated type
 --> src/lib.rs:9:10
  |
9 | const _: bool::Pr = ();
  |          ^^^^^^^^ help: use fully-qualified syntax: `<bool as Trait>::Pr`

I'd like to see #105961 merged first. Thus I consider this issue blocked for now.

@rustbot label T-compiler F-inherent_associated_types requires-nightly S-blocked
@rustbot claim

Activity

added
requires-nightlyThis issue requires a nightly compiler in some way.
S-blockedStatus: Blocked on something else such as an RFC or other implementation work.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jan 11, 2023
changed the title [-]Inherent associated types defined on trait object types don't resolve successfully[/-] [+]Inherent associated types defined on non-ADTs don't resolve successfully[/+] on Jan 11, 2023
fmease

fmease commented on Feb 20, 2023

@fmease
Author
removed
S-blockedStatus: Blocked on something else such as an RFC or other implementation work.
on Feb 20, 2023
compiler-errors

compiler-errors commented on Feb 22, 2023

@compiler-errors
Member

Copied from the other issue:

my understanding is that this just requires to assemble candidates for incoherent impls as well, just like method candidate assembly does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-inherent_associated_types`#![feature(inherent_associated_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Can Do

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @compiler-errors@fmease@rustbot

      Issue actions

        Inherent associated types defined on non-ADTs don't resolve successfully · Issue #106719 · rust-lang/rust