From 12cbfa4b38f037a410a69de00af19a400d5988ac Mon Sep 17 00:00:00 2001 From: John Lapeyre Date: Wed, 14 Feb 2024 19:32:51 -0500 Subject: [PATCH] * Fix clippy lint in test. Use suggestion * Widen acceptable versions of hashbrown * Use conditional compilation to choose more efficient implementation This allows rust 1.70 but gives no perf penalty for 1.75. There may well be another way around CI failure. --- crates/oq3_lexer/src/tests.rs | 10 +++++----- crates/oq3_semantics/Cargo.toml | 2 +- crates/oq3_syntax/Cargo.toml | 1 + crates/oq3_syntax/src/ptr.rs | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/oq3_lexer/src/tests.rs b/crates/oq3_lexer/src/tests.rs index 946e262..d2f2189 100644 --- a/crates/oq3_lexer/src/tests.rs +++ b/crates/oq3_lexer/src/tests.rs @@ -4,13 +4,13 @@ use super::*; use expect_test::{expect, Expect}; +use std::fmt::Write; -// FIXME: Probably do what clippy asks for here -#[allow(clippy::format_collect)] fn check_lexing(src: &str, expect: Expect) { - let actual: String = tokenize(src) - .map(|token| format!("{:?}\n", token)) - .collect(); + let actual: String = tokenize(src).fold(String::new(), |mut output, token| { + let _ = writeln!(output, "{token:?}"); + output + }); expect.assert_eq(&actual) } diff --git a/crates/oq3_semantics/Cargo.toml b/crates/oq3_semantics/Cargo.toml index 7bc01a9..51253c8 100644 --- a/crates/oq3_semantics/Cargo.toml +++ b/crates/oq3_semantics/Cargo.toml @@ -17,7 +17,7 @@ doctest = false [dependencies] oq3_source_file.workspace = true oq3_syntax.workspace = true -hashbrown = { version = "0.14" } +hashbrown = { version = "0.12.3" } rowan = "0.15.11" boolenum = "0.1" diff --git a/crates/oq3_syntax/Cargo.toml b/crates/oq3_syntax/Cargo.toml index a959b68..b8a11f3 100644 --- a/crates/oq3_syntax/Cargo.toml +++ b/crates/oq3_syntax/Cargo.toml @@ -27,6 +27,7 @@ smol_str = "0.2.0" stdx = { version = "0.0.188", package = "ra_ap_stdx"} triomphe = { version = "0.1.8", default-features = false, features = ["std"] } xshell = "0.2.2" +rustversion = "1.0" # local crates oq3_lexer.workspace = true oq3_parser.workspace = true diff --git a/crates/oq3_syntax/src/ptr.rs b/crates/oq3_syntax/src/ptr.rs index 5da617d..6921bd5 100644 --- a/crates/oq3_syntax/src/ptr.rs +++ b/crates/oq3_syntax/src/ptr.rs @@ -32,6 +32,14 @@ pub struct AstPtr { } impl Clone for AstPtr { + #[rustversion::before(1.74)] + fn clone(&self) -> AstPtr { + AstPtr { + raw: self.raw.clone(), + _ty: PhantomData, + } + } + #[rustversion::since(1.74)] fn clone(&self) -> AstPtr { AstPtr { raw: self.raw, @@ -67,10 +75,16 @@ impl AstPtr { N::cast(syntax_node).unwrap() } + #[rustversion::since(1.74)] pub fn syntax_node_ptr(&self) -> SyntaxNodePtr { self.raw } + #[rustversion::before(1.74)] + pub fn syntax_node_ptr(&self) -> SyntaxNodePtr { + self.raw.clone() + } + pub fn text_range(&self) -> TextRange { self.raw.text_range() }