Skip to content

associated constants should support references to outer type parameters #28809

Closed
@pnkfelix

Description

@pnkfelix

associated constants should support references to outer type parameters

Here is an example, adapted from the Zeroable trait from core::non_zero (playpen):

#![feature(associated_consts)]
trait Zble { const Z: Self; }
impl Zble for i32 { const Z: i32 = 0; }

impl<T> Zble for *const T { const Z: *const T = ::std::ptr::null(); }

fn main() { }

An attempt to compile this yields the error:

<anon>:5:45: 5:46 error: cannot use an outer type parameter in this context [E0402]
<anon>:5 impl<T> Zble for *const T { const Z: *const T = ::std::ptr::null(); }
                                                     ^
<anon>:5:45: 5:46 error: use of undeclared type name `T` [E0412]
<anon>:5 impl<T> Zble for *const T { const Z: *const T = ::std::ptr::null(); }
                                                     ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyP-mediumMedium priorityT-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