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

Clippy related fixes #469

Merged
merged 19 commits into from
Mar 16, 2024
Merged

Clippy related fixes #469

merged 19 commits into from
Mar 16, 2024

Conversation

tempdragon
Copy link
Contributor

@tempdragon tempdragon commented Mar 11, 2024

  1. I don't know if you are interested in merging this half-generated(if not fully) commit. If not, feel free to close it. Everything is generated if not mentioned.
  2. I do apologize for a likely delay in answering the reviews.
  3. I renamed the methods from_low_high_rvalues and from_low_high in tempdragon/rustc_codegen_gcc@a7d39b8
  4. All life time related modifications were done by using cargo clippy --fix --lib -p rustc_codegen_gcc --allow-dirtyxs, as is done in tempdragon/rustc_codegen_gcc@ad97b8c. However, since I am not an expert in lifetime, I can't guarantee its correctness(But it passed the workflow anyway.)
  5. In tempdragon/rustc_codegen_gcc@d2cda90, the shift was removed for use of i, but the shift variable still looks weird here.
  6. I used a clone() to solve pattern_type_mismatch lint in tempdragon/rustc_codegen_gcc@8d4d878, but it looks less efficient. I should apologize because I do doubt if there is a better way to fix this here.

Probably gonna solve #457.

1. Fix Pattern Type Mismatch by Adding deref's
2. Move commented `else if` to previous block in `intrinsic.rs`
1. Use `clone_from` in place of `clone()` in `builder.rs`
2. Change `&name` to `name.clone()` in `debuginfo.rs`(Is this really
efficient? But I can't find other workarounds.)
cmd: `cargo clippy --fix --lib -p rustc_codegen_gcc --allow-dirtyxs`
This looks like an (inverted) exclusive-or but I still leave it as it is in clippy.
Changed for clippy naming convention requirement:
```
warning: methods called `from_*` usually take no `self`
   --> src/int.rs:996:22
    |
996 |     fn from_low_high(&self, typ: Type<'gcc>, low: i64, high: i64) -> RValue<'gcc> {
    |                      ^^^^^
    |
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention
    = note: `#[warn(clippy::wrong_self_convention)]` on by default
```
Copy link
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

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

Thanks! The clone() should not be necessary.

src/builder.rs Outdated
bx: &mut Builder<'a, 'gcc, 'tcx>,
rvalue: RValue<'gcc>,
) -> RValue<'gcc> {
fn set_rvalue_location<'gcc>(bx: &mut Builder<'_, 'gcc, '_>, rvalue: RValue<'gcc>) -> RValue<'gcc> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I like this change (since I fear this might make the lifetime error messages harder to understand), but I'm not sure if there's a way to disable this lint in a way that clippy will still warn about lifetimes that could be removed on simple references.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we should simply close the lint, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revert the whole tempdragon@ad97b8c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted in tempdragon/rustc_codegen_gcc@390f906, adding #![allow(clippy::needless_lifetimes)] to allow this in clippy.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this specific function (at least) was not reverted.

src/debuginfo.rs Show resolved Hide resolved
src/debuginfo.rs Show resolved Hide resolved
src/debuginfo.rs Outdated Show resolved Hide resolved
src/declare.rs Outdated Show resolved Hide resolved
src/int.rs Show resolved Hide resolved
src/intrinsic/mod.rs Outdated Show resolved Hide resolved
Comment on lines 312 to 321
/*else if use_integer_compare {
let integer_ty = self.type_ix(layout.size.bits()); // FIXME(antoyo): LLVM creates an integer of 96 bits for [i32; 3], but gcc doesn't support this, so it creates an integer of 128 bits.
let ptr_ty = self.type_ptr_to(integer_ty);
let a_ptr = self.bitcast(a, ptr_ty);
let a_val = self.load(integer_ty, a_ptr, layout.align.abi);
let b_ptr = self.bitcast(b, ptr_ty);
let b_val = self.load(integer_ty, b_ptr, layout.align.abi);
self.icmp(IntPredicate::IntEQ, a_val, b_val)
}*/
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is not correct. Please revert to the original code, but put the else on the same line as the end of the comment, like this:

}*/ else {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly, the rustfmt doesn't seem to allow this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It automatically inserts a newline and then cause the following warning:

warning: this is an `else {..}` but the formatting might hide it
   --> src/intrinsic/mod.rs:311:18
    |
311 |   ...   }
    |  ________^
312 | | ...   /*else if use_integer_compare {
313 | | ...       let integer_ty = self.type_ix(layout.size.bits()); // FIXME(antoyo): LLVM creates...
314 | | ...       let ptr_ty = self.type_ptr_to(integer_ty);
...   |
320 | | ...   }*/
321 | | ...   else {
    | |___________^
    |
    = note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
    = note: `#[warn(clippy::suspicious_else_formatting)]` on by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't currently know if there is a way that fits both your requirements and rustfmt and clippy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I try to have clippy ignore this or should I handle this in other ways?

src/intrinsic/mod.rs Outdated Show resolved Hide resolved
@antoyo
Copy link
Contributor

antoyo commented Mar 15, 2024

Also, if you want, please add cargo clippy --all-targets -- -D warnings somewhere in one CI workflow.

@tempdragon
Copy link
Contributor Author

tempdragon commented Mar 16, 2024

Also, if you want, please add cargo clippy --all-targets -- -D warnings somewhere in one CI workflow.

Added in 4e4efb9

src/intrinsic/mod.rs Outdated Show resolved Hide resolved
src/intrinsic/mod.rs Outdated Show resolved Hide resolved
src/intrinsic/mod.rs Outdated Show resolved Hide resolved
src/intrinsic/mod.rs Show resolved Hide resolved
src/attributes.rs Outdated Show resolved Hide resolved
src/consts.rs Outdated Show resolved Hide resolved
src/intrinsic/mod.rs Outdated Show resolved Hide resolved
src/intrinsic/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

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

This is good to me.

@tempdragon: Please tell me if you wanted to do any other changes or if I can merge this PR.

@tempdragon
Copy link
Contributor Author

Look good to me. Thanks for your review!

@antoyo antoyo merged commit 7ff5d39 into rust-lang:master Mar 16, 2024
34 checks passed
@antoyo
Copy link
Contributor

antoyo commented Mar 16, 2024

Thanks for your contribution!

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.

2 participants