Skip to content
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

Complicated type generated by circular trait associated types not shortened in some cases #109827

Open
Zannick opened this issue Apr 1, 2023 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Zannick
Copy link

Zannick commented Apr 1, 2023

I tried this code:

#![allow(unused)]

pub mod ext {
pub trait EnumArray<T> {
    type Array;
}
}

pub mod world {

use crate::context::*;
use super::ext;
use std::hash::Hash;
use std::fmt::{self, format, Debug, Display};

pub trait Accessible: Sync {
    type Context: Ctx;
    fn can_access(&self, ctx: &Self::Context) -> bool;
}

pub trait Id: Copy + Clone + Debug + Eq + Hash + Ord + PartialOrd + PartialEq + Send + Sync {}

pub trait Location: Accessible {
    type LocId: Id;
}

pub trait Exit: Accessible {
    type ExitId: Id;
    type SpotId: Id + Default + ext::EnumArray<Option<ContextWrapper<Self::Context>>>
    where //<Self::Context as Ctx>::World: World<Exit = Self>,
    <Self::SpotId as ext::EnumArray<Option<ContextWrapper<Self::Context>>>>::Array: Sync
    ;
}

pub trait Action: Accessible {
    type ActionId: Id;
}
pub trait Warp: Accessible {
    type WarpId: Id;
}

pub trait World: Sync {
    type Location: Location;
    type Exit: Exit<
        Context = <Self::Location as Accessible>::Context,
    >;
    type Action: Action<
        Context = <Self::Location as Accessible>::Context,
    >;
    type Warp: Warp<
        Context = <Self::Location as Accessible>::Context,
    >;
}
}

pub mod context {

use crate::world::*;
use std::hash::Hash;
use std::fmt::{self, format, Debug, Display};
use std::marker::PhantomData;

pub trait Ctx: Clone + Eq + Debug + Hash + Send + Sync {
type World: World;
type Location: Location;
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BaseContextWrapper<T, S, L, E, A, Wp> {
    ctx: T,
    // ...
    p: PhantomData<S>,
    s: PhantomData<L>,
    e: PhantomData<E>,
    a: PhantomData<A>,
    wp: PhantomData<Wp>,
}

pub type ContextWrapper<T> = BaseContextWrapper<
    T,
    <<<T as Ctx>::World as World>::Exit as Exit>::SpotId,
    <<<T as Ctx>::World as World>::Location as Location>::LocId,
    <<<T as Ctx>::World as World>::Exit as Exit>::ExitId,
    <<<T as Ctx>::World as World>::Action as Action>::ActionId,
    <<<T as Ctx>::World as World>::Warp as Warp>::WarpId,
    >;
    
}

use crate::context::*;
use crate::world::*;
    
pub fn process<T>()
where
T: Ctx
{
    let vec: Vec<ContextWrapper<T>> = Vec::new();
    std::cmp::min(vec, 0);
}

I expected to see this happen:
error message appears with shortened type and a file reference to see the full type, as I've seen in other error messages like:

    = note: expected struct `Vec<BaseContextWrapper<T, <<<T as Ctx>::World as World>::Exit as Exit>::SpotId, ..., ..., ..., ...>>`
            the full type name has been written to '/playground/target/debug/deps/playground-10e50725c1766eba.long-type-6458468699417712645.txt'
                 found type `{integer}`

Instead, this happened:
enormous error message with no elision:

Compiling playground v0.0.1 (/playground)
error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): `<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId as EnumArray<Option<BaseContextWrapper<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Location as world::Location>::LocId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::ExitId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Action as world::Action>::ActionId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Warp as world::Warp>::WarpId>>>>::Array` cannot be shared between threads safely
  --> src/lib.rs:31:33
   |
31 |     type SpotId: Id + Default + ext::EnumArray<Option<ContextWrapper<Self::Context>>>
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId as EnumArray<Option<BaseContextWrapper<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Location as world::Location>::LocId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::ExitId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Action as world::Action>::ActionId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Warp as world::Warp>::WarpId>>>>::Array` cannot be shared between threads safely
   |
   = help: the trait `Sync` is not implemented for `<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId as EnumArray<Option<BaseContextWrapper<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Location as world::Location>::LocId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::ExitId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Action as world::Action>::ActionId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Warp as world::Warp>::WarpId>>>>::Array`
note: required by a bound in `world::Exit::SpotId`
  --> src/lib.rs:33:85
   |
31 |     type SpotId: Id + Default + ext::EnumArray<Option<ContextWrapper<Self::Context>>>
   |          ------ required by a bound in this associated type
32 |     where //<Self::Context as Ctx>::World: World<Exit = Self>,
33 |     <Self::SpotId as ext::EnumArray<Option<ContextWrapper<Self::Context>>>>::Array: Sync
   |                                                                                     ^^^^ required by this bound in `Exit::SpotId`
help: consider further restricting the associated type
   |
29 | pub trait Exit: Accessible where <<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId as EnumArray<Option<BaseContextWrapper<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::SpotId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Location as world::Location>::LocId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Exit as world::Exit>::ExitId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Action as world::Action>::ActionId, <<<<<<<Self as Accessible>::Context as context::Ctx>::World as world::World>::Location as Accessible>::Context as context::Ctx>::World as world::World>::Warp as world::Warp>::WarpId>>>>::Array: Sync {
   |                            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Note: this error comes from remarking out the trait bound on line 32 as above. That bound is meant to close the type association loop so that <SpotId as EnumArray>::Array is always Sync, which works as long as process() is not defined. A similarly long error still appears if both are left in. (I added the process() function to show an error that does elide part of the type.)

Meta

playground

My original error message on stable spelled out both std::option::Option and world::Accessible, so it was longer as well.

@Zannick Zannick added the C-bug Category: This is a bug. label Apr 1, 2023
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@Enselic Enselic added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants