From de4a2142295eec982bdc1b81d02941f6de1322e5 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 10 Jan 2025 15:27:53 +0200 Subject: [PATCH 1/4] Fix `compile_fail` tests for 1.84 Rust --- tests/compile_fail/as_ref/renamed_generic.stderr | 3 +++ tests/compile_fail/debug/lifetime_no_debug.stderr | 2 +- tests/compile_fail/debug/unclosed_brace.stderr | 4 ++-- .../compile_fail/display/shared_format_unclosed_brace.stderr | 4 ++-- tests/compile_fail/display/unclosed_brace.stderr | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/compile_fail/as_ref/renamed_generic.stderr b/tests/compile_fail/as_ref/renamed_generic.stderr index 07311720..445e89af 100644 --- a/tests/compile_fail/as_ref/renamed_generic.stderr +++ b/tests/compile_fail/as_ref/renamed_generic.stderr @@ -13,6 +13,9 @@ error[E0599]: the method `as_ref` exists for struct `Baz`, but its trait bo = note: trait bound `Foo: AsRef>` was not satisfied note: the trait `AsRef` must be implemented --> $RUST/core/src/convert/mod.rs + | + | pub trait AsRef { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_ref`, perhaps you need to implement it: candidate #1: `AsRef` diff --git a/tests/compile_fail/debug/lifetime_no_debug.stderr b/tests/compile_fail/debug/lifetime_no_debug.stderr index 66d02bba..b809f71e 100644 --- a/tests/compile_fail/debug/lifetime_no_debug.stderr +++ b/tests/compile_fail/debug/lifetime_no_debug.stderr @@ -4,7 +4,7 @@ error[E0277]: `NoDebug<'_>` doesn't implement `Debug` 5 | #[derive(derive_more::Debug)] | ^^^^^^^^^^^^^^^^^^ `NoDebug<'_>` cannot be formatted using `{:?}` | - = help: the trait `Debug` is not implemented for `NoDebug<'_>`, which is required by `&NoDebug<'_>: Debug` + = help: the trait `Debug` is not implemented for `NoDebug<'_>` = note: add `#[derive(Debug)]` to `NoDebug<'_>` or manually `impl Debug for NoDebug<'_>` = note: required for `&NoDebug<'_>` to implement `Debug` = note: required for the cast from `&&NoDebug<'_>` to `&dyn Debug` diff --git a/tests/compile_fail/debug/unclosed_brace.stderr b/tests/compile_fail/debug/unclosed_brace.stderr index 35e2a943..aed8beff 100644 --- a/tests/compile_fail/debug/unclosed_brace.stderr +++ b/tests/compile_fail/debug/unclosed_brace.stderr @@ -1,8 +1,8 @@ -error: invalid format string: expected `'}'`, found `')'` +error: invalid format string: expected `}`, found `)` --> tests/compile_fail/debug/unclosed_brace.rs:3:21 | 3 | #[debug("Stuff({)", bar)] - | -^ expected `'}'` in format string + | -^ expected `}` in format string | | | because of this opening brace | diff --git a/tests/compile_fail/display/shared_format_unclosed_brace.stderr b/tests/compile_fail/display/shared_format_unclosed_brace.stderr index 4d4861f3..0912169f 100644 --- a/tests/compile_fail/display/shared_format_unclosed_brace.stderr +++ b/tests/compile_fail/display/shared_format_unclosed_brace.stderr @@ -1,8 +1,8 @@ -error: invalid format string: expected `'}'`, found `')'` +error: invalid format string: expected `}`, found `)` --> tests/compile_fail/display/shared_format_unclosed_brace.rs:2:19 | 2 | #[display("Stuff({)")] - | -^ expected `'}'` in format string + | -^ expected `}` in format string | | | because of this opening brace | diff --git a/tests/compile_fail/display/unclosed_brace.stderr b/tests/compile_fail/display/unclosed_brace.stderr index c2301613..fb4e911b 100644 --- a/tests/compile_fail/display/unclosed_brace.stderr +++ b/tests/compile_fail/display/unclosed_brace.stderr @@ -1,8 +1,8 @@ -error: invalid format string: expected `'}'`, found `')'` +error: invalid format string: expected `}`, found `)` --> tests/compile_fail/display/unclosed_brace.rs:2:19 | 2 | #[display("Stuff({)", bar)] - | -^ expected `'}'` in format string + | -^ expected `}` in format string | | | because of this opening brace | From e66d3cac5f04ba13059cb01c133085c196ef3e54 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 10 Jan 2025 15:33:41 +0200 Subject: [PATCH 2/4] Make Clippy happy --- impl/src/fmt/display.rs | 2 +- impl/src/fmt/mod.rs | 2 +- impl/src/fmt/parsing.rs | 19 +++++-------------- impl/src/into.rs | 2 +- impl/src/parsing.rs | 2 +- impl/src/utils.rs | 4 ++-- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/impl/src/fmt/display.rs b/impl/src/fmt/display.rs index 10cf3200..5e89773a 100644 --- a/impl/src/fmt/display.rs +++ b/impl/src/fmt/display.rs @@ -262,7 +262,7 @@ impl Expansion<'_> { .shared_attr .map_or(true, |attr| attr.contains_arg("_variant")); // If `shared_attr` is a transparent call to `_variant`, then we consider it being absent. - let has_shared_attr = self.shared_attr.map_or(false, |attr| { + let has_shared_attr = self.shared_attr.is_some_and(|attr| { attr.transparent_call().map_or(true, |(_, called_trait)| { &called_trait != self.trait_ident || !shared_attr_contains_variant }) diff --git a/impl/src/fmt/mod.rs b/impl/src/fmt/mod.rs index e09d3d68..1e0172bd 100644 --- a/impl/src/fmt/mod.rs +++ b/impl/src/fmt/mod.rs @@ -293,7 +293,7 @@ impl FmtAttribute { fields.fmt_args_idents().filter_map(move |field_name| { (used_args.iter().any(|arg| field_name == arg) && !self.args.iter().any(|arg| { - arg.alias.as_ref().map_or(false, |(n, _)| n == &field_name) + arg.alias.as_ref().is_some_and(|(n, _)| n == &field_name) })) .then(|| quote! { #field_name = *#field_name }) }) diff --git a/impl/src/fmt/parsing.rs b/impl/src/fmt/parsing.rs index 8a5d7527..ff4fbd0d 100644 --- a/impl/src/fmt/parsing.rs +++ b/impl/src/fmt/parsing.rs @@ -522,7 +522,7 @@ fn identifier(input: &str) -> Option<(LeftToParse<'_>, Identifier<'_>)> { ), &mut and_then(char('_'), take_while1(check_char(XID::is_xid_continue))), ]), - |(i, _)| (i, &input[..(input.as_bytes().len() - i.as_bytes().len())]), + |(i, _)| (i, &input[..(input.len() - i.len())]), )(input) } @@ -614,10 +614,7 @@ fn take_while0( while let Some(step) = parser(cur) { cur = step; } - ( - cur, - &input[..(input.as_bytes().len() - cur.as_bytes().len())], - ) + (cur, &input[..(input.len() - cur.len())]) } } @@ -631,10 +628,7 @@ fn take_while1( while let Some(step) = parser(cur) { cur = step; } - Some(( - cur, - &input[..(input.as_bytes().len() - cur.as_bytes().len())], - )) + Some((cur, &input[..(input.len() - cur.len())])) } } @@ -662,16 +656,13 @@ fn take_until1( cur = b; } - Some(( - cur, - &input[..(input.as_bytes().len() - cur.as_bytes().len())], - )) + Some((cur, &input[..(input.len() - cur.len())])) } } /// Checks whether `input` starts with `s`. fn str(s: &str) -> impl FnMut(&str) -> Option> + '_ { - move |input| input.starts_with(s).then(|| &input[s.as_bytes().len()..]) + move |input| input.starts_with(s).then(|| &input[s.len()..]) } /// Checks whether `input` starts with `c`. diff --git a/impl/src/into.rs b/impl/src/into.rs index 0c699755..27b959e2 100644 --- a/impl/src/into.rs +++ b/impl/src/into.rs @@ -576,7 +576,7 @@ where .filter(|(top_level, owned, ref_, ref_mut)| { [top_level, owned, ref_, ref_mut] .into_iter() - .any(|l| l.as_ref().map_or(false, |l| !l.is_empty())) + .any(|l| l.as_ref().is_some_and(|l| !l.is_empty())) }) else { return Ok(()); diff --git a/impl/src/parsing.rs b/impl/src/parsing.rs index 1bd2aa5f..4b2d844d 100644 --- a/impl/src/parsing.rs +++ b/impl/src/parsing.rs @@ -73,7 +73,7 @@ impl Parse for Expr { impl PartialEq for Expr { fn eq(&self, other: &syn::Ident) -> bool { - self.ident().map_or(false, |i| i == other) + self.ident().is_some_and(|i| i == other) } } diff --git a/impl/src/utils.rs b/impl/src/utils.rs index 7485d2b9..85d815b5 100644 --- a/impl/src/utils.rs +++ b/impl/src/utils.rs @@ -2329,7 +2329,7 @@ mod generics_search { impl<'ast> Visit<'ast> for Visitor<'_> { fn visit_type_path(&mut self, tp: &'ast syn::TypePath) { - self.found |= tp.path.get_ident().map_or(false, |ident| { + self.found |= tp.path.get_ident().is_some_and(|ident| { self.search.types.contains(ident) || self.search.consts.contains(ident) }); @@ -2346,7 +2346,7 @@ mod generics_search { self.found |= ep .path .get_ident() - .map_or(false, |ident| self.search.consts.contains(ident)); + .is_some_and(|ident| self.search.consts.contains(ident)); syn::visit::visit_expr_path(self, ep) } From eefe08a7c5d699374e6f949d663ecc24ce9717c8 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 10 Jan 2025 15:36:20 +0200 Subject: [PATCH 3/4] Fix --- tests/compile_fail/as_mut/renamed_generic.stderr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/compile_fail/as_mut/renamed_generic.stderr b/tests/compile_fail/as_mut/renamed_generic.stderr index 190faaed..08e2cb40 100644 --- a/tests/compile_fail/as_mut/renamed_generic.stderr +++ b/tests/compile_fail/as_mut/renamed_generic.stderr @@ -13,6 +13,9 @@ error[E0599]: the method `as_mut` exists for struct `Baz`, but its trait bo = note: trait bound `Foo: AsMut>` was not satisfied note: the trait `AsMut` must be implemented --> $RUST/core/src/convert/mod.rs + | + | pub trait AsMut { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_mut`, perhaps you need to implement it: candidate #1: `AsMut` From a4335792b2dbdea7dcd7f0c27d99f78742ab81a6 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 10 Jan 2025 15:39:01 +0200 Subject: [PATCH 4/4] Fix --- tests/compile_fail/as_mut/renamed_generic.stderr | 3 --- tests/compile_fail/as_ref/renamed_generic.stderr | 3 --- 2 files changed, 6 deletions(-) diff --git a/tests/compile_fail/as_mut/renamed_generic.stderr b/tests/compile_fail/as_mut/renamed_generic.stderr index 08e2cb40..190faaed 100644 --- a/tests/compile_fail/as_mut/renamed_generic.stderr +++ b/tests/compile_fail/as_mut/renamed_generic.stderr @@ -13,9 +13,6 @@ error[E0599]: the method `as_mut` exists for struct `Baz`, but its trait bo = note: trait bound `Foo: AsMut>` was not satisfied note: the trait `AsMut` must be implemented --> $RUST/core/src/convert/mod.rs - | - | pub trait AsMut { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_mut`, perhaps you need to implement it: candidate #1: `AsMut` diff --git a/tests/compile_fail/as_ref/renamed_generic.stderr b/tests/compile_fail/as_ref/renamed_generic.stderr index 445e89af..07311720 100644 --- a/tests/compile_fail/as_ref/renamed_generic.stderr +++ b/tests/compile_fail/as_ref/renamed_generic.stderr @@ -13,9 +13,6 @@ error[E0599]: the method `as_ref` exists for struct `Baz`, but its trait bo = note: trait bound `Foo: AsRef>` was not satisfied note: the trait `AsRef` must be implemented --> $RUST/core/src/convert/mod.rs - | - | pub trait AsRef { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope = note: the following trait defines an item `as_ref`, perhaps you need to implement it: candidate #1: `AsRef`