Skip to content

Implicit returns with multiple #cfg[...] cause compilation errors #38337

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
Susurrus opened this issue Dec 13, 2016 · 3 comments
Closed

Implicit returns with multiple #cfg[...] cause compilation errors #38337

Susurrus opened this issue Dec 13, 2016 · 3 comments
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Susurrus
Copy link
Contributor

Susurrus commented Dec 13, 2016

If there are two different #cfg[...] one after each other and they utilize implicit returns (don't have a trailing ';'), then a compilation error will occur.

Example of the error: https://is.gd/fiScoc
Fixed: https://is.gd/Z87TE0

I believe this is a compiler bug because in the fixed version there's still an implicit return as part of the last #cfg[...] and there isn't an error about it.

@sinkuu
Copy link
Contributor

sinkuu commented Dec 13, 2016

/* #[cfg(unix)]    */ return Ok("unix".to_string());
/* #[cfg(windows)] */ Ok("windows".to_string())

is syntactically valid, while this is not:

/* #[cfg(unix)]    */ Ok("unix".to_string())
/* #[cfg(windows)] */ Ok("windows".to_string())

As stated in #29850 (comment), the current implementation doesn't implicitly fix such code.

@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed A-compiler labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-parser Area: The lexing & parsing of Rust source code to an AST label Jun 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@cyplo
Copy link
Contributor

cyplo commented Nov 1, 2017

Still a problem on rustc 1.23.0-nightly (8b22e70 2017-10-31)

@Mark-Simulacrum
Copy link
Member

This seems like expected behavior to me so I'm going to go ahead and close. Expressions can't be adjacent like this without some separator in general (and cfg is after parsing, not before/during).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

5 participants