Skip to content

while cfg!(unix) { ... } suggests to use loop instead #43268

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

Closed
oli-obk opened this issue Jul 16, 2017 · 6 comments · Fixed by #44248
Closed

while cfg!(unix) { ... } suggests to use loop instead #43268

oli-obk opened this issue Jul 16, 2017 · 6 comments · Fixed by #44248
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jul 16, 2017

If any linting or suggestion is done in this case, it should suggest if cfg!(unix) { loop { ... } }

cc @jseyfried this has been in rustc forever, but clippy is only lately going crazy on it. Could this have come from your PR, too?

@jseyfried
Copy link
Contributor

@oli-obk Hmm, cfg! shouldn't have been affected, but I'll investigate.

@jseyfried jseyfried self-assigned this Jul 17, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jul 19, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 28, 2017
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 1, 2017

@jseyfried this is messing up clippy pretty bad. Any idea where to start looking?

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 7, 2017

So I tried to figure out what's going on, but I got lost in the code. As far as I can see it https://github.com/rust-lang/rust/blob/master/src/libsyntax/ext/expand.rs#L486 should be setting the expansion info. But it appears the span passed to https://github.com/rust-lang/rust/blob/master/src/libsyntax/ext/expand.rs#L492 doesn't contain the expansion info. So maybe we need to generate a new span here with the mark from https://github.com/rust-lang/rust/blob/master/src/libsyntax/ext/expand.rs#L465 ?

@jseyfried
Copy link
Contributor

@oli-obk The span passed to https://github.com/rust-lang/rust/blob/master/src/libsyntax/ext/expand.rs#L492 is the call site span, so it shouldn't contain the expansion info.

The issue here is that cfg! is using the call site span directly in the expansion here (sp is call site span).

To fix this, the cfg macro should add expansion info to the call site span like format! does here. Adding that line in cfg.rs should fix this issue.

Are there other built-in macros that also have this problem in practice or is it just cfg!?

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 7, 2017

I'd assume others have it too, but I'll check.

So the passed call site span should only be used directly for error reporting, but never for creating ast items?

@jseyfried
Copy link
Contributor

jseyfried commented Aug 7, 2017

Right, unless you want an AST item with the raw (unexpanded) call site span -- I don't think we ever want that.

bors added a commit that referenced this issue Sep 4, 2017
Produce expansion info for more builtin macros

r? @jseyfried

fixes #43268
bors added a commit that referenced this issue Sep 4, 2017
Produce expansion info for more builtin macros

r? @jseyfried

fixes #43268
bors added a commit that referenced this issue Sep 5, 2017
Produce expansion info for more builtin macros

r? @jseyfried

fixes #43268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants