Skip to content

ICE: cannot relate bound region: ReLateBound #82612

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
cart opened this issue Feb 27, 2021 · 3 comments · Fixed by #82627
Closed

ICE: cannot relate bound region: ReLateBound #82612

cart opened this issue Feb 27, 2021 · 3 comments · Fixed by #82627
Assignees
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cart
Copy link

cart commented Feb 27, 2021

Code

While writing a SparseArray impl, I forgot a return on value.get_or_insert_with(func). This should be an error, but I got an ice instead. This fails with the expected on stable.

use std::marker::PhantomData;

pub trait SparseSetIndex: Clone {
    fn sparse_set_index(&self) -> usize;
    fn get_sparse_set_index(value: usize) -> Self;
}


#[derive(Debug)]
pub struct SparseArray<I, V = I> {
    values: Vec<Option<V>>,
    marker: PhantomData<I>,
}

impl<I: SparseSetIndex, V> Default for SparseArray<I, V> {
    fn default() -> Self {
        Self::new()
    }
}

impl<I: SparseSetIndex, V> SparseArray<I, V> {
    #[inline]
    pub fn get_or_insert_with(&mut self, index: I, func: impl FnOnce() -> V) -> &mut V {
        let index = index.sparse_set_index();
        if index < self.values.len() {
            // SAFE: just checked bounds
            let value = unsafe { self.values.get_unchecked_mut(index) };
            value.get_or_insert_with(func)
        }
        self.values.resize_with(index + 1, || None);
        // SAFE: just inserted
        unsafe {
            let value = self.values.get_unchecked_mut(index);
            *value = Some(func());
            value.as_mut().unwrap()
        }
    }
}
fn main() {
}

playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a3776450ab79249a20b477f8365c88df

(Note that switching to stable resolves the ICE)

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (98f8cce6d 2021-02-25)
binary: rustc
commit-hash: 98f8cce6db6c6c6660eeffee2b3903104e547ecf
commit-date: 2021-02-25
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:576:17: cannot relate bound region: ReLateBound(DebruijnIndex(0), BoundRegion { kind: BrAnon(0) }) <= '_#14r

thread 'rustc' panicked at 'Box<Any>', /rustc/9c09c1f7cfcf9de0522bcd1cfda32b552195c464/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (9c09c1f7c 2021-02-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:21:1: 38:2>::get_or_insert_with`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground`

To learn more, run the command again with --verbose.
@cart cart added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 27, 2021
@bjorn3 bjorn3 added the A-lifetimes Area: Lifetimes / regions label Feb 27, 2021
@SNCPlay42
Copy link
Contributor

@rustbot label regression-from-stable-to-nightly

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 28, 2021
@apiraino
Copy link
Contributor

Bisection result

searched nightlies: from nightly-2021-02-22 to nightly-2021-02-28
regressed nightly: nightly-2021-02-24
searched commits: from a15f484 to fe1bf8e
regressed commit: a4e595d

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve --regress ice 

@JohnTitor
Copy link
Member

JohnTitor commented Feb 28, 2021

Caused by #81769:

let found = self.resolve_vars_with_obligations(found);
if let hir::FnRetTy::Return(ty) = fn_decl.output {
let ty = AstConv::ast_ty_to_ty(self, ty);
let ty = self.normalize_associated_types_in(expr.span, ty);
if self.can_coerce(found, ty) {

@JohnTitor JohnTitor self-assigned this Feb 28, 2021
@bors bors closed this as completed in 2c40e13 Mar 2, 2021
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 29, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants