Skip to content

MIR-borrowck: ICE during diagnostic search for assignment (unwrap of None) #45199

Description

@pnkfelix

PR #44806 added some code to search for the lexically first assignment in order to report an illegal assignment.

However, oddly enough, for some tests this search, which ends in an unwrap, is causing the compiler to ICE.

For example:

%  build/x86_64-apple-darwin/stage1/bin/rustc  -Z borrowck-mir \
     ../src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs
[...]
error[E0384]: re-assignment of immutable variable `val` (Mir)
  --> ../src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs:15:5
   |
15 |        for &x in &vector {
   |   _____^
   |  |_____|
   | ||
16 | ||         let cap = vector.capacity();
17 | ||         vector.extend(repeat(0));      //~ ERROR cannot borrow
18 | ||         vector[1] = 5;   //~ ERROR cannot borrow
19 | ||     }
   | ||     ^
   | ||_____|
   | |______re-assignment of immutable variable
   |        first assignment to `val`

error[E0384]: re-assignment of immutable variable `x` (Mir)
  --> ../src/test/compile-fail/borrowck/borrowck-for-loop-head-linkage.rs:15:10
   |
15 |     for &x in &vector {
   |          ^
   |          |
   |          re-assignment of immutable variable
   |          first assignment to `x`

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.22.0-dev running on x86_64-apple-darwin

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /Users/fklock/Dev/Mozilla/rust.git/src/libcore/option.rs:335:20

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 11, 2017
  2. pnkfelix commented on Oct 11, 2017

    @pnkfelix
    ContributorAuthor

    Its worth noting that the diagnostic reported by AST-borrowck is very different from that for MIR-borrowck. This is almost certainly because the MIR-borrowck is seeing a desugared for-loop (and thus we're seeing reports of an assignment to val that does not actually occur in the surface level syntax.

    Nonetheless, part of resolving this bug might include trying figure out how to make the MIR-borrowck diagnostic more understandable to the end user in this scenario.

  3. pnkfelix commented on Oct 18, 2017

    @pnkfelix
    ContributorAuthor

    (another approach that I did not consider earlier: Change the MIR construction to accommodate for-loops. E.g. maybe the MIR assignment statement could take a flag indicating that it is an assignment arising from for-desugaring, and thus it is "safe" even when it is reassigning a variable declared without mut...)

  4. changed the title [-]MIR-borrowck: ICE during diagnostic search for assignment[/-] [+]MIR-borrowck: ICE during diagnostic search for assignment (unwrap of None)[/+] on Nov 1, 2017
  5. matthewjasper commented on Nov 10, 2017

    @matthewjasper
    Contributor

    Working on this (and this error message in general)

  6. nikomatsakis commented on Nov 10, 2017

    @nikomatsakis
    Contributor

    @matthewjasper nice! please stop in on gitter with any questions, if you've not done so already.

  7. added this to the NLL prototype milestone on Nov 15, 2017
  8. matthewjasper commented on Nov 15, 2017

    @matthewjasper
    Contributor

    Minified case (that still ICEs after #45936)

    fn main() {
        let x = String::new();
        x = String::new();
    }
  9. added a commit that references this issue on Nov 27, 2017
    def3d47
  10. added a commit that references this issue on Nov 27, 2017
    560a5da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions