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

Warning "unnecessary braces" for expr attribute after updating nightly #71080

Closed
Boscop opened this issue Apr 12, 2020 · 4 comments
Closed

Warning "unnecessary braces" for expr attribute after updating nightly #71080

Boscop opened this issue Apr 12, 2020 · 4 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Boscop
Copy link

Boscop commented Apr 12, 2020

I just updated my nightly from 02-14 to 04-12, and now I get this warning:

warning: unnecessary braces around function argument
    |
281 |             #[auto_enum(Iterator)]
    |             ^^^^^^^^^^^^^^^^^^^^^^ help: remove these braces
    |
    = note: `#[warn(unused_braces)]` on by default

for this code using auto_enums:

	pub fn backup_pixels(&self, iter: impl Iterator<Item = Pixel<Rgb888>>, pixels: &mut Vec<(usize, u8)>) {
		pixels.extend(iter.flat_map(|Pixel(Point { x, y }, _color)| {
			#[auto_enum(Iterator)]
			let r = if (0 .. self.width as _).contains(&x) && (0 .. self.height as _).contains(&y) {
				let index = (x + y * self.width as i32) as usize * 3;
				self.buffer[index .. index + 3].iter().enumerate().map(move |(i, &col)| (index + i, col))
			} else {
				std::iter::empty()
			};
			r
		}));
	}

Notice that there are no braces.
It didn't produce a warning with the old nightly.

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2020
@taiki-e
Copy link
Member

taiki-e commented Apr 13, 2020

Hmm... unused braces generated by macros seem to be properly ignored: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c4c2befbd2e7486399bfbb521723d0a5

bors bot added a commit to taiki-e/auto_enums that referenced this issue Apr 13, 2020
88: Fix unused braces warnings r=taiki-e a=taiki-e

Basically due to this function:

https://github.com/taiki-e/auto_enums/blob/f77fd83a2b2c1b694cdc23cad0d301a7402c12b7/core/src/utils.rs#L55-L57

`brace_token` of the block that passed to `f` should have `call_site` span.
If `f` generates unused braces containing the span of `this.brace_token`, 
this will cause confusing warnings: rust-lang/rust#71080

Co-authored-by: Taiki Endo <te316e89@gmail.com>
@Boscop
Copy link
Author

Boscop commented Apr 13, 2020

@taiki-e I guess this issue can be closed then?

@taiki-e
Copy link
Member

taiki-e commented Apr 13, 2020

Yes, this is due to #[auto_enum] incorrectly generates a block that contains the span of the brace of the if expression (i.e., bug of auto_enums crate).

@Boscop
Copy link
Author

Boscop commented Apr 13, 2020

Ah ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants