Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 867068c6 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: Fix clippy errors

- error: `splitn` called with `1` split
- error: this loop never actually loops
- error: this comparison involving the minimum or maximum element for
         this type contains a case that is always true or always false

Bug: 343315863
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: ./build.py --target clippy
Test: ./build.py --target test
Test: Deploy to Guybrush, tested PhoneHub/SmartLock/FastPair/NearbyShare
Test: bluetooth_AdapterQuickHealth.AVL.all_floss
Flag: EXEMPT, Floss-only changes
Change-Id: I3ca8e36ab85802ebec617618ee3e3eab5d541b7f
parent 87b86e23
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -521,7 +521,7 @@ async fn handle_client_command(
        });
    }

    'readline: loop {
    'foreground_actions: loop {
        let m = rx.recv().await;

        if m.is_none() {
@@ -788,31 +788,26 @@ async fn handle_client_command(
                    break;
                }
                Ok(line) => {
                    // Currently Chrome OS uses Rust 1.60 so use the 1-time loop block to
                    // workaround this.
                    // With Rust 1.65 onwards we can convert this loop hack into a named block:
                    // https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#break-from-labeled-blocks
                    // TODO: Use named block when Android and Chrome OS Rust upgrade Rust to 1.65.
                    loop {
                    'readline: {
                        let args = match shell_words::split(line.as_str()) {
                            Ok(words) => words,
                            Err(e) => {
                                print_error!("Error parsing arguments: {}", e);
                                break;
                                break 'readline;
                            }
                        };

                        let (cmd, rest) = match args.split_first() {
                            Some(pair) => pair,
                            None => break,
                            None => break 'readline,
                        };

                        if cmd == "quit" {
                            break 'readline;
                            break 'foreground_actions;
                        }

                        handler.process_cmd_line(cmd, &rest.to_vec());
                        break;
                        break 'readline;
                    }

                    // Ready to do readline again.
+1 −1
Original line number Diff line number Diff line
@@ -2246,7 +2246,7 @@ impl IBluetooth for Bluetooth {
        let intf = self.intf.lock().unwrap();

        // Checks if the duration is valid.
        if mode == BtDiscMode::LimitedDiscoverable && (duration > 60 || duration <= 0) {
        if mode == BtDiscMode::LimitedDiscoverable && (duration > 60 || duration == 0) {
            warn!("Invalid duration for setting the device into limited discoverable mode. The valid duration is 1~60 seconds.");
            return false;
        }
+1 −4
Original line number Diff line number Diff line
@@ -2021,10 +2021,7 @@ impl BluetoothMedia {
        // Defaults to Idle if no calls are present.
        // Revisit this logic if the system supports multiple concurrent calls in the future (e.g., three-way-call).
        let mut call_state = CallState::Idle;
        for c in self.call_list.iter() {
            call_state = c.state;
            break;
        }
        self.call_list.first().map(|c| call_state = c.state);
        self.telephony_callbacks.lock().unwrap().for_all_callbacks(|callback| {
            callback.on_telephony_event(*addr, u8::from(event), u8::from(call_state));
        });
+1 −1
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ impl Stack {
                // When pairing is busy for any reason, the bond cannot be created.
                // Allow retries until it is ready for bonding.
                Message::CreateBondWithRetry(device, bt_transport, num_attempts, retry_delay) => {
                    if num_attempts <= 0 {
                    if num_attempts == 0 {
                        continue;
                    }

+2 −4
Original line number Diff line number Diff line
@@ -77,10 +77,8 @@ pub fn parse_at_command_data(at_string: String) -> Result<AtCommand, String> {
    };
    // We want to keep the flow of this method consistent, but AtCommandType::Execute commands do
    // not have arguments. To resolve this we split those commands differently.
    let mut command_parts = match at_type {
        AtCommandType::Execute => clean_at_string.splitn(1, at_type_delimiter),
        _ => clean_at_string.splitn(2, at_type_delimiter),
    };
    let mut command_parts = clean_at_string
        .splitn(if at_type == AtCommandType::Execute { 1 } else { 2 }, at_type_delimiter);
    let command = match command_parts.next() {
        Some(command) => command,
        // In practice this cannot happen as parse_at_command_type already found the delimiter.