rust-lang / rust-lang/rust

Code that used to error on Rust 1.77 causes a compiler hang on 1.78 and later

Open
#144,696 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug fixed-by-next-solver I-hang P-medium regression-from-stable-to-stable S-has-mcve T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

I tried this code:

From @Buzzec via discord. Somewhat minimized (removed anyhow dependancy), but seems fragile to changes, so I wasn't able to quickly minimize further.

use std::borrow::Cow;
use std::fmt::Debug;
use std::iter::once;

pub trait SqlType: Sized {
    fn from_sql() -> Result<Self, ()>;
    fn to_sql(&self) -> Result<String, ()>;
}

pub trait Table {
    type Columns;
}

pub trait TopLevelTable: Table {
    const TABLE_NAME: &'static str;
}

pub trait ColumnType: Into<<Self::Table as Table>::Columns> + 'static + Copy + Debug {
    type Table: Table;
    type ColumnType;

    fn column_sql() -> Cow<'static, str>;
}

pub trait ProvidesColumns<C> {
    type ColumnIds;
    type Output;

    fn column_ids(&self, columns: &C) -> Self::ColumnIds;

    fn result_columns(
        &self,
        columns: &C,
        column_ids: &Self::ColumnIds,
    ) -> impl Iterator<Item = Cow<'static, str>>;

    fn output_from_row(
        &self,
        column: &C,
        column_ids: &Self::ColumnIds,
    ) -> Result<Self::Output, ()>;
}

impl<T, C> ProvidesColumns<C> for T
where
    T: TopLevelTable,
    C: ColumnType<Table = T>,
    C::ColumnType: SqlType,
{
    type ColumnIds = usize;
    type Output = C::ColumnType;

    fn column_ids(&self, _columns: &C) -> Self::ColumnIds {
        todo!()
    }

    fn result_columns(
        &self,
        columns: &C,
        column_ids: &Self::ColumnIds,
    ) -> impl Iterator<Item = Cow<'static, str>> {
        once(format!("t{}.{} AS c{column_ids}", "cool", columns.column_sql()).into())
    }

    fn output_from_row(
        &self,
        _column: &C,
        column_ids: &Self::ColumnIds,
    ) -> Result<Self::Output, ()> {
        todo!()
    }
}

impl<C1, C2, T> ProvidesColumns<(C1, C2)> for T
where
    T: ProvidesColumns<C1>,
    T: ProvidesColumns<C2>,
{
    type ColumnIds = (
        <T as ProvidesColumns<C1>>::ColumnIds,
        <T as ProvidesColumns<C2>>::ColumnIds,
    );
    type Output = (
        <T as ProvidesColumns<C1>>::Output,
        <T as ProvidesColumns<C2>>::Output,
    );

    fn column_ids(
        &self,
        columns: &(C1, C2),
    ) -> Self::ColumnIds {
        (
            <T as ProvidesColumns<C1>>::column_ids(self, &columns.0),
            <T as ProvidesColumns<C2>>::column_ids(self, &columns.1),
        )
    }

    fn result_columns(
        &self,
        columns: &(C1, C2),
        column_ids: &Self::ColumnIds,
    ) -> impl Iterator<Item = Cow<'static, str>> {
        let c1_sql =
            <T as ProvidesColumns<C1>>::result_columns(self, &columns.0, &column_ids.0);
        let c2_sql =
            <T as ProvidesColumns<C2>>::result_columns(self, &columns.1, &column_ids.1);
        c1_sql.chain(c2_sql)
    }

    fn output_from_row(
        &self,
        column: &(C1, C2),
        column_ids: &Self::ColumnIds,
    ) -> Result<Self::Output, ()> {
        let c1_output = <T as ProvidesColumns<C1>>::output_from_row(
            self,
            &column.0,
            &column_ids.0,
        )?;
        let c2_output = <T as ProvidesColumns<C2>>::output_from_row(
            self,
            &column.1,
            &column_ids.1,
        )?;
        Ok((c1_output, c2_output))
    }
}

I expected to see this happen: An error is emitted and compilation fails (in less than a second) on 1.77.

$ cargo +1.77 build
   Compiling bisect-thing v0.1.0 (/tmp/bisect-thing)
error[E0599]: no method named `column_sql` found for reference `&C` in the current scope
  --> src/lib.rs:62:65
   |
62 |         once(format!("t{}.{} AS c{column_ids}", "cool", columns.column_sql()).into())
   |                                                         --------^^^^^^^^^^--
   |                                                         |       |
   |                                                         |       this is an associated function, not a method
   |                                                         help: use associated function syntax instead: `C::column_sql()`
   |
   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `ColumnType`
  --> src/lib.rs:22:5
   |
22 |     fn column_sql() -> Cow<'static, str>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0599`.
error: could not compile `bisect-thing` (lib) due to 1 previous error

Instead, this happened: cargo +1.78 build seems to hang forever.

Version it worked on

It most recently worked on: Rust 1.77 and nightly-2024-02-23

(nightly-2024-02-23)

rustc 1.78.0-nightly (397937d81 2024-02-22)
binary: rustc
commit-hash: 397937d812852f9bbeb671005cb399dbcb357cde
commit-date: 2024-02-22
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

(stable 1.77)

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6
Version with regression

rustc --version --verbose: (nightly-2024-02-24)

rustc 1.78.0-nightly (8f359beca 2024-02-23)
binary: rustc
commit-hash: 8f359beca4e58bc3ae795a666301a8f47023044c
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

rustc --version --verbose: (stable 1.78)

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Bisection with `cargo-bisect-rustc`

Bisection script:

!/bin/bash
timeout 3 cargo build
if [[ "$?" = 124 ]]; then
    # timeout; failure
    exit 1
else
    # error emitted and exited; success
    exit 0
fi

Bisection result:

searched toolchains nightly-2024-02-01 through nightly-2024-03-16


********************************************************************************
Regression in nightly-2024-02-24
********************************************************************************

fetching https://static.rust-lang.org/dist/2024-02-23/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-02-23: 40 B / 40 B [================================================================================================================================================================================================================] 100.00 % 1.36 MB/s converted 2024-02-23 to 397937d812852f9bbeb671005cb399dbcb357cde
fetching https://static.rust-lang.org/dist/2024-02-24/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2024-02-24: 40 B / 40 B [==============================================================================================================================================================================================================] 100.00 % 205.23 KB/s converted 2024-02-24 to 8f359beca4e58bc3ae795a666301a8f47023044c
looking for regression commit between 2024-02-23 and 2024-02-24
fetching (via remote github) commits from max(397937d812852f9bbeb671005cb399dbcb357cde, 2024-02-21) to 8f359beca4e58bc3ae795a666301a8f47023044c
ending github query because we found starting sha: 397937d812852f9bbeb671005cb399dbcb357cde
get_commits_between returning commits, len: 11
  commit[0] 2024-02-22: Auto merge of #119989 - lcnr:sub_relations-bye-bye, r=compiler-errors
  commit[1] 2024-02-23: Auto merge of #120730 - estebank:confusable-api, r=oli-obk
  commit[2] 2024-02-23: Auto merge of #121341 - GrigorenkoPV:bootstrap-rustup-cargo, r=onur-ozkan
  commit[3] 2024-02-23: Auto merge of #121432 - mj10021:issue-119851-fix, r=nnethercote
  commit[4] 2024-02-23: Auto merge of #121448 - klensy:bump-22-02-24, r=clubby789
  commit[5] 2024-02-23: Auto merge of #121442 - lcnr:region-var-universe-uwu, r=compiler-errors
  commit[6] 2024-02-23: Auto merge of #121491 - matthiaskrgr:rollup-wkzqawy, r=matthiaskrgr
  commit[7] 2024-02-23: Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnay
  commit[8] 2024-02-23: Auto merge of #121514 - matthiaskrgr:rollup-5f0vhv7, r=matthiaskrgr
  commit[9] 2024-02-23: Auto merge of #121303 - GrigorenkoPV:static_mut_refs, r=oli-obk,RalfJung
  commit[10] 2024-02-23: Auto merge of #119536 - Jules-Bertholet:const-barrier, r=dtolnay
ERROR: no CI builds available between 397937d812852f9bbeb671005cb399dbcb357cde and 8f359beca4e58bc3ae795a666301a8f47023044c within last 167 days

@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 regression from the code in src/lib.rs by running cargo build with Rust 1.77 and 1.78, then inspect the compiler changes around the nightly-2024-02-24 regression identified by the bisection. Done means the sample terminates with a compilation error rather than hanging, while preserving the expected diagnostic behavior.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.