rust-lang / rust-lang/rust

`Cargo Build` gets stuck compiling my code

Open
#135,050 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-hang S-needs-repro
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

While writing some code I wanted to see if it compiled, and instead cargo build just hung, either forever or longer than I was willing to late. It's a bug either way. I think I got it stuck in an infinite loop resolving traits

Code is here. I was editing mask.rs when I encountered the issue.

I think the problem code is

pub trait Maskable<T>: Copy {
    type Mask: Mask;

    fn set_masked<R: Splat<Self>>(&mut self, mask: Self::Mask, value: R);
}

impl<T, const N: usize> Maskable<T> for Col<T, N>
where
    T: Copy,
{
    type Mask = Col<bool, N>;

    fn set_masked<R: Splat<Self>>(&mut self, mask: Self::Mask, value: R) {
        let value: Self = value.splat();
        for (i, &m) in mask.iter().enumerate() {
            if m {
                self[i] = value[i]
            }
        }
    }
}

impl<S: Copy, T: Copy, const H: usize, const W: usize> Maskable<T> for Mat<S, W, H>
where
    Col<S, W>: Copy + Maskable<T>,
{
    type Mask = Col<Col<S, W>::Mask, H>;

    fn set_masked<R: Splat<Self>>(&mut self, mask: Self::Mask, value: R) {
        let value: Self = value.splat();
        for (i, &m) in mask.iter().enumerate() {
            self[i].set_masked(m, value[i]);
        }
    }
}

(this code is bad and wrong but it probably shouldn't do this)

I cant include a backtrace because Cargo never terminates

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 hang with the trait definitions from mask.rs using cargo build, then inspect the compiler's trait-resolution behavior for the Maskable and Splat bounds. Done means compilation terminates with an appropriate result or diagnostic instead of hanging indefinitely.

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.