rust-lang / rust-lang/rust

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

Open
#155,415 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug D-confusing P-medium regression-from-stable-to-stable T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic from src/main.rs with --diagnostic-width=100 using the Diesel example, then compare the abbreviated and fully qualified error messages. Investigate the compiler diagnostic output involved in rendering repeated type names; done means the errors distinguish users::columns::id, posts::columns::id, and comments::columns::id as in the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.