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

Fix stacked borrow violation and add miri CI #25

Merged
merged 3 commits into from
Apr 23, 2020
Merged

Fix stacked borrow violation and add miri CI #25

merged 3 commits into from
Apr 23, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Apr 23, 2020

Fixes #24.

Miri flagged that we borrow a reference to just the first element and
then write through it to elements other than the first. The new
implementation borrows the whole buffer before writing.
@dtolnay dtolnay merged commit f7cd2ea into master Apr 23, 2020
@dtolnay dtolnay deleted the borrow branch April 23, 2020 00:38
brson added a commit to brson/tikv that referenced this pull request Apr 23, 2020
This fixes some undefined behavior, but there's probably no practical impact.

See dtolnay/ryu#25

Signed-off-by: Brian Anderson <[email protected]>
name: Miri
script:
- rustup component add miri || travis_terminate 0
- cargo miri test
Copy link

@RalfJung RalfJung Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see Miri being added here. :)

cargo miri test will interactively ask for confirmation to install things, and will probably not work. Miri is just not available for the latest nightly so right now we do not enter this code path.
The recommended Miri CI integration is given in our README.

@@ -51,13 +51,15 @@ fn test_ryu() {

#[test]
fn test_random() {
let n = if cfg!(miri) { 100 } else { 1000000 };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I like this style... so far I always used #[cfg(miri)] for this but that means we need 4 lines to define one constant.

let f: f64 = rand::random();
assert_eq!(f, buffer.format_finite(f).parse().unwrap());
}
}

#[cfg(not(miri))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the usual alternative I use these days is #[cfg_attr(miri, ignore)]. Then at least it is clear in the output that we are skipping some tests.

It doesn't really make a difference, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Miri reports stacked borrowing error in unsafe cast from element to array
2 participants