Skip to content

Diagnostic emits unprefixed type for the same type name leading to confusion #155415

@weiznich

Description

@weiznich

Code

I tried this code:

use diesel::prelude::*; // diesel = { version = "2.3.7", default-features = false, features = ["with-deprecated"] }

table! {
    users {
        id -> Integer,
        name -> Text,
        hair_color -> Nullable<Text>,
    }
}

table! {
    posts {
        id -> Integer,
        title -> Text,
        user_id -> Integer,
    }
}

table! {
    comments {
        id -> Integer,
        text -> Text,
        post_id -> Integer,
    }
}

joinable!(comments -> posts (post_id));
joinable!(posts -> users (user_id));

allow_tables_to_appear_in_same_query!(users, posts, comments);
allow_columns_to_appear_in_same_group_by_clause!(
    posts::title,
    users::id,
    posts::user_id,
    users::name,
    posts::id,
    users::hair_color
);

fn main() {
    let source = users::table
        .inner_join(posts::table.inner_join(comments::table))
        .group_by((users::id, posts::id))
        .select((users::all_columns, posts::all_columns, comments::id));

    println!("Hello, world!");
}

Reproducing this requires --diagnostic-width=100 to be set

I expected to see this happen: Rustc emits an error message disambiguating all involved types

error[E0277]: the trait bound `users::columns::id: IsContainedInGroupBy<comments::columns::id>` is not satisfied
error[E0277]: the trait bound `posts::columns::id: IsContainedInGroupBy<comments::columns::id>` is not satisfied
Full error message
error[E0277]: the trait bound `users::columns::id: IsContainedInGroupBy<comments::columns::id>` is not satisfied
  --> src/main.rs:44:10
   |
44 |         .select((users::all_columns, posts::all_columns, comments::id));
   |          ^^^^^^ unsatisfied trait bound
   |
help: the trait `IsContainedInGroupBy<comments::columns::id>` is not implemented for `users::columns::id`
  --> src/main.rs:5:9
   |
 5 |         id -> Integer,
   |         ^^
   = note: if your query contains columns from several tables in your group by or select clause make sure to call `allow_columns_to_appear_in_same_group_by_clause!` with these columns
   = help: the following other types implement trait `IsContainedInGroupBy<T>`:
             `users::columns::id` implements `IsContainedInGroupBy<posts::columns::id>`
             `users::columns::id` implements `IsContainedInGroupBy<posts::columns::title>`
             `users::columns::id` implements `IsContainedInGroupBy<posts::columns::user_id>`
             `users::columns::id` implements `IsContainedInGroupBy<users::columns::hair_color>`
             `users::columns::id` implements `IsContainedInGroupBy<users::columns::id>`
             `users::columns::id` implements `IsContainedInGroupBy<users::columns::name>`
   = note: required for `(users::columns::id, posts::columns::id)` to implement `IsContainedInGroupBy<comments::columns::id>`
note: required for `comments::columns::id` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
  --> src/main.rs:21:9
   |
21 |         id -> Integer,
   |         ^^
   = note: 2 redundant requirements hidden
   = note: required for `((id, name, hair_color), (id, title, user_id), id)` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
   = note: required for `SelectStatement<..., ..., ..., ..., ..., ..., ...>` to implement `SelectDsl<((id, name, hair_color), ..., ...)>`
   = note: the full name for the type has been written to '/tmp/testing/target/debug/deps/testing-d8f695771be6e993.long-type-12488973070328796207.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `posts::columns::id: IsContainedInGroupBy<comments::columns::id>` is not satisfied
  --> src/main.rs:44:10
   |
44 |         .select((users::all_columns, posts::all_columns, comments::id));
   |          ^^^^^^ unsatisfied trait bound
   |
help: the trait `IsContainedInGroupBy<comments::columns::id>` is not implemented for `posts::columns::id`
  --> src/main.rs:13:9
   |
13 |         id -> Integer,
   |         ^^
   = note: if your query contains columns from several tables in your group by or select clause make sure to call `allow_columns_to_appear_in_same_group_by_clause!` with these columns
   = help: the following other types implement trait `IsContainedInGroupBy<T>`:
             `posts::columns::id` implements `IsContainedInGroupBy<posts::columns::id>`
             `posts::columns::id` implements `IsContainedInGroupBy<posts::columns::title>`
             `posts::columns::id` implements `IsContainedInGroupBy<posts::columns::user_id>`
             `posts::columns::id` implements `IsContainedInGroupBy<users::columns::hair_color>`
             `posts::columns::id` implements `IsContainedInGroupBy<users::columns::id>`
             `posts::columns::id` implements `IsContainedInGroupBy<users::columns::name>`
   = note: required for `(posts::columns::id,)` to implement `IsContainedInGroupBy<comments::columns::id>`
   = note: 1 redundant requirement hidden
   = note: required for `(users::columns::id, posts::columns::id)` to implement `IsContainedInGroupBy<comments::columns::id>`
note: required for `comments::columns::id` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
  --> src/main.rs:21:9
   |
21 |         id -> Integer,
   |         ^^
   = note: 2 redundant requirements hidden
   = note: required for `((id, name, hair_color), (id, title, user_id), id)` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
   = note: required for `SelectStatement<..., ..., ..., ..., ..., ..., ...>` to implement `SelectDsl<((id, name, hair_color), ..., ...)>`
   = note: the full name for the type has been written to '/tmp/testing/target/debug/deps/testing-d8f695771be6e993.long-type-12488973070328796207.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

Instead, this happened: Rustc emits an error message using the same ambiguous name for multiple types:

error[E0277]: the trait bound `id: IsContainedInGroupBy<id>` is not satisfied
error[E0277]: the trait bound `id: IsContainedInGroupBy<id>` is not satisfied

Note how rustc mentions the only the id type in this error message, although it represents 3 different distinct types in this case

Full error message
error[E0277]: the trait bound `id: IsContainedInGroupBy<id>` is not satisfied
  --> src/main.rs:44:10
   |
44 |         .select((users::all_columns, posts::all_columns, comments::id));
   |          ^^^^^^ unsatisfied trait bound
   |
help: the trait `diesel::expression::IsContainedInGroupBy<comments::columns::id>` is not implemented for `users::columns::id`
  --> src/main.rs:5:9
   |
 5 |         id -> Integer,
   |         ^^
   = note: if your query contains columns from several tables in your group by or select clause make sure to call `allow_columns_to_appear_in_same_group_by_clause!` with these columns
   = help: the following other types implement trait `diesel::expression::IsContainedInGroupBy<T>`:
             `users::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::id>`
             `users::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::title>`
             `users::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::user_id>`
             `users::columns::id` implements `IsContainedInGroupBy<hair_color>`
             `users::columns::id` implements `diesel::expression::IsContainedInGroupBy<users::columns::id>`
             `users::columns::id` implements `diesel::expression::IsContainedInGroupBy<users::columns::name>`
   = note: required for `(users::columns::id, posts::columns::id)` to implement `diesel::expression::IsContainedInGroupBy<comments::columns::id>`
note: required for `comments::columns::id` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
  --> src/main.rs:21:9
   |
21 |         id -> Integer,
   |         ^^
   = note: 2 redundant requirements hidden
   = note: required for `((id, name, hair_color), (id, title, user_id), id)` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
   = note: required for `SelectStatement<..., ..., ..., ..., ..., ..., ...>` to implement `SelectDsl<((id, name, hair_color), ..., ...)>`
   = note: the full name for the type has been written to '/tmp/testing/target/debug/deps/testing-4af8272b4201a243.long-type-6638943933197451221.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `id: IsContainedInGroupBy<id>` is not satisfied
  --> src/main.rs:44:10
   |
44 |         .select((users::all_columns, posts::all_columns, comments::id));
   |          ^^^^^^ unsatisfied trait bound
   |
help: the trait `diesel::expression::IsContainedInGroupBy<comments::columns::id>` is not implemented for `posts::columns::id`
  --> src/main.rs:13:9
   |
13 |         id -> Integer,
   |         ^^
   = note: if your query contains columns from several tables in your group by or select clause make sure to call `allow_columns_to_appear_in_same_group_by_clause!` with these columns
   = help: the following other types implement trait `diesel::expression::IsContainedInGroupBy<T>`:
             `posts::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::id>`
             `posts::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::title>`
             `posts::columns::id` implements `diesel::expression::IsContainedInGroupBy<posts::columns::user_id>`
             `posts::columns::id` implements `IsContainedInGroupBy<hair_color>`
             `posts::columns::id` implements `diesel::expression::IsContainedInGroupBy<users::columns::id>`
             `posts::columns::id` implements `diesel::expression::IsContainedInGroupBy<users::columns::name>`
   = note: required for `(posts::columns::id,)` to implement `diesel::expression::IsContainedInGroupBy<comments::columns::id>`
   = note: 1 redundant requirement hidden
   = note: required for `(users::columns::id, posts::columns::id)` to implement `diesel::expression::IsContainedInGroupBy<comments::columns::id>`
note: required for `comments::columns::id` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
  --> src/main.rs:21:9
   |
21 |         id -> Integer,
   |         ^^
   = note: 2 redundant requirements hidden
   = note: required for `((id, name, hair_color), (id, title, user_id), id)` to implement `ValidGrouping<(users::columns::id, posts::columns::id)>`
   = note: required for `SelectStatement<..., ..., ..., ..., ..., ..., ...>` to implement `SelectDsl<((id, name, hair_color), ..., ...)>`
   = note: the full name for the type has been written to '/tmp/testing/target/debug/deps/testing-4af8272b4201a243.long-type-6665319231285164524.txt'
   = note: consider using `--verbose` to print the full type name to the console
   = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

Version it worked on

It most recently worked on: 1.94.0

Version with regression

rustc --version --verbose:

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 22.1.2

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions