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

Disallow stylistic lint #11457

Closed
wants to merge 2 commits into from
Closed

Disallow stylistic lint #11457

wants to merge 2 commits into from

Conversation

TisButMe
Copy link

See #11432

@brson
Copy link
Contributor

brson commented Jan 11, 2014

Adding more of these would be a good newbie project #3070. Just coming up with new ideas for them and putting them in the issue would be good.

@huonw
Copy link
Member

huonw commented Jan 11, 2014

Does this bootstrap without some library changes? (i.e. for now, just adding #[allow(...)] to the crates that complain, we can make the adjustments progressively.)

@TisButMe
Copy link
Author

The next round of fixes to do occurs in macros expansions, such as:

static $name: ::std::local_data::Key<$ty> = &::std::local_data::Key;

which is not recognized as uppercase. I'm not sure what the smart way to fix these is, however.

EDIT: I could disable checking if the ident starts with $ in lint.rs. Starting a variable name with $ seems to be illegal, so I can't think of a bad side-effect.

EDIT2: The lint check seems to occur after macro expansion, which means the args of the macro have to be uppercase. This means changing the macro:

declare_special_idents_and_keywords!

Not sure I want to meddle with this...

@brson
Copy link
Contributor

brson commented Jan 15, 2014

This looks pretty sweet, and I like that it already caught a lot of stylistic violations. I don't quite understand what's blocking. Is one of our macros generating incorrect identifiers?

@TisButMe
Copy link
Author

I'm not very familiar with macros expansion in rust, so I can only guess.

Some macros seem to define static variables with things like $name, where $name is provided by the macro use. In some macro, the identifier provided is not UPPER_CASE, so after macro expansion it fails.

The macro that stops make check now is one that (seems to) define the language keywords. I have not put enough time in it to really realize if it's safe to change its (only, as far as I and grep can tell) use.

@huonw
Copy link
Member

huonw commented Jan 15, 2014

It's probably ok to just put #[allow(non_uppercase_statics)]; on the token.rs file so that this can land, and others can go and fix up the little bits and pieces later.

(Also, this needs a rebase.)

@TisButMe
Copy link
Author

So, I put the #[allow(non_uppercase_statics)] on top of the complaining files, but somehow it still doesn't pass a make check ?

I'm unsure where to go from there

@lucy
Copy link
Contributor

lucy commented Jan 16, 2014

I think the allow attributes have to either be added before every item that violates the lint or have a leading semicolon. E.g.

#[allow(non_camel_case_types)];

type a_not_camel_case = bool;
type b_not_camel_case = bool;

works, while

#[allow(non_camel_case_types)]

type a_not_camel_case = bool;
type b_not_camel_case = bool;

only allows non-camel-case-types for the a_not_camel_case type.

@TisButMe
Copy link
Author

Thanks, it now passes that stage, opening up another lot of fixes to be made.

@@ -53,10 +53,10 @@ pub fn keep_going(data: &[u8], f: |*u8, uint| -> i64) -> i64 {
return (origamt - amt) as i64;
}

pub type fd_t = libc::c_int;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an exception for this? It should really be fd_t

@alexcrichton
Copy link
Member

Nice work, and thanks!

Could you also rebase the commits into two stages? The first is enabling the lints and the second would just be dealing with the fallout.

@TisButMe
Copy link
Author

Just to be sure, (not so good at git yet), you want me to move HEAD to the commit enabling the lints, do a rebase there, and then move back to the current stage and rebase too ?

@alexcrichton
Copy link
Member

I normally rebase by using git rebase -i <some commit before your first commit> and then you can instruct git how to squash things (and even re-order)

@TisButMe
Copy link
Author

Is this what you wanted ?

@alexcrichton
Copy link
Member

I think this ended up picking up a lot of extra commits from all over the place. If you take a look at github's commits tab you can tell if it's gotten to the right point.

@adrientetar
Copy link
Contributor

Looks like it worked but the branch history is bloated. I would start from a clean branch and cherry-pick the two squashed commits, d910867 and b64697d.

@TisButMe
Copy link
Author

Agreed. Is there any better way to do that than closing this PR, creating a new branch, rebase -i on this one removing every commit except these 2, and the PR-ing again ?

@adrientetar
Copy link
Contributor

Here is what I would do:
checkout to master: git checkout master
create a new working branch: git checkout -b new
cherry-pick commits: git cherry-pick d910867 && git cherry-pick b64697d
swap branches: git branch -m disallow_stylistic_lint old && git branch -m new disallow_stylistic_lint
Then a push and it should be good to go.

@adrientetar
Copy link
Contributor

Note that you can probably achieve that with by resetting the branch but starting from a clean one is always guaranteed to succeed.

(The other way around would be git reset <LAST_GOOD_COMMIT> && git checkout . && git clean -fd then cherry-picking.)

@TisButMe TisButMe closed this Jan 18, 2014
@TisButMe TisButMe deleted the disallow_stylistic_lint branch January 18, 2014 12:36
@TisButMe TisButMe reopened this Jan 18, 2014
@TisButMe
Copy link
Author

The branch should now be clean. After swapping, the remote branch was ahead from the (swapped and cleaned) local one, and pulling would have included all the removed useless commits (right ?) so I deleted the remote, and pushed again. Are there better ways ?

@adrientetar
Copy link
Contributor

@TisButMe Sorry I forgot to precise, you have to use --force to overwrite remote when it is ahead i.e. git push --force origin <branch>.

@TisButMe
Copy link
Author

@adridu59 Thanks ! I'll do it the right way next time then :)

@huonw
Copy link
Member

huonw commented Jan 18, 2014

There are still 7 "junk" commits, from what I can see.

@TisButMe
Copy link
Author

There we go.

@adrientetar
Copy link
Contributor

@TisButMe I think you have to rebase against master since #11001 renamed iterators, hence the build errors.

@huonw
Copy link
Member

huonw commented Feb 1, 2014

This needs a rebase.

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to open with a rebase!

@brson
Copy link
Contributor

brson commented Feb 6, 2014

Hope this gets picked up again!

@TisButMe
Copy link
Author

TisButMe commented Feb 6, 2014

Sorry for the lack of activity, I am a bit busy at the moment. I'll try to
come back to it when I have a little more free time :)

2014-02-06 Brian Anderson notifications@github.com:

Hope this gets picked up again!

Reply to this email directly or view it on GitHubhttps://github.com//pull/11457#issuecomment-34287818
.

@adrientetar adrientetar mentioned this pull request Feb 6, 2014
@mrshu
Copy link
Contributor

mrshu commented Feb 13, 2014

I tried to go for this in the meantime and by just setting NonCamelCaseTypes to warn make check ended up with 330 errors.

What do you think the correct approach to this should be? I'd like to continue working on this. Should I send a work in progress pull request and temporarily put #[allow(non_camel_case_types)] everywhere?

@brson
Copy link
Contributor

brson commented Feb 13, 2014

@mrshu Were they legitimate violations or are there 330 places where we really need to violate the style guide?

@mrshu
Copy link
Contributor

mrshu commented Feb 13, 2014

@brson There are things like X86_64_Win64 or BasicBlock_opaque where I see the logic behind the naming. Also, I noticed a few _indenter and things like general_const and const_val which probably make sense too.

So to answer your question, I do not really know.

@brson
Copy link
Contributor

brson commented Feb 13, 2014

I guess then I'd say turn it on and put #[allow(non_camel_case_types)] at the smallest scope possible to contain the problem. rustc and syntax are an exception because they are ancient and follow a variety of coding styles, so you might as well just allow the bogosity for the entire crates until somebody cleans them up.

@mrshu
Copy link
Contributor

mrshu commented Feb 13, 2014

@brson thanks for clarification.

Here is what I got btw: http://paste.pm/e1a.js

@TisButMe
Copy link
Author

To anyone wanting to restart work on this: there are already files that
have been updated to fit the "correct" style in this PR-related files, so
before putting #[allow()] everywhere maybe check if I didn't fix that
particular occurrence already.

2014-02-14 0:13 GMT+01:00 Marek Šuppa notifications@github.com:

@brson https://github.com/brson thanks for clarification.

Here is what I got btw: http://paste.pm/e1a.js


Reply to this email directly or view it on GitHubhttps://github.com//pull/11457#issuecomment-35038123
.

@mrshu
Copy link
Contributor

mrshu commented Feb 14, 2014

Thanks @TisButMe. I am right now just following @brson's comment and trying to clean up rustc and syntax. I'll merge your work when I get there.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 8, 2024
fix: incorrect suggestions generated by `manual_retain` lint

fixes rust-lang#10393, fixes rust-lang#11457, fixes rust-lang#12081

rust-lang#10393: In the current implementation of `manual_retain`, if the argument to the closure is matched using tuple, they are all treated as the result of a call to `map.into_iter().filter(<f>)`. However, such tuple pattern matching can also occur in many different containers that stores tuples internally. The correct approach is to apply different lint policies depending on whether the receiver of `into_iter` is a map or not.

rust-lang#11457 and rust-lang#12081: In the current implementation of `manual_retain`, if the argument to the closure is `Binding`, the closure will be used directly in the `retain` method, which will result in incorrect suggestion because the first argument to the `retain` closure may be of a different type. In addition, if the argument to the closure is `Ref + Binding`, the lint will simply remove the `Ref` part and use the `Binding` part as the argument to the new closure, which will lead to bad suggestion for the same reason. The correct approach is to detect each of these cases and apply lint suggestions conservatively.

changelog: [`manual_retain`] refactor and add check for various patterns
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.

8 participants