Skip to content

Commit edd709e

Browse files
Applying Clippy to small parts of the repo. (#316)
* Clippy changes. * More clippy changes.
1 parent ce9e665 commit edd709e

File tree

16 files changed

+175
-219
lines changed

16 files changed

+175
-219
lines changed

core_lang/src/build_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl BuildConfig {
2020
let mut path = canonicalized_manifest_path.clone();
2121
path.push("src");
2222
Self {
23-
file_name: file_name,
23+
file_name,
2424
dir_of_code: path,
2525
manifest_path: canonicalized_manifest_path,
2626
print_intermediate_asm: false,

core_lang/src/error.rs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use source_span::{
77
fmt::{Formatter, Style},
88
Position,
99
};
10+
use std::fmt;
1011
use thiserror::Error;
1112

1213
macro_rules! check {
@@ -223,83 +224,99 @@ pub enum Warning<'sc> {
223224
},
224225
}
225226

226-
impl<'sc> Warning<'sc> {
227-
fn to_string(&self) -> String {
227+
impl<'sc> fmt::Display for Warning<'sc> {
228+
// This trait requires `fmt` with this exact signature.
229+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
228230
use Warning::*;
229231
match self {
230-
NonClassCaseStructName { struct_name } => format!(
232+
NonClassCaseStructName { struct_name } => {
233+
write!(f,
231234
"Struct name \"{}\" is not idiomatic. Structs should have a ClassCase name, like \
232235
\"{}\".",
233236
struct_name,
234237
to_class_case(struct_name)
235-
),
236-
NonClassCaseTraitName { name } => format!(
238+
)
239+
}
240+
NonClassCaseTraitName { name } => {
241+
write!(f,
237242
"Trait name \"{}\" is not idiomatic. Traits should have a ClassCase name, like \
238243
\"{}\".",
239244
name,
240245
to_class_case(name)
241-
),
242-
NonClassCaseEnumName { enum_name } => format!(
246+
)
247+
}
248+
NonClassCaseEnumName { enum_name } => write!(
249+
f,
243250
"Enum \"{}\"'s capitalization is not idiomatic. Enums should have a ClassCase \
244251
name, like \"{}\".",
245252
enum_name,
246253
to_class_case(enum_name)
247254
),
248-
NonSnakeCaseStructFieldName { field_name } => format!(
255+
NonSnakeCaseStructFieldName { field_name } => write!(
256+
f,
249257
"Struct field name \"{}\" is not idiomatic. Struct field names should have a \
250258
snake_case name, like \"{}\".",
251259
field_name,
252260
to_snake_case(field_name)
253261
),
254-
NonClassCaseEnumVariantName { variant_name } => format!(
262+
NonClassCaseEnumVariantName { variant_name } => write!(
263+
f,
255264
"Enum variant name \"{}\" is not idiomatic. Enum variant names should be \
256265
ClassCase, like \"{}\".",
257266
variant_name,
258267
to_class_case(variant_name)
259268
),
260-
NonSnakeCaseFunctionName { name } => format!(
269+
NonSnakeCaseFunctionName { name } => {
270+
write!(f,
261271
"Function name \"{}\" is not idiomatic. Function names should be snake_case, like \
262272
\"{}\".",
263273
name,
264274
to_snake_case(name)
265-
),
275+
)
276+
}
266277
LossOfPrecision {
267278
initial_type,
268279
cast_to,
269-
} => format!(
280+
} => write!(
281+
f,
270282
"This cast, from type {} to type {}, will lose precision.",
271283
initial_type.friendly_type_str(),
272284
cast_to.friendly_type_str()
273285
),
274-
UnusedReturnValue { r#type } => format!(
286+
UnusedReturnValue { r#type } => write!(
287+
f,
275288
"This returns a value of type {}, which is not assigned to anything and is \
276289
ignored.",
277290
r#type.friendly_type_str()
278291
),
279-
SimilarMethodFound { lib, module, name } => format!(
292+
SimilarMethodFound { lib, module, name } => write!(
293+
f,
280294
"A method with the same name was found for type {} in dependency \"{}::{}\". \
281295
Traits must be in scope in order to access their methods. ",
282296
name, lib, module
283297
),
284-
OverridesOtherSymbol { name } => format!(
298+
OverridesOtherSymbol { name } => write!(
299+
f,
285300
"This import would override another symbol with the same name \"{}\" in this \
286301
namespace.",
287302
name
288303
),
289-
OverridingTraitImplementation => format!(
304+
OverridingTraitImplementation => write!(
305+
f,
290306
"This trait implementation overrides another one that was previously defined."
291307
),
292-
DeadDeclaration => "This declaration is never used.".into(),
293-
DeadStructDeclaration => "This struct is never instantiated.".into(),
294-
DeadFunctionDeclaration => "This function is never called.".into(),
295-
UnreachableCode => "This code is unreachable.".into(),
308+
DeadDeclaration => write!(f, "This declaration is never used."),
309+
DeadStructDeclaration => write!(f, "This struct is never instantiated."),
310+
DeadFunctionDeclaration => write!(f, "This function is never called."),
311+
UnreachableCode => write!(f, "This code is unreachable."),
296312
DeadEnumVariant { variant_name } => {
297-
format!("Enum variant {} is never constructed.", variant_name)
313+
write!(f, "Enum variant {} is never constructed.", variant_name)
298314
}
299-
DeadTrait => "This trait is never implemented.".into(),
300-
DeadMethod => "This method is never called.".into(),
301-
StructFieldNeverRead => "This struct field is never accessed.".into(),
302-
ShadowingReservedRegister { reg_name } => format!(
315+
DeadTrait => write!(f, "This trait is never implemented."),
316+
DeadMethod => write!(f, "This method is never called."),
317+
StructFieldNeverRead => write!(f, "This struct field is never accessed."),
318+
ShadowingReservedRegister { reg_name } => write!(
319+
f,
303320
"This register declaration shadows the reserved register, \"{}\".",
304321
reg_name
305322
),
@@ -1043,6 +1060,6 @@ impl<'sc> CompileError<'sc> {
10431060
let err_start = Position::new(start_line - 1, start_col - 1);
10441061
let err_end = Position::new(end_line - 1, end_col - 1);
10451062
let err_span = source_span::Span::new(err_start, err_end, err_end.next_column());
1046-
fmt.add(err_span, Some(friendly_string.clone()), style);
1063+
fmt.add(err_span, Some(friendly_string), style);
10471064
}
10481065
}

core_lang/src/ident.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ impl<'sc> Ident<'sc> {
3535
pair: Pair<'sc, Rule>,
3636
config: Option<&BuildConfig>,
3737
) -> CompileResult<'sc, Ident<'sc>> {
38-
let path = if let Some(config) = config {
39-
Some(config.path())
40-
} else {
41-
None
42-
};
38+
let path = config.map(|config| config.path());
4339
let span = {
4440
let pair = pair.clone();
4541
if pair.as_rule() != Rule::ident {

core_lang/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ fn parse_root_from_pairs<'sc>(
562562
Rule::docstring => {
563563
let docstring = decl_inner.as_str().to_string().split_off(3);
564564
let docstring = docstring.as_str().trim();
565-
unassigned_docstring.push_str("\n");
565+
unassigned_docstring.push('\n');
566566
unassigned_docstring.push_str(docstring);
567567
}
568568
_ => {

core_lang/src/parse_tree/declaration/abi_declaration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'sc> AbiDeclaration<'sc> {
5353
warnings,
5454
errors
5555
);
56-
let fn_sig_name = fn_sig.name.primary_name.clone();
56+
let fn_sig_name = fn_sig.name.primary_name;
5757
interface_surface.push(fn_sig);
5858
if !unassigned_docstring.is_empty() {
5959
docstrings.insert(
@@ -72,7 +72,7 @@ impl<'sc> AbiDeclaration<'sc> {
7272
Rule::docstring => {
7373
let docstring = func.as_str().to_string().split_off(3);
7474
let docstring = docstring.as_str().trim();
75-
unassigned_docstring.push_str("\n");
75+
unassigned_docstring.push('\n');
7676
unassigned_docstring.push_str(docstring);
7777
}
7878
x => unreachable!("guaranteed to not be here: {:?}", x),

core_lang/src/parse_tree/declaration/struct_declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'sc> StructField<'sc> {
164164
warnings,
165165
span.clone(),
166166
Warning::NonSnakeCaseStructFieldName {
167-
field_name: name.primary_name.clone()
167+
field_name: name.primary_name
168168
}
169169
);
170170
let r#type = check!(

0 commit comments

Comments
 (0)