Skip to content

inhabitedness cache handles cycles incorrectly #44402

Closed
@nikomatsakis

Description

@nikomatsakis

In this example, I get an (incorrect) compilation error:

#![feature(never_type)]

struct Foo { 
    field1: !,
    field2: Option<&'static Bar>,
}

struct Bar {
    field1: &'static Foo
}

fn test_a() {
  let x: Option<Foo> = None;
  match x { None => () }
}

fn test_b() {
  let x: Option<Bar> = None;
  match x { None => () }
}
    
fn main() { }

But if you comment out test_a, you don't. This is because the inhabitedness code, if it starts from Foo, incorrectly caches a result for Bar -- the result is incorrect because Bar did not fully explore Foo, since we found a cycle.

Encountered while fixing #44137 -- I will fix en passante.

Metadata

Metadata

Assignees

Labels

B-unstableBlocker: Implemented in the nightly compiler and unstable.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions