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

Assert MIR terminators are printed incorrectly #71000

Closed
jonas-schievink opened this issue Apr 10, 2020 · 2 comments · Fixed by #71021
Closed

Assert MIR terminators are printed incorrectly #71000

jonas-schievink opened this issue Apr 10, 2020 · 2 comments · Fixed by #71021
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Apr 10, 2020

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.

@jonas-schievink jonas-schievink added A-pretty Area: Pretty printing (including `-Z unpretty`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. labels Apr 10, 2020
@jonas-schievink
Copy link
Contributor Author

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)

@jonas-schievink jonas-schievink added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Apr 10, 2020
@robojumper
Copy link
Contributor

@rustbot claim

@rustbot rustbot self-assigned this Apr 11, 2020
Centril added a commit to Centril/rust that referenced this issue Apr 11, 2020
… r=jonas-schievink

Use write!-style syntax for MIR assert terminator

Fixes rust-lang#71000.

r? @jonas-schievink
@bors bors closed this as completed in d8dcdec Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler 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