Skip to content

rustdoc: synthetic impls are faulty in the presence of assoc const equality constraints  #111102

Open
@fmease

Description

@fmease

Given

#![feature(associated_const_equality)]

use std::marker::Unpin; // or any other auto trait

pub struct Outer<T>(Inner<T>);
pub struct Inner<T>(T);

// (A)
impl<const F: bool, T: Trait<FLAG = {F}>> Unpin for Inner<T> {}

// (B)
//impl<T: Trait<FLAG = true>> Unpin for Inner<T> {}

pub trait Trait {
    const FLAG: bool;
}

the impl of Unpin (or any other auto trait chosen) synthesized for the generic type Outer looks like

impl<T> !Unpin for Outer<T> // for either case, (A) or (B)
//      ^ note the `!`

while I expected the impls to be

// for case (A):
impl<T> Unpin for Outer<T> where T: Trait 
// for case (B):
impl<T> Unpin for Outer<T> where T: Trait<FLAG = true>
For comparison, the analog involving type equality constraints
use std::marker::Unpin; // or any other auto trait

pub struct Outer<T>(Inner<T>);
pub struct Inner<T>(T);

// (A)
impl<F: Bool, T: Trait<Flag = F>> Unpin for Inner<T> {}

//   ---> synthetic impl:
//   impl<T> Unpin for Outer<T> where T: Trait

// (B)
// impl<T: Trait<Flag = True>> Unpin for Inner<T> {}

//   ---> synthetic impl:
//   impl<T> Unpin for Outer<T> where T: Trait<Flag = True>

pub trait Trait {
    type Flag: Bool;
}

pub trait Bool {}
impl Bool for True {}
pub enum True {}

(adding T-compiler next to T-rustdoc since AutoTraitFinder lives in rustc)

@rustbot label C-bug T-rustdoc T-compiler A-auto-traits A-synthetic-impls F-associated_const_equality

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-synthetic-implsArea: Synthetic impls, used by rustdoc to document auto traits and traits with blanket implsC-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    Can Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions