-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[do not merge] Relicensing rewrite #3251
Conversation
I'll do |
I haven't seen the code of #2814. Did it add both |
Yes and yes.
They're really the same lint with an additional check for one :)
…On Tue, Oct 2, 2018, 4:11 PM Philipp Hansch ***@***.***> wrote:
I haven't seen the code of #2814
<#2814>. Did it add
both fn_to_numeric_cast and fn_to_numeric_cast_with_truncation?
I will start with fn_to_numeric_cast later today.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3251 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABivSJ3aMZo3gCk-I-koYTuQvMLFTeJVks5ug3QBgaJpZM4XDzll>
.
|
Ok, I have a basic version of I currently have the following test cases: fn foo() -> String { String::new() }
fn test_function_to_numeric_cast() {
let _ = foo as i8;
let _ = foo as i16;
let _ = foo as i32;
let _ = foo as i64;
let _ = foo as i128;
let _ = foo as isize;
let _ = foo as u8;
let _ = foo as u16;
let _ = foo as u32;
let _ = foo as u64;
let _ = foo as u128;
// Casting to usize is OK and should not warn
let _ = foo as usize;
} |
You need to handle both, there's an automatic coercion from FnDef to FnPtr. You'll hit the FnPtr edge for cases where you explicitly cast a variable of type (FnDef is a zero-sized type that is unique for each function, letting things like Testcase is ok. |
I added the handling of |
tests/ui/fn_to_numeric_cast.rs
Outdated
@@ -0,0 +1,49 @@ | |||
#![feature(tool_lints)] | |||
|
|||
#[warn(clippy::fn_to_numeric_cast)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[warn()]
-> #![warn()]
I pushed a first version of the I'm not 100% clear on two things:
|
let _ = foo as u16; | ||
let _ = foo as u32; | ||
|
||
// TODO: Is it bad to have these tests? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are compile-test flags you can set to ignore tests on specific architectures.
If the pointer width of the architechture is 32bit or something else, then the tests will most likely produce different results.
The changes look good! I may hold off on merging since I'll be talking about this with someone from Mozilla's legal team tomorrow morning anyway as a sanity-check. You need to update the test expectations btw. |
This collapses both lint tests into one file. Somehow allowing the other lint in the respective files did not work correctly. Maybe that's fixed as part of fixing #3198.
For some reason (maybe #3198), (I also merged in master, let me know if I should rebase instead) |
merge is fine. Thanks! |
Probably should have edited out the |
Well, this introduced a couple of dogfood failures and compiler warnings according to travis :/
|
That was previously broken, perhaps introduced by a rust compiler change? |
From the relicensing meta-issue (#3093) we have consent to relicense from all copyright holders except for:
.cloned()
over.map(|x| x.clone())
#427There may be people we have missed, before the final relicense we'll do a proper check.
Anyway, #2814 and #427 need to be rewritten for us to be able to relicense. Ideally, they should be written by someone who has not seen their code.
This PR removes the lints introduced in those PRs. Someone who has not seen those PRs (or this one) needs to rewrite them from scratch. I'll attempt to describe them:
map_clone
(style): catches.map(|x| x.clone())
and.map(|x| *x)
and.map(|&x| x)
, suggests.cloned()
(ensure there are no adjustments!)fn_to_numeric_cast
(style, ideally inCastPass
): Cast a function to something other than a usizefn_to_numeric_cast_with_truncation
(correctness): Same as above, but the target type is smaller.Make these changes as PRs to this branch, and we'll land it all together.
cc @oli-obk @phansch @flip1995
@oli-obk / @flip1995 reviewed the
fn_to_numeric_cast*
lints so shouldn't be the ones to re-add them.Anyone up for writing these lints? :)