Skip to content

Seemingly incorrect error for missing trait bounds on associated type #81162

Closed

Description

@djc

I tried this code:

fn test() {
    let data = read::<[f32; 128]>("foo", 128);
}

fn read<T>(fname: &str, dimension: usize) -> Vec<T>
where
    for<'a> T: TryFrom<&'a [f32]>,
    for<'a> <T as TryFrom<&'a [f32]>>::Error: std::fmt::Debug,

I expected to see this happen: this should work, since [f32; N] implements TryFrom<&[f32]> with Error = TrySliceError and TrySliceError implements Debug.

Instead, this happened:

error[E0277]: `<[f32; 128] as TryFrom<&'a [f32]>>::Error` doesn't implement `Debug`
  --> tests/foo.rs:7:16
   |
7  |     let data = read::<[f32; 128]>("foo", 128);
   |                ^^^^^^^^^^^^^^^^^^^^^^^^ `<[f32; 128] as TryFrom<&'a [f32]>>::Error` cannot be formatted using `{:?}` because it doesn't implement `Debug`
...
10 | fn read<T>(fname: &str, dimension: usize) -> Vec<T>
   |    ---------- required by a bound in this
...
13 |     for<'a> <T as TryFrom<&'a [f32]>>::Error: std::fmt::Debug,
   |                                               --------------- required by this bound in `read`
   |
   = help: the trait `for<'a> Debug` is not implemented for `<[f32; 128] as TryFrom<&'a [f32]>>::Error`

Meta

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0

Activity

  1. added
    C-bug
    on Jan 18, 2021
  2. added
    A-diagnostics
    A-trait-system
    T-compiler
    on Jan 18, 2021
  3. estebank commented on Jan 19, 2021

    @estebank
    Contributor

    Note that not using for<'a> makes the code compile, but doesn't have the same lifetime semantics.

    I think that the lifetime introduced in each bound is considered to be independent of each other, so they aren't unified.

  4. added
    A-lifetimes
    on Jan 19, 2021
  5. estebank commented on Nov 10, 2026

    @estebank
    Contributor

    This now compiles.

  6. added
    E-needs-test
    and removed
    C-bug
    on Nov 10, 2026
  7. zakrad commented on Nov 11, 2026

    @zakrad
    Contributor

    @rustbot claim

  8. added a commit that references this issue on Nov 11, 2026
    c3029de
  9. added 2 commits that reference this issue on Nov 12, 2026
    a5aa4fa
    b8a88ea
  10. added a commit that references this issue on Nov 12, 2026
    2e33509
  11. added a commit that references this issue on Nov 13, 2026
    0069ba7
  12. added a commit that references this issue on Nov 16, 2026
    c5fe849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsA-lifetimesA-trait-systemE-needs-testT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions