Skip to content

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

@zachs18

Description

@zachs18

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.P-mediumMedium priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions