Skip to content

Commit bce9d90

Browse files
authored
Use #![no_std] in test crates wherever feasible. (#798) (#799)
In the original code: ``` generate rustdoc JSON: real 0m20.535s user 0m17.535s sys 0m2.646s cargo test: real 0m1.223s user 0m11.498s sys 0m0.737s 19MB in localdata/test_data ``` With `#![no_std]` where easily feasible: ``` generate rustdoc JSON: real 0m15.892s user 0m13.102s sys 0m2.543s cargo test: real 0m1.070s user 0m10.122s sys 0m0.791s 8.6MB in localdata/test_data ```
1 parent a327a6e commit bce9d90

File tree

77 files changed

+182
-30
lines changed
  • src/adapter
  • test_crates
    • associated_consts/src
    • automatically_derived/src
    • consts/src
    • cyclic_overlapping_glob_and_local_item/src
    • declarative_macros/src
    • enum_discriminants/src
    • enums_are_not_modules/src
    • explicit_reexport_of_matching_names/src
    • extern_fn/src
    • features/src
    • function_abi/src
    • function_export_name/src
    • function_export_name_2021/src
    • function_has_body/src
    • generic_param_positions/src
    • glob_of_enum_does_not_shadow_local_fn/src
    • glob_of_glob_reexport/src
    • glob_of_renamed_reexport/src
    • glob_reexport/src
    • glob_reexport_cycle/src
    • glob_reexport_enum_variants/src
    • glob_vs_glob_no_shadowing_for_same_item/src
    • glob_vs_glob_no_shadowing_for_same_multiply_renamed_item/src
    • glob_vs_glob_no_shadowing_for_same_renamed_item/src
    • glob_vs_glob_shadowing/src
    • glob_vs_glob_shadowing_downstream/src
    • importable_paths/src
    • infinite_corecursive_reexport/src
    • infinite_indirect_recursive_reexport/src
    • infinite_recursive_reexport/src
    • modules/src
    • nested_overlapping_glob_and_local_item/src
    • nested_reexport_as_underscore/src
    • no_shadowing_across_namespaces/src
    • non_exhaustive_attribute/src
    • overlapping_glob_and_local_item/src
    • overlapping_glob_and_local_module/src
    • overlapping_glob_and_private_import/src
    • overlapping_glob_and_renamed_module/src
    • overlapping_glob_of_enum_with_local_item/src
    • overlapping_reexport_as_underscore/src
    • proc_macros/src
    • pub_generic_type_alias_added_defaults/src
    • pub_generic_type_alias_changed_defaults/src
    • pub_generic_type_alias_omitted_default/src
    • pub_generic_type_alias_reexport/src
    • pub_generic_type_alias_same_signature_but_not_equivalent/src
    • pub_generic_type_alias_shuffled_order/src
    • pub_inside_pub_crate_mod/src
    • pub_type_alias_of_composite_type/src
    • pub_type_alias_of_type_alias/src
    • pub_type_alias_reexport/src
    • pub_type_alias_shuffled_order/src
    • reexport/src
    • reexport_as_underscore/src
    • reexport_consts_and_statics/src
    • reexport_declarative_macro/src
    • reexport_from_private_module/src
    • renaming_mod_reexport/src
    • renaming_reexport/src
    • renaming_reexport_of_reexport/src
    • static_export_name/src
    • static_export_name_2021/src
    • statics/src
    • struct_fields_position/src
    • structs_are_not_modules/src
    • supertrait/src
    • swapping_names/src
    • traits_with_associated_types/src
    • type_and_value_with_matching_names/src
    • type_generic_bounds/src
    • union_fields_position/src
    • unions/src
    • unions_are_not_modules/src
    • visibility_modifier_avoids_shadowing/src
    • visibility_modifier_causes_shadowing/src

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+182
-30
lines changed

src/adapter/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4575,7 +4575,7 @@ fn type_generic_bounds() {
45754575
kind: "Union".into(),
45764576
name: "ExampleUnion".into(),
45774577
generic: "T".into(),
4578-
bound: "std::fmt::Debug".into(),
4578+
bound: "core::fmt::Debug".into(),
45794579
},
45804580
Output {
45814581
kind: "Union".into(),

test_crates/associated_consts/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub struct Counter(i64);
24

35
impl Counter {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#![no_std]
2+
13
#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
24
pub struct Example(i64);

test_crates/consts/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub const FIRST: u32 = 1;
24

35
pub mod inner {

test_crates/cyclic_overlapping_glob_and_local_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `Foo` only as itself
35
// - `inner::Foo` also as `inner::nested::Foo`, `nested::Foo`, and `nested::inner::Foo`.

test_crates/declarative_macros/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
/// Usable externally as:
24
/// ```rust
35
/// declarative_macros::top_level!();

test_crates/enum_discriminants/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
#![allow(incomplete_features)]
24
#![feature(repr128)]
35
/// Some examples from <https://doc.rust-lang.org/reference/items/enumerations.html#implicit-discriminants>

test_crates/enums_are_not_modules/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub enum Foo {
24
// Enum variants are the exception: they are both visible and importable.
35
Variant,

test_crates/explicit_reexport_of_matching_names/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! In Rust, type names and value names (including both `fn` and `const`) have different,
24
//! mutually-disjoint namespaces. It's allowed for those namespaces to have matching names.
35
//! When the name is used, the surrounding context determines whether it's resolved

test_crates/extern_fn/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
extern "C" {
24
pub fn legacy_extern_fn();
35
}

test_crates/features/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#![no_std]
2+

test_crates/function_abi/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub extern "C-unwind" fn example_unwind() {}
24

35
pub extern "C" fn example_not_unwind() {}

test_crates/function_export_name/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
#[unsafe(no_mangle)]
24
pub fn example_not_mangled() {}
35

test_crates/function_export_name_2021/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
#[no_mangle]
24
pub fn example_not_mangled() {}
35

test_crates/function_has_body/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub fn top_level() {}
24

35
pub struct Foo;

test_crates/generic_param_positions/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
#![allow(unused_variables)]
24

35
pub fn function<'a, 'b, T, U, const N: usize, const M: usize>(left: &'a [T; N], right: &'b [U; M]) {}
@@ -9,7 +11,7 @@ pub trait Trait<'a, T, const N: usize> {
911
pub fn impl_trait<T, U>(first: T, impld: impl Into<U>) -> impl Iterator<Item = T> {}
1012

1113
pub struct Example<'a, 'b> {
12-
_marker: std::marker::PhantomData<&'a &'b ()>,
14+
_marker: core::marker::PhantomData<&'a &'b ()>,
1315
}
1416

1517
impl<'a, 'b> Example<'a, 'b> {
@@ -19,7 +21,7 @@ impl<'a, 'b> Example<'a, 'b> {
1921
}
2022

2123
pub struct SingleLifetimeElided<'a> {
22-
_marker: std::marker::PhantomData<&'a ()>,
24+
_marker: core::marker::PhantomData<&'a ()>,
2325
}
2426

2527
impl SingleLifetimeElided<'_> {

test_crates/glob_of_enum_does_not_shadow_local_fn/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `Foo` only as itself.
35
// - `inner::First` as itself: it's a function, variants are in the type namespace so no conflict.

test_crates/glob_of_glob_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `foo`
35
//! - `Bar`

test_crates/glob_of_renamed_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `renamed_foo`
35
//! - `RenamedBar`

test_crates/glob_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `foo`, also as `inner::foo`
35
//! - `Bar`, also as `inner::Bar`

test_crates/glob_reexport_cycle/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `first::foo`, also as `second::foo`
35
//! - `second::Bar`, also as `first::Bar`

test_crates/glob_reexport_enum_variants/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `First`
35
//! - `Second`

test_crates/glob_vs_glob_no_shadowing_for_same_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// There's no shadowing across glob re-exports of the same name
24
// if it's the same item both times.
35
//

test_crates/glob_vs_glob_no_shadowing_for_same_multiply_renamed_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// There's no shadowing across glob re-exports of the same name
24
// if it's the same item both times.
35
//

test_crates/glob_vs_glob_no_shadowing_for_same_renamed_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// There's no shadowing across glob re-exports of the same name
24
// if it's the same item both times.
35
//

test_crates/glob_vs_glob_shadowing/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports only the names `Bar` and `Baz`.
24
// While both `Foo` structs are public, their names conflict and are not exported.
35

test_crates/glob_vs_glob_shadowing_downstream/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate only exports the name `second::Bar`.
24
// Inside `first`, the name `Foo` conflicts between the two glob exports.
35
//

test_crates/importable_paths/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub struct PublicImportable {}
24

35
mod private {

test_crates/infinite_corecursive_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! The below function should be available as:
24
//! - `a::foo()`
35
//! - `b::a::foo()`

test_crates/infinite_indirect_recursive_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! The below function should be available as:
24
//! - `foo()`
35
//! - `nested::foo()`

test_crates/infinite_recursive_reexport/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! The below function should be available as:
24
//! - `foo()`
35
//! - `inner::foo()`

test_crates/modules/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
pub mod hello {
24
pub mod world {
35
pub struct T1 {}

test_crates/nested_overlapping_glob_and_local_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `Foo` only as itself
35
// - `inner::Foo` also as `inner::nested::Foo`, so `inner`'s glob import is a no-op

test_crates/nested_reexport_as_underscore/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This crate does not re-export any *nameable* items.
24
//!
35
//! However, glob imports of this file (in the style of a prelude)

test_crates/no_shadowing_across_namespaces/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// Glob imports do not import items whose names would conflict
24
// with locally-defined items with those names.
35
//

test_crates/non_exhaustive_attribute/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
#[non_exhaustive]
24
pub enum NonExhaustiveEnum {
35
First,

test_crates/overlapping_glob_and_local_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `Foo` only as itself
35
// - `inner::Foo` only as itself, meaning that the glob import is a no-op here

test_crates/overlapping_glob_and_local_module/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `sibling::duplicated::Foo` only as itself
35
// - `inner::duplicated::Bar` only as itself.

test_crates/overlapping_glob_and_private_import/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate does not export any names!
24
// The only name it could export is `sibling::Foo`, but shadowing prevents it.
35

test_crates/overlapping_glob_and_renamed_module/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `sibling::duplicated::Foo` only as itself
35
// - `inner::duplicated::Bar` only as itself.

test_crates/overlapping_glob_of_enum_with_local_item/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
// This crate exports:
24
// - `Foo` only as itself
35
// - `inner::First` only as itself, overriding the glob import

test_crates/overlapping_reexport_as_underscore/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This crate re-exports only the struct `Example`.
24
//!
35
//! Even though `second` imports two items named `Example`, one of them is renamed to `_`

test_crates/proc_macros/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! Notes on test completeness, as of Rust 1.81:
24
//! - Functions annotated with `#[proc_macro]` must be private, or else it's a compile error.
35
//! - All proc macros must be defined at the root of the crate, or else it's a compile error.

test_crates/pub_generic_type_alias_added_defaults/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `inner::Foo`
35
//! - `inner::Bar`
@@ -10,12 +12,12 @@
1012
1113
pub mod inner {
1214
pub struct Foo<'a, T, const N: usize> {
13-
_marker: std::marker::PhantomData<&'a T>,
15+
_marker: core::marker::PhantomData<&'a T>,
1416
_n: [i64; N],
1517
}
1618

1719
pub struct Bar<'a, const N: usize, T> {
18-
_marker: std::marker::PhantomData<&'a T>,
20+
_marker: core::marker::PhantomData<&'a T>,
1921
_n: [i64; N],
2022
}
2123
}

test_crates/pub_generic_type_alias_changed_defaults/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package does *not* include any re-exports of `inner::Foo` and `inner::Bar`.
24
//!
35
//! All type aliases change the semantics of the underlying type's generic parameters,
@@ -9,12 +11,12 @@
911
1012
pub mod inner {
1113
pub struct Foo<'a, T = i64, const N: usize = 5> {
12-
_marker: std::marker::PhantomData<&'a T>,
14+
_marker: core::marker::PhantomData<&'a T>,
1315
_n: [i64; N],
1416
}
1517

1618
pub struct Bar<'a, const N: usize = 5, T = i64> {
17-
_marker: std::marker::PhantomData<&'a T>,
19+
_marker: core::marker::PhantomData<&'a T>,
1820
_n: [i64; N],
1921
}
2022
}

test_crates/pub_generic_type_alias_omitted_default/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `inner::DefaultConst`
35
//! - `inner::DefaultType`
@@ -14,19 +16,19 @@
1416
1517
pub mod inner {
1618
pub struct DefaultConst<'a, T, const N: usize = 5> {
17-
_marker: std::marker::PhantomData<&'a [T; N]>,
19+
_marker: core::marker::PhantomData<&'a [T; N]>,
1820
}
1921

2022
pub struct DefaultType<'a, const N: usize, T = i64> {
21-
_marker: std::marker::PhantomData<&'a [T; N]>,
23+
_marker: core::marker::PhantomData<&'a [T; N]>,
2224
}
2325

2426
pub struct ConstOnly<const N: usize = 5> {
25-
_marker: std::marker::PhantomData<[i64; N]>,
27+
_marker: core::marker::PhantomData<[i64; N]>,
2628
}
2729

2830
pub struct TypeOnly<T = i64> {
29-
_marker: std::marker::PhantomData<T>,
31+
_marker: core::marker::PhantomData<T>,
3032
}
3133
}
3234

test_crates/pub_generic_type_alias_reexport/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following renames of `Foo` (which itself is not directly visible):
24
//! - `Exported<'a, T, const N: usize>`
35
//! - `ExportedRenamedParams<'b, U, const M: usize>`
@@ -19,7 +21,7 @@
1921
2022
mod inner {
2123
pub struct Foo<'a, T, const N: usize> {
22-
_marker: std::marker::PhantomData<&'a T>,
24+
_marker: core::marker::PhantomData<&'a T>,
2325
_n: [i64; N],
2426
}
2527

test_crates/pub_generic_type_alias_same_signature_but_not_equivalent/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `inner::GenericFoo<A, B>`
35
//! - `ChangedFoo<const A: usize, const B: usize>`
@@ -8,7 +10,7 @@
810
911
pub mod inner {
1012
pub struct GenericFoo<A, B> {
11-
_marker: std::marker::PhantomData<(A, B)>,
13+
_marker: core::marker::PhantomData<(A, B)>,
1214
}
1315
}
1416

test_crates/pub_generic_type_alias_shuffled_order/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![no_std]
2+
13
//! This package exports the following:
24
//! - `inner::GenericFoo<A, B>`
35
//! - `inner::LifetimeFoo<'a, 'b>`
@@ -13,11 +15,11 @@
1315
1416
pub mod inner {
1517
pub struct GenericFoo<A, B> {
16-
_marker: std::marker::PhantomData<(A, B)>,
18+
_marker: core::marker::PhantomData<(A, B)>,
1719
}
1820

1921
pub struct LifetimeFoo<'a, 'b> {
20-
_marker: std::marker::PhantomData<&'a &'b ()>,
22+
_marker: core::marker::PhantomData<&'a &'b ()>,
2123
}
2224

2325
pub struct ConstFoo<const A: usize, const B: usize> {

0 commit comments

Comments
 (0)