Skip to content

Commit

Permalink
Work around prelude redundant import warnings
Browse files Browse the repository at this point in the history
rust-lang/rust#117772

    warning: the item `String` is imported redundantly
       --> src/ensure.rs:2:5
        |
    2   | use alloc::string::String;
        |     ^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:115:13
        |
    115 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here
        |
        = note: `#[warn(unused_imports)]` on by default

    warning: the item `Box` is imported redundantly
       --> src/error.rs:7:5
        |
    7   | use alloc::boxed::Box;
        |     ^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:115:13
        |
    115 |     pub use super::v1::*;
        |             --------- the item `Box` is already defined here

    warning: the item `Box` is imported redundantly
       --> src/ptr.rs:1:5
        |
    1   | use alloc::boxed::Box;
        |     ^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:115:13
        |
    115 |     pub use super::v1::*;
        |             --------- the item `Box` is already defined here
  • Loading branch information
dtolnay committed Feb 19, 2024
1 parent 6e4f86b commit dfc7bc0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use self::ChainState::*;
use crate::StdError;

#[cfg(feature = "std")]
use alloc::vec;
use alloc::vec::{self, Vec};

#[cfg(feature = "std")]
pub(crate) use crate::Chain;
Expand Down
2 changes: 2 additions & 0 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl ErrorImpl {
#[cfg(any(std_backtrace, feature = "backtrace"))]
{
use crate::backtrace::BacktraceStatus;
use alloc::string::ToString;

let backtrace = unsafe { Self::backtrace(this) };
if let BacktraceStatus::Captured = backtrace.status() {
Expand Down Expand Up @@ -102,6 +103,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use alloc::string::String;

#[test]
fn one_digit() {
Expand Down
2 changes: 2 additions & 0 deletions src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ use core::fmt::{Debug, Display};

#[cfg(feature = "std")]
use crate::StdError;
#[cfg(feature = "std")]
use alloc::boxed::Box;

pub struct Adhoc;

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
#![doc(html_root_url = "https://docs.rs/anyhow/1.0.79")]
#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![deny(dead_code, unused_imports, unused_mut)]
#![cfg_attr(
not(anyhow_no_unsafe_op_in_unsafe_fn_lint),
Expand Down Expand Up @@ -247,6 +247,9 @@ compile_error!("Build script probe failed to compile.");

extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

#[macro_use]
mod backtrace;
mod chain;
Expand Down
3 changes: 3 additions & 0 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::StdError;
use core::fmt::{self, Debug, Display};

#[cfg(feature = "std")]
use alloc::boxed::Box;

#[cfg(error_generic_member_access)]
use std::error::Request;

Expand Down
1 change: 0 additions & 1 deletion tests/test_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod drop;

use self::drop::{DetectDrop, Flag};
use anyhow::Error;
use std::marker::Unpin;
use std::mem;

#[test]
Expand Down

0 comments on commit dfc7bc0

Please sign in to comment.