Skip to content

Commit

Permalink
Resolve std_instead_of_core clippy restriction on std::error
Browse files Browse the repository at this point in the history
    warning: used import from `std` instead of `core`
       --> src/exception.rs:21:6
        |
    21  | impl std::error::Error for Exception {}
        |      ^^^ help: consider importing the item from `core`: `core`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core
    note: the lint level is defined here
       --> src/lib.rs:378:5
        |
    378 |     clippy::std_instead_of_core
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Loading branch information
dtolnay committed Jun 14, 2024
1 parent dd532b6 commit 3cf7826
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn main() {
println!("cargo:rustc-check-cfg=cfg(compile_error_if_alloc)");
println!("cargo:rustc-check-cfg=cfg(compile_error_if_std)");
println!("cargo:rustc-check-cfg=cfg(cxx_experimental_no_alloc)");
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
println!("cargo:rustc-check-cfg=cfg(no_core_ffi_c_char)");
println!("cargo:rustc-check-cfg=cfg(skip_ui_tests)");
}
Expand All @@ -48,6 +49,11 @@ fn main() {
// core::ffi::c_char
println!("cargo:rustc-cfg=no_core_ffi_c_char");
}

if rustc.minor < 81 {
// core::error::Error
println!("cargo:rustc-cfg=no_core_error");
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
use alloc::boxed::Box;
use core::fmt::{self, Display};

#[cfg(all(feature = "std", not(no_core_error)))]
use core::error::Error as StdError;
#[cfg(all(feature = "std", no_core_error))]
use std::error::Error as StdError;

/// Exception thrown from an `extern "C++"` function.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Debug)]
Expand All @@ -18,7 +23,7 @@ impl Display for Exception {

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Exception {}
impl StdError for Exception {}

impl Exception {
#[allow(missing_docs)]
Expand Down

0 comments on commit 3cf7826

Please sign in to comment.