Skip to content

Commit a4babe5

Browse files
committed
Fix all clippy violations
1 parent fa8964f commit a4babe5

7 files changed

Lines changed: 120 additions & 91 deletions

File tree

rust/ruby-prism-sys/build/vendored.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn source_files<P: AsRef<Path>>(root_dir: P) -> Vec<String> {
114114

115115
if Path::new(&path)
116116
.extension()
117-
.map_or(false, |ext| ext.eq_ignore_ascii_case("c"))
117+
.is_some_and(|ext| ext.eq_ignore_ascii_case("c"))
118118
{
119119
files.push(path);
120120
}

rust/ruby-prism-sys/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//!
55
#![deny(unused_extern_crates)]
66
#![warn(
7-
box_pointers,
87
clippy::all,
98
clippy::nursery,
109
clippy::pedantic,

rust/ruby-prism-sys/tests/pack_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn pack_parse_test() {
3030
endian_out.as_mut_ptr(),
3131
size_out.as_mut_ptr(),
3232
length_type_out.as_mut_ptr(),
33-
&mut length_out,
33+
&raw mut length_out,
3434
encoding_out.as_mut_ptr(),
3535
);
3636

rust/ruby-prism-sys/tests/utils_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ mod string {
6666
let mut s = make_string(PM_STRING_SHARED);
6767

6868
unsafe {
69-
let len = pm_string_length(&s.pm_string);
69+
let len = pm_string_length(&raw const s.pm_string);
7070
assert_eq!(len, 16);
7171

72-
let result_start = pm_string_source(&s.pm_string);
72+
let result_start = pm_string_source(&raw const s.pm_string);
7373
assert_eq!(s.start_ptr(), result_start);
7474

75-
pm_string_free(&mut s.pm_string);
75+
pm_string_free(&raw mut s.pm_string);
7676
}
7777
}
7878

@@ -81,10 +81,10 @@ mod string {
8181
let s = make_string(PM_STRING_OWNED);
8282

8383
unsafe {
84-
let result_len = pm_string_length(&s.pm_string);
84+
let result_len = pm_string_length(&raw const s.pm_string);
8585
assert_eq!(result_len, 16);
8686

87-
let result_start = pm_string_source(&s.pm_string);
87+
let result_start = pm_string_source(&raw const s.pm_string);
8888
assert_eq!(s.pm_string.source, result_start);
8989

9090
// Don't drop the pm_string--we don't own it anymore!
@@ -96,13 +96,13 @@ mod string {
9696
let mut s = make_string(PM_STRING_CONSTANT);
9797

9898
unsafe {
99-
let result_len = pm_string_length(&s.pm_string);
99+
let result_len = pm_string_length(&raw const s.pm_string);
100100
assert_eq!(result_len, 16);
101101

102-
let result_start = pm_string_source(&s.pm_string);
102+
let result_start = pm_string_source(&raw const s.pm_string);
103103
assert_eq!(s.pm_string.source, result_start);
104104

105-
pm_string_free(&mut s.pm_string);
105+
pm_string_free(&raw mut s.pm_string);
106106
}
107107
}
108108

@@ -111,10 +111,10 @@ mod string {
111111
let s = make_string(PM_STRING_MAPPED);
112112

113113
unsafe {
114-
let result_len = pm_string_length(&s.pm_string);
114+
let result_len = pm_string_length(&raw const s.pm_string);
115115
assert_eq!(result_len, 16);
116116

117-
let result_start = pm_string_source(&s.pm_string);
117+
let result_start = pm_string_source(&raw const s.pm_string);
118118
assert_eq!(s.pm_string.source, result_start);
119119
}
120120
}

rust/ruby-prism/build.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ fn write_node(file: &mut File, flags: &[Flags], node: &Node) -> Result<(), Box<d
247247
writeln!(file, "impl<'pr> {}<'pr> {{", node.name)?;
248248
writeln!(file, " /// Converts this node to a generic node.")?;
249249
writeln!(file, " #[must_use]")?;
250-
writeln!(file, " pub fn as_node(&self) -> Node<'pr> {{")?;
250+
writeln!(file, " pub const fn as_node(&self) -> Node<'pr> {{")?;
251251
writeln!(file, " Node::{} {{ parser: self.parser, pointer: self.pointer, marker: PhantomData }}", node.name)?;
252252
writeln!(file, " }}")?;
253253
writeln!(file)?;
254254
writeln!(file, " /// Returns the location of this node.")?;
255255
writeln!(file, " #[must_use]")?;
256256
writeln!(file, " pub fn location(&self) -> Location<'pr> {{")?;
257-
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &mut (*self.pointer).base.location }};")?;
257+
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &raw mut (*self.pointer).base.location }};")?;
258258
writeln!(file, " Location::new(self.parser, unsafe {{ &(*pointer) }})")?;
259259
writeln!(file, " }}")?;
260260
writeln!(file)?;
@@ -326,7 +326,7 @@ fn write_node(file: &mut File, flags: &[Flags], node: &Node) -> Result<(), Box<d
326326
},
327327
NodeFieldType::NodeList => {
328328
writeln!(file, " pub fn {}(&self) -> NodeList<'pr> {{", field.name)?;
329-
writeln!(file, " let pointer: *mut pm_node_list = unsafe {{ &mut (*self.pointer).{} }};", field.name)?;
329+
writeln!(file, " let pointer: *mut pm_node_list = unsafe {{ &raw mut (*self.pointer).{} }};", field.name)?;
330330
writeln!(file, " NodeList {{ parser: self.parser, pointer: unsafe {{ NonNull::new_unchecked(pointer) }}, marker: PhantomData }}")?;
331331
writeln!(file, " }}")?;
332332
},
@@ -359,19 +359,19 @@ fn write_node(file: &mut File, flags: &[Flags], node: &Node) -> Result<(), Box<d
359359
},
360360
NodeFieldType::ConstantList => {
361361
writeln!(file, " pub fn {}(&self) -> ConstantList<'pr> {{", field.name)?;
362-
writeln!(file, " let pointer: *mut pm_constant_id_list_t = unsafe {{ &mut (*self.pointer).{} }};", field.name)?;
362+
writeln!(file, " let pointer: *mut pm_constant_id_list_t = unsafe {{ &raw mut (*self.pointer).{} }};", field.name)?;
363363
writeln!(file, " ConstantList {{ parser: self.parser, pointer: unsafe {{ NonNull::new_unchecked(pointer) }}, marker: PhantomData }}")?;
364364
writeln!(file, " }}")?;
365365
},
366366
NodeFieldType::Location => {
367367
writeln!(file, " pub fn {}(&self) -> Location<'pr> {{", field.name)?;
368-
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &mut (*self.pointer).{} }};", field.name)?;
368+
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &raw mut (*self.pointer).{} }};", field.name)?;
369369
writeln!(file, " Location::new(self.parser, unsafe {{ &(*pointer) }})")?;
370370
writeln!(file, " }}")?;
371371
},
372372
NodeFieldType::OptionalLocation => {
373373
writeln!(file, " pub fn {}(&self) -> Option<Location<'pr>> {{", field.name)?;
374-
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &mut (*self.pointer).{} }};", field.name)?;
374+
writeln!(file, " let pointer: *mut pm_location_t = unsafe {{ &raw mut (*self.pointer).{} }};", field.name)?;
375375
writeln!(file, " let start = unsafe {{ (*pointer).start }};")?;
376376
writeln!(file, " if start.is_null() {{")?;
377377
writeln!(file, " None")?;
@@ -392,7 +392,7 @@ fn write_node(file: &mut File, flags: &[Flags], node: &Node) -> Result<(), Box<d
392392
},
393393
NodeFieldType::Integer => {
394394
writeln!(file, " pub fn {}(&self) -> Integer<'pr> {{", field.name)?;
395-
writeln!(file, " Integer::new(unsafe {{ &(*self.pointer).{} }})", field.name)?;
395+
writeln!(file, " Integer::new(unsafe {{ &raw const(*self.pointer).{} }})", field.name)?;
396396
writeln!(file, " }}")?;
397397
},
398398
NodeFieldType::Double => {
@@ -523,7 +523,7 @@ fn write_visit(file: &mut File, config: &Config) -> Result<(), Box<dyn std::erro
523523
}
524524
},
525525
NodeFieldType::NodeList => {
526-
writeln!(file, " for node in node.{}().iter() {{", field.name)?;
526+
writeln!(file, " for node in &node.{}() {{", field.name)?;
527527
writeln!(file, " visitor.visit(&node);")?;
528528
writeln!(file, " }}")?;
529529
},
@@ -533,7 +533,7 @@ fn write_visit(file: &mut File, config: &Config) -> Result<(), Box<dyn std::erro
533533

534534
writeln!(file, "}}")?;
535535
} else {
536-
writeln!(file, "pub fn visit{}<'pr, V>(_visitor: &mut V, _node: &{}<'pr>)", struct_name(&node.name), node.name)?;
536+
writeln!(file, "pub const fn visit{}<'pr, V>(_visitor: &mut V, _node: &{}<'pr>)", struct_name(&node.name), node.name)?;
537537
writeln!(file, "where")?;
538538
writeln!(file, " V: Visit<'pr> + ?Sized,")?;
539539
writeln!(file, "{{}}")?;
@@ -552,14 +552,14 @@ fn write_bindings(config: &Config) -> Result<(), Box<dyn std::error::Error>> {
552552

553553
write!(
554554
file,
555-
r#"
555+
r"
556556
use std::marker::PhantomData;
557557
use std::ptr::NonNull;
558558
559559
#[allow(clippy::wildcard_imports)]
560560
use ruby_prism_sys::*;
561561
use crate::{{ConstantId, ConstantList, Integer, Location, NodeList}};
562-
"#
562+
"
563563
)?;
564564

565565
for node in &config.nodes {
@@ -578,7 +578,7 @@ use crate::{{ConstantId, ConstantList, Integer, Location, NodeList}};
578578
writeln!(file, "pub enum Node<'pr> {{")?;
579579

580580
for node in &config.nodes {
581-
writeln!(file, " /// The {} node", node.name)?;
581+
writeln!(file, " /// The `{}` node", node.name)?;
582582
writeln!(file, " {} {{", node.name)?;
583583
writeln!(file, " /// The pointer to the associated parser this node came from.")?;
584584
writeln!(file, " parser: NonNull<pm_parser_t>,")?;
@@ -596,7 +596,7 @@ use crate::{{ConstantId, ConstantList, Integer, Location, NodeList}};
596596

597597
writeln!(
598598
file,
599-
r#"
599+
r"
600600
impl<'pr> Node<'pr> {{
601601
/// Creates a new node from the given pointer.
602602
///
@@ -607,7 +607,7 @@ impl<'pr> Node<'pr> {{
607607
#[allow(clippy::not_unsafe_ptr_arg_deref)]
608608
pub(crate) fn new(parser: NonNull<pm_parser_t>, node: *mut pm_node_t) -> Self {{
609609
match unsafe {{ (*node).type_ }} {{
610-
"#
610+
"
611611
)?;
612612

613613
for node in &config.nodes {
@@ -633,7 +633,7 @@ impl<'pr> Node<'pr> {{
633633
for node in &config.nodes {
634634
writeln!(file, " /// Returns the node as a `{}`.", node.name)?;
635635
writeln!(file, " #[must_use]")?;
636-
writeln!(file, " pub fn as{}(&self) -> Option<{}<'pr>> {{", struct_name(&node.name), node.name)?;
636+
writeln!(file, " pub const fn as{}(&self) -> Option<{}<'pr>> {{", struct_name(&node.name), node.name)?;
637637
writeln!(file, " match *self {{")?;
638638
writeln!(file, " Self::{} {{ parser, pointer, marker }} => Some({} {{ parser, pointer, marker }}),", node.name, node.name)?;
639639
writeln!(file, " _ => None")?;

rust/ruby-prism/examples/wasm/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let comments_count = result.comments().count();
88
let warnings_count = result.warnings().count();
99
let errors_count = result.errors().count();
10-
println!(" comments: {}", comments_count);
11-
println!(" warnings: {}", warnings_count);
12-
println!(" errors: {}", errors_count);
10+
println!(" comments: {comments_count}");
11+
println!(" warnings: {warnings_count}");
12+
println!(" errors: {errors_count}");
1313
}

0 commit comments

Comments
 (0)