compiler-cli
compiler-core
language-server
···
19
19
pub fn command(paths: &ProjectPaths, packages_to_add: Vec<String>, dev: bool) -> Result<()> {
20
20
let config = crate::config::root_config(paths)?;
21
21
if packages_to_add.iter().any(|name| name == &config.name) {
22
22
-
return Err(Error::CannotAddSelfAsDependency {
23
23
-
name: config.name.clone(),
24
24
-
});
22
22
+
return Err(Error::CannotAddSelfAsDependency { name: config.name });
25
23
}
26
24
27
25
let mut new_package_requirements = Vec::with_capacity(packages_to_add.len());
···
90
90
91
91
// Get the manifest packages and add the root package to the vec
92
92
let mut packages = manifest.packages.iter().cloned().collect_vec();
93
93
-
packages.append(&mut vec![root_package.clone()]);
93
93
+
packages.push(root_package);
94
94
95
95
list_package_and_dependencies_tree(std::io::stdout(), options, packages.clone(), config.name)
96
96
}
···
148
148
149
149
if let Some(package) = package {
150
150
let tree = Vec::from([eco_format!("{0} v{1}", package.name, package.version)]);
151
151
-
let tree = list_dependencies_tree(
152
152
-
tree.clone(),
153
153
-
package.clone(),
154
154
-
packages,
155
155
-
EcoString::new(),
156
156
-
invert,
157
157
-
);
151
151
+
let tree =
152
152
+
list_dependencies_tree(tree, package.clone(), packages, EcoString::new(), invert);
158
153
159
154
tree.iter()
160
155
.try_for_each(|line| writeln!(buffer, "{line}"))
···
161
161
if password.chars().count() < required_length {
162
162
println!("\nPlease use a password at least {required_length} characters long.\n")
163
163
} else {
164
164
-
self.local_password = Some(password.clone());
164
164
+
self.local_password = Some(password);
165
165
return Ok(());
166
166
}
167
167
}
···
3
3
4
4
#![warn(
5
5
clippy::all,
6
6
+
clippy::redundant_clone,
6
7
clippy::dbg_macro,
7
8
clippy::todo,
8
9
clippy::mem_forget,
···
1337
1337
shared_accessors,
1338
1338
// TODO: improve the ownership here so that we can use the
1339
1339
// `return_type_constructor` below rather than looking it up twice.
1340
1340
-
type_: type_.clone(),
1340
1340
+
type_,
1341
1341
variant_specific_accessors,
1342
1342
variant_positional_accessors: positional_accessors,
1343
1343
};
···
1880
1880
deprecation,
1881
1881
implementations,
1882
1882
} = constant;
1883
1883
-
let type_ = type_.clone();
1884
1883
let type_ = type_::generalise(type_);
1885
1884
let variant = ValueConstructorVariant::ModuleConstant {
1886
1885
documentation: doc.as_ref().map(|(_, doc)| doc.clone()),
···
583
583
if let Some(arg) = arguments
584
584
.iter()
585
585
.zip(arg_types)
586
586
-
.find_map(|(arg, arg_type)| arg.find_node(byte_index, arg_type.clone()))
586
586
+
.find_map(|(arg, arg_type)| arg.find_node(byte_index, arg_type))
587
587
{
588
588
return Some(arg);
589
589
}
···
604
604
if let Some(arg) = arguments
605
605
.iter()
606
606
.zip(arg_types)
607
607
-
.find_map(|(arg, arg_type)| arg.find_node(byte_index, arg_type.clone()))
607
607
+
.find_map(|(arg, arg_type)| arg.find_node(byte_index, arg_type))
608
608
{
609
609
return Some(arg);
610
610
}
···
634
634
if let Some(e) = elements
635
635
.iter()
636
636
.zip(elem_types)
637
637
-
.find_map(|(e, e_type)| e.find_node(byte_index, e_type.clone()))
637
637
+
.find_map(|(e, e_type)| e.find_node(byte_index, e_type))
638
638
{
639
639
return Some(e);
640
640
}
···
1090
1090
.cloned(),
1091
1091
);
1092
1092
}
1093
1093
-
v.visit_type_ast(return_, return_type.clone());
1093
1093
+
v.visit_type_ast(return_, return_type);
1094
1094
}
1095
1095
1096
1096
pub fn visit_type_ast_var<'a, V>(_v: &mut V, _location: &'a SrcSpan, _name: &'a EcoString)
···
1519
1519
}
1520
1520
}
1521
1521
if let Some(return_) = return_annotation {
1522
1522
-
v.visit_type_ast(
1523
1523
-
return_,
1524
1524
-
type_.fn_types().map(|(_, return_)| return_.clone()),
1525
1525
-
);
1522
1522
+
v.visit_type_ast(return_, type_.fn_types().map(|(_, return_)| return_));
1526
1523
}
1527
1524
1528
1525
for statement in body {
···
302
302
Version::parse(COMPILER_VERSION).expect("Parse compiler semantic version");
303
303
304
304
// We ignore the pre-release and build metadata when checking compatibility
305
305
-
let mut version_without_pre = compiler_version.clone();
305
305
+
let mut version_without_pre = compiler_version;
306
306
version_without_pre.pre = vec![];
307
307
version_without_pre.build = None;
308
308
if !range.contains(&version_without_pre) {
···
125
125
.chain(repo_link)
126
126
.chain([Link {
127
127
name: "Hex".into(),
128
128
-
path: format!("https://hex.pm/packages/{0}", config.name).to_string(),
128
128
+
path: format!("https://hex.pm/packages/{0}", config.name),
129
129
}])
130
130
.collect(),
131
131
DocContext::Build => doc_links.chain(repo_link).collect(),
···
338
338
339
339
files.push(OutputFile {
340
340
path: Utf8PathBuf::from("search-data.json"),
341
341
-
content: Content::Text(search_data_json.to_string()),
341
341
+
content: Content::Text(search_data_json),
342
342
});
343
343
344
344
files.push(OutputFile {
···
8
8
passphrase: &str,
9
9
) -> Result<String, age::EncryptError> {
10
10
let passphrase = age::secrecy::SecretString::from(passphrase);
11
11
-
let recipient = age::scrypt::Recipient::new(passphrase.clone());
11
11
+
let recipient = age::scrypt::Recipient::new(passphrase);
12
12
13
13
let encrypted = age::encrypt_and_armor(&recipient, message)?;
14
14
···
251
251
rest: _,
252
252
} => {
253
253
if let Some(variable) = std::mem::take(prefix_name) {
254
254
-
self.body
255
255
-
.assign_literal_string(variable.clone(), prefix.clone());
254
254
+
self.body.assign_literal_string(variable, prefix.clone());
256
255
}
257
256
return true;
258
257
}
···
2563
2562
branch_mode: &BranchMode,
2564
2563
) -> RuntimeCheck {
2565
2564
match (kind, branch_mode) {
2566
2566
-
(RuntimeCheckKind::Int { int_value }, _) => RuntimeCheck::Int {
2567
2567
-
int_value: int_value.clone(),
2568
2568
-
},
2565
2565
+
(RuntimeCheckKind::Int { int_value }, _) => RuntimeCheck::Int { int_value },
2569
2566
(RuntimeCheckKind::Float { float_value }, _) => RuntimeCheck::Float { float_value },
2570
2570
-
(RuntimeCheckKind::String { value }, _) => RuntimeCheck::String {
2571
2571
-
value: value.clone(),
2572
2572
-
},
2567
2567
+
(RuntimeCheckKind::String { value }, _) => RuntimeCheck::String { value },
2573
2568
(RuntimeCheckKind::StringPrefix { prefix }, _) => RuntimeCheck::StringPrefix {
2574
2574
-
prefix: prefix.clone(),
2569
2569
+
prefix,
2575
2570
rest: self.fresh_variable(string()),
2576
2571
},
2577
2572
(RuntimeCheckKind::Tuple { .. }, BranchMode::Tuple { elements }) => {
···
145
145
let output_path = format!("{module_name}.mjs");
146
146
let module_alias = module_name.split('/').next_back().unwrap_or(&module_name);
147
147
let input_path = format!("{module_alias}.gleam",);
148
148
-
let mut source_map_builder =
149
149
-
sourcemap::SourceMapBuilder::new(Some(&output_path.clone()));
148
148
+
let mut source_map_builder = sourcemap::SourceMapBuilder::new(Some(&output_path));
150
149
let _ = source_map_builder.add_source(&input_path);
151
150
Some(Rc::new(RefCell::new(DebugIgnore(source_map_builder))))
152
151
} else {
···
1292
1292
};
1293
1293
1294
1294
match self.variable_assignment {
1295
1295
-
VariableAssignment::Declare => {
1296
1296
-
let_doc(arena, local_variable_name.clone(), assigned_value)
1297
1297
-
}
1295
1295
+
VariableAssignment::Declare => let_doc(arena, local_variable_name, assigned_value),
1298
1296
VariableAssignment::Reassign => {
1299
1299
-
reassignment_doc(arena, local_variable_name.clone(), assigned_value)
1297
1297
+
reassignment_doc(arena, local_variable_name, assigned_value)
1300
1298
}
1301
1299
}
1302
1300
}
···
3
3
4
4
#![warn(
5
5
clippy::all,
6
6
+
clippy::redundant_clone,
6
7
clippy::dbg_macro,
7
8
clippy::todo,
8
9
clippy::mem_forget,
···
3727
3727
match self.parse_const_value()? {
3728
3728
Some(value) if value.location() == SrcSpan { start, end } => {
3729
3729
return Ok(Some(RecordUpdateArg {
3730
3730
-
label: name.clone(),
3730
3730
+
label: name,
3731
3731
location: SrcSpan { start, end },
3732
3732
value,
3733
3733
}));
···
1084
1084
// of the function, in which case accept the extra link.
1085
1085
if let Ok(mut type_) = type_.try_borrow_mut() {
1086
1086
*type_ = TypeVar::Link {
1087
1087
-
type_: collapse_links(t.clone()),
1087
1087
+
type_: collapse_links(t),
1088
1088
}
1089
1089
}
1090
1090
Ok(())
···
1508
1508
)),
1509
1509
) => {
1510
1510
self.problems.error(Error::UnknownModuleValue {
1511
1511
-
name: name.clone(),
1511
1511
+
name,
1512
1512
module_name: module_name.clone(),
1513
1513
location,
1514
1514
value_constructors,
···
1926
1926
let left = self.infer(left);
1927
1927
let right = self.infer(right);
1928
1928
let unify_left = unify(input_type.clone(), left.type_());
1929
1929
-
let unify_right = unify(input_type.clone(), right.type_());
1929
1929
+
let unify_right = unify(input_type, right.type_());
1930
1930
1931
1931
if unify_left.is_ok() && unify_right.is_ok() {
1932
1932
// We only want to warn for redundant comparisons if it makes sense
···
2145
2145
} = assignment;
2146
2146
let value = self.expr_in_new_scope(|this| this.infer(value));
2147
2147
let type_ = value.type_();
2148
2148
-
let kind = self.infer_assignment_kind(kind.clone());
2148
2148
+
let kind = self.infer_assignment_kind(kind);
2149
2149
2150
2150
// Ensure the pattern matches the type of the value
2151
2151
let mut pattern_typer = pattern::PatternTyper::new(
···
2172
2172
.map(|type_| self.instantiate(type_, &mut hashmap![]))
2173
2173
{
2174
2174
Ok(annotated_type) => {
2175
2175
-
if let Err(error) = unify(annotated_type, type_.clone())
2175
2175
+
if let Err(error) = unify(annotated_type, type_)
2176
2176
.map_err(|e| convert_unify_error(e, value.type_defining_location()))
2177
2177
{
2178
2178
self.problems.error(error);
···
2606
2606
// so the whole expression has to be inferred as a regular
2607
2607
// record access.
2608
2608
Ok(variable) => {
2609
2609
-
self.infer_guard_record_access(variable, label.clone(), label_location)
2609
2609
+
self.infer_guard_record_access(variable, label, label_location)
2610
2610
}
2611
2611
}
2612
2612
} else {
2613
2613
// If it doesn't this has to be a regular record access and
2614
2614
// we try and infer it as such.
2615
2615
let inferred_container = self.infer_clause_guard(*container.clone());
2616
2616
-
self.infer_guard_record_access(
2617
2617
-
inferred_container,
2618
2618
-
label.clone(),
2619
2619
-
label_location,
2620
2620
-
)
2616
2616
+
self.infer_guard_record_access(inferred_container, label, label_location)
2621
2617
};
2622
2618
2623
2619
match result {
···
3133
3129
spread_start: u32,
3134
3130
) -> Result<TypedExpr, Error> {
3135
3131
// infer the constructor being used
3136
3136
-
let typed_constructor = self.infer_or_error(constructor.clone())?;
3132
3132
+
let typed_constructor = self.infer_or_error(constructor)?;
3137
3133
let (module, name) = match &typed_constructor {
3138
3134
TypedExpr::ModuleSelect {
3139
3135
module_alias,
···
4075
4071
} else {
4076
4072
self.problems.error(convert_unify_error(
4077
4073
UnifyError::CouldNotUnify {
4078
4078
-
expected: expected_type.clone(),
4074
4074
+
expected: expected_type,
4079
4075
given: typed_record_type,
4080
4076
situation: None,
4081
4077
},
···
4129
4125
} else {
4130
4126
self.problems.error(self.unknown_field_error(
4131
4127
field_map.fields.keys().cloned().collect(),
4132
4132
-
expected_type.clone(),
4128
4128
+
expected_type,
4133
4129
argument.location,
4134
4130
label.clone(),
4135
4131
FieldAccessUsage::Other,
···
4206
4202
Error::UnsafeRecordUpdate {
4207
4203
location: record.base.location(),
4208
4204
reason: UnsafeRecordUpdateReason::IncompatibleFieldTypes {
4209
4209
-
constructed_variant: expected_type.clone(),
4210
4210
-
record_variant: typed_record_type.clone(),
4205
4205
+
constructed_variant: expected_type,
4206
4206
+
record_variant: typed_record_type,
4211
4207
expected_field_type: expected,
4212
4208
record_field_type: given,
4213
4209
field,
···
4794
4790
arity: usize,
4795
4791
) -> TypedExpr {
4796
4792
match self.infer_var(
4797
4797
-
name.clone(),
4793
4793
+
name,
4798
4794
location,
4799
4795
ValueUsage::Call { arity },
4800
4796
ReferenceRegistration::Register,
···
209
209
Deprecation::Deprecated { message } => {
210
210
problems.warning(Warning::DeprecatedItem {
211
211
location: *location,
212
212
-
message: message.clone(),
212
212
+
message,
213
213
layer: Layer::Type,
214
214
})
215
215
}
···
151
151
name.clone(),
152
152
LocalVariable {
153
153
location,
154
154
-
origin: origin.clone(),
155
155
-
type_: type_.clone(),
154
154
+
origin,
155
155
+
type_,
156
156
usage: Usage::UnusedSoFar,
157
157
scope: Scope::CurrentBitArrayPattern,
158
158
},
···
805
805
};
806
806
self.insert_variable(
807
807
&name,
808
808
-
pattern.type_().clone(),
808
808
+
pattern.type_(),
809
809
location,
810
810
VariableOrigin {
811
811
syntax: VariableSyntax::AssignmentPattern(full_location),
···
1188
1188
Deprecation::Deprecated { message } => {
1189
1189
self.problems.warning(Warning::DeprecatedItem {
1190
1190
location,
1191
1191
-
message: message.clone(),
1191
1191
+
message,
1192
1192
layer: Layer::Value,
1193
1193
})
1194
1194
}
···
1215
1215
.instantiate(constructor_type, &mut hashmap![], self.hydrator);
1216
1216
match instantiated_constructor_type.deref() {
1217
1217
Type::Fn { arguments, return_ } => {
1218
1218
-
self.unify_types(type_.clone(), return_.clone(), location);
1218
1218
+
self.unify_types(type_, return_.clone(), location);
1219
1219
1220
1220
if let Some((variable_to_infer, inferred_variant)) =
1221
1221
subject_variable.zip(return_.custom_type_inferred_variant())
···
1597
1597
};
1598
1598
1599
1599
let unit = segment.unit();
1600
1600
-
let bits = size.clone() * unit;
1600
1600
+
let bits = size * unit;
1601
1601
1602
1602
// If the size is above the JS limit we raise a warning.
1603
1603
if bits > BigInt::from(52) {
···
208
208
209
209
/// Record a type variable in this module.
210
210
pub fn type_variable_in_scope(&mut self, id: u64, local_alias: EcoString) {
211
211
-
_ = self.type_variables.insert(id, local_alias.clone());
211
211
+
_ = self.type_variables.insert(id, local_alias);
212
212
}
213
213
214
214
/// Record an imported module in this module.
···
309
309
_ = self.local_value_constructors.remove_by_right(&local_alias);
310
310
_ = self
311
311
.local_value_constructors
312
312
-
.insert((module_name.clone(), value_name), local_alias.clone());
312
312
+
.insert((module_name, value_name), local_alias.clone());
313
313
}
314
314
315
315
/// Get the name and optional module qualifier for a named constructor.
···
1193
1193
) {
1194
1194
self.visit_typed_pattern(pattern);
1195
1195
if !name.starts_with('_') {
1196
1196
-
_ = self.variables.insert(name.clone(), pattern.type_().clone());
1196
1196
+
_ = self.variables.insert(name.clone(), pattern.type_());
1197
1197
}
1198
1198
}
1199
1199
}
···
2990
2990
} else if needs_space_before_callback {
2991
2991
format!(" {callback_start}")
2992
2992
} else {
2993
2993
-
callback_start.to_string()
2993
2993
+
callback_start
2994
2994
},
2995
2995
)
2996
2996
} else {
···
6693
6693
argument_names.generate_label_and_name(call_argument, argument_type);
6694
6694
let pretty_type = printer.print_type(argument_type);
6695
6695
if let Some(label) = label {
6696
6696
-
let label = label_names.rename_to_avoid_shadowing(label.clone());
6696
6696
+
let label = label_names.rename_to_avoid_shadowing(label);
6697
6697
format!("{label} {name}: {pretty_type}")
6698
6698
} else {
6699
6699
format!("{name}: {pretty_type}")
···
1619
1619
pattern: &'ast Pattern<Arc<Type>>,
1620
1620
) {
1621
1621
self.visit_typed_pattern(pattern);
1622
1622
-
self.push_completion(name, pattern.type_().clone());
1622
1622
+
self.push_completion(name, pattern.type_());
1623
1623
}
1624
1624
}
···
422
422
record_type,
423
423
..
424
424
} => {
425
425
-
completer.expected_type = Some(field_type.clone());
425
425
+
completer.expected_type = Some(field_type);
426
426
let mut completions = vec![];
427
427
completions.append(&mut completer.completion_values());
428
428
-
completions
429
429
-
.append(&mut completer.completion_field_accessors(record_type.clone()));
428
428
+
completions.append(&mut completer.completion_field_accessors(record_type));
430
429
Some(completions)
431
430
}
432
431
···
3
3
4
4
#![warn(
5
5
clippy::all,
6
6
+
clippy::redundant_clone,
6
7
clippy::dbg_macro,
7
8
clippy::todo,
8
9
clippy::mem_forget,