Skip to content
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

mir typeck: subtyping cannot deal with bivariance #104409

Closed
lcnr opened this issue Nov 14, 2022 · 2 comments · Fixed by #104411
Closed

mir typeck: subtyping cannot deal with bivariance #104409

lcnr opened this issue Nov 14, 2022 · 2 comments · Fixed by #104411
Assignees
Labels
A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 14, 2022

trait Trait {
    type Assoc;
}

struct Foo<T, U>(T)
where
    T: Trait<Assoc = U>;

impl Trait for for<'a> fn(&'a ()) {
    type Assoc = u32;
}
impl Trait for fn(&'static ()) {
    type Assoc = String;
}
    
fn foo(x: Foo<for<'a> fn(&'a ()), u32>) -> Foo<fn(&'static ()), String> {
    x
}

fn main() {}

results in the following ICE:

error: internal compiler error: broken MIR in DefId(0:15 ~ example[9884]::foo) (_0 = move _1): bad assignment (Foo<fn(&()), std::string::String> = Foo<for<'a> fn(&'a ()), u32>): NoSolution
  --> <source>:17:5
   |
17 |     x
   |     ^

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1561:30
stack backtrace:
----------- SNIP ----------------------
  17:     0x7fe0e8c751b3 - <rustc_errors[1020869c0a53ac34]::HandlerInner>::panic_if_treat_err_as_bug
  18:     0x7fe0e8c73258 - <rustc_errors[1020869c0a53ac34]::HandlerInner>::emit_diagnostic
  19:     0x7fe0ea774481 - <rustc_errors[1020869c0a53ac34]::HandlerInner>::emit_diag_at_span::<rustc_span[efd8b0f1895919e0]::span_encoding::Span>
  20:     0x7fe0ea774603 - <rustc_errors[1020869c0a53ac34]::HandlerInner>::span_bug::<rustc_span[efd8b0f1895919e0]::span_encoding::Span, &str>
  21:     0x7fe0ea773c55 - <rustc_errors[1020869c0a53ac34]::Handler>::delay_span_bug::<rustc_span[efd8b0f1895919e0]::span_encoding::Span, &str>
  22:     0x7fe0e9228157 - <rustc_borrowck[e2ad9be94bf77b7a]::type_check::TypeChecker>::typeck_mir
  23:     0x7fe0e919c351 - rustc_borrowck[e2ad9be94bf77b7a]::type_check::type_check
  24:     0x7fe0e9187179 - rustc_borrowck[e2ad9be94bf77b7a]::nll::compute_regions
  25:     0x7fe0e915c6e8 - rustc_borrowck[e2ad9be94bf77b7a]::do_mir_borrowck
  26:     0x7fe0e9b8f296 - rustc_borrowck[e2ad9be94bf77b7a]::mir_borrowck

godbolt

This should compile

@lcnr lcnr added C-bug Category: This is a bug. A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) T-types Relevant to the types team, which will review and decide on the PR/issue. labels Nov 14, 2022
@Rageking8
Copy link
Contributor

@rustbot label +I-ICE

@rustbot rustbot added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 14, 2022
@lcnr
Copy link
Contributor Author

lcnr commented Nov 14, 2022

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 19, 2022
…rors

nll: correctly deal with bivariance

fixes rust-lang#104409

when in a bivariant context, relating stuff should always trivially succeed. Also changes the mir validator to correctly deal with higher ranked regions.

r? types cc `@RalfJung`
@bors bors closed this as completed in 00876c6 Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-variance Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants