Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fmease opened this issue May 2, 2023 · 0 comments
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented May 2, 2023

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

@rustbot rustbot added A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

2 participants