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

cfg: composing/nested and+not does not work #10546

Closed
pnkfelix opened this issue Nov 18, 2013 · 3 comments
Closed

cfg: composing/nested and+not does not work #10546

pnkfelix opened this issue Nov 18, 2013 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)

Comments

@pnkfelix
Copy link
Member

It is hard (maybe impossible) to compile certain combinations of cfg flags.
E.g.: I believe the following should always compile, for any choice of a and b cfg switches:

#[cfg(and(not(a),not(b)))]
fn f() { println!("Got it"); }

#[cfg(a)]
fn f() { println!("in a"); }

#[cfg(b)]
fn f() { println!("in b"); }

fn main() {
    f();
}

But currently you get:

% rustc d.rs
d.rs:11:4: 11:5 error: unresolved name `f`.
d.rs:11     f();
            ^
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/librustc/lib.rs:396

I believe this is because our current cfg implementation is largely just a hack, rather than a proper expression evaluator. See also #2119.

@huonw
Copy link
Member

huonw commented Nov 18, 2013

FWIW, not is the only predicate handled by cfg, and it cannot even be nested, i.e. #[cfg(not(not(a)))] is testing that the flag not(a) doesn't exist, not that a does exist.

@pnkfelix
Copy link
Member Author

Oh wait, I misunderstood the current syntax. There is no cfg(and(..)) operator; and-ing is implicit by feeding multiple arguments into cfg

@pnkfelix
Copy link
Member Author

(Closing as not-a-real bug, other than the potential desire to implement #2119 properly.)

((Though this does illustrate the serious need to document the cfg semantics properly somewhere.))

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 11, 2023
…dnet

fix(needless_return): do not trigger on ambiguous match arms return

If we see a case where match returns something other than `()`, we just skip `needless_return` lint in that case

Should fix rust-lang#10546

Relevant Zulip Discussion: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Issue.20.2310546

---

changelog: FP: [`needless_return`]: No longer lints match statements with incompatible branches
[rust-lang#10593](rust-lang/rust-clippy#10593)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)
Projects
None yet
Development

No branches or pull requests

2 participants