Skip to content

Resolution problem with associated types with defaults #26681

Closed

Description

STR

#![feature(associated_consts)]

trait Foo {
    type Bar;
}

#[cfg(not(works))]
trait Baz {
    type Fv: Foo = u8;
    const C: <Self::Fv as Foo>::Bar = 6665;
}

#[cfg(works)]
trait Baz {
    type Fv: Foo = u8;
    const C: <Self::Fv as Foo>::Bar;
}

Results

<anon>:9:15: 9:23 error: failed to resolve. Use of undeclared type or module `Self`
<anon>:9     const C: <Self::Fv as Foo>::Bar = 6665;
                       ^~~~~~~~
<anon>:9:15: 9:23 error: use of `Self` outside of an impl or trait
<anon>:9     const C: <Self::Fv as Foo>::Bar = 6665;
                       ^~~~~~~~
error: aborting due to 2 previous errors

Removing the default (#[cfg(works)]) removes the error. cc @quantheory

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

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-typesystemArea: The type systemC-bugCategory: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions