diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cfg.rs | 32 | ||||
-rw-r--r-- | tests/compiletest.rs | 9 | ||||
-rw-r--r-- | tests/drop_order.rs | 50 | ||||
-rw-r--r-- | tests/include/basic-safe-part.rs | 38 | ||||
-rw-r--r-- | tests/lint.rs | 271 | ||||
-rw-r--r-- | tests/lint.txt | 10 | ||||
-rw-r--r-- | tests/pin_project.rs | 102 | ||||
-rw-r--r-- | tests/pinned_drop.rs | 6 | ||||
-rw-r--r-- | tests/proper_unpin.rs | 42 | ||||
-rw-r--r-- | tests/ui/cfg/cfg_attr-resolve.rs | 2 | ||||
-rw-r--r-- | tests/ui/cfg/cfg_attr-resolve.stderr | 6 | ||||
-rw-r--r-- | tests/ui/pin_project/packed-enum.stderr | 6 | ||||
-rw-r--r-- | tests/ui/pin_project/private_in_public-enum.stderr | 4 | ||||
-rw-r--r-- | tests/ui/pin_project/project_replace_unsized.stderr | 6 | ||||
-rw-r--r-- | tests/ui/pin_project/project_replace_unsized_fn_params.rs (renamed from tests/ui/pin_project/project_replace_unsized_locals.rs) | 2 | ||||
-rw-r--r-- | tests/ui/pin_project/project_replace_unsized_fn_params.stderr (renamed from tests/ui/pin_project/project_replace_unsized_locals.stderr) | 10 | ||||
-rw-r--r-- | tests/ui/pinned_drop/call-drop-inner.stderr | 10 |
17 files changed, 461 insertions, 145 deletions
diff --git a/tests/cfg.rs b/tests/cfg.rs index 9fde697..2fdcfbb 100644 --- a/tests/cfg.rs +++ b/tests/cfg.rs @@ -37,9 +37,9 @@ fn cfg() { assert_unpin!(SameName); #[cfg(target_os = "linux")] - let _x = SameName { inner: Linux }; + let _ = SameName { inner: Linux }; #[cfg(not(target_os = "linux"))] - let _x = SameName { inner: Other }; + let _ = SameName { inner: Other }; #[pin_project(project_replace)] struct DifferentName { @@ -57,9 +57,9 @@ fn cfg() { assert_unpin!(DifferentName); #[cfg(target_os = "linux")] - let _x = DifferentName { l: Linux }; + let _ = DifferentName { l: Linux }; #[cfg(not(target_os = "linux"))] - let _x = DifferentName { o: Other }; + let _ = DifferentName { o: Other }; #[pin_project(project_replace)] struct TupleStruct( @@ -77,9 +77,9 @@ fn cfg() { assert_unpin!(TupleStruct); #[cfg(target_os = "linux")] - let _x = TupleStruct(Linux); + let _ = TupleStruct(Linux); #[cfg(not(target_os = "linux"))] - let _x = TupleStruct(Other); + let _ = TupleStruct(Other); // enums @@ -105,14 +105,14 @@ fn cfg() { assert_unpin!(Variant); #[cfg(target_os = "linux")] - let _x = Variant::Inner(Linux); + let _ = Variant::Inner(Linux); #[cfg(not(target_os = "linux"))] - let _x = Variant::Inner(Other); + let _ = Variant::Inner(Other); #[cfg(target_os = "linux")] - let _x = Variant::Linux(Linux); + let _ = Variant::Linux(Linux); #[cfg(not(target_os = "linux"))] - let _x = Variant::Other(Other); + let _ = Variant::Other(Other); #[pin_project( project = FieldProj, @@ -158,19 +158,19 @@ fn cfg() { assert_unpin!(Field); #[cfg(target_os = "linux")] - let _x = Field::SameName { inner: Linux }; + let _ = Field::SameName { inner: Linux }; #[cfg(not(target_os = "linux"))] - let _x = Field::SameName { inner: Other }; + let _ = Field::SameName { inner: Other }; #[cfg(target_os = "linux")] - let _x = Field::DifferentName { l: Linux }; + let _ = Field::DifferentName { l: Linux }; #[cfg(not(target_os = "linux"))] - let _x = Field::DifferentName { w: Other }; + let _ = Field::DifferentName { w: Other }; #[cfg(target_os = "linux")] - let _x = Field::TupleVariant(Linux); + let _ = Field::TupleVariant(Linux); #[cfg(not(target_os = "linux"))] - let _x = Field::TupleVariant(Other); + let _ = Field::TupleVariant(Other); } #[test] diff --git a/tests/compiletest.rs b/tests/compiletest.rs index be01ba8..057df7c 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,9 +1,16 @@ #![cfg(not(miri))] #![warn(rust_2018_idioms, single_use_lifetimes)] -#[rustversion::attr(not(nightly), ignore)] +use std::env; + +// Run `./dev.sh +$toolchain test --test compiletest` to update this. +#[rustversion::attr(before(2020-10-28), ignore)] // Note: This date is commit-date and the day before the toolchain date. #[test] fn ui() { + if env::var_os("CI").is_none() { + env::set_var("TRYBUILD", "overwrite"); + } + let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/cfg/*.rs"); t.compile_fail("tests/ui/not_unpin/*.rs"); diff --git a/tests/drop_order.rs b/tests/drop_order.rs index 1931b68..1557188 100644 --- a/tests/drop_order.rs +++ b/tests/drop_order.rs @@ -38,12 +38,14 @@ struct TupleUnpinned<'a>(D<'a>, D<'a>); #[pin_project(project_replace = EnumProj)] enum Enum<'a> { + #[allow(dead_code)] // false positive that fixed in Rust 1.38 StructPinned { #[pin] f1: D<'a>, #[pin] f2: D<'a>, }, + #[allow(dead_code)] // false positive that fixed in Rust 1.38 StructUnpinned { f1: D<'a>, f2: D<'a>, @@ -60,9 +62,9 @@ fn struct_pinned() { } { let c = Cell::new(0); - let mut _x = StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); + let mut x = StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); } } @@ -74,9 +76,9 @@ fn struct_unpinned() { } { let c = Cell::new(0); - let mut _x = StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); + let mut x = StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); } } @@ -88,9 +90,9 @@ fn tuple_pinned() { } { let c = Cell::new(0); - let mut _x = TuplePinned(D(&c, 1), D(&c, 2)); - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(TuplePinned(D(&c, 3), D(&c, 4))); + let mut x = TuplePinned(D(&c, 1), D(&c, 2)); + let y = Pin::new(&mut x); + let _z = y.project_replace(TuplePinned(D(&c, 3), D(&c, 4))); } } @@ -102,9 +104,9 @@ fn tuple_unpinned() { } { let c = Cell::new(0); - let mut _x = TupleUnpinned(D(&c, 1), D(&c, 2)); - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(TupleUnpinned(D(&c, 3), D(&c, 4))); + let mut x = TupleUnpinned(D(&c, 1), D(&c, 2)); + let y = Pin::new(&mut x); + let _z = y.project_replace(TupleUnpinned(D(&c, 3), D(&c, 4))); } } @@ -116,9 +118,9 @@ fn enum_struct() { } { let c = Cell::new(0); - let mut _x = Enum::StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(Enum::StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); + let mut x = Enum::StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); } { @@ -127,9 +129,9 @@ fn enum_struct() { } { let c = Cell::new(0); - let mut _x = Enum::StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(Enum::StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); + let mut x = Enum::StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); } } @@ -141,9 +143,9 @@ fn enum_tuple() { } { let c = Cell::new(0); - let mut _x = Enum::TuplePinned(D(&c, 1), D(&c, 2)); - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(Enum::TuplePinned(D(&c, 3), D(&c, 4))); + let mut x = Enum::TuplePinned(D(&c, 1), D(&c, 2)); + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::TuplePinned(D(&c, 3), D(&c, 4))); } { @@ -152,8 +154,8 @@ fn enum_tuple() { } { let c = Cell::new(0); - let mut _x = Enum::TupleUnpinned(D(&c, 1), D(&c, 2)); - let _y = Pin::new(&mut _x); - let _z = _y.project_replace(Enum::TupleUnpinned(D(&c, 3), D(&c, 4))); + let mut x = Enum::TupleUnpinned(D(&c, 1), D(&c, 2)); + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::TupleUnpinned(D(&c, 3), D(&c, 4))); } } diff --git a/tests/include/basic-safe-part.rs b/tests/include/basic-safe-part.rs index c8d24bd..0b7c43e 100644 --- a/tests/include/basic-safe-part.rs +++ b/tests/include/basic-safe-part.rs @@ -8,11 +8,29 @@ pub struct DefaultStruct<T, U> { pub unpinned: U, } +#[::pin_project::pin_project( + project = DefaultStructNamedProj, + project_ref = DefaultStructNamedProjRef, +)] +#[derive(Debug)] +pub struct DefaultStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, +} + #[::pin_project::pin_project] #[derive(Debug)] pub struct DefaultTupleStruct<T, U>(#[pin] pub T, pub U); #[::pin_project::pin_project( + project = DefaultTupleStructNamedProj, + project_ref = DefaultTupleStructNamedProjRef, +)] +#[derive(Debug)] +pub struct DefaultTupleStructNamed<T, U>(#[pin] pub T, pub U); + +#[::pin_project::pin_project( project = DefaultEnumProj, project_ref = DefaultEnumProjRef, )] @@ -78,11 +96,31 @@ pub struct ReplaceStruct<T, U> { pub unpinned: U, } +#[::pin_project::pin_project( + project = ReplaceStructNamedProj, + project_ref = ReplaceStructNamedProjRef, + project_replace = ReplaceStructNamedProjOwn, +)] +#[derive(Debug)] +pub struct ReplaceStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, +} + #[::pin_project::pin_project(project_replace)] #[derive(Debug)] pub struct ReplaceTupleStruct<T, U>(#[pin] pub T, pub U); #[::pin_project::pin_project( + project = ReplaceTupleStructNamedProj, + project_ref = ReplaceTupleStructNamedProjRef, + project_replace = ReplaceTupleStructNamedProjOwn, +)] +#[derive(Debug)] +pub struct ReplaceTupleStructNamed<T, U>(#[pin] pub T, pub U); + +#[::pin_project::pin_project( project = ReplaceEnumProj, project_ref = ReplaceEnumProjRef, project_replace = ReplaceEnumProjOwn, diff --git a/tests/lint.rs b/tests/lint.rs index 86cb121..c7f1380 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -54,11 +54,29 @@ pub mod basic { pub unpinned: U, } + #[::pin_project::pin_project( + project = DefaultStructNamedProj, + project_ref = DefaultStructNamedProjRef, + )] + #[derive(Debug)] + pub struct DefaultStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + #[::pin_project::pin_project] #[derive(Debug)] pub struct DefaultTupleStruct<T, U>(#[pin] pub T, pub U); #[::pin_project::pin_project( + project = DefaultTupleStructNamedProj, + project_ref = DefaultTupleStructNamedProjRef, + )] + #[derive(Debug)] + pub struct DefaultTupleStructNamed<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( project = DefaultEnumProj, project_ref = DefaultEnumProjRef, )] @@ -124,11 +142,31 @@ pub mod basic { pub unpinned: U, } + #[::pin_project::pin_project( + project = ReplaceStructNamedProj, + project_ref = ReplaceStructNamedProjRef, + project_replace = ReplaceStructNamedProjOwn, + )] + #[derive(Debug)] + pub struct ReplaceStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + #[::pin_project::pin_project(project_replace)] #[derive(Debug)] pub struct ReplaceTupleStruct<T, U>(#[pin] pub T, pub U); #[::pin_project::pin_project( + project = ReplaceTupleStructNamedProj, + project_ref = ReplaceTupleStructNamedProjRef, + project_replace = ReplaceTupleStructNamedProjOwn, + )] + #[derive(Debug)] + pub struct ReplaceTupleStructNamed<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( project = ReplaceEnumProj, project_ref = ReplaceEnumProjRef, project_replace = ReplaceEnumProjOwn, @@ -223,6 +261,207 @@ pub mod forbid_unsafe { #![forbid(unsafe_code)] include!("include/basic-safe-part.rs"); + + pub mod inside_macro { + #[rustfmt::skip] + macro_rules! mac { + () => { + #[::pin_project::pin_project] + #[derive(Debug)] + pub struct DefaultStruct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project( + project = DefaultStructNamedProj, + project_ref = DefaultStructNamedProjRef, + )] + #[derive(Debug)] + pub struct DefaultStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project] + #[derive(Debug)] + pub struct DefaultTupleStruct<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + project = DefaultTupleStructNamedProj, + project_ref = DefaultTupleStructNamedProjRef, + )] + #[derive(Debug)] + pub struct DefaultTupleStructNamed<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + project = DefaultEnumProj, + project_ref = DefaultEnumProjRef, + )] + #[derive(Debug)] + pub enum DefaultEnum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + + #[::pin_project::pin_project(PinnedDrop)] + #[derive(Debug)] + pub struct PinnedDropStruct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pinned_drop] + impl<T, U> PinnedDrop for PinnedDropStruct<T, U> { + fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } + + #[::pin_project::pin_project(PinnedDrop)] + #[derive(Debug)] + pub struct PinnedDropTupleStruct<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pinned_drop] + impl<T, U> PinnedDrop for PinnedDropTupleStruct<T, U> { + fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } + + #[::pin_project::pin_project( + PinnedDrop, + project = PinnedDropEnumProj, + project_ref = PinnedDropEnumProjRef, + )] + #[derive(Debug)] + pub enum PinnedDropEnum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + + #[::pin_project::pinned_drop] + impl<T, U> PinnedDrop for PinnedDropEnum<T, U> { + fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } + + #[::pin_project::pin_project(project_replace)] + #[derive(Debug)] + pub struct ReplaceStruct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project( + project = ReplaceStructNamedProj, + project_ref = ReplaceStructNamedProjRef, + project_replace = ReplaceStructNamedProjOwn, + )] + #[derive(Debug)] + pub struct ReplaceStructNamed<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project(project_replace)] + #[derive(Debug)] + pub struct ReplaceTupleStruct<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + project = ReplaceTupleStructNamedProj, + project_ref = ReplaceTupleStructNamedProjRef, + project_replace = ReplaceTupleStructNamedProjOwn, + )] + #[derive(Debug)] + pub struct ReplaceTupleStructNamed<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + project = ReplaceEnumProj, + project_ref = ReplaceEnumProjRef, + project_replace = ReplaceEnumProjOwn, + )] + #[derive(Debug)] + pub enum ReplaceEnum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + + #[::pin_project::pin_project(UnsafeUnpin)] + #[derive(Debug)] + pub struct UnsafeUnpinStruct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project(UnsafeUnpin)] + #[derive(Debug)] + pub struct UnsafeUnpinTupleStruct<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + UnsafeUnpin, + project = UnsafeUnpinEnumProj, + project_ref = UnsafeUnpinEnumProjRef, + )] + #[derive(Debug)] + pub enum UnsafeUnpinEnum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + + #[::pin_project::pin_project(!Unpin)] + #[derive(Debug)] + pub struct NotUnpinStruct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } + + #[::pin_project::pin_project(!Unpin)] + #[derive(Debug)] + pub struct NotUnpinTupleStruct<T, U>(#[pin] pub T, pub U); + + #[::pin_project::pin_project( + !Unpin, + project = NotUnpinEnumProj, + project_ref = NotUnpinEnumProjRef, + )] + #[derive(Debug)] + pub enum NotUnpinEnum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, + } + }; + } + + mac!(); + } } pub mod box_pointers { @@ -782,32 +1021,34 @@ pub mod clippy_used_underscore_binding { } } +// Run `./dev.sh +$toolchain test --test lint` to update this. #[cfg(not(miri))] #[allow(box_pointers)] #[allow(clippy::restriction)] -#[rustversion::attr(not(nightly), ignore)] +#[rustversion::attr(before(2020-11-08), ignore)] // Note: This date is commit-date and the day before the toolchain date. #[test] fn check_lint_list() { - use std::{env, fs, path::PathBuf, process::Command, str}; + use std::{env, fs, path::Path, process::Command, str}; type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; fn assert_eq(expected_path: &str, actual: &str) -> Result<()> { - let manifest_dir = env::var_os("CARGO_MANIFEST_DIR") - .map(PathBuf::from) - .expect("CARGO_MANIFEST_DIR not set"); - let expected_path = manifest_dir.join(expected_path); - let expected = fs::read_to_string(&expected_path)?; + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + let expected_path = &manifest_dir.join(expected_path); + let expected = fs::read_to_string(expected_path)?; if expected != actual { - if env::var_os("CI").map_or(false, |v| v == "true") { - panic!( - "assertion failed:\n\nEXPECTED:\n{0}\n{1}\n{0}\n\nACTUAL:\n{0}\n{2}\n{0}\n", - "-".repeat(60), - expected, - actual, - ); + if env::var_os("CI").is_some() { + let actual_path = + &manifest_dir.join("target").join(expected_path.file_name().unwrap()); + fs::write(actual_path, actual)?; + let status = Command::new("git") + .args(&["--no-pager", "diff", "--no-index", "--"]) + .args(&[expected_path, actual_path]) + .status()?; + assert!(!status.success()); + panic!("assertion failed"); } else { - fs::write(&expected_path, actual)?; + fs::write(expected_path, actual)?; } } Ok(()) diff --git a/tests/lint.txt b/tests/lint.txt index e4c9f98..a258fb8 100644 --- a/tests/lint.txt +++ b/tests/lint.txt @@ -59,6 +59,7 @@ Lint checks provided by rustc: drop-bounds warn bounds of the form `T: Drop` are useless ellipsis-inclusive-range-patterns warn `...` range patterns are deprecated exported-private-dependencies warn public interface leaks type from a private dependency + function-item-references warn suggest casting to a function pointer when attempting to take references to function items illegal-floating-point-literal-pattern warn floating-point literals cannot be used in patterns improper-ctypes warn proper use of libc types in foreign modules improper-ctypes-definitions warn proper use of libc types in foreign item definitions @@ -72,6 +73,7 @@ Lint checks provided by rustc: mixed-script-confusables warn detects Unicode scripts whose mixed script confusables codepoints are solely used mutable-borrow-reservation-conflict warn reservation of a two-phased borrow conflicts with other shared borrows nontrivial-structural-match warn constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types + non-autolinks warn detects URLs that could be written using only angle brackets non-camel-case-types warn types, variants, traits and type parameters should have camel case names non-shorthand-field-patterns warn using `Struct { x: x }` instead of `Struct { x }` in a pattern non-snake-case warn variables, methods, functions, lifetime parameters and modules should have snake case names @@ -79,17 +81,20 @@ Lint checks provided by rustc: no-mangle-generic-items warn generic items must be mangled overlapping-patterns warn detects overlapping patterns path-statements warn path statements with no effect + private-intra-doc-links warn linking from a public item to a private one private-in-public warn detect private items in public interfaces not caught by the old implementation proc-macro-derive-resolution-fallback warn detects proc macro derives using inaccessible names from parent modules redundant-semicolons warn detects unnecessary trailing semicolons renamed-and-removed-lints warn lints that have been renamed or removed safe-packed-borrows warn safe borrows of fields of packed structs were erroneously allowed stable-features warn stable features found in `#[feature]` directive + temporary-cstring-as-ptr warn detects getting the inner pointer of a temporary `CString` trivial-bounds warn these bounds don't depend on an type parameters type-alias-bounds warn bounds in type aliases are not enforced tyvar-behind-raw-pointer warn raw pointer to an inference variable uncommon-codepoints warn detects uncommon Unicode codepoints in identifiers unconditional-recursion warn functions that cannot return without calling themselves + uninhabited-static warn uninhabited static unknown-lints warn unrecognized lint attribute unnameable-test-items warn detects an item that cannot be named being marked as `#[test_case]` unreachable-code warn detects unreachable code paths @@ -130,6 +135,7 @@ Lint checks provided by rustc: soft-unstable deny a feature gate that doesn't break dependent crates unconditional-panic deny operation will cause a panic at runtime unknown-crate-types deny unknown crate type found in `#[crate_type]` directive + useless-deprecated deny detects deprecation attributes with no effect Lint groups provided by rustc: @@ -137,11 +143,11 @@ Lint groups provided by rustc: name sub-lints ---- --------- warnings all lints that are set to issue warnings - future-incompatible keyword-idents, anonymous-parameters, illegal-floating-point-literal-pattern, private-in-public, pub-use-of-private-extern-crate, invalid-type-param-default, safe-packed-borrows, patterns-in-fns-without-body, late-bound-lifetime-arguments, order-dependent-trait-objects, coherence-leak-check, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate, unstable-name-collisions, where-clauses-object-safety, proc-macro-derive-resolution-fallback, macro-expanded-macro-exports-accessed-by-absolute-paths, ill-formed-attribute-input, conflicting-repr-hints, ambiguous-associated-items, mutable-borrow-reservation-conflict, indirect-structural-match, pointer-structural-match, nontrivial-structural-match, soft-unstable, cenum-impl-drop-cast, const-evaluatable-unchecked, array-into-iter + future-incompatible keyword-idents, anonymous-parameters, illegal-floating-point-literal-pattern, private-in-public, pub-use-of-private-extern-crate, invalid-type-param-default, safe-packed-borrows, patterns-in-fns-without-body, late-bound-lifetime-arguments, order-dependent-trait-objects, coherence-leak-check, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate, unstable-name-collisions, where-clauses-object-safety, proc-macro-derive-resolution-fallback, macro-expanded-macro-exports-accessed-by-absolute-paths, ill-formed-attribute-input, conflicting-repr-hints, ambiguous-associated-items, mutable-borrow-reservation-conflict, indirect-structural-match, pointer-structural-match, nontrivial-structural-match, soft-unstable, cenum-impl-drop-cast, const-evaluatable-unchecked, uninhabited-static, array-into-iter nonstandard-style non-camel-case-types, non-snake-case, non-upper-case-globals rust-2018-compatibility keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate rust-2018-idioms bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements - rustdoc broken-intra-doc-links, private-intra-doc-links, invalid-codeblock-attributes, missing-doc-code-examples, private-doc-tests, invalid-html-tags + rustdoc non-autolinks, broken-intra-doc-links, private-intra-doc-links, invalid-codeblock-attributes, missing-doc-code-examples, private-doc-tests, invalid-html-tags unused unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unreachable-patterns, overlapping-patterns, unused-must-use, unused-unsafe, path-statements, unused-attributes, unused-macros, unused-allocation, unused-doc-comments, unused-extern-crates, unused-features, unused-labels, unused-parens, unused-braces, redundant-semicolons diff --git a/tests/pin_project.rs b/tests/pin_project.rs index d9c37e5..17dbd2a 100644 --- a/tests/pin_project.rs +++ b/tests/pin_project.rs @@ -28,31 +28,34 @@ fn projection() { let mut s_orig = Pin::new(&mut s); let s = s_orig.as_mut().project(); - let x: Pin<&mut i32> = s.f1; - assert_eq!(*x, 1); - let y: &mut i32 = s.f2; - assert_eq!(*y, 2); + let _: Pin<&mut i32> = s.f1; + assert_eq!(*s.f1, 1); + let _: &mut i32 = s.f2; + assert_eq!(*s.f2, 2); assert_eq!(s_orig.as_ref().f1, 1); assert_eq!(s_orig.as_ref().f2, 2); let mut s = Struct { f1: 1, f2: 2 }; - - let StructProj { f1, f2 } = Pin::new(&mut s).project(); - let _: Pin<&mut i32> = f1; - let _: &mut i32 = f2; - - let StructProjRef { f1, f2 } = Pin::new(&s).project_ref(); - let _: Pin<&i32> = f1; - let _: &i32 = f2; - let mut s = Pin::new(&mut s); - let StructProjOwn { f1, f2 } = s.as_mut().project_replace(Struct { f1: 3, f2: 4 }); - let _: PhantomData<i32> = f1; - let _: i32 = f2; - assert_eq!(f2, 2); - assert_eq!(s.f1, 3); - assert_eq!(s.f2, 4); + { + let StructProj { f1, f2 } = s.as_mut().project(); + let _: Pin<&mut i32> = f1; + let _: &mut i32 = f2; + } + { + let StructProjRef { f1, f2 } = s.as_ref().project_ref(); + let _: Pin<&i32> = f1; + let _: &i32 = f2; + } + { + let StructProjOwn { f1, f2 } = s.as_mut().project_replace(Struct { f1: 3, f2: 4 }); + let _: PhantomData<i32> = f1; + let _: i32 = f2; + assert_eq!(f2, 2); + assert_eq!(s.f1, 3); + assert_eq!(s.f2, 4); + } #[pin_project(project_replace)] struct TupleStruct<T, U>(#[pin] T, U); @@ -60,10 +63,10 @@ fn projection() { let mut s = TupleStruct(1, 2); let s = Pin::new(&mut s).project(); - let x: Pin<&mut i32> = s.0; - assert_eq!(*x, 1); - let y: &mut i32 = s.1; - assert_eq!(*y, 2); + let _: Pin<&mut i32> = s.0; + assert_eq!(*s.0, 1); + let _: &mut i32 = s.1; + assert_eq!(*s.1, 2); #[pin_project(project = EnumProj, project_ref = EnumProjRef, project_replace = EnumProjOwn)] #[derive(Eq, PartialEq, Debug)] @@ -78,10 +81,9 @@ fn projection() { } let mut e = Enum::Tuple(1, 2); - let mut e_orig = Pin::new(&mut e); - let e = e_orig.as_mut().project(); + let mut e = Pin::new(&mut e); - match e { + match e.as_mut().project() { EnumProj::Tuple(x, y) => { let x: Pin<&mut i32> = x; assert_eq!(*x, 1); @@ -91,34 +93,36 @@ fn projection() { EnumProj::Struct { f1, f2 } => { let _: Pin<&mut i32> = f1; let _: &mut i32 = f2; + unreachable!() } - EnumProj::Unit => {} + EnumProj::Unit => unreachable!(), } - assert_eq!(Pin::into_ref(e_orig).get_ref(), &Enum::Tuple(1, 2)); + assert_eq!(&*e, &Enum::Tuple(1, 2)); let mut e = Enum::Struct { f1: 3, f2: 4 }; - let mut e = Pin::new(&mut e).project(); + let mut e = Pin::new(&mut e); - match &mut e { + match e.as_mut().project() { EnumProj::Tuple(x, y) => { - let _: &mut Pin<&mut i32> = x; - let _: &mut &mut i32 = y; + let _: Pin<&mut i32> = x; + let _: &mut i32 = y; + unreachable!() } EnumProj::Struct { f1, f2 } => { - let x: &mut Pin<&mut i32> = f1; - assert_eq!(**x, 3); - let y: &mut &mut i32 = f2; - assert_eq!(**y, 4); + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 3); + let _: &mut i32 = f2; + assert_eq!(*f2, 4); } - EnumProj::Unit => {} + EnumProj::Unit => unreachable!(), } - if let EnumProj::Struct { f1, f2 } = e { - let x: Pin<&mut i32> = f1; - assert_eq!(*x, 3); - let y: &mut i32 = f2; - assert_eq!(*y, 4); + if let EnumProj::Struct { f1, f2 } = e.as_mut().project() { + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 3); + let _: &mut i32 = f2; + assert_eq!(*f2, 4); } } @@ -140,7 +144,7 @@ fn enum_project_set() { let new_e = Enum::V2(val.as_ref().get_ref() == &25); e_orig.set(new_e); } - _ => unreachable!(), + EnumProj::V2(_) => unreachable!(), } assert_eq!(e, Enum::V2(true)); @@ -288,7 +292,7 @@ fn trait_bounds_on_type_generics() { f: &'a mut T, } - let _: Struct6<'_> = Struct6 { f: &mut [0u8; 16] }; + let _: Struct6<'_> = Struct6 { f: &mut [0_u8; 16] }; #[pin_project(project_replace)] pub struct Struct7<T: 'static> { @@ -433,7 +437,7 @@ fn lifetime_project() { #[pin_project(project_replace)] struct Struct2<'a, T, U> { #[pin] - pinned: &'a mut T, + pinned: &'a T, unpinned: U, } @@ -462,16 +466,16 @@ fn lifetime_project() { } impl<'b, T, U> Struct2<'b, T, U> { - fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a &'b mut T> { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a &'b T> { self.project_ref().pinned } - fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b mut T> { + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b T> { self.project().pinned } - fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&&'b mut T> { + fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&&'b T> { self.project_ref().pinned } - fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut &'b mut T> { + fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut &'b T> { self.project().pinned } } diff --git a/tests/pinned_drop.rs b/tests/pinned_drop.rs index e369ecb..78b73dc 100644 --- a/tests/pinned_drop.rs +++ b/tests/pinned_drop.rs @@ -201,19 +201,19 @@ fn self_ty_inside_macro_call() { } impl<T: Send> Struct<T> { - const ASSOC1: &'static str = "1"; + const ASSOC1: usize = 1; fn assoc1() {} } trait Trait { type Assoc2; - const ASSOC2: &'static str; + const ASSOC2: usize; fn assoc2(); } impl<T: Send> Trait for Struct<T> { type Assoc2 = (); - const ASSOC2: &'static str = "2"; + const ASSOC2: usize = 2; fn assoc2() {} } diff --git a/tests/proper_unpin.rs b/tests/proper_unpin.rs index ce2a6c8..8873572 100644 --- a/tests/proper_unpin.rs +++ b/tests/proper_unpin.rs @@ -16,16 +16,30 @@ pub mod default { assert_not_unpin!(Inner<PhantomPinned>); #[pin_project] - struct Foo<T, U> { + struct Struct<T, U> { #[pin] f1: Inner<T>, f2: U, } - assert_unpin!(Foo<(), ()>); - assert_unpin!(Foo<(), PhantomPinned>); - assert_not_unpin!(Foo<PhantomPinned, ()>); - assert_not_unpin!(Foo<PhantomPinned, PhantomPinned>); + assert_unpin!(Struct<(), ()>); + assert_unpin!(Struct<(), PhantomPinned>); + assert_not_unpin!(Struct<PhantomPinned, ()>); + assert_not_unpin!(Struct<PhantomPinned, PhantomPinned>); + + #[pin_project(project = EnumProj, project_ref = EnumProjRef)] + enum Enum<T, U> { + V1 { + #[pin] + f1: Inner<T>, + f2: U, + }, + } + + assert_unpin!(Enum<(), ()>); + assert_unpin!(Enum<(), PhantomPinned>); + assert_not_unpin!(Enum<PhantomPinned, ()>); + assert_not_unpin!(Enum<PhantomPinned, PhantomPinned>); #[pin_project] struct TrivialBounds { @@ -36,13 +50,13 @@ pub mod default { assert_not_unpin!(TrivialBounds); #[pin_project] - struct Bar<'a, T, U> { + struct PinRef<'a, T, U> { #[pin] f1: &'a mut Inner<T>, f2: U, } - assert_unpin!(Bar<'_, PhantomPinned, PhantomPinned>); + assert_unpin!(PinRef<'_, PhantomPinned, PhantomPinned>); } pub mod cfg { @@ -105,16 +119,16 @@ pub mod not_unpin { } #[pin_project(!Unpin)] - struct Foo<T, U> { + struct Struct<T, U> { #[pin] inner: Inner<T>, other: U, } - assert_not_unpin!(Foo<(), ()>); - assert_not_unpin!(Foo<(), PhantomPinned>); - assert_not_unpin!(Foo<PhantomPinned, ()>); - assert_not_unpin!(Foo<PhantomPinned, PhantomPinned>); + assert_not_unpin!(Struct<(), ()>); + assert_not_unpin!(Struct<(), PhantomPinned>); + assert_not_unpin!(Struct<PhantomPinned, ()>); + assert_not_unpin!(Struct<PhantomPinned, PhantomPinned>); #[pin_project(!Unpin)] struct TrivialBounds { @@ -125,11 +139,11 @@ pub mod not_unpin { assert_not_unpin!(TrivialBounds); #[pin_project(!Unpin)] - struct Bar<'a, T, U> { + struct PinRef<'a, T, U> { #[pin] inner: &'a mut Inner<T>, other: U, } - assert_not_unpin!(Bar<'_, (), ()>); + assert_not_unpin!(PinRef<'_, (), ()>); } diff --git a/tests/ui/cfg/cfg_attr-resolve.rs b/tests/ui/cfg/cfg_attr-resolve.rs index c7a246a..e36cc95 100644 --- a/tests/ui/cfg/cfg_attr-resolve.rs +++ b/tests/ui/cfg/cfg_attr-resolve.rs @@ -7,5 +7,5 @@ struct Foo<T> { fn main() { let mut x = Foo { f: 0_u8 }; - let _x = Pin::new(&mut x).project(); //~ ERROR E0599 + let _ = Pin::new(&mut x).project(); //~ ERROR E0599 } diff --git a/tests/ui/cfg/cfg_attr-resolve.stderr b/tests/ui/cfg/cfg_attr-resolve.stderr index ee1fa03..12bcc67 100644 --- a/tests/ui/cfg/cfg_attr-resolve.stderr +++ b/tests/ui/cfg/cfg_attr-resolve.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `project` found for struct `Pin<&mut Foo<u8>>` in the current scope - --> $DIR/cfg_attr-resolve.rs:10:31 + --> $DIR/cfg_attr-resolve.rs:10:30 | -10 | let _x = Pin::new(&mut x).project(); //~ ERROR E0599 - | ^^^^^^^ method not found in `Pin<&mut Foo<u8>>` +10 | let _ = Pin::new(&mut x).project(); //~ ERROR E0599 + | ^^^^^^^ method not found in `Pin<&mut Foo<u8>>` diff --git a/tests/ui/pin_project/packed-enum.stderr b/tests/ui/pin_project/packed-enum.stderr index 0a5d31b..afc8b30 100644 --- a/tests/ui/pin_project/packed-enum.stderr +++ b/tests/ui/pin_project/packed-enum.stderr @@ -1,4 +1,4 @@ -error[E0517]: attribute should be applied to struct or union +error[E0517]: attribute should be applied to a struct or union --> $DIR/packed-enum.rs:3:8 | 3 | #[repr(packed)] //~ ERROR E0517 @@ -8,7 +8,7 @@ error[E0517]: attribute should be applied to struct or union 6 | | } | |_- not a struct or union -error[E0517]: attribute should be applied to struct or union +error[E0517]: attribute should be applied to a struct or union --> $DIR/packed-enum.rs:9:8 | 9 | #[repr(packed)] //~ ERROR E0517 @@ -18,7 +18,7 @@ error[E0517]: attribute should be applied to struct or union 12 | | } | |_- not a struct or union -error[E0517]: attribute should be applied to struct or union +error[E0517]: attribute should be applied to a struct or union --> $DIR/packed-enum.rs:14:8 | 14 | #[repr(packed)] //~ ERROR E0517 diff --git a/tests/ui/pin_project/private_in_public-enum.stderr b/tests/ui/pin_project/private_in_public-enum.stderr index a14756b..6e3316c 100644 --- a/tests/ui/pin_project/private_in_public-enum.stderr +++ b/tests/ui/pin_project/private_in_public-enum.stderr @@ -5,7 +5,7 @@ error[E0446]: private type `PrivateEnum` in public interface | ^^^^^^^^^^^ can't leak private type ... 9 | enum PrivateEnum { - | - `PrivateEnum` declared as private + | ---------------- `PrivateEnum` declared as private error[E0446]: private type `foo::PrivateEnum` in public interface --> $DIR/private_in_public-enum.rs:15:11 @@ -14,4 +14,4 @@ error[E0446]: private type `foo::PrivateEnum` in public interface | ^^^^^^^^^^^ can't leak private type ... 18 | enum PrivateEnum { - | - `foo::PrivateEnum` declared as private + | ---------------- `foo::PrivateEnum` declared as private diff --git a/tests/ui/pin_project/project_replace_unsized.stderr b/tests/ui/pin_project/project_replace_unsized.stderr index b6ecb1b..e40db5f 100644 --- a/tests/ui/pin_project/project_replace_unsized.stderr +++ b/tests/ui/pin_project/project_replace_unsized.stderr @@ -7,7 +7,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim | - this type parameter needs to be `Sized` | = note: required because it appears within the type `Struct<T>` - = help: unsized locals are gated as an unstable feature + = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | 3 | #[pin_project(&project_replace)] //~ ERROR E0277 @@ -42,7 +42,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim | - this type parameter needs to be `Sized` | = note: required because it appears within the type `TupleStruct<T>` - = help: unsized locals are gated as an unstable feature + = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | 8 | #[pin_project(&project_replace)] //~ ERROR E0277 @@ -67,4 +67,4 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim | doesn't have a size known at compile-time | = note: all function arguments must have a statically known size - = help: unsized locals are gated as an unstable feature + = help: unsized fn params are gated as an unstable feature diff --git a/tests/ui/pin_project/project_replace_unsized_locals.rs b/tests/ui/pin_project/project_replace_unsized_fn_params.rs index 7e28e2c..e0fa25b 100644 --- a/tests/ui/pin_project/project_replace_unsized_locals.rs +++ b/tests/ui/pin_project/project_replace_unsized_fn_params.rs @@ -1,4 +1,4 @@ -#![feature(unsized_locals)] +#![feature(unsized_fn_params)] use pin_project::pin_project; diff --git a/tests/ui/pin_project/project_replace_unsized_locals.stderr b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr index ad965e5..622d12f 100644 --- a/tests/ui/pin_project/project_replace_unsized_locals.stderr +++ b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_locals.rs:6:8 + --> $DIR/project_replace_unsized_fn_params.rs:6:8 | 6 | struct Struct<T: ?Sized> { | ^^^^^^^-^^^^^^^^^ @@ -11,7 +11,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim = note: the return type of a function must have a statically known size error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_locals.rs:7:5 + --> $DIR/project_replace_unsized_fn_params.rs:7:5 | 6 | struct Struct<T: ?Sized> { | - this type parameter needs to be `Sized` @@ -19,7 +19,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim | ^ doesn't have a size known at compile-time error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_locals.rs:5:1 + --> $DIR/project_replace_unsized_fn_params.rs:5:1 | 5 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -31,7 +31,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_locals.rs:11:8 + --> $DIR/project_replace_unsized_fn_params.rs:11:8 | 11 | struct TupleStruct<T: ?Sized>(T); | ^^^^^^^^^^^^-^^^^^^^^^ @@ -43,7 +43,7 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim = note: the return type of a function must have a statically known size error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_locals.rs:10:1 + --> $DIR/project_replace_unsized_fn_params.rs:10:1 | 10 | #[pin_project(project_replace)] //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/pinned_drop/call-drop-inner.stderr b/tests/ui/pinned_drop/call-drop-inner.stderr index eb55ce7..53194b0 100644 --- a/tests/ui/pinned_drop/call-drop-inner.stderr +++ b/tests/ui/pinned_drop/call-drop-inner.stderr @@ -1,10 +1,14 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/call-drop-inner.rs:12:9 | -9 | #[pinned_drop] - | -------------- defined here -... 12 | __drop_inner(__self); | ^^^^^^^^^^^^ ------ supplied 1 argument | | | expected 0 arguments + | +note: function defined here + --> $DIR/call-drop-inner.rs:9:1 + | +9 | #[pinned_drop] + | ^^^^^^^^^^^^^^ + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) |