diff --git a/src/common/bin_serde.rs b/src/common/bin_serde.rs index d2810221d..ff5e769a3 100644 --- a/src/common/bin_serde.rs +++ b/src/common/bin_serde.rs @@ -113,18 +113,18 @@ mod tests { assert_eq!(tx.read().unwrap(), 23); } - #[test] - pub fn different_types() { - impl DeSerialize for u8 { - type Bytes = [u8; std::mem::size_of::()]; - fn serialize(&self) -> [u8; 1] { - self.to_ne_bytes() - } - fn deserialize(bytes: [u8; 1]) -> Self { - Self::from_ne_bytes(bytes) - } + impl DeSerialize for u8 { + type Bytes = [u8; std::mem::size_of::()]; + fn serialize(&self) -> [u8; 1] { + self.to_ne_bytes() + } + fn deserialize(bytes: [u8; 1]) -> Self { + Self::from_ne_bytes(bytes) } + } + #[test] + pub fn different_types() { let (mut tx, mut rx) = BinPipe::pair().unwrap(); tx.write(&42i32).unwrap(); assert_eq!(rx.read().unwrap(), 42); diff --git a/src/defaults/settings_dsl.rs b/src/defaults/settings_dsl.rs index bc5d6fcb2..25d525395 100644 --- a/src/defaults/settings_dsl.rs +++ b/src/defaults/settings_dsl.rs @@ -1,6 +1,5 @@ macro_rules! add_from { ($ctor:ident, $type:ty) => { - #[allow(non_local_definitions)] impl From<$type> for $crate::defaults::SudoDefault { fn from(value: $type) -> Self { $crate::defaults::SudoDefault::$ctor(value.into()) @@ -9,8 +8,8 @@ macro_rules! add_from { }; ($ctor:ident, $type:ty, negatable$(, $vetting_function:expr)?) => { - #[allow(non_local_definitions)] impl From<$type> for $crate::defaults::SudoDefault { + #[allow(clippy::from_str_radix_10)] fn from(value: $type) -> Self { $crate::defaults::SudoDefault::$ctor(OptTuple { default: value.into(), @@ -19,8 +18,8 @@ macro_rules! add_from { } } - #[allow(non_local_definitions)] impl From<($type, $type)> for $crate::defaults::SudoDefault { + #[allow(clippy::from_str_radix_10)] fn from((value, neg): ($type, $type)) -> Self { $crate::defaults::SudoDefault::$ctor(OptTuple { default: value.into(), @@ -64,19 +63,19 @@ macro_rules! defaults { $(stringify!($name)),* ]; + add_from!(Flag, bool); + add_from!(Integer, i64, negatable, |text| i64::from_str_radix(text, 10).ok()); + add_from!(Text, &'static str, negatable); + add_from!(Text, Option<&'static str>, negatable); + add_from!(List, &'static [&'static str]); + add_from!(Enum, StrEnum<'static>, negatable); + // because of the nature of radix and ranges, 'let mut result' is not always necessary, and // a radix of 10 can also not always be avoided (and for uniformity, I would also not avoid this // if this was hand-written code. #[allow(unused_mut)] #[allow(clippy::from_str_radix_10)] pub fn sudo_default(var: &str) -> Option { - add_from!(Flag, bool); - add_from!(Integer, i64, negatable, |text| i64::from_str_radix(text, 10).ok()); - add_from!(Text, &'static str, negatable); - add_from!(Text, Option<&'static str>, negatable); - add_from!(List, &'static [&'static str]); - add_from!(Enum, StrEnum<'static>, negatable); - Some( match var { $(stringify!($name) => { diff --git a/src/defaults/strenum.rs b/src/defaults/strenum.rs index b667e918f..8edd4dfd0 100644 --- a/src/defaults/strenum.rs +++ b/src/defaults/strenum.rs @@ -25,7 +25,7 @@ impl<'a> StrEnum<'a> { } } -impl<'a> std::ops::Deref for StrEnum<'a> { +impl std::ops::Deref for StrEnum<'_> { type Target = str; fn deref(&self) -> &str { self.get() diff --git a/src/exec/use_pty/monitor.rs b/src/exec/use_pty/monitor.rs index 9af942ae6..bb321db43 100644 --- a/src/exec/use_pty/monitor.rs +++ b/src/exec/use_pty/monitor.rs @@ -436,7 +436,7 @@ enum MonitorEvent { ReadableBackchannel, } -impl<'a> Process for MonitorClosure<'a> { +impl Process for MonitorClosure<'_> { type Event = MonitorEvent; type Break = io::Error; type Exit = CommandStatus; @@ -450,7 +450,7 @@ impl<'a> Process for MonitorClosure<'a> { } } -impl<'a> HandleSigchld for MonitorClosure<'a> { +impl HandleSigchld for MonitorClosure<'_> { const OPTIONS: WaitOptions = WaitOptions::new().untraced().no_hang(); fn on_exit(&mut self, exit_code: c_int, registry: &mut EventRegistry) { diff --git a/src/exec/use_pty/pipe/ring_buffer.rs b/src/exec/use_pty/pipe/ring_buffer.rs index c66ed68b4..f87555ecf 100644 --- a/src/exec/use_pty/pipe/ring_buffer.rs +++ b/src/exec/use_pty/pipe/ring_buffer.rs @@ -25,8 +25,6 @@ impl RingBuffer { self.len == self.storage.len() } - // rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519 - #[allow(clippy::unused_io_amount)] pub(super) fn insert(&mut self, read: &mut R) -> io::Result { let inserted_len = if self.is_empty() { // Case 1.1. The buffer is empty, meaning that there are two unfilled slices in @@ -63,8 +61,6 @@ impl RingBuffer { self.len == 0 } - // rustc 1.77.1 clippy gives false diagnostics, https://github.com/rust-lang/rust-clippy/issues/12519 - #[allow(clippy::unused_io_amount)] pub(super) fn remove(&mut self, write: &mut W) -> io::Result { let removed_len = if self.is_full() { // Case 2.1. The buffer is full, meaning that there are two filled slices in `storage`: diff --git a/src/sudoers/ast.rs b/src/sudoers/ast.rs index b2e4ad805..75dbd9f2a 100644 --- a/src/sudoers/ast.rs +++ b/src/sudoers/ast.rs @@ -193,7 +193,6 @@ impl Sudo { /// identifier = name /// | # /// ``` - impl Parse for Identifier { fn parse(stream: &mut impl CharStream) -> Parsed { if accept_if(|c| c == '#', stream).is_some() { @@ -215,7 +214,6 @@ impl Many for Identifier {} /// /// This computes the correct negation with multiple exclamation marks in the parsing stage so we /// are not bothered by it later. - impl Parse for Qualified { fn parse(stream: &mut impl CharStream) -> Parsed { if is_syntax('!', stream)? { @@ -242,7 +240,6 @@ impl Many for Qualified { } /// Helper function for parsing `Meta` things where T is not a token - fn parse_meta( stream: &mut impl CharStream, embed: impl FnOnce(SudoString) -> T, @@ -259,7 +256,6 @@ fn parse_meta( } /// Since Identifier is not a token, add the parser for `Meta` - impl Parse for Meta { fn parse(stream: &mut impl CharStream) -> Parsed { parse_meta(stream, Identifier::Name) @@ -365,7 +361,6 @@ impl Parse for MetaOrTag { /// ```text /// commandspec = [tag modifiers]*, command /// ``` - impl Parse for CommandSpec { fn parse(stream: &mut impl CharStream) -> Parsed { let mut tags = vec![]; @@ -414,7 +409,6 @@ impl Parse for CommandSpec { /// ```text /// (host,runas,commandspec) = hostlist, "=", [runas?, commandspec]+ /// ``` - impl Parse for (SpecList, Vec<(Option, CommandSpec)>) { fn parse(stream: &mut impl CharStream) -> Parsed { let hosts = try_nonterminal(stream)?; @@ -463,7 +457,6 @@ impl Many for (Option, CommandSpec) {} /// ``` /// There is a syntactical ambiguity in the sudoer Directive and Permission specifications, so we /// have to parse them 'together' and do a delayed decision on which category we are in. - impl Parse for Sudo { // note: original sudo would reject: // "User_Alias, user machine = command" @@ -520,7 +513,6 @@ impl Parse for Sudo { } /// Parse the include/include dir part that comes after the '#' or '@' prefix symbol - fn parse_include(stream: &mut impl CharStream) -> Parsed { fn get_path(stream: &mut impl CharStream) -> Parsed { if accept_if(|c| c == '"', stream).is_some() { diff --git a/src/sudoers/ast_names.rs b/src/sudoers/ast_names.rs index 6c488838d..e7a310d69 100644 --- a/src/sudoers/ast_names.rs +++ b/src/sudoers/ast_names.rs @@ -1,4 +1,4 @@ -/// This module contains user-friendly names for the various items in the AST, to report in case they are missing +//! This module contains user-friendly names for the various items in the AST, to report in case they are missing pub trait UserFriendly { const DESCRIPTION: &'static str; diff --git a/src/sudoers/basic_parser.rs b/src/sudoers/basic_parser.rs index 8b4364833..b3756f457 100644 --- a/src/sudoers/basic_parser.rs +++ b/src/sudoers/basic_parser.rs @@ -273,15 +273,11 @@ impl Parse for Option { } /// Parsing method for lists of items separated by a given character; this adheres to the contract of the [Parse] trait. -#[allow(clippy::multiple_bound_locations)] -pub(super) fn parse_list( +pub(super) fn parse_list( sep_by: char, max: usize, stream: &mut impl CharStream, -) -> Parsed> -where - T: Parse + UserFriendly, -{ +) -> Parsed> { let mut elems = Vec::new(); elems.push(try_nonterminal(stream)?); while maybe(try_syntax(sep_by, stream))?.is_some() { diff --git a/src/sudoers/mod.rs b/src/sudoers/mod.rs index 6f37d2379..8ee572a2d 100644 --- a/src/sudoers/mod.rs +++ b/src/sudoers/mod.rs @@ -286,7 +286,6 @@ pub(super) struct AliasTable { } /// A vector with a list defining the order in which it needs to be processed - type VecOrd = (Vec, Vec); fn elems(vec: &VecOrd) -> impl Iterator { @@ -297,7 +296,6 @@ fn elems(vec: &VecOrd) -> impl Iterator { /// user/group. Not that in the sudoers file, later permissions override earlier restrictions. /// The `cmdline` argument should already be ready to essentially feed to an exec() call; or be /// a special command like 'sudoedit'. - // This code is structure to allow easily reading the 'happy path'; i.e. as soon as something // doesn't match, we escape using the '?' mechanism. fn check_permission, Group: UnixGroup>( @@ -339,7 +337,6 @@ fn check_permission, Group: UnixGroup>( /// Process a raw parsed AST bit of RunAs + Command specifications: /// - RunAs specifications distribute over the commands that follow (until overridden) /// - Tags accumulate over the entire line - fn distribute_tags( runas_cmds: &[(Option, CommandSpec)], ) -> impl Iterator, (Tag, &Spec))> { @@ -364,7 +361,6 @@ type FoundAliases = HashMap; /// Find an item matching a certain predicate in an collection (optionally attributed) list of /// identifiers; identifiers can be directly identifying, wildcards, and can either be positive or /// negative (i.e. preceeded by an even number of exclamation marks in the sudoers file) - fn find_item<'a, Predicate, Iter, T: 'a>( items: Iter, matches: &Predicate, @@ -487,7 +483,6 @@ fn unfold_alias_table(table: &VecOrd>) -> HashMap<&String, &Vec(table: &VecOrd>, pred: &Predicate) -> FoundAliases where Predicate: Fn(&T) -> bool, @@ -510,7 +505,6 @@ where } /// Code to map an ast::Identifier to the UnixUser trait - fn match_identifier(user: &impl UnixUser, ident: &ast::Identifier) -> bool { match ident { Identifier::Name(name) => user.has_name(name), @@ -756,7 +750,6 @@ fn analyze( /// Alias definition inin a Sudoers file can come in any order; and aliases can refer to other aliases, etc. /// It is much easier if they are presented in a "definitional order" (i.e. aliases that use other aliases occur later) /// At the same time, this is a good place to detect problems in the aliases, such as unknown aliases and cycles. - fn sanitize_alias_table(table: &Vec>, diagnostics: &mut Vec) -> Vec { fn remqualify(item: &Qualified) -> &U { match item { diff --git a/src/system/interface.rs b/src/system/interface.rs index 9b12603da..e81507e66 100644 --- a/src/system/interface.rs +++ b/src/system/interface.rs @@ -96,9 +96,10 @@ mod test { test_group(group(cstr!("daemon")), "daemon", 1); } + impl UnixUser for () {} + #[test] fn test_default() { - impl UnixUser for () {} assert!(!().has_name("root")); assert!(!().has_uid(0)); assert!(!().is_root());