Skip to content

Commit 38301f1

Browse files
Merge pull request #8 from rodrimati1992/0.2_patch
0.2.7 patch
2 parents 305eed8 + 3d48592 commit 38301f1

File tree

27 files changed

+203
-59
lines changed

27 files changed

+203
-59
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ members=[
33
"const_format",
44
"const_format_proc_macros",
55
"print_errors",
6+
"print_warnings",
67
]

const_format/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "const_format"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
authors = ["rodrimati1992 <[email protected]>"]
55
edition = "2018"
66
license = "Zlib"
@@ -34,7 +34,7 @@ only_new_tests = ["testing"]
3434
all = ["fmt", "derive", "constant_time_as_str", "assert"]
3535

3636
[dependencies.const_format_proc_macros]
37-
version = "=0.2.6"
37+
version = "=0.2.7"
3838
path = "../const_format_proc_macros"
3939

4040
[dev-dependencies]

const_format/src/fmt/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// <_< clippy you silly
2+
#![allow(clippy::enum_variant_names)]
3+
14
use core::fmt::{self, Display};
25

36
/// An error while trying to write into a StrWriter.

const_format/src/fmt/formatter.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ impl ComputeStrLength {
7979
self.len
8080
}
8181

82+
/// Whether the length of the computed string is zero.
83+
pub const fn is_empty(&self) -> bool {
84+
self.len == 0
85+
}
86+
8287
/// For borrowing this mutably in macros,just takes and returns a `&mut Self`.
8388
#[inline(always)]
8489
pub const fn borrow_mutably(&mut self) -> &mut Self {

const_format/src/fmt/str_writer_mut.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ macro_rules! write_integer_fn {
755755
cursor-=1;
756756
let digit = (n & 0b1111) as u8;
757757
this_buffer[cursor] = hex_as_ascii(digit);
758-
n = n >> 4;
758+
n >>= 4;
759759
if n == 0 { break }
760760
}
761761

@@ -790,7 +790,7 @@ macro_rules! write_integer_fn {
790790
cursor-=1;
791791
let digit = (n & 1) as u8;
792792
this_buffer[cursor] = hex_as_ascii(digit);
793-
n = n >> 1;
793+
n >>= 1;
794794
if n == 0 { break }
795795
}
796796

@@ -989,7 +989,7 @@ impl<'w, E> StrWriterMut<'w, E> {
989989
borrow_fields!(self, self_len, self_buffer);
990990

991991
// Truncating non-ascii u8s
992-
character = character & 0b111_1111;
992+
character &= 0b111_1111;
993993

994994
let end = *self_len + repeated;
995995

const_format/src/formatting.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ pub const fn hex_as_ascii(n: u8) -> u8 {
230230
}
231231

232232
#[doc(hidden)]
233+
// Really clippy? Array indexing can panic you know.
234+
#[allow(clippy::no_effect)]
233235
pub const FOR_ESCAPING: &ForEscaping = {
234236
let mut is_backslash_escaped = 0;
235237

const_format/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@
322322
#![deny(clippy::missing_safety_doc)]
323323
#![deny(clippy::shadow_unrelated)]
324324
#![deny(clippy::wildcard_imports)]
325+
// All The methods that take self by value are for small Copy types
326+
#![allow(clippy::wrong_self_convention)]
325327
#![deny(missing_docs)]
326328

327329
include! {"const_debug_derive.rs"}

const_format/src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ macro_rules! strwriter_as_str {
257257
($expr:expr) => {
258258
unsafe {
259259
let writer: &'static $crate::StrWriter = $expr;
260-
$crate::pmr::transmute::<&'static [u8], &'static str>(writer.as_bytes_alt())
260+
#[allow(clippy::transmute_bytes_to_str)]
261+
let ret = $crate::pmr::transmute::<&'static [u8], &'static str>(writer.as_bytes_alt());
262+
ret
261263
}
262264
};
263265
}

const_format/src/marker_traits/format_marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ macro_rules! std_kind_impls {
185185
///
186186
/// [`PWrapper`]: ../struct.PWrapper.html
187187
///
188+
#[allow(clippy::type_complexity)]
188189
pub struct IsAFormatMarker<K, T: ?Sized, R: ?Sized>(
189190
PhantomData<(
190191
PhantomData<fn() -> PhantomData<K>>,

const_format/src/marker_traits/write_marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ where
181181
///
182182
/// [`IsNotAStrWriter`]: ./struct.IsNotAStrWriter.html
183183
///
184+
#[allow(clippy::type_complexity)]
184185
pub struct IsAWriteMarker<K, T: ?Sized, R: ?Sized>(
185186
PhantomData<(
186187
PhantomData<fn() -> PhantomData<K>>,

const_format/src/pargument.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::wrong_self_convention)]
2+
13
use crate::{
24
formatting::{Formatting, FormattingFlags},
35
wrapper_types::PWrapper,

const_format/src/wrapper_types/pwrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl PWrapper<Integer> {
312312
out.start -= 1;
313313
let digit = (n & 1) as u8;
314314
out.array[out.start] = b'0' + digit;
315-
n = n >> 1;
315+
n >>= 1;
316316
if n == 0 {
317317
break;
318318
}
@@ -352,7 +352,7 @@ impl PWrapper<Integer> {
352352
0..=9 => b'0' + digit,
353353
_ => b'A' - 10 + digit,
354354
};
355-
n = n >> 4;
355+
n >>= 4;
356356
if n == 0 {
357357
break;
358358
}

const_format_proc_macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "const_format_proc_macros"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
authors = ["rodrimati1992 <[email protected]>"]
55
edition = "2018"
66
license = "Zlib"

const_format_proc_macros/src/format_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
format_str_parsing::FormatStr, formatting::FormattingFlags, parse_utils::StrRawness,
2+
format_str::FormatStr, formatting::FormattingFlags, parse_utils::StrRawness,
33
parse_utils::TokenStream2Ext, shared_arg_parsing::ExprArg, spanned::Spans,
44
};
55

const_format_proc_macros/src/format_args/parsing.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{
44
};
55

66
use crate::{
7-
format_str_parsing::{FmtArg, FmtStrComponent, FormatStr, WhichArg},
7+
format_str::{FmtArg, FmtStrComponent, FormatStr, WhichArg},
88
parse_utils::{LitStr, MyParse, ParseBuffer, ParseStream, TokenTreeExt},
99
shared_arg_parsing::ExprArg,
1010
spanned::Spans,
@@ -70,7 +70,7 @@ fn parse_fmt_lit(this: &mut FormatStr, input: ParseStream<'_>) -> Result<(), cra
7070
input.parse_unwrap_tt(|input| {
7171
let tt = input.next();
7272

73-
let res = match tt {
73+
match tt {
7474
Some(TokenTree::Literal(lit)) => {
7575
let mut lit = lit_str_to_fmt_lit(&LitStr::parse_from_literal(&lit)?)?;
7676

@@ -89,10 +89,8 @@ fn parse_fmt_lit(this: &mut FormatStr, input: ParseStream<'_>) -> Result<(), cra
8989
}
9090
Ok(())
9191
}
92-
_ => return Ok(()),
93-
};
94-
95-
res
92+
_ => Ok(()),
93+
}
9694
})
9795
}
9896

const_format_proc_macros/src/format_macro.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) fn concatcp_impl(value: ExprArgs) -> Result<TokenStream2, crate::Erro
3131

3232
let #fmt_var = __cf_osRcTFl4A::pmr::FormattingFlags::NEW;
3333

34+
#[allow(clippy::eval_order_dependence)]
3435
let array = [
3536
#({
3637
let arg = #concat_args;
@@ -95,6 +96,7 @@ pub(crate) fn formatcp_impl(fmt_args: FormatArgs) -> Result<TokenStream2, crate:
9596

9697
#( #locals )*
9798

99+
#[allow(clippy::eval_order_dependence)]
98100
let array = [
99101
#({
100102
let arg = #parg_constructor;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::{formatting::FormattingFlags, parse_utils::StrRawness};
2+
3+
mod errors;
4+
5+
mod parsing;
6+
7+
#[cfg(test)]
8+
mod tests;
9+
10+
pub(crate) use self::errors::{ParseError, ParseErrorKind};
11+
12+
#[derive(Debug, PartialEq)]
13+
pub(crate) struct FormatStr {
14+
pub(crate) list: Vec<FmtStrComponent>,
15+
}
16+
17+
#[derive(Debug, PartialEq)]
18+
pub(crate) enum FmtStrComponent {
19+
Str(String, StrRawness),
20+
Arg(FmtArg),
21+
}
22+
23+
/// An argument in the format string eg: `"{foo:?}"`
24+
#[derive(Debug, PartialEq)]
25+
pub(crate) struct FmtArg {
26+
pub(crate) which_arg: WhichArg,
27+
pub(crate) formatting: FormattingFlags,
28+
pub(crate) rawness: StrRawness,
29+
}
30+
31+
#[derive(Debug, PartialEq)]
32+
pub(crate) enum WhichArg {
33+
Ident(String),
34+
Positional(Option<usize>),
35+
}

const_format_proc_macros/src/format_str_parsing.rs renamed to const_format_proc_macros/src/format_str/parsing.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,16 @@
1+
use super::{FmtArg, FmtStrComponent, FormatStr, ParseError, ParseErrorKind, WhichArg};
2+
13
use crate::{
24
formatting::{FormattingFlags, IsAlternate, NumberFormatting},
35
parse_utils::StrRawness,
46
};
57

6-
mod errors;
7-
8-
#[cfg(test)]
9-
mod tests;
10-
11-
pub(crate) use self::errors::{ParseError, ParseErrorKind};
12-
13-
#[derive(Debug, PartialEq)]
14-
pub(crate) struct FormatStr {
15-
pub(crate) list: Vec<FmtStrComponent>,
16-
}
17-
18-
#[derive(Debug, PartialEq)]
19-
pub(crate) enum FmtStrComponent {
20-
Str(String, StrRawness),
21-
Arg(FmtArg),
22-
}
23-
24-
/// An argument in the format string eg: `"{foo:?}"`
25-
#[derive(Debug, PartialEq)]
26-
pub(crate) struct FmtArg {
27-
pub(crate) which_arg: WhichArg,
28-
pub(crate) formatting: FormattingFlags,
29-
pub(crate) rawness: StrRawness,
30-
}
31-
32-
#[derive(Debug, PartialEq)]
33-
pub(crate) enum WhichArg {
34-
Ident(String),
35-
Positional(Option<usize>),
36-
}
37-
38-
/////////////////////////////////////
39-
408
#[cfg(test)]
419
impl FmtStrComponent {
42-
fn str(s: &str) -> Self {
10+
pub(super) fn str(s: &str) -> Self {
4311
Self::Str(s.to_string(), StrRawness::dummy())
4412
}
45-
fn arg(which_arg: WhichArg, formatting: FormattingFlags) -> Self {
13+
pub(super) fn arg(which_arg: WhichArg, formatting: FormattingFlags) -> Self {
4614
Self::Arg(FmtArg {
4715
which_arg,
4816
formatting,
@@ -63,7 +31,7 @@ impl FmtArg {
6331

6432
#[allow(dead_code)]
6533
impl WhichArg {
66-
fn ident(s: &str) -> Self {
34+
pub(super) fn ident(s: &str) -> Self {
6735
Self::Ident(s.to_string())
6836
}
6937
}
@@ -98,7 +66,7 @@ fn parse_format_str(input: &str, rawness: StrRawness) -> Result<FormatStr, Parse
9866

9967
if let Some(open_pos) = open_pos {
10068
let after_open = open_pos + 1;
101-
if input[after_open..].chars().next() == Some('{') {
69+
if input[after_open..].starts_with('{') {
10270
components.push_arg_str("{".to_string(), rawness);
10371

10472
arg_start = open_pos + 2;

const_format_proc_macros/src/format_str_parsing/tests.rs renamed to const_format_proc_macros/src/format_str/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::*;
22

33
use super::{ParseError as PE, ParseErrorKind as PEK};
44

5-
use crate::formatting::{FormattingFlags as FF, IsAlternate};
5+
use crate::formatting::{FormattingFlags as FF, IsAlternate, NumberFormatting};
66

77
use fastrand::Rng;
88

const_format_proc_macros/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::or_fun_call)]
2+
13
use proc_macro::TokenStream as TokenStream1;
24

35
use proc_macro2::TokenStream as TokenStream2;
@@ -16,7 +18,7 @@ mod derive_debug;
1618

1719
mod format_args;
1820

19-
mod format_str_parsing;
21+
mod format_str;
2022

2123
mod format_macro;
2224

const_format_proc_macros/src/parse_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ impl LitStr {
169169
let mut range = 1..value.len() - 1;
170170
let span = literal.span();
171171

172-
let is_raw = if value.starts_with("r") {
173-
let hashes = value[1..].bytes().take_while(|x| *x == b'#').count();
172+
let is_raw = if let Some(suffix) = value.strip_prefix('r') {
173+
let hashes = suffix.bytes().take_while(|x| *x == b'#').count();
174174

175175
if value.as_bytes()[1 + hashes] != b'"' {
176176
return Err(Error::new(
@@ -263,7 +263,7 @@ impl StrRawness {
263263
buffer.push('"');
264264
buffer.push_str(str);
265265
buffer.push('"');
266-
buffer.extend(hashes.clone());
266+
buffer.extend(hashes);
267267
}
268268
None => {
269269
buffer.reserve(2 + str.len());

const_format_proc_macros/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Peekable2<I: Iterator> {
3131
}
3232

3333
impl Peekable2<std::ops::Range<u8>> {
34+
#[allow(clippy::new_ret_no_self)]
3435
pub fn new<I: IntoIterator>(iter: I) -> Peekable2<I::IntoIter> {
3536
Peekable2 {
3637
iter: iter.into_iter().fuse(),

print_clippy_warnings/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "print_clippy_warnings"
3+
version = "0.1.0"
4+
authors = ["rodrimati1992 <[email protected]>"]
5+
edition = "2018"
6+
7+
[features]
8+
nightly = ["const_format/assert"]
9+
10+
[dependencies]
11+
const_format = {path = "../const_format/"}

0 commit comments

Comments
 (0)