Skip to content

Assert MIR terminators are printed incorrectly #71000

@jonas-schievink

Description

@jonas-schievink
Contributor
fn f(slice: &[u8]) -> u8 {
    (*slice)[0]
}
fn f(_1: &[u8]) -> u8 {
    debug slice => _1;                   // in scope 0 at src/main.rs:1:6: 1:11
    let mut _0: u8;                      // return place in scope 0 at src/main.rs:1:23: 1:25
    let _2: usize;                       // in scope 0 at src/main.rs:2:14: 2:15
    let mut _3: usize;                   // in scope 0 at src/main.rs:2:5: 2:16
    let mut _4: bool;                    // in scope 0 at src/main.rs:2:5: 2:16

    bb0: {
        StorageLive(_2);                 // bb0[0]: scope 0 at src/main.rs:2:14: 2:15
        _2 = const 0usize;               // bb0[1]: scope 0 at src/main.rs:2:14: 2:15
                                         // ty::Const
                                         // + ty: usize
                                         // + val: Value(Scalar(0x0000000000000000))
                                         // mir::Constant
                                         // + span: src/main.rs:2:14: 2:15
                                         // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
        _3 = Len((*_1));                 // bb0[2]: scope 0 at src/main.rs:2:5: 2:16
        _4 = Lt(_2, _3);                 // bb0[3]: scope 0 at src/main.rs:2:5: 2:16
        assert(move _4, "index out of bounds: the len is move _3 but the index is _2") -> bb1; // bb0[4]: scope 0 at src/main.rs:2:5: 2:16
    }

    bb1: {
        _0 = (*_1)[_2];                  // bb1[0]: scope 0 at src/main.rs:2:5: 2:16
        StorageDead(_2);                 // bb1[1]: scope 0 at src/main.rs:3:1: 3:2
        return;                          // bb1[2]: scope 0 at src/main.rs:3:2: 3:2
    }
}

Note how it says "index out of bounds: the len is move _3 but the index is _2". The formatting arguments are inlined into the message.

It should either mirror the format! string syntax, or at least use braces around the arguments so that they don't look like they're part of the string itself.

This issue has been assigned to @robojumper via this comment.

Activity

added
A-prettyArea: Pretty printing (including `-Z unpretty`)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
C-bugCategory: This is a bug.
on Apr 10, 2020
jonas-schievink

jonas-schievink commented on Apr 10, 2020

@jonas-schievink
ContributorAuthor

The code for formatting the Assert terminator is here:

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use AssertKind::*;
match self {
BoundsCheck { ref len, ref index } => {
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index)
}
_ => write!(f, "{}", self.description()),
}
}

The printed message just needs to be changed so that the result looks closer to how the write! macro itself is invoked. Something like this maybe:

assert(move _4, "index out of bounds: the len is {} but the index is", move _3, _2)

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Apr 10, 2020
robojumper

robojumper commented on Apr 11, 2020

@robojumper
Contributor

@rustbot claim

self-assigned this
on Apr 11, 2020
added a commit that references this issue on Apr 11, 2020
d8dcdec
added a commit that references this issue on Apr 11, 2020
c6a6be0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-prettyArea: Pretty printing (including `-Z unpretty`)C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-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

    Participants

    @jonas-schievink@robojumper@rustbot

    Issue actions

      `Assert` MIR terminators are printed incorrectly · Issue #71000 · rust-lang/rust