From 15691ec43162cb50ba02bf39adac38f113688e77 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 17 Jun 2024 09:15:22 +1000 Subject: [PATCH] Modernize lazy-static infra (#219) --- .github/workflows/rust.yml | 60 +++++++++++++++++ .gitignore | 1 + .travis.yml | 36 ----------- Cargo.toml | 14 +--- appveyor.yml | 61 ------------------ compiletest/Cargo.toml | 11 ---- compiletest/src/lib.rs | 11 ---- compiletest/tests/compile-fail/README.md | 22 ------- .../incorrect_visibility_restriction.rs | 10 --- .../tests/compile-fail/static_is_sized.rs | 11 ---- compiletest/tests/compile_tests.rs | 19 ------ src/inline_lazy.rs | 1 + .../incorrect_visibility_restriction.rs | 8 +++ .../incorrect_visibility_restriction.stderr | 10 +++ .../compile_fail}/static_is_private.rs | 4 +- tests/compile_fail/static_is_private.stderr | 14 ++++ tests/compile_fail/static_is_sized.rs | 9 +++ tests/compile_fail/static_is_sized.stderr | 64 +++++++++++++++++++ tests/ui.rs | 6 ++ 19 files changed, 178 insertions(+), 194 deletions(-) create mode 100644 .github/workflows/rust.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 compiletest/Cargo.toml delete mode 100644 compiletest/src/lib.rs delete mode 100644 compiletest/tests/compile-fail/README.md delete mode 100644 compiletest/tests/compile-fail/incorrect_visibility_restriction.rs delete mode 100644 compiletest/tests/compile-fail/static_is_sized.rs delete mode 100644 compiletest/tests/compile_tests.rs create mode 100644 tests/compile_fail/incorrect_visibility_restriction.rs create mode 100644 tests/compile_fail/incorrect_visibility_restriction.stderr rename {compiletest/tests/compile-fail => tests/compile_fail}/static_is_private.rs (54%) create mode 100644 tests/compile_fail/static_is_private.stderr create mode 100644 tests/compile_fail/static_is_sized.rs create mode 100644 tests/compile_fail/static_is_sized.stderr create mode 100644 tests/ui.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..e5ccb61 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,60 @@ +name: Rust + +on: [push, pull_request] + +env: + CARGO_TERM_COLOR: always + +permissions: + contents: read + +jobs: + check: + name: "Tests" + runs-on: ubuntu-latest + strategy: + matrix: + channel: + - stable + - beta + - nightly + + steps: + - name: Checkout repository + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + + - name: Install Rust Toolchain + run: rustup default ${{ matrix.channel }} + + - name: Install cargo-hack + run: cargo install cargo-hack + + - name: Powerset + run: cargo hack test --feature-powerset --lib + + miri: + name: "Miri" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Miri + run: | + rustup toolchain install nightly --component miri + cargo +nightly miri setup + - name: Default features + run: cargo +nightly miri test + + embedded: + name: Build (embedded) + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + + - name: Install Rust toolchain + run: | + rustup default nightly + rustup target add thumbv7em-none-eabi + + - name: Default features + run: cargo build -Z avoid-dev-deps --features spin_no_std --target thumbv7em-none-eabi diff --git a/.gitignore b/.gitignore index bde55ce..23b8f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target doc Cargo.lock .cargo +wip diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7f9892f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: rust -matrix: - include: - - rust: 1.40.0 - script: - - cargo test --tests - - rust: stable - script: - - cargo test - - cargo test --features spin_no_std - - os: osx - - rust: beta - - rust: nightly - script: - - cargo test - - cargo bench - - cargo test --features spin_no_std - - cargo bench --features spin_no_std - - cd compiletest - - cargo clean - - cargo test - - cd ../ - - - rust: nightly - before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - script: - - cargo doc --no-deps --all-features - after_success: - - travis-cargo --only nightly doc-upload -script: - - cargo test - -env: - global: - - secure: YXu24LptjeYirjWYjWGsMT2m3mB7LvQATE6TVo7VEUXv8GYoy2ORIHD83PeImxC93MmZ01QeUezRzuCW51ZcK92VnNSBttlF60SvIX18VsJrV92tsAhievFstqYQ+fB8DIuQ8noU0jPz7GpI+R9dlTRSImAqWOnVIghA+Wzz7Js= diff --git a/Cargo.toml b/Cargo.toml index ed77654..3de0e4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ documentation = "https://docs.rs/lazy_static" repository = "https://github.com/rust-lang-nursery/lazy-static.rs" keywords = ["macro", "lazy", "static"] categories = [ "no-std", "rust-patterns", "memory-management" ] -exclude = ["/.travis.yml", "/appveyor.yml"] +exclude = [".github"] [dependencies.spin] -version = "0.9.3" +version = "0.9.8" default-features = false features = ["once"] optional = true @@ -25,12 +25,4 @@ spin_no_std = ["spin"] [dev-dependencies] doc-comment = "0.3.1" - -[badges] -appveyor = { repository = "rust-lang-nursery/lazy-static.rs" } -travis-ci = { repository = "rust-lang-nursery/lazy-static.rs" } - -is-it-maintained-issue-resolution = { repository = "rust-lang-nursery/lazy-static.rs" } -is-it-maintained-open-issues = { repository = "rust-lang-nursery/lazy-static.rs" } - -maintenance = { status = "passively-maintained" } +trybuild = "1" diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index b138452..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,61 +0,0 @@ -environment: - global: - PROJECT_NAME: lazy_static - # When this was added there were revocation check failures when using the - # libcurl backend as libcurl checks by default, but rustup doesn't provide the - # switch to turn this off. Switch to Hyper which looks to not check for - # revocation by default like libcurl does. - RUSTUP_USE_REQWEST: 1 - CARGO_HTTP_CHECK_REVOKE: false - matrix: - # Stable channel - - TARGET: i686-pc-windows-gnu - CHANNEL: stable - - TARGET: i686-pc-windows-msvc - CHANNEL: stable - - TARGET: x86_64-pc-windows-gnu - CHANNEL: stable - - TARGET: x86_64-pc-windows-msvc - CHANNEL: stable - # Beta channel - - TARGET: i686-pc-windows-gnu - CHANNEL: beta - - TARGET: i686-pc-windows-msvc - CHANNEL: beta - - TARGET: x86_64-pc-windows-gnu - CHANNEL: beta - - TARGET: x86_64-pc-windows-msvc - CHANNEL: beta - # Nightly channel - - TARGET: i686-pc-windows-gnu - CHANNEL: nightly - - TARGET: i686-pc-windows-msvc - CHANNEL: nightly - - TARGET: x86_64-pc-windows-gnu - CHANNEL: nightly - - TARGET: x86_64-pc-windows-msvc - CHANNEL: nightly - -# Install Rust and Cargo -# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml) -install: - - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - - rustup-init.exe -y --default-toolchain %CHANNEL% --default-host %TARGET% - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin - - if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin - - if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin - - rustc -V - - cargo -V - -build: false - -test_script: - - cargo build --verbose - - cargo test - - if [%CHANNEL%]==[nightly] ( - cd compiletest && - cargo clean && - cargo build --verbose && - cargo test && - cd ../ - ) diff --git a/compiletest/Cargo.toml b/compiletest/Cargo.toml deleted file mode 100644 index e25d5a7..0000000 --- a/compiletest/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "lazy_static_compiletest" -version = "0.0.1" -publish = false -authors = ["lazy_static contributors"] - -[dependencies.lazy_static] -path = "../" - -[dependencies.compiletest_rs] -version = "0.3" diff --git a/compiletest/src/lib.rs b/compiletest/src/lib.rs deleted file mode 100644 index 0452765..0000000 --- a/compiletest/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -/* -This library is a shim around `lazy_static` that disambiguates it with the `lazy_static` -that's shipped with the Rust toolchain. We re-export the entire public API of `lazy_static` -under a different crate name so that can be imported in the compile tests. - -This currently appears to use the right local build of `lazy_static`. -*/ - -extern crate lazy_static; - -pub use self::lazy_static::*; diff --git a/compiletest/tests/compile-fail/README.md b/compiletest/tests/compile-fail/README.md deleted file mode 100644 index 58dbc3b..0000000 --- a/compiletest/tests/compile-fail/README.md +++ /dev/null @@ -1,22 +0,0 @@ -This directory contains snippets of code that should yield a -warning/note/help/error at compilation. Syntax of annotations is described in -[rust documentation](https://github.com/rust-lang/rust/blob/master/src/test/COMPILER_TESTS.md). -For more information check out [`compiletest` crate](https://github.com/laumann/compiletest-rs). - -To run compile tests issue `cargo +nightly --test`. - -## Notes on working with `compiletest` crate - -* Currently code that is inside macro should not be annotated, as `compiletest` - crate cannot deal with the fact that macro invocations effectively changes - line numbering. To prevent this add a `// error-pattern:` - on the top of the file and make sure that you set `deny` lint level - if you want to test compiler message different than error. -* `compiletest` crate by default sets `allow(dead_code)` lint level so make sure - that you change it to something suiting your needs even if the warning is - issued prior to any macro invocation. -* If you get a message `error: 0 unexpected errors found, 1 expected errors not found` - despite the fact that some error was bound to occur don't worry - it's a known - issue in the `compiletest` crate and your error was probably not registered - - make sure that your annotations are correct and that you are setting correct - lint levels. diff --git a/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs b/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs deleted file mode 100644 index 360e23d..0000000 --- a/compiletest/tests/compile-fail/incorrect_visibility_restriction.rs +++ /dev/null @@ -1,10 +0,0 @@ -// incorrect visibility restriction -#[macro_use] -extern crate lazy_static_compiletest as lazy_static; - -lazy_static! { - pub(nonsense) static ref WRONG: () = (); - //~^ ERROR incorrect visibility restriction -} - -fn main() { } diff --git a/compiletest/tests/compile-fail/static_is_sized.rs b/compiletest/tests/compile-fail/static_is_sized.rs deleted file mode 100644 index ac1cad4..0000000 --- a/compiletest/tests/compile-fail/static_is_sized.rs +++ /dev/null @@ -1,11 +0,0 @@ -// error-pattern:the size for values of type `str` cannot be known at compilation time -#[macro_use] -extern crate lazy_static_compiletest as lazy_static; - -lazy_static! { - pub static ref FOO: str = panic!(); -} - - -fn main() { -} diff --git a/compiletest/tests/compile_tests.rs b/compiletest/tests/compile_tests.rs deleted file mode 100644 index d908077..0000000 --- a/compiletest/tests/compile_tests.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate compiletest_rs as compiletest; - -fn run_mode(mode: &'static str) { - let mut config = compiletest::Config::default(); - config.mode = mode.parse().expect("Invalid mode"); - config.src_base = ["tests", mode].iter().collect(); - - config.verbose = true; - - config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps/".to_owned()); - config.clean_rmeta(); - - compiletest::run_tests(&config); -} - -#[test] -fn compile_test() { - run_mode("compile-fail"); -} diff --git a/src/inline_lazy.rs b/src/inline_lazy.rs index 9281c33..36d52d3 100644 --- a/src/inline_lazy.rs +++ b/src/inline_lazy.rs @@ -15,6 +15,7 @@ use self::std::sync::Once; #[allow(deprecated)] pub use self::std::sync::ONCE_INIT; +#[allow(dead_code)] // Used in macros pub struct Lazy(Cell>, Once); impl Lazy { diff --git a/tests/compile_fail/incorrect_visibility_restriction.rs b/tests/compile_fail/incorrect_visibility_restriction.rs new file mode 100644 index 0000000..5d44f02 --- /dev/null +++ b/tests/compile_fail/incorrect_visibility_restriction.rs @@ -0,0 +1,8 @@ +#[macro_use] +extern crate lazy_static; + +lazy_static! { + pub(nonsense) static ref WRONG: () = (); +} + +fn main() { } diff --git a/tests/compile_fail/incorrect_visibility_restriction.stderr b/tests/compile_fail/incorrect_visibility_restriction.stderr new file mode 100644 index 0000000..045ce14 --- /dev/null +++ b/tests/compile_fail/incorrect_visibility_restriction.stderr @@ -0,0 +1,10 @@ +error[E0704]: incorrect visibility restriction + --> tests/compile_fail/incorrect_visibility_restriction.rs:5:9 + | +5 | pub(nonsense) static ref WRONG: () = (); + | ^^^^^^^^ help: make this visible only to module `nonsense` with `in`: `in nonsense` + | + = help: some possible visibility restrictions are: + `pub(crate)`: visible only on the current crate + `pub(super)`: visible only in the current module's parent + `pub(in path::to::module)`: visible only on the specified path diff --git a/compiletest/tests/compile-fail/static_is_private.rs b/tests/compile_fail/static_is_private.rs similarity index 54% rename from compiletest/tests/compile-fail/static_is_private.rs rename to tests/compile_fail/static_is_private.rs index 6ebc8f5..4486f01 100644 --- a/compiletest/tests/compile-fail/static_is_private.rs +++ b/tests/compile_fail/static_is_private.rs @@ -1,5 +1,5 @@ #[macro_use] -extern crate lazy_static_compiletest as lazy_static; +extern crate lazy_static; mod outer { pub mod inner { @@ -10,5 +10,5 @@ mod outer { } fn main() { - assert_eq!(*outer::inner::FOO, ()); //~ ERROR static `FOO` is private + assert_eq!(*outer::inner::FOO, ()); } diff --git a/tests/compile_fail/static_is_private.stderr b/tests/compile_fail/static_is_private.stderr new file mode 100644 index 0000000..38007d4 --- /dev/null +++ b/tests/compile_fail/static_is_private.stderr @@ -0,0 +1,14 @@ +error[E0603]: static `FOO` is private + --> tests/compile_fail/static_is_private.rs:13:31 + | +13 | assert_eq!(*outer::inner::FOO, ()); + | ^^^ private static + | +note: the static `FOO` is defined here + --> tests/compile_fail/static_is_private.rs:6:9 + | +6 | / lazy_static! { +7 | | pub(in outer) static ref FOO: () = (); +8 | | } + | |_________^ + = note: this error originates in the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/compile_fail/static_is_sized.rs b/tests/compile_fail/static_is_sized.rs new file mode 100644 index 0000000..69a9a06 --- /dev/null +++ b/tests/compile_fail/static_is_sized.rs @@ -0,0 +1,9 @@ +#[macro_use] +extern crate lazy_static; + +lazy_static! { + pub static ref FOO: str = panic!(); +} + + +fn main() { } diff --git a/tests/compile_fail/static_is_sized.stderr b/tests/compile_fail/static_is_sized.stderr new file mode 100644 index 0000000..49407ab --- /dev/null +++ b/tests/compile_fail/static_is_sized.stderr @@ -0,0 +1,64 @@ +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> tests/compile_fail/static_is_sized.rs:4:1 + | +4 | / lazy_static! { +5 | | pub static ref FOO: str = panic!(); +6 | | } + | |_^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` +note: required by an implicit `Sized` bound in `Lazy` + --> src/inline_lazy.rs + | + | pub struct Lazy(Cell>, Once); + | ^ required by the implicit `Sized` requirement on this type parameter in `Lazy` + = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> tests/compile_fail/static_is_sized.rs:4:1 + | +4 | / lazy_static! { +5 | | pub static ref FOO: str = panic!(); +6 | | } + | |_^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` +note: required by an implicit `Sized` bound in `Lazy` + --> src/inline_lazy.rs + | + | pub struct Lazy(Cell>, Once); + | ^ required by the implicit `Sized` requirement on this type parameter in `Lazy` + = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> tests/compile_fail/static_is_sized.rs:5:25 + | +5 | pub static ref FOO: str = panic!(); + | ^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: the return type of a function must have a statically known size + +error[E0599]: the method `get` exists for struct `Lazy`, but its trait bounds were not satisfied + --> tests/compile_fail/static_is_sized.rs:4:1 + | +4 | / lazy_static! { +5 | | pub static ref FOO: str = panic!(); +6 | | } + | |_^ method cannot be called on `Lazy` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `str: Sized` + = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> tests/compile_fail/static_is_sized.rs:4:1 + | +4 | / lazy_static! { +5 | | pub static ref FOO: str = panic!(); +6 | | } + | |_^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: the return type of a function must have a statically known size + = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui.rs b/tests/ui.rs new file mode 100644 index 0000000..af007cd --- /dev/null +++ b/tests/ui.rs @@ -0,0 +1,6 @@ +#[test] +#[cfg(not(miri))] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile_fail/*.rs"); +}