Skip to content

Internal Compiler Error for needless_pass_by_value: cannot relate region: ReErased #10344

New issue

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

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

Already on GitHub? Sign in to your account

Closed
base0x10 opened this issue Feb 14, 2023 · 2 comments

Comments

@base0x10
Copy link

Summary

Rustc panics when running clippy with the lint needless_pass_by_value from the pedantic group. The error seems to be triggered when type_allowed_to_implement_copy is checked for parameters with erased lifetimes. I've produced a minimal failing input and found the first nightly release impacted.

Error

Internal compiler error: compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs:203:17: cannot relate region: ReErased.

Full backtrace copied into this gist.

Reproduction

#![warn(clippy::needless_pass_by_value)]

struct Input<'a> {
        _baz: &'a u32,
}

fn funct(foo: Input) {
    let _bar = &foo;
}

Versions

Up to date beta and nightly toolchains are impacted but not stable. I bisected nightly toolchains and found that nightly-2023-01-21 is not impacted but nightly-2023-1-22 is impacted.

@base0x10
Copy link
Author

I've taken an initial look, but I'm not very familiar with rustc internals.

On the offending code path, needless_pass_by_value.rs is checking if the parameter is allowed to implement copy. type_allowed_to_implement_copy checks each field in the parameter with the lexical region resolver to determine which lifetimes (regions) outlive which others.

This is where I am most unsure. The lexical region resolver wants to pin down all of the lifetimes. It typically does this by looking for the least-upper-bound (lub in the resolver code). The lifetime for foo and for bar should probably both be Empty. The lifetime of bar should be empty because it isn't ever used. foo's lifetime must be at least as long as bar's lifetime (Empty), and as long as 'a, but we never need to borrow from behind 'a.

One of the lifetimes, however, is re_erased rather than Empty. IIUC this is the error, and re_erased shouldn't leak backwards in time from code generation to type checking.

@matthiaskrgr
Copy link
Member

Duplicate of rust-lang/rust#107147 , should be fixed by #10328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants