-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
[WIP] [Refactor] Defining clippy rules #91
Changes from 6 commits
dac0805
55a074e
e4996ad
683c918
78bd71d
555e70b
c7ff384
2e12e0a
c681084
f7bbd1d
c74f253
f2b66f3
0138ad9
c69fe9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use source_map::{Span, SpanWithSource}; | |
|
||
use crate::{ | ||
behavior::objects::ObjectBuilder, | ||
types::{cast_as_string, SynthesisedArgument}, | ||
types::{calling::CallingInput, cast_as_string, SynthesisedArgument}, | ||
CheckingData, Constant, Environment, Instance, Type, TypeId, | ||
}; | ||
|
||
|
@@ -26,13 +26,13 @@ where | |
M::Expression: 'a, | ||
{ | ||
fn part_to_type<T: crate::ReadFromFS, M: crate::ASTImplementation>( | ||
first: TemplateLiteralPart<M::Expression>, | ||
first: &TemplateLiteralPart<M::Expression>, | ||
environment: &mut Environment, | ||
checking_data: &mut CheckingData<T, M>, | ||
) -> crate::TypeId { | ||
match first { | ||
TemplateLiteralPart::Static(static_part) => { | ||
checking_data.types.new_constant_type(Constant::String(static_part.to_owned())) | ||
checking_data.types.new_constant_type(Constant::String((*static_part).to_owned())) | ||
} | ||
TemplateLiteralPart::Dynamic(expression) => { | ||
// TODO tidy | ||
|
@@ -67,7 +67,7 @@ where | |
for part in parts_iter { | ||
match part { | ||
p @ TemplateLiteralPart::Static(_) => { | ||
let value = part_to_type(p, environment, checking_data); | ||
let value = part_to_type(&p, environment, checking_data); | ||
static_parts.append( | ||
environment, | ||
crate::context::facts::Publicity::Public, | ||
|
@@ -79,12 +79,12 @@ where | |
static_part_count += 1; | ||
} | ||
p @ TemplateLiteralPart::Dynamic(_) => { | ||
let ty = part_to_type(p, environment, checking_data); | ||
let ty = part_to_type(&p, environment, checking_data); | ||
arguments.push(SynthesisedArgument::NonSpread { | ||
ty, | ||
// TODO position | ||
position: SpanWithSource::NULL_SPAN, | ||
}) | ||
}); | ||
} | ||
} | ||
} | ||
|
@@ -101,21 +101,23 @@ where | |
let call_site = position.clone().with_source(environment.get_source()); | ||
crate::types::calling::call_type_handle_errors( | ||
tag, | ||
crate::types::calling::CalledWithNew::None, | ||
crate::behavior::functions::ThisValue::UseParent, | ||
None, | ||
arguments, | ||
call_site, | ||
CallingInput { | ||
called_with_new: crate::types::calling::CalledWithNew::None, | ||
this_value: crate::behavior::functions::ThisValue::UseParent, | ||
call_site, | ||
call_site_type_arguments: None, | ||
}, | ||
environment, | ||
arguments, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a reason I didn't add it, it's because |
||
checking_data, | ||
) | ||
.0 | ||
} else { | ||
// Bit weird but makes Rust happy | ||
if let Some(first) = parts_iter.next() { | ||
let mut acc = part_to_type(first, environment, checking_data); | ||
let mut acc = part_to_type(&first, environment, checking_data); | ||
for rest in parts_iter { | ||
let other = part_to_type(rest, environment, checking_data); | ||
let other = part_to_type(&rest, environment, checking_data); | ||
let result = super::operations::evaluate_mathematical_operation( | ||
acc, | ||
crate::behavior::operations::MathematicalAndBitwise::Add, | ||
|
@@ -125,14 +127,14 @@ where | |
); | ||
match result { | ||
Ok(result) => acc = result, | ||
Err(_) => { | ||
Err(()) => { | ||
crate::utils::notify!("Invalid template literal concatenation"); | ||
} | ||
} | ||
} | ||
acc | ||
} else { | ||
checking_data.types.new_constant_type(Constant::String("".into())) | ||
checking_data.types.new_constant_type(Constant::String(String::new())) | ||
} | ||
} | ||
} |
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.
Interesting. I haven't had much experience with
#[must_use]
. Is there a heuristic for when to it is needed? Was there any code that didn't use this result?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.
According to this (old) reddit post by one of clippy maintainer here is how they decide which function should be marked with
#[must_use]
. Also, a lot of people were complaining about false positive, but it looks like it has been fixed and is working pretty well now.After adding
#[must_use]
, there was no additional error, so I guess everything was used