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/de.rs:8:5
        |
    8   | use alloc::string::String;
        |     ^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here
        |
        = note: `#[warn(unused_imports)]` on by default

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

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

    warning: the item `String` is imported redundantly
       --> src/error.rs:5:21
        |
    5   | use alloc::string::{String, ToString};
        |                     ^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `ToString` is imported redundantly
       --> src/error.rs:5:29
        |
    5   | use alloc::string::{String, ToString};
        |                             ^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToString` is already defined here

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

    warning: the item `indexmap` is imported redundantly
      --> src/map.rs:23:16
       |
    23 | use indexmap::{self, IndexMap};
       |                ^^^^ the item `indexmap` is already defined here
       |
       = note: `#[warn(unused_imports)]` on by default

    warning: the item `String` is imported redundantly
       --> src/ser.rs:5:21
        |
    5   | use alloc::string::{String, ToString};
        |                     ^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `ToString` is imported redundantly
       --> src/ser.rs:5:29
        |
    5   | use alloc::string::{String, ToString};
        |                             ^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToString` is already defined here

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

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

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

    warning: the item `ToOwned` is imported redundantly
       --> src/value/de.rs:5:26
        |
    5   | use alloc::borrow::{Cow, ToOwned};
        |                          ^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToOwned` is already defined here

    warning: the item `String` is imported redundantly
       --> src/value/de.rs:6:5
        |
    6   | use alloc::string::String;
        |     ^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `Vec` is imported redundantly
       --> src/value/de.rs:9:24
        |
    9   | use alloc::vec::{self, Vec};
        |                        ^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `Vec` is already defined here

    warning: the item `String` is imported redundantly
       --> src/value/from.rs:5:21
        |
    5   | use alloc::string::{String, ToString};
        |                     ^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `ToString` is imported redundantly
       --> src/value/from.rs:5:29
        |
    5   | use alloc::string::{String, ToString};
        |                             ^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToString` is already defined here

    warning: the item `Vec` is imported redundantly
       --> src/value/from.rs:6:5
        |
    6   | use alloc::vec::Vec;
        |     ^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `Vec` is already defined here

    warning: the item `ToOwned` is imported redundantly
       --> src/value/index.rs:3:5
        |
    3   | use alloc::borrow::ToOwned;
        |     ^^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToOwned` is already defined here

    warning: the item `String` is imported redundantly
       --> src/value/index.rs:4:5
        |
    4   | use alloc::string::String;
        |     ^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `String` is imported redundantly
       --> src/value/partial_eq.rs:2:5
        |
    2   | use alloc::string::String;
        |     ^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `ToOwned` is imported redundantly
       --> src/value/ser.rs:4:5
        |
    4   | use alloc::borrow::ToOwned;
        |     ^^^^^^^^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToOwned` is already defined here

    warning: the item `String` is imported redundantly
       --> src/value/ser.rs:5:21
        |
    5   | use alloc::string::{String, ToString};
        |                     ^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `String` is already defined here

    warning: the item `ToString` is imported redundantly
       --> src/value/ser.rs:5:29
        |
    5   | use alloc::string::{String, ToString};
        |                             ^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `ToString` is already defined here

    warning: the item `Vec` is imported redundantly
       --> src/value/ser.rs:6:5
        |
    6   | use alloc::vec::Vec;
        |     ^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `Vec` is already defined here

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

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

    warning: the item `Vec` is imported redundantly
       --> tests/../src/lexical/bignum.rs:6:5
        |
    6   | use alloc::vec::Vec;
        |     ^^^^^^^^^^^^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
        |
    125 |     pub use super::v1::*;
        |             --------- the item `Vec` is already defined here
        |
        = note: `#[warn(unused_imports)]` on by default
  • Loading branch information
dtolnay committed Feb 20, 2024
1 parent 34a04c5 commit 6fb7026
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lexical/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Big integer type definition.

use super::math::*;
#[allow(unused_imports)]
use alloc::vec::Vec;

/// Storage for a big integer type.
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,14 @@
#![deny(clippy::question_mark_used)]
#![allow(non_upper_case_globals)]
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]

extern crate alloc;

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

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[doc(inline)]
Expand Down
10 changes: 9 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use serde::de;
#[cfg(not(feature = "preserve_order"))]
use alloc::collections::{btree_map, BTreeMap};
#[cfg(feature = "preserve_order")]
use indexmap::{self, IndexMap};
use indexmap::IndexMap;

/// Represents a JSON key/value type.
pub struct Map<K, V> {
Expand Down Expand Up @@ -176,6 +176,8 @@ impl Map<String, Value> {
/// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
/// last element of the map and popping it off. This perturbs the position
/// of what used to be the last element!
///
/// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
#[cfg(feature = "preserve_order")]
#[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
#[inline]
Expand All @@ -192,6 +194,8 @@ impl Map<String, Value> {
/// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
/// last element of the map and popping it off. This perturbs the position
/// of what used to be the last element!
///
/// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
#[cfg(feature = "preserve_order")]
#[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
#[inline]
Expand All @@ -208,6 +212,8 @@ impl Map<String, Value> {
/// Like [`Vec::remove`], the entry is removed by shifting all of the
/// elements that follow it, preserving their relative order. This perturbs
/// the index of all of those elements!
///
/// [`Vec::remove`]: std::vec::Vec::remove
#[cfg(feature = "preserve_order")]
#[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
#[inline]
Expand All @@ -224,6 +230,8 @@ impl Map<String, Value> {
/// Like [`Vec::remove`], the entry is removed by shifting all of the
/// elements that follow it, preserving their relative order. This perturbs
/// the index of all of those elements!
///
/// [`Vec::remove`]: std::vec::Vec::remove
#[cfg(feature = "preserve_order")]
#[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
#[inline]
Expand Down
2 changes: 2 additions & 0 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::iter::LineColIterator;
use crate::raw::BorrowedRawDeserializer;
#[cfg(all(feature = "raw_value", feature = "std"))]
use crate::raw::OwnedRawDeserializer;
#[cfg(all(feature = "raw_value", feature = "std"))]
use alloc::string::String;
#[cfg(feature = "raw_value")]
use serde::de::Visitor;

Expand Down
1 change: 0 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use std::iter;
use std::marker::PhantomData;
use std::mem;
use std::str::FromStr;
use std::string::ToString;
use std::{f32, f64};
use std::{i16, i32, i64, i8};
use std::{u16, u32, u64, u8};
Expand Down

0 comments on commit 6fb7026

Please sign in to comment.