Skip to content

Commit 93165b7

Browse files
committed
chore: cleanup.
1 parent d25a1b9 commit 93165b7

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

crates/oxc_ast/src/generated/span.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Auto-generated code, DO NOT EDIT DIRECTLY!
22
// To edit this generated file you have to edit `tasks/ast_codegen/src/generators/impl_get_span.rs`
33

4+
#![allow(clippy::match_same_arms)]
5+
46
use crate::ast::*;
57
use oxc_span::{GetSpan, Span};
68

tasks/ast_codegen/src/generators/impl_get_span.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use itertools::Itertools;
22
use proc_macro2::TokenStream;
33
use quote::quote;
4-
use syn::Variant;
4+
use syn::{parse_quote, Attribute, Variant};
55

66
use crate::{
77
schema::{REnum, RStruct, RType},
@@ -33,8 +33,12 @@ impl Generator for ImplGetSpanGenerator {
3333

3434
GeneratorOutput::One(quote! {
3535
#header
36+
insert!("#![allow(clippy::match_same_arms)]");
37+
endl!();
38+
3639
use crate::ast::*;
3740
use oxc_span::{GetSpan, Span};
41+
3842
#(#impls)*
3943
})
4044
}

tasks/ast_codegen/src/linker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn linker(ty: &mut RType, ctx: &CodegenCtx) -> Result<bool> {
9191
Inherit::Linked { .. } => Ok(it),
9292
})
9393
.collect::<Vec<std::result::Result<Inherit, Inherit>>>();
94-
let unresolved = inherits.iter().any(|it| it.is_err());
94+
let unresolved = inherits.iter().any(std::result::Result::is_err);
9595

9696
ty.meta.inherits = inherits.into_iter().map(|it| it.unwrap_or_else(|it| it)).collect();
9797

tasks/ast_codegen/src/main.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO: remove me please!
2-
#![allow(dead_code)]
2+
#![allow(dead_code, unused_imports)]
33
mod defs;
44
mod generators;
55
mod linker;
@@ -55,31 +55,31 @@ enum GeneratorOutput {
5555
}
5656

5757
impl GeneratorOutput {
58-
pub fn as_none(self) {
59-
match self {
60-
Self::None => {}
61-
_ => panic!(),
62-
}
58+
pub fn as_none(&self) {
59+
assert!(matches!(self, Self::None));
6360
}
6461

65-
pub fn as_one(self) -> TokenStream {
66-
match self {
67-
Self::One(it) => it,
68-
_ => panic!(),
62+
pub fn as_one(&self) -> &TokenStream {
63+
if let Self::One(it) = self {
64+
it
65+
} else {
66+
panic!();
6967
}
7068
}
7169

72-
pub fn as_many(self) -> HashMap<String, TokenStream> {
73-
match self {
74-
Self::Many(it) => it,
75-
_ => panic!(),
70+
pub fn as_many(&self) -> &HashMap<String, TokenStream> {
71+
if let Self::Many(it) = self {
72+
it
73+
} else {
74+
panic!();
7675
}
7776
}
7877

79-
pub fn as_info(self) -> String {
80-
match self {
81-
Self::Info(it) => it,
82-
_ => panic!(),
78+
pub fn as_info(&self) -> &String {
79+
if let Self::Info(it) = self {
80+
it
81+
} else {
82+
panic!();
8383
}
8484
}
8585
}
@@ -186,7 +186,7 @@ fn output_dir() -> Result<String> {
186186

187187
#[allow(clippy::print_stdout)]
188188
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
189-
let CodegenResult { schema, outputs } = files()
189+
let CodegenResult { outputs, .. } = files()
190190
.fold(AstCodegen::default(), AstCodegen::add_file)
191191
.with(AstGenerator)
192192
.with(AstKindGenerator)
@@ -199,8 +199,8 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
199199

200200
{
201201
let span_path = format!("{output_dir}/span.rs");
202-
let mut span_file = fs::File::create(&span_path)?;
203-
let output = outputs[ImplGetSpanGenerator.name()].clone().as_one();
202+
let mut span_file = fs::File::create(span_path)?;
203+
let output = outputs[ImplGetSpanGenerator.name()].as_one();
204204
let span_content = pprint(output);
205205

206206
span_file.write_all(span_content.as_bytes())?;

tasks/ast_codegen/src/pprint.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ impl Replacer for EndlReplacer {
2727
fn replace_append(&mut self, _: &Captures, _: &mut String) {}
2828
}
2929

30-
pub fn pprint(input: TokenStream) -> String {
30+
pub fn pprint(input: &TokenStream) -> String {
3131
lazy_static! {
3232
static ref INSERT_REGEX: Regex = Regex::new(
33-
format!(r#"(?m)^{INSERT_MACRO_IDENT}!\([\n\s\S]*?\"([\s\S]*?)\"[\n\s\S]*?\);$"#).as_str()
33+
format!(r#"(?m)^{INSERT_MACRO_IDENT}!\([\n\s\S]*?\"([\s\S]*?)\"[\n\s\S]*?\);$"#)
34+
.as_str()
3435
)
3536
.unwrap();
3637
};

0 commit comments

Comments
 (0)