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 issue12118: Return value/use extra::test::black_box in benchmarks that are optimised to nothing #12212

Closed
wants to merge 1 commit into from

Conversation

lpy
Copy link
Contributor

@lpy lpy commented Feb 12, 2014

A try to fix #12118.
@huonw Could you please review that.

@lpy
Copy link
Contributor Author

lpy commented Feb 12, 2014

#12118

x: 1,
y: 2,
z: 3,
})
}));
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't need black_box because it can just return it from the closure (and bh.iter will black_box it)

Copy link
Member

Choose a reason for hiding this comment

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

This one was already fixed :)

Copy link
Member

Choose a reason for hiding this comment

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

By "already fixed" I mean, there's no need to add the black_box call or change it in any way (the arena.alloc function is very fast): the lack of a trailing semicolon meant that it was returned by the closure.

@huonw
Copy link
Member

huonw commented Feb 12, 2014

Thanks!

@lpy
Copy link
Contributor Author

lpy commented Feb 13, 2014

thank you both of you.

@@ -269,6 +269,7 @@ mod tests {
mod bench {

use extra::test::BenchHarness;
use extra::test::black_box;
Copy link
Member

Choose a reason for hiding this comment

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

This import isn't needed anymore

@lpy
Copy link
Contributor Author

lpy commented Feb 13, 2014

Thank you

@@ -4464,13 +4465,14 @@ mod bench {
ptr::set_memory(vp, 0, 1024);
v.set_len(1024);
}
&v
Copy link
Member

Choose a reason for hiding this comment

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

You can just return v instead of &v.

(The test failures are because v is defined inside the closure, and so returning a reference would be creating a dangling pointer.)

@lpy
Copy link
Contributor Author

lpy commented Feb 13, 2014

Thank you.

@lpy lpy restored the issue12118 branch February 18, 2014 12:08
@lpy lpy deleted the issue12118 branch February 18, 2014 12:08
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
Fix a typo in the `inlayHints.renderColons` option description

The description said the same thing twice: "trailing colons for parameter hints, and trailing colons for parameter hints".
I'm assuming one of those is supposed to be about the leading colon for type hints.

Also, I wasn't sure how to regenerate the generated file(s?) so I just manually updated them. Hopefully that isn't a problem. If how to do that is in the documentation somewhere I'd love to know.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 8, 2024
…s-fix, r=Jarcho

Fix false positive in `redundant_type_annotations` lint

This PR changes the `redundant_type_annotations` lint to allow slice type annotations (i.e., `&[u8]`) for byte string literals. It will still consider _array_ type annotations (i.e., `&[u8; 4]`) as redundant. The reasoning behind this is that the type of byte string literals is by default a reference to an array, but, by using a type annotation, you can force it to be a slice. For example:
```rust
let a: &[u8; 4] = b"test";
let b: &[u8] = b"test";
```

Now, the type annotation for `a` will still be linted (as it is still redundant), but the type annotation for `b` will not.

Fixes rust-lang#12212.

changelog: [`redundant_type_annotations`]: Fix false positive with byte string literals
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.

Return value/use extra::test::black_box in benchmarks that are optimised to nothing
4 participants