Skip to content

Clippy Error redundant else block in src\webserver\http.rs #1095

@Phoenix79-spec

Description

@Phoenix79-spec

Introduction

Running cargo clippy produces a redundant else block error when target_family != "unix"

To Reproduce

Use a non unix environment
Clone the sqlpage repository.
run cargo clippy

Actual behavior

error: redundant else block
   --> src\webserver\http.rs:505:6
    |
505 |       } else {
    |  ______^
506 | |         if let Some(domain) = &config.https_domain {
507 | |             let mut listen_on_https = listen_on;
508 | |             listen_on_https.set_port(443);
...   |
523 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#redundant_else
note: the lint level is defined here
   --> src\lib.rs:1:9
    |
  1 | #![deny(clippy::pedantic)]
    |         ^^^^^^^^^^^^^^^^
    = note: `#[deny(clippy::redundant_else)]` implied by `#[deny(clippy::pedantic)]`
help: remove the `else` block and move the contents out
    |
505 ~     }
506 +     if let Some(domain) = &config.https_domain {
507 +         let mut listen_on_https = listen_on;
508 +         listen_on_https.set_port(443);
509 +         log::debug!("Will start HTTPS server on {listen_on_https}");
510 +         let config = make_auto_rustls_config(domain, config);
511 +         server = server
512 +             .bind_rustls_0_23(listen_on_https, config)
513 +             .map_err(|e| bind_error(e, listen_on_https))?;
514 +     } else if listen_on.port() == 443 {
515 +         bail!("Please specify a value for https_domain in the configuration file. This is required when using HTTPS (port 443)");
516 +     }
517 +     if listen_on.port() != 443 {
518 +         log::debug!("Will start HTTP server on {listen_on}");
519 +         server = server
520 +             .bind(listen_on)
521 +             .map_err(|e| bind_error(e, listen_on))?;
522 +     }
    |

Expected behavior

I expected there to be no errors from clippy when run against the main repository.

Version information

  • OS: Windows Server 2022
  • Database n/a
  • SQLPage Version 0.39.1

Additional context

This error will not appear when target_family="unix" because conditional compilation skips anyhow::bail! on unix systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions