Skip to content

Use suggestion for redundant_closure #485

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

Merged
merged 2 commits into from
Dec 8, 2015
Merged

Use suggestion for redundant_closure #485

merged 2 commits into from
Dec 8, 2015

Conversation

sanxiyn
Copy link
Member

@sanxiyn sanxiyn commented Dec 8, 2015

cc #442.

@Manishearth
Copy link
Member

tests/compile-fail/eta.rs:15:27: 15:44 error: redundant closure found
tests/compile-fail/eta.rs:15     let c = Some(1u8).map(|a| {1+2; foo}(a));
                                                       ^~~~~~~~~~~~~~~~~
tests/compile-fail/eta.rs:4:9: 4:26 note: lint level defined here
tests/compile-fail/eta.rs:4 #![deny(redundant_closure)]
                                    ^~~~~~~~~~~~~~~~~
tests/compile-fail/eta.rs:15:27: 15:44 help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#redundant_closure
tests/compile-fail/eta.rs:15:27: 15:44 help: remove closure as shown:
tests/compile-fail/eta.rs:       let c = Some(1u8).map({1+2; foo});

The last suggestion has an extra block.

Also, the help should be shown before the "for further information". Perhaps we should have a span_lint_and_then similar to span_lint_and_note which runs a closure at the correct time if the lint level is correct.

@sanxiyn
Copy link
Member Author

sanxiyn commented Dec 8, 2015

Eh, an extra block is a pre-existing problem.

@Manishearth
Copy link
Member

Wait, nvm, we need that anyway. Sorry about the confusion. Okay, could you handle the build failure and the ordering of the suggestion and wiki link?

@sanxiyn
Copy link
Member Author

sanxiyn commented Dec 8, 2015

Done.

pub fn span_lint_and_then<T: LintContext, F>(cx: &T, lint: &'static Lint, sp: Span,
msg: &str, f: F) where F: Fn() {
cx.span_lint(lint, sp, msg);
f();
Copy link
Member

Choose a reason for hiding this comment

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

f() should only be run if the lint level is correct :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. Fixed.

@Manishearth
Copy link
Member

r+ pending travis

llogiq added a commit that referenced this pull request Dec 8, 2015
Use suggestion for redundant_closure
@llogiq llogiq merged commit 2fbe762 into rust-lang:master Dec 8, 2015
@sanxiyn sanxiyn deleted the suggestion branch December 9, 2015 06:03
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.

3 participants