From c77191e53a87d7214e9ee0ceeead57194d9c7af4 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 5 Aug 2021 10:56:50 +1000 Subject: [PATCH 01/10] add note about avoiding zero flags --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6f58a42f..d45e5afc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,6 +254,8 @@ //! assert!(none.is_empty()); //! } //! ``` +//! +//! Users should generally avoid defining a flag with a value of zero. #![cfg_attr(not(test), no_std)] #![doc(html_root_url = "https://docs.rs/bitflags/1.2.1")] From fd87b239aab166ef7e3bfba65c7dfca29d66b1ac Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 5 Aug 2021 11:06:04 +1000 Subject: [PATCH 02/10] commit stderr for compilefail tests --- .gitignore | 1 + tests/compile-fail/private_flags.stderr | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/compile-fail/private_flags.stderr diff --git a/.gitignore b/.gitignore index fbd9642b..61c33314 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +wip target Cargo.lock diff --git a/tests/compile-fail/private_flags.stderr b/tests/compile-fail/private_flags.stderr new file mode 100644 index 00000000..d23f8320 --- /dev/null +++ b/tests/compile-fail/private_flags.stderr @@ -0,0 +1,18 @@ +error[E0603]: struct `Flags2` is private + --> $DIR/private_flags.rs:17:26 + | +17 | let flag2 = example::Flags2::FLAG_B; + | ^^^^^^ private struct + | +note: the struct `Flags2` is defined here + --> $DIR/private_flags.rs:4:5 + | +4 | / bitflags! { +5 | | pub struct Flags1: u32 { +6 | | const FLAG_A = 0b00000001; +7 | | } +... | +11 | | } +12 | | } + | |_____^ + = note: this error originates in the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) From 72a01b9e33cdb8bba8e5a85f617cdce981a846ea Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 5 Aug 2021 11:07:15 +1000 Subject: [PATCH 03/10] remove trailing comment --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d45e5afc..d2cdd010 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1205,7 +1205,7 @@ mod tests { #[test] fn test_set_ops_const() { // These just test that these compile and don't cause use-site panics - // (would be possible if we had some sort of UB), which is enoug + // (would be possible if we had some sort of UB) const INTERSECT: Flags = Flags::all().intersection(Flags::C); const UNION: Flags = Flags::A.union(Flags::C); const DIFFERENCE: Flags = Flags::all().difference(Flags::A); From ab6c459cb4457d0bb29e6cd9ef8f1934d3f8b4a3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 5 Aug 2021 11:28:42 +1000 Subject: [PATCH 04/10] prepare for 1.3.0 release --- CHANGELOG.md | 42 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d491015..301d1e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,45 @@ +# 1.3.0 + +- End empty doc comment with full stop ([#202]) + +- Fix typo in crate root docs ([#206]) + +- Document from_bits_unchecked unsafety ([#207]) + +- Let `is_all()` ignore extra bits ([#211]) + +- Allows empty flag definition ([#225]) + +- Making crate accessible from std ([#227]) + +- Make `from_bits` a const fn ([#229]) + +- Allow multiple bitflags structs in one macro invocation ([#235]) + +- Add named functions to perform set operations ([#244]) + +- Fix typos in method docs ([#245]) + +- Modernization of the `bitflags` macro to take advantage of newer features and 2018 idioms ([#246]) + +- Fix regression (in an unreleased feature) and simplify tests ([#247]) + +- Use `Self` and fix bug when overriding `stringify!` ([#249]) + +[#202]: https://github.com/bitflags/bitflags/pull/202 +[#206]: https://github.com/bitflags/bitflags/pull/206 +[#207]: https://github.com/bitflags/bitflags/pull/207 +[#211]: https://github.com/bitflags/bitflags/pull/211 +[#225]: https://github.com/bitflags/bitflags/pull/225 +[#227]: https://github.com/bitflags/bitflags/pull/227 +[#229]: https://github.com/bitflags/bitflags/pull/229 +[#235]: https://github.com/bitflags/bitflags/pull/235 +[#244]: https://github.com/bitflags/bitflags/pull/244 +[#245]: https://github.com/bitflags/bitflags/pull/245 +[#246]: https://github.com/bitflags/bitflags/pull/246 +[#247]: https://github.com/bitflags/bitflags/pull/247 +[#249]: https://github.com/bitflags/bitflags/pull/249 + # 1.2.1 - Remove extraneous `#[inline]` attributes ([#194]) diff --git a/Cargo.toml b/Cargo.toml index 44d0f193..e68efdd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "bitflags" # NB: When modifying, also modify: # 1. html_root_url in lib.rs # 2. number in readme (for breaking changes) -version = "1.2.1" +version = "1.3.0" edition = "2018" authors = ["The Rust Project Developers"] license = "MIT/Apache-2.0" diff --git a/README.md b/README.md index 005a0a4e..0da0f853 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -bitflags = "1.2" +bitflags = "1.3" ``` and this to your source code: diff --git a/src/lib.rs b/src/lib.rs index d2cdd010..f54b7127 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,7 +258,7 @@ //! Users should generally avoid defining a flag with a value of zero. #![cfg_attr(not(test), no_std)] -#![doc(html_root_url = "https://docs.rs/bitflags/1.2.1")] +#![doc(html_root_url = "https://docs.rs/bitflags/1.3.0")] #[doc(hidden)] pub extern crate core as _core; From eb31b1ae4b033d24bf23f291c9c0af71dddac78e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 5 Aug 2021 12:48:40 +1000 Subject: [PATCH 05/10] allow stderr to be ignored on non-beta compilers --- Cargo.toml | 1 + tests/compile-fail/.gitignore | 1 + ...flags.stderr => private_flags.stderr.beta} | 0 tests/compiletest.rs | 39 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/compile-fail/.gitignore rename tests/compile-fail/{private_flags.stderr => private_flags.stderr.beta} (100%) diff --git a/Cargo.toml b/Cargo.toml index e68efdd8..45914ef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ compiler_builtins = { version = '0.1.2', optional = true } [dev-dependencies] trybuild = "1.0" +rustversion = "1.0" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/tests/compile-fail/.gitignore b/tests/compile-fail/.gitignore new file mode 100644 index 00000000..4dd9abc8 --- /dev/null +++ b/tests/compile-fail/.gitignore @@ -0,0 +1 @@ +*.stderr diff --git a/tests/compile-fail/private_flags.stderr b/tests/compile-fail/private_flags.stderr.beta similarity index 100% rename from tests/compile-fail/private_flags.stderr rename to tests/compile-fail/private_flags.stderr.beta diff --git a/tests/compiletest.rs b/tests/compiletest.rs index db50dfda..eb5334c5 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,5 +1,44 @@ +use std::{ + fs, + ffi::OsStr, + io, + path::Path, +}; + #[test] fn compile_fail() { + prepare_stderr_files("tests/compile-fail").unwrap(); + let t = trybuild::TestCases::new(); t.compile_fail("tests/compile-fail/*.rs"); } + +fn prepare_stderr_files(path: impl AsRef) -> io::Result<()> { + for entry in fs::read_dir(path)? { + let entry = entry?; + + if entry.path().extension().and_then(OsStr::to_str) == Some("beta") { + let renamed = entry.path().with_extension(""); + + if renamed.exists() { + fs::remove_file(&renamed)?; + } + + rename_beta_stderr(entry.path(), renamed)?; + } + } + + Ok(()) +} + +#[rustversion::beta] +fn rename_beta_stderr(from: impl AsRef, to: impl AsRef) -> io::Result<()> { + fs::copy(from, to)?; + + Ok(()) +} + +#[rustversion::not(beta)] +fn rename_beta_stderr(_: impl AsRef, _: impl AsRef) -> io::Result<()> { + Ok(()) +} From 80a48b0485e52249e14c7b56aa60c3ae9be05df7 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Aug 2021 07:45:34 +1000 Subject: [PATCH 06/10] Update CHANGELOG.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 301d1e99..0c0cf8eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.3.0 -- End empty doc comment with full stop ([#202]) +- End `empty` doc comment with full stop ([#202]) - Fix typo in crate root docs ([#206]) From 22a8878ce211c27d0b3273a4452a5417c34c73ff Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Aug 2021 07:45:40 +1000 Subject: [PATCH 07/10] Update CHANGELOG.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c0cf8eb..1981d51a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Document from_bits_unchecked unsafety ([#207]) -- Let `is_all()` ignore extra bits ([#211]) +- Let `is_all` ignore extra bits ([#211]) - Allows empty flag definition ([#225]) From 2de2af803e41a67d44dc5ee81557d6182b0d28ed Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Aug 2021 07:45:51 +1000 Subject: [PATCH 08/10] Update CHANGELOG.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1981d51a..6bb9564b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 1.3.0 +- Add `#[repr(transparent)]` ([#187]) + - End `empty` doc comment with full stop ([#202]) - Fix typo in crate root docs ([#206]) From 7ae1fad352865b1098e423b59e5f9fc49ae820a5 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Aug 2021 07:45:56 +1000 Subject: [PATCH 09/10] Update CHANGELOG.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb9564b..91fd4bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Use `Self` and fix bug when overriding `stringify!` ([#249]) +[#187]: https://github.com/bitflags/bitflags/pull/187 [#202]: https://github.com/bitflags/bitflags/pull/202 [#206]: https://github.com/bitflags/bitflags/pull/206 [#207]: https://github.com/bitflags/bitflags/pull/207 From cf728d0257d9b0c26c57752d031e2b19efe5963a Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Aug 2021 07:51:11 +1000 Subject: [PATCH 10/10] comment the infra for stderr checking in beta --- tests/compiletest.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index eb5334c5..ae0c9df2 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -13,6 +13,14 @@ fn compile_fail() { t.compile_fail("tests/compile-fail/*.rs"); } +// Compiler messages may change between versions +// We don't want to have to track these too closely for `bitflags`, but +// having some message to check makes sure user-facing errors are sensical. +// +// The approach we use is to run the test on all compilers, but only check stderr +// output on beta (which is the next stable release). We do this by default ignoring +// any `.stderr` files in the `compile-fail` directory, and copying `.stderr.beta` files +// when we happen to be running on a beta compiler. fn prepare_stderr_files(path: impl AsRef) -> io::Result<()> { for entry in fs::read_dir(path)? { let entry = entry?; @@ -20,6 +28,9 @@ fn prepare_stderr_files(path: impl AsRef) -> io::Result<()> { if entry.path().extension().and_then(OsStr::to_str) == Some("beta") { let renamed = entry.path().with_extension(""); + // Unconditionally remove a corresponding `.stderr` file for a `.stderr.beta` + // file if it exists. On `beta` compilers, we'll recreate it. On other compilers, + // we don't want to end up checking it anyways. if renamed.exists() { fs::remove_file(&renamed)?; }