Skip to content

Commit 7235ab4

Browse files
authored
Bump Rust to 1.89 (#8007)
Rust pointed out that our PartialEq derive on StdFn can return arbitrary/unintended results, but I don't think it matter much for now. Clippy has collapsed multiple nested if expressions into a single if using if-let chaining, which recently stabilized.
1 parent 9445feb commit 7235ab4

26 files changed

+318
-350
lines changed

rust/kcl-lib/src/docs/gen_std_tests.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ fn init_handlebars() -> Result<handlebars::Handlebars<'static>> {
4343
_: &mut handlebars::RenderContext,
4444
out: &mut dyn handlebars::Output|
4545
-> handlebars::HelperResult {
46-
if let Some(param) = h.param(0) {
47-
if let Some(string) = param.value().as_str() {
48-
// Only get the first part before the newline.
49-
// This is to prevent the YAML from breaking.
50-
let string = string.split('\n').next().unwrap_or("");
51-
out.write(string)?;
52-
return Ok(());
53-
}
46+
if let Some(param) = h.param(0)
47+
&& let Some(string) = param.value().as_str()
48+
{
49+
// Only get the first part before the newline.
50+
// This is to prevent the YAML from breaking.
51+
let string = string.split('\n').next().unwrap_or("");
52+
out.write(string)?;
53+
return Ok(());
5454
}
5555
out.write("")?;
5656
Ok(())
@@ -362,10 +362,11 @@ fn generate_function_from_kcl(
362362
fn docs_for_type(ty: &str, kcl_std: &ModData) -> Option<String> {
363363
let key = if ty.starts_with("number") { "number" } else { ty };
364364

365-
if !key.contains('|') && !key.contains('[') {
366-
if let Some(data) = kcl_std.find_by_name(key) {
367-
return data.summary().cloned();
368-
}
365+
if !key.contains('|')
366+
&& !key.contains('[')
367+
&& let Some(data) = kcl_std.find_by_name(key)
368+
{
369+
return data.summary().cloned();
369370
}
370371

371372
None

rust/kcl-lib/src/docs/kcl_doc.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ impl ModData {
476476

477477
#[allow(clippy::iter_over_hash_type)]
478478
for (k, v) in &self.children {
479-
if k.starts_with("M:") {
480-
if let Some(result) = v.expect_mod().find_by_name(name) {
481-
return Some(result);
482-
}
479+
if k.starts_with("M:")
480+
&& let Some(result) = v.expect_mod().find_by_name(name)
481+
{
482+
return Some(result);
483483
}
484484
}
485485

@@ -1069,10 +1069,10 @@ trait ApplyMeta {
10691069
}
10701070
}
10711071
assert!(example.is_none());
1072-
if let Some(d) = &mut description {
1073-
if d.is_empty() {
1074-
description = None;
1075-
}
1072+
if let Some(d) = &mut description
1073+
&& d.is_empty()
1074+
{
1075+
description = None;
10761076
}
10771077

10781078
self.apply_docs(
@@ -1251,15 +1251,15 @@ mod test {
12511251
#[test]
12521252
fn smoke() {
12531253
let result = walk_prelude();
1254-
if let DocData::Const(d) = result.find_by_name("PI").unwrap() {
1255-
if d.name == "PI" {
1256-
assert!(d.value.as_ref().unwrap().starts_with('3'));
1257-
assert_eq!(d.ty, Some("number(_?)".to_owned()));
1258-
assert_eq!(d.qual_name, "std::math::PI");
1259-
assert!(d.summary.is_some());
1260-
assert!(!d.examples.is_empty());
1261-
return;
1262-
}
1254+
if let DocData::Const(d) = result.find_by_name("PI").unwrap()
1255+
&& d.name == "PI"
1256+
{
1257+
assert!(d.value.as_ref().unwrap().starts_with('3'));
1258+
assert_eq!(d.ty, Some("number(_?)".to_owned()));
1259+
assert_eq!(d.qual_name, "std::math::PI");
1260+
assert!(d.summary.is_some());
1261+
assert!(!d.examples.is_empty());
1262+
return;
12631263
}
12641264
panic!("didn't find PI");
12651265
}

rust/kcl-lib/src/engine/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,14 @@ pub fn new_zoo_client(token: Option<String>, engine_addr: Option<String>) -> any
892892
let token = if let Some(token) = token {
893893
token
894894
} else if let Ok(token) = std::env::var("KITTYCAD_API_TOKEN") {
895-
if let Ok(zoo_token) = zoo_token_env {
896-
if zoo_token != token {
897-
return Err(anyhow::anyhow!(
898-
"Both environment variables KITTYCAD_API_TOKEN=`{}` and ZOO_API_TOKEN=`{}` are set. Use only one.",
899-
token,
900-
zoo_token
901-
));
902-
}
895+
if let Ok(zoo_token) = zoo_token_env
896+
&& zoo_token != token
897+
{
898+
return Err(anyhow::anyhow!(
899+
"Both environment variables KITTYCAD_API_TOKEN=`{}` and ZOO_API_TOKEN=`{}` are set. Use only one.",
900+
token,
901+
zoo_token
902+
));
903903
}
904904
token
905905
} else if let Ok(token) = zoo_token_env {
@@ -917,14 +917,14 @@ pub fn new_zoo_client(token: Option<String>, engine_addr: Option<String>) -> any
917917
if let Some(addr) = engine_addr {
918918
client.set_base_url(addr);
919919
} else if let Ok(addr) = std::env::var("ZOO_HOST") {
920-
if let Ok(kittycad_host) = kittycad_host_env {
921-
if kittycad_host != addr {
922-
return Err(anyhow::anyhow!(
923-
"Both environment variables KITTYCAD_HOST=`{}` and ZOO_HOST=`{}` are set. Use only one.",
924-
kittycad_host,
925-
addr
926-
));
927-
}
920+
if let Ok(kittycad_host) = kittycad_host_env
921+
&& kittycad_host != addr
922+
{
923+
return Err(anyhow::anyhow!(
924+
"Both environment variables KITTYCAD_HOST=`{}` and ZOO_HOST=`{}` are set. Use only one.",
925+
kittycad_host,
926+
addr
927+
));
928928
}
929929
client.set_base_url(addr);
930930
} else if let Ok(addr) = kittycad_host_env {

rust/kcl-lib/src/execution/annotations.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ pub(super) fn expect_properties<'a>(
9999
}
100100

101101
pub(super) fn expect_ident(expr: &Expr) -> Result<&str, KclError> {
102-
if let Expr::Name(name) = expr {
103-
if let Some(name) = name.local_ident() {
104-
return Ok(*name);
105-
}
102+
if let Expr::Name(name) = expr
103+
&& let Some(name) = name.local_ident()
104+
{
105+
return Ok(*name);
106106
}
107107

108108
Err(KclError::new_semantic(KclErrorDetails::new(
@@ -132,11 +132,11 @@ pub(super) fn many_of(
132132
Expr::ArrayExpression(e) => {
133133
let mut result = Vec::new();
134134
for e in &e.elements {
135-
if let Expr::Name(name) = e {
136-
if let Some(name) = name.local_ident() {
137-
result.push(*name);
138-
continue;
139-
}
135+
if let Expr::Name(name) = e
136+
&& let Some(name) = name.local_ident()
137+
{
138+
result.push(*name);
139+
continue;
140140
}
141141
return Err(KclError::new_semantic(KclErrorDetails::new(
142142
UNEXPECTED_MSG.to_owned(),
@@ -171,10 +171,10 @@ pub(super) fn many_of(
171171

172172
// Returns the unparsed number literal.
173173
pub(super) fn expect_number(expr: &Expr) -> Result<String, KclError> {
174-
if let Expr::Literal(lit) = expr {
175-
if let LiteralValue::Number { .. } = &lit.value {
176-
return Ok(lit.raw.clone());
177-
}
174+
if let Expr::Literal(lit) = expr
175+
&& let LiteralValue::Number { .. } = &lit.value
176+
{
177+
return Ok(lit.raw.clone());
178178
}
179179

180180
Err(KclError::new_semantic(KclErrorDetails::new(
@@ -189,19 +189,19 @@ pub(super) fn get_impl(annotations: &[Node<Annotation>], source_range: SourceRan
189189
continue;
190190
}
191191
for p in attr.properties.as_ref().unwrap() {
192-
if &*p.key.name == IMPL {
193-
if let Some(s) = p.value.ident_name() {
194-
return Impl::from_str(s).map(Some).map_err(|_| {
195-
KclError::new_semantic(KclErrorDetails::new(
196-
format!(
197-
"Invalid value for {} attribute, expected one of: {}",
198-
IMPL,
199-
IMPL_VALUES.join(", ")
200-
),
201-
vec![source_range],
202-
))
203-
});
204-
}
192+
if &*p.key.name == IMPL
193+
&& let Some(s) = p.value.ident_name()
194+
{
195+
return Impl::from_str(s).map(Some).map_err(|_| {
196+
KclError::new_semantic(KclErrorDetails::new(
197+
format!(
198+
"Invalid value for {} attribute, expected one of: {}",
199+
IMPL,
200+
IMPL_VALUES.join(", ")
201+
),
202+
vec![source_range],
203+
))
204+
});
205205
}
206206
}
207207
}

rust/kcl-lib/src/execution/artifact.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,10 @@ pub(super) fn build_artifact_graph(
588588
// current plane ID.
589589
// THIS IS THE ONLY THING WE CAN ASSUME IS ALWAYS SEQUENTIAL SINCE ITS PART OF THE
590590
// SAME ATOMIC COMMANDS BATCHING.
591-
if let ModelingCmd::StartPath(_) = artifact_command.command {
592-
if let Some(plane_id) = current_plane_id {
593-
path_to_plane_id_map.insert(artifact_command.cmd_id, plane_id);
594-
}
591+
if let ModelingCmd::StartPath(_) = artifact_command.command
592+
&& let Some(plane_id) = current_plane_id
593+
{
594+
path_to_plane_id_map.insert(artifact_command.cmd_id, plane_id);
595595
}
596596
if let ModelingCmd::SketchModeDisable(_) = artifact_command.command {
597597
current_plane_id = None;

rust/kcl-lib/src/execution/exec_ast.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,15 +1198,14 @@ impl Node<BinaryExpression> {
11981198
meta.extend(right_value.metadata());
11991199

12001200
// First check if we are doing string concatenation.
1201-
if self.operator == BinaryOperator::Add {
1202-
if let (KclValue::String { value: left, meta: _ }, KclValue::String { value: right, meta: _ }) =
1201+
if self.operator == BinaryOperator::Add
1202+
&& let (KclValue::String { value: left, meta: _ }, KclValue::String { value: right, meta: _ }) =
12031203
(&left_value, &right_value)
1204-
{
1205-
return Ok(KclValue::String {
1206-
value: format!("{left}{right}"),
1207-
meta,
1208-
});
1209-
}
1204+
{
1205+
return Ok(KclValue::String {
1206+
value: format!("{left}{right}"),
1207+
meta,
1208+
});
12101209
}
12111210

12121211
// Then check if we have solids.

rust/kcl-lib/src/execution/fn_call.rs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ impl FunctionDefinition<'_> {
383383
exec_state.push_op(Operation::GroupEnd);
384384
}
385385

386-
if self.is_std {
387-
if let Ok(Some(result)) = &mut result {
388-
update_memory_for_tags_of_geometry(result, exec_state)?;
389-
}
386+
if self.is_std
387+
&& let Ok(Some(result)) = &mut result
388+
{
389+
update_memory_for_tags_of_geometry(result, exec_state)?;
390390
}
391391

392392
coerce_result_type(result, self, exec_state)
@@ -581,25 +581,25 @@ fn type_check_params_kw(
581581
) -> Result<(), KclError> {
582582
// If it's possible the input arg was meant to be labelled and we probably don't want to use
583583
// it as the input arg, then treat it as labelled.
584-
if let Some((Some(label), _)) = &args.unlabeled {
585-
if (fn_def.input_arg.is_none() || exec_state.pipe_value().is_some())
586-
&& fn_def.named_args.iter().any(|p| p.0 == label)
587-
&& !args.labeled.contains_key(label)
588-
{
589-
let (label, arg) = args.unlabeled.take().unwrap();
590-
args.labeled.insert(label.unwrap(), arg);
591-
}
584+
if let Some((Some(label), _)) = &args.unlabeled
585+
&& (fn_def.input_arg.is_none() || exec_state.pipe_value().is_some())
586+
&& fn_def.named_args.iter().any(|p| p.0 == label)
587+
&& !args.labeled.contains_key(label)
588+
{
589+
let (label, arg) = args.unlabeled.take().unwrap();
590+
args.labeled.insert(label.unwrap(), arg);
592591
}
593592

594593
for (label, arg) in &mut args.labeled {
595594
match fn_def.named_args.get(label) {
596595
Some((def, ty)) => {
597596
// For optional args, passing None should be the same as not passing an arg.
598-
if !(def.is_some() && matches!(arg.value, KclValue::KclNone { .. })) {
599-
if let Some(ty) = ty {
600-
let rty = RuntimeType::from_parsed(ty.clone(), exec_state, arg.source_range)
601-
.map_err(|e| KclError::new_semantic(e.into()))?;
602-
arg.value = arg
597+
if !(def.is_some() && matches!(arg.value, KclValue::KclNone { .. }))
598+
&& let Some(ty) = ty
599+
{
600+
let rty = RuntimeType::from_parsed(ty.clone(), exec_state, arg.source_range)
601+
.map_err(|e| KclError::new_semantic(e.into()))?;
602+
arg.value = arg
603603
.value
604604
.coerce(
605605
&rty,
@@ -620,7 +620,6 @@ fn type_check_params_kw(
620620
vec![arg.source_range],
621621
))
622622
})?;
623-
}
624623
}
625624
}
626625
None => {
@@ -687,18 +686,18 @@ fn type_check_params_kw(
687686
))
688687
})?;
689688
}
690-
} else if let Some((name, _)) = &fn_def.input_arg {
691-
if let Some(arg) = args.labeled.get(name) {
692-
exec_state.err(CompilationError::err(
693-
arg.source_range,
694-
format!(
695-
"{} expects an unlabeled first argument (`@{name}`), but it is labelled in the call",
696-
fn_name
697-
.map(|n| format!("The function `{n}`"))
698-
.unwrap_or_else(|| "This function".to_owned()),
699-
),
700-
));
701-
}
689+
} else if let Some((name, _)) = &fn_def.input_arg
690+
&& let Some(arg) = args.labeled.get(name)
691+
{
692+
exec_state.err(CompilationError::err(
693+
arg.source_range,
694+
format!(
695+
"{} expects an unlabeled first argument (`@{name}`), but it is labelled in the call",
696+
fn_name
697+
.map(|n| format!("The function `{n}`"))
698+
.unwrap_or_else(|| "This function".to_owned()),
699+
),
700+
));
702701
}
703702

704703
Ok(())

rust/kcl-lib/src/execution/geometry.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,41 +1283,6 @@ pub enum Path {
12831283
},
12841284
}
12851285

1286-
/// What kind of path is this?
1287-
#[derive(Display)]
1288-
enum PathType {
1289-
ToPoint,
1290-
Base,
1291-
TangentialArc,
1292-
TangentialArcTo,
1293-
Circle,
1294-
CircleThreePoint,
1295-
Horizontal,
1296-
AngledLineTo,
1297-
Arc,
1298-
Ellipse,
1299-
Conic,
1300-
}
1301-
1302-
impl From<&Path> for PathType {
1303-
fn from(value: &Path) -> Self {
1304-
match value {
1305-
Path::ToPoint { .. } => Self::ToPoint,
1306-
Path::TangentialArcTo { .. } => Self::TangentialArcTo,
1307-
Path::TangentialArc { .. } => Self::TangentialArc,
1308-
Path::Circle { .. } => Self::Circle,
1309-
Path::CircleThreePoint { .. } => Self::CircleThreePoint,
1310-
Path::Horizontal { .. } => Self::Horizontal,
1311-
Path::AngledLineTo { .. } => Self::AngledLineTo,
1312-
Path::Base { .. } => Self::Base,
1313-
Path::Arc { .. } => Self::Arc,
1314-
Path::ArcThreePoint { .. } => Self::Arc,
1315-
Path::Ellipse { .. } => Self::Ellipse,
1316-
Path::Conic { .. } => Self::Conic,
1317-
}
1318-
}
1319-
}
1320-
13211286
impl Path {
13221287
pub fn get_id(&self) -> uuid::Uuid {
13231288
match self {

0 commit comments

Comments
 (0)