From 78dfce4e2bfdd5fe86f676a4c8b00fae5e3e2c5a Mon Sep 17 00:00:00 2001 From: Haibo Huang Date: Tue, 5 Jan 2021 21:36:55 -0800 Subject: Upgrade rust/crates/pin-project-lite to 0.2.1 Test: make Change-Id: Id43005242bae99ea6f523997b369af3fe538dc46 --- tests/auxiliary/mod.rs | 2 + tests/compiletest.rs | 8 +- tests/include/basic.rs | 25 ++++ tests/lint.rs | 142 ++++++++++++++----- tests/lint.txt | 148 -------------------- tests/proper_unpin.rs | 31 ++++- tests/test.rs | 215 ++++++++++++++++++++++++++--- tests/ui/invalid-bounds.stderr | 90 ++++++++---- tests/ui/invalid.stderr | 31 +++-- tests/ui/overlapping_lifetime_names.stderr | 4 +- tests/ui/unsupported.stderr | 64 ++++++--- 11 files changed, 498 insertions(+), 262 deletions(-) delete mode 100644 tests/lint.txt (limited to 'tests') diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index 1457099..e39037c 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -1,4 +1,6 @@ #![allow(dead_code, unused_macros)] +#![allow(box_pointers, unreachable_pub)] +#![allow(clippy::restriction)] macro_rules! assert_unpin { ($ty:ty) => { diff --git a/tests/compiletest.rs b/tests/compiletest.rs index d181491..af75bc5 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,8 +1,14 @@ #![warn(rust_2018_idioms, single_use_lifetimes)] -#[rustversion::attr(not(nightly), ignore)] +use std::env; + +#[rustversion::attr(before(2020-12-03), 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/*.rs"); } diff --git a/tests/include/basic.rs b/tests/include/basic.rs index 967cf81..25121f2 100644 --- a/tests/include/basic.rs +++ b/tests/include/basic.rs @@ -8,3 +8,28 @@ pub unpinned: U, } } + +::pin_project_lite::pin_project! { + #[project = DefaultStructProj] + #[project_ref = DefaultStructProjRef] + #[derive(Debug)] + pub struct DefaultStructNamed { + #[pin] + pub pinned: T, + pub unpinned: U, + } +} + +::pin_project_lite::pin_project! { + #[project = DefaultEnumProj] + #[project_ref = DefaultEnumProjRef] + #[derive(Debug)] + pub enum DefaultEnum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} diff --git a/tests/lint.rs b/tests/lint.rs index e81a13c..bbc3033 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -40,6 +40,8 @@ // Check interoperability with rustc and clippy lints. +mod auxiliary; + pub mod basic { include!("include/basic.rs"); } @@ -55,6 +57,20 @@ pub mod box_pointers { pub u: Box, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + p: Box, + u: Box, + }, + Unit, + } + } } pub mod explicit_outlives_requirements { @@ -72,6 +88,40 @@ pub mod explicit_outlives_requirements { pub unpinned: &'a mut U, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum<'a, T, U> + where + T: ?Sized, + U: ?Sized, + { + Struct { + #[pin] + pinned: &'a mut T, + unpinned: &'a mut U, + }, + Unit, + } + } +} + +pub mod variant_size_differences { + use pin_project_lite::pin_project; + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[allow(missing_debug_implementations, missing_copy_implementations)] // https://github.com/rust-lang/rust/pull/74060 + #[allow(variant_size_differences)] // for the type itself + #[allow(clippy::large_enum_variant)] // for the type itself + pub enum Enum { + V1 { f: u8 }, + V2 { f: [u8; 1024] }, + } + } } pub mod clippy_mut_mut { @@ -85,6 +135,20 @@ pub mod clippy_mut_mut { pub unpinned: &'a mut U, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum<'a, T, U> { + Struct { + #[pin] + pinned: &'a mut T, + unpinned: &'a mut U, + }, + Unit, + } + } } #[allow(unreachable_pub)] @@ -99,6 +163,21 @@ mod clippy_redundant_pub_crate { pub unpinned: U, } } + + #[allow(dead_code)] + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + } } pub mod clippy_type_repetition_in_bounds { @@ -115,6 +194,23 @@ pub mod clippy_type_repetition_in_bounds { pub unpinned: U, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum + where + Enum: Sized, + { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + } } pub mod clippy_used_underscore_binding { @@ -128,43 +224,17 @@ pub mod clippy_used_underscore_binding { pub _unpinned: U, } } -} -#[allow(box_pointers)] -#[allow(clippy::restriction)] -#[rustversion::attr(not(nightly), ignore)] -#[test] -fn check_lint_list() { - use std::{env, fs, path::PathBuf, process::Command, str}; - - type Result> = std::result::Result; - - 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)?; - 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, - ); - } else { - fs::write(&expected_path, actual)?; - } + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + _pinned: T, + _unpinned: U, + }, } - Ok(()) } - - (|| -> Result<()> { - let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); - let output = Command::new(rustc).args(&["-W", "help"]).output()?; - let new = str::from_utf8(&output.stdout)?; - assert_eq("tests/lint.txt", new) - })() - .unwrap_or_else(|e| panic!("{}", e)); } diff --git a/tests/lint.txt b/tests/lint.txt deleted file mode 100644 index e4c9f98..0000000 --- a/tests/lint.txt +++ /dev/null @@ -1,148 +0,0 @@ - -Available lint options: - -W Warn about - -A Allow - -D Deny - -F Forbid (deny and all attempts to override) - - -Lint checks provided by rustc: - - name default meaning - ---- ------- ------- - absolute-paths-not-starting-with-crate allow fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name - anonymous-parameters allow detects anonymous parameters - box-pointers allow use of owned (Box type) heap memory - deprecated-in-future allow detects use of items that will be deprecated in a future version - elided-lifetimes-in-paths allow hidden lifetime parameters in types are deprecated - explicit-outlives-requirements allow outlives requirements can be inferred - invalid-html-tags allow detects invalid HTML tags in doc comments - keyword-idents allow detects edition keywords being used as an identifier - macro-use-extern-crate allow the `#[macro_use]` attribute is now deprecated in favor of using macros via the module system - meta-variable-misuse allow possible meta-variable misuse at macro definition - missing-copy-implementations allow detects potentially-forgotten implementations of `Copy` - missing-crate-level-docs allow detects crates with no crate-level documentation - missing-debug-implementations allow detects missing implementations of Debug - missing-docs allow detects missing documentation for public members - missing-doc-code-examples allow detects publicly-exported items without code samples in their documentation - non-ascii-idents allow detects non-ASCII identifiers - pointer-structural-match allow pointers are not structural-match - private-doc-tests allow detects code samples in docs of private items not documented by rustdoc - single-use-lifetimes allow detects lifetime parameters that are only used once - trivial-casts allow detects trivial casts which could be removed - trivial-numeric-casts allow detects trivial casts of numeric types which could be removed - unaligned-references allow detects unaligned references to fields of packed structs - unreachable-pub allow `pub` items not reachable from crate root - unsafe-code allow usage of `unsafe` code - unsafe-op-in-unsafe-fn allow unsafe operations in unsafe functions without an explicit unsafe block are deprecated - unstable-features allow enabling unstable features (deprecated. do not use) - unused-crate-dependencies allow crate dependencies that are never used - unused-extern-crates allow extern crates that are never used - unused-import-braces allow unnecessary braces around an imported item - unused-lifetimes allow detects lifetime parameters that are never used - unused-qualifications allow detects unnecessarily qualified names - unused-results allow unused result of an expression in a statement - variant-size-differences allow detects enums with widely varying variant sizes - array-into-iter warn detects calling `into_iter` on arrays - asm-sub-register warn using only a subset of a register for inline asm inputs - bare-trait-objects warn suggest using `dyn Trait` for trait objects - bindings-with-variant-name warn detects pattern bindings with the same name as one of the matched variants - broken-intra-doc-links warn failures in resolving intra-doc link targets - cenum-impl-drop-cast warn a C-like enum implementing Drop is cast - clashing-extern-declarations warn detects when an extern fn has been declared with the same name but different types - coherence-leak-check warn distinct impls distinguished only by the leak-check code - confusable-idents warn detects visually confusable pairs between identifiers - const-evaluatable-unchecked warn detects a generic constant is used in a type without a emitting a warning - const-item-mutation warn detects attempts to mutate a `const` item - dead-code warn detect unused, unexported items - deprecated warn detects use of deprecated items - 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 - 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 - incomplete-features warn incomplete features that may function improperly in some or all cases - indirect-structural-match warn constant used in pattern contains value of non-structural-match type in a field or a variant - inline-no-sanitize warn detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]` - invalid-codeblock-attributes warn codeblock attribute looks a lot like a known one - invalid-value warn an invalid value is being created (such as a NULL reference) - irrefutable-let-patterns warn detects irrefutable patterns in if-let and while-let statements - late-bound-lifetime-arguments warn detects generic lifetime arguments in path segments with late bound lifetime parameters - 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-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 - non-upper-case-globals warn static constants should have uppercase identifiers - 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-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 - 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 - 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 - unreachable-patterns warn detects unreachable patterns - unstable-name-collisions warn detects name collision with an existing but unstable method - unused-allocation warn detects unnecessary allocations that can be eliminated - unused-assignments warn detect assignments that will never be read - unused-attributes warn detects attributes that were not used by the compiler - unused-braces warn unnecessary braces around an expression - unused-comparisons warn comparisons made useless by limits of the types involved - unused-doc-comments warn detects doc comments that aren't used by rustdoc - unused-features warn unused features found in crate-level `#[feature]` directives - unused-imports warn imports that are never used - unused-labels warn detects labels that are never used - unused-macros warn detects macros that were not used - unused-must-use warn unused result of a type flagged as `#[must_use]` - unused-mut warn detect mut variables which don't need to be mutable - unused-parens warn `if`, `match`, `while` and `return` do not need parentheses - unused-unsafe warn unnecessary use of an `unsafe` block - unused-variables warn detect variables which are not used in any way - warnings warn mass-change the level for lints which produce warnings - where-clauses-object-safety warn checks the object safety of where clauses - while-true warn suggest using `loop { }` instead of `while true { }` - ambiguous-associated-items deny ambiguous associated items - arithmetic-overflow deny arithmetic operation overflows - conflicting-repr-hints deny conflicts between `#[repr(..)]` hints that were previously accepted and used in practice - const-err deny constant evaluation detected erroneous expression - ill-formed-attribute-input deny ill-formed attribute inputs that were previously accepted and used in practice - incomplete-include deny trailing content in included file - invalid-type-param-default deny type parameter default erroneously allowed in invalid location - macro-expanded-macro-exports-accessed-by-absolute-paths deny macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths - mutable-transmutes deny mutating transmuted &mut T from &T may cause undefined behavior - no-mangle-const-items deny const items will not have their symbols exported - order-dependent-trait-objects deny trait-object types were treated as different depending on marker-trait order - overflowing-literals deny literal out of range for its type - patterns-in-fns-without-body deny patterns in functions without body were erroneously allowed - pub-use-of-private-extern-crate deny detect public re-exports of private extern crates - 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 - - -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 - 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 - 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 - - -Compiler plugins can provide additional lints and lint groups. To see a listing of these, re-run `rustc -W help` with a crate filename. diff --git a/tests/proper_unpin.rs b/tests/proper_unpin.rs index bbee78c..b1c72c1 100644 --- a/tests/proper_unpin.rs +++ b/tests/proper_unpin.rs @@ -16,17 +16,34 @@ pub mod default { assert_not_unpin!(Inner); pin_project! { - struct Foo { + struct Struct { #[pin] f1: Inner, f2: U, } } - assert_unpin!(Foo<(), ()>); - assert_unpin!(Foo<(), PhantomPinned>); - assert_not_unpin!(Foo); - assert_not_unpin!(Foo); + assert_unpin!(Struct<(), ()>); + assert_unpin!(Struct<(), PhantomPinned>); + assert_not_unpin!(Struct); + assert_not_unpin!(Struct); + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V1 { + #[pin] + f1: Inner, + f2: U, + }, + } + } + + assert_unpin!(Enum<(), ()>); + assert_unpin!(Enum<(), PhantomPinned>); + assert_not_unpin!(Enum); + assert_not_unpin!(Enum); pin_project! { struct TrivialBounds { @@ -38,12 +55,12 @@ pub mod default { assert_not_unpin!(TrivialBounds); pin_project! { - struct Bar<'a, T, U> { + struct PinRef<'a, T, U> { #[pin] f1: &'a mut Inner, f2: U, } } - assert_unpin!(Bar<'_, PhantomPinned, PhantomPinned>); + assert_unpin!(PinRef<'_, PhantomPinned, PhantomPinned>); } diff --git a/tests/test.rs b/tests/test.rs index 1af2b59..cd4f48b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -10,6 +10,8 @@ use pin_project_lite::pin_project; #[test] fn projection() { pin_project! { + #[project = StructProj] + #[project_ref = StructProjRef] struct Struct { #[pin] f1: T, @@ -21,21 +23,89 @@ 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 mut s = Pin::new(&mut s); + { + 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 s = Pin::new(&mut s).project(); + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Eq, PartialEq, Debug)] + enum Enum { + Struct { + #[pin] + f1: C, + f2: D, + }, + Unit, + } + } - let _: Pin<&mut i32> = s.f1; - let _: &mut i32 = s.f2; + let mut e = Enum::Struct { f1: 1, f2: 2 }; + let mut e = Pin::new(&mut e); + + match e.as_mut().project() { + EnumProj::Struct { f1, f2 } => { + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 1); + let _: &mut i32 = f2; + assert_eq!(*f2, 2); + } + EnumProj::Unit => unreachable!(), + } + + assert_eq!(&*e, &Enum::Struct { f1: 1, f2: 2 }); + + if let EnumProj::Struct { f1, f2 } = e.as_mut().project() { + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 1); + let _: &mut i32 = f2; + assert_eq!(*f2, 2); + } +} + +#[test] +fn enum_project_set() { + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Eq, PartialEq, Debug)] + enum Enum { + V1 { #[pin] f: u8 }, + V2 { f: bool }, + } + } + + let mut e = Enum::V1 { f: 25 }; + let mut e_orig = Pin::new(&mut e); + let e_proj = e_orig.as_mut().project(); + + match e_proj { + EnumProj::V1 { f } => { + let new_e = Enum::V2 { f: f.as_ref().get_ref() == &25 }; + e_orig.set(new_e); + } + EnumProj::V2 { .. } => unreachable!(), + } + + assert_eq!(e, Enum::V2 { f: true }); } #[test] @@ -48,6 +118,17 @@ fn where_clause() { f: T, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum + where + T: Copy, + { + V { f: T }, + } + } } #[test] @@ -86,6 +167,18 @@ fn where_clause_and_associated_type_field() { trait Static: 'static {} impl Static for Struct3 {} + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum + where + I: Iterator, + { + V1 { #[pin] f: I }, + V2 { f: I::Item }, + } + } } #[test] @@ -114,6 +207,20 @@ fn move_out() { let x = Struct { f: NotCopy }; let _val: NotCopy = x.f; + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V { f: NotCopy }, + } + } + + let x = Enum::V { f: NotCopy }; + #[allow(clippy::infallible_destructuring_match)] + let _val: NotCopy = match x { + Enum::V { f } => f, + }; } #[test] @@ -154,7 +261,7 @@ fn trait_bounds_on_type_generics() { } } - let _: Struct6<'_> = Struct6 { f: &mut [0u8; 16] }; + let _: Struct6<'_> = Struct6 { f: &mut [0_u8; 16] }; pin_project! { pub struct Struct7 { @@ -172,6 +279,14 @@ fn trait_bounds_on_type_generics() { f2: &'b u8, } } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum<'a, T: ?Sized> { + V { f: &'a mut T }, + } + } } #[test] @@ -200,11 +315,23 @@ fn lifetime_project() { pin_project! { struct Struct2<'a, T, U> { #[pin] - pinned: &'a mut T, + pinned: &'a T, unpinned: U, } } + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V { + #[pin] + pinned: T, + unpinned: U, + }, + } + } + impl Struct1 { fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { self.project_ref().pinned @@ -221,19 +348,42 @@ 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 } } + + impl Enum { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { + match self.project_ref() { + EnumProjRef::V { pinned, .. } => pinned, + } + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { + match self.project() { + EnumProj::V { pinned, .. } => pinned, + } + } + fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&T> { + match self.project_ref() { + EnumProjRef::V { pinned, .. } => pinned, + } + } + fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut T> { + match self.project() { + EnumProj::V { pinned, .. } => pinned, + } + } + } } mod visibility { @@ -278,7 +428,7 @@ fn dst() { let mut x = Struct1 { f: 0_u8 }; let x: Pin<&mut Struct1> = Pin::new(&mut x as _); - let _y: &mut (dyn core::fmt::Debug) = x.project().f; + let _: &mut (dyn core::fmt::Debug) = x.project().f; pin_project! { pub struct Struct2 { @@ -289,7 +439,7 @@ fn dst() { let mut x = Struct2 { f: 0_u8 }; let x: Pin<&mut Struct2> = Pin::new(&mut x as _); - let _y: Pin<&mut (dyn core::fmt::Debug + Unpin)> = x.project().f; + let _: Pin<&mut (dyn core::fmt::Debug + Unpin)> = x.project().f; pin_project! { struct Struct3 @@ -413,3 +563,36 @@ fn trailing_comma() { // } // } } + +#[test] +fn attrs() { + pin_project! { + #[project = Enum1Proj] + #[project_ref = Enum1ProjRef] + enum Enum1 { + #[cfg(not(any()))] + V { + f: () + }, + } + } + + pin_project! { + /// dox1 + #[project = Enum2Proj] + #[project_ref = Enum2ProjRef] + /// dox2 + #[derive(Debug)] + /// dox3 + enum Enum2 { + /// dox4 + V1 { + // TODO + // /// dox5 + f: () + }, + /// dox6 + V2, + } + } +} diff --git a/tests/ui/invalid-bounds.stderr b/tests/ui/invalid-bounds.stderr index 59e9b13..a565cce 100644 --- a/tests/ui/invalid-bounds.stderr +++ b/tests/ui/invalid-bounds.stderr @@ -1,14 +1,26 @@ -error: no rules expected the token `:` - --> $DIR/invalid-bounds.rs:4:33 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:3:1 | -4 | struct Generics1 { //~ ERROR no rules expected the token `:` - | ^ no rules expected this token in macro call +3 | / pin_project! { +4 | | struct Generics1 { //~ ERROR no rules expected the token `:` +5 | | field: T, +6 | | } +7 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `:` - --> $DIR/invalid-bounds.rs:10:33 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:9:1 + | +9 | / pin_project! { +10 | | struct Generics2 { //~ ERROR no rules expected the token `:` +11 | | field: T, +12 | | } +13 | | } + | |_^ no rules expected this token in macro call | -10 | struct Generics2 { //~ ERROR no rules expected the token `:` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: expected one of `+`, `,`, `=`, or `>`, found `:` --> $DIR/invalid-bounds.rs:15:1 @@ -58,23 +70,45 @@ error: expected one of `+`, `,`, `=`, or `>`, found `:` | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `Sized` - --> $DIR/invalid-bounds.rs:34:34 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:33:1 + | +33 | / pin_project! { +34 | | struct Generics6 { //~ ERROR no rules expected the token `Sized` +35 | | field: T, +36 | | } +37 | | } + | |_^ no rules expected this token in macro call | -34 | struct Generics6 { //~ ERROR no rules expected the token `Sized` - | ^^^^^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `:` - --> $DIR/invalid-bounds.rs:42:20 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:39:1 + | +39 | / pin_project! { +40 | | struct WhereClause1 +41 | | where +42 | | T: 'static : Sized //~ ERROR no rules expected the token `:` +... | +45 | | } +46 | | } + | |_^ no rules expected this token in macro call | -42 | T: 'static : Sized //~ ERROR no rules expected the token `:` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `:` - --> $DIR/invalid-bounds.rs:51:20 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:48:1 + | +48 | / pin_project! { +49 | | struct WhereClause2 +50 | | where +51 | | T: 'static : ?Sized //~ ERROR no rules expected the token `:` +... | +54 | | } +55 | | } + | |_^ no rules expected this token in macro call | -51 | T: 'static : ?Sized //~ ERROR no rules expected the token `:` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: expected `where`, or `{` after struct name, found `:` --> $DIR/invalid-bounds.rs:57:1 @@ -127,8 +161,16 @@ error: expected `where`, or `{` after struct name, found `:` | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `Sized` - --> $DIR/invalid-bounds.rs:87:21 +error: no rules expected the token `[` + --> $DIR/invalid-bounds.rs:84:1 | -87 | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` - | ^^^^^ no rules expected this token in macro call +84 | / pin_project! { +85 | | struct WhereClause6 +86 | | where +87 | | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` +... | +90 | | } +91 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/invalid.stderr b/tests/ui/invalid.stderr index f780e2e..06f2d79 100644 --- a/tests/ui/invalid.stderr +++ b/tests/ui/invalid.stderr @@ -1,14 +1,29 @@ -error: no rules expected the token `(` - --> $DIR/invalid.rs:5:14 +error: no rules expected the token `[` + --> $DIR/invalid.rs:3:1 | -5 | #[pin()] //~ ERROR no rules expected the token `(` - | ^ no rules expected this token in macro call +3 | / pin_project! { +4 | | struct A { +5 | | #[pin()] //~ ERROR no rules expected the token `(` +6 | | pinned: T, +7 | | } +8 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `#` - --> $DIR/invalid.rs:20:9 +error: no rules expected the token `[` + --> $DIR/invalid.rs:17:1 + | +17 | / pin_project! { +18 | | struct C { +19 | | #[pin] +20 | | #[pin] //~ ERROR no rules expected the token `#` +21 | | pinned: T, +22 | | } +23 | | } + | |_^ no rules expected this token in macro call | -20 | #[pin] //~ ERROR no rules expected the token `#` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find attribute `pin` in this scope --> $DIR/invalid.rs:11:7 diff --git a/tests/ui/overlapping_lifetime_names.stderr b/tests/ui/overlapping_lifetime_names.stderr index f86942c..8a9bb4f 100644 --- a/tests/ui/overlapping_lifetime_names.stderr +++ b/tests/ui/overlapping_lifetime_names.stderr @@ -8,7 +8,7 @@ error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in 6 | | field: &'__pin mut T, 7 | | } 8 | | } - | |_^ lifetime '__pin already in scope + | |_^ lifetime `'__pin` already in scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,7 +22,7 @@ error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in 6 | | field: &'__pin mut T, 7 | | } 8 | | } - | |_^ lifetime '__pin already in scope + | |_^ lifetime `'__pin` already in scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unsupported.stderr b/tests/ui/unsupported.stderr index 4f7b1ae..2cd17df 100644 --- a/tests/ui/unsupported.stderr +++ b/tests/ui/unsupported.stderr @@ -1,29 +1,53 @@ -error: no rules expected the token `}` - --> $DIR/unsupported.rs:4:21 +error: no rules expected the token `[` + --> $DIR/unsupported.rs:3:1 | -4 | struct Struct1 {} //~ ERROR no rules expected the token `}` - | ^ no rules expected this token in macro call +3 | / pin_project! { +4 | | struct Struct1 {} //~ ERROR no rules expected the token `}` +5 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `(` - --> $DIR/unsupported.rs:8:19 +error: no rules expected the token `[` + --> $DIR/unsupported.rs:7:1 + | +7 | / pin_project! { +8 | | struct Struct2(); //~ ERROR no rules expected the token `(` +9 | | } + | |_^ no rules expected this token in macro call | -8 | struct Struct2(); //~ ERROR no rules expected the token `(` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `;` - --> $DIR/unsupported.rs:12:19 +error: no rules expected the token `[` + --> $DIR/unsupported.rs:11:1 + | +11 | / pin_project! { +12 | | struct Struct3; //~ ERROR no rules expected the token `;` +13 | | } + | |_^ no rules expected this token in macro call | -12 | struct Struct3; //~ ERROR no rules expected the token `;` - | ^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `enum` - --> $DIR/unsupported.rs:16:5 +error: no rules expected the token `[` + --> $DIR/unsupported.rs:15:1 | -16 | enum Enum { //~ ERROR no rules expected the token `enum` - | ^^^^ no rules expected this token in macro call +15 | / pin_project! { +16 | | enum Enum { //~ ERROR no rules expected the token `enum` +17 | | A(u8) +18 | | } +19 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `union` - --> $DIR/unsupported.rs:22:5 +error: no rules expected the token `[` + --> $DIR/unsupported.rs:21:1 + | +21 | / pin_project! { +22 | | union Union { //~ ERROR no rules expected the token `union` +23 | | x: u8, +24 | | } +25 | | } + | |_^ no rules expected this token in macro call | -22 | union Union { //~ ERROR no rules expected the token `union` - | ^^^^^ no rules expected this token in macro call + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit v1.2.3