Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Replace argument #266

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ struct Args {
project: Option<Ident>,
/// `project_ref = <ident>` argument.
project_ref: Option<Ident>,
/// `project_replace [= <ident>]` or `Replace` argument.
/// `project_replace [= <ident>]` argument.
project_replace: ProjReplace,
}

enum ProjReplace {
None,
/// `project_replace` or `Replace`.
/// `project_replace`.
Unnamed {
span: Span,
},
Expand Down Expand Up @@ -242,8 +242,6 @@ impl Parse for Args {
let mut not_unpin = None;
let mut project = None;
let mut project_ref = None;

let mut replace = None;
let mut project_replace_value = None;
let mut project_replace_span = None;

Expand Down Expand Up @@ -290,9 +288,10 @@ impl Parse for Args {
}
}
"Replace" => {
if replace.replace(token.span()).is_some() {
return Err(error!(token, "duplicate `Replace` argument"));
}
return Err(error!(
token,
"`Replace` argument was removed, use `project_replace` argument instead"
));
}
_ => return Err(error!(token, "unexpected argument: {}", token)),
}
Expand Down Expand Up @@ -333,19 +332,12 @@ impl Parse for Args {
span,
"arguments `PinnedDrop` and `project_replace` are mutually exclusive",
));
} else if replace.is_some() {
return Err(Error::new(
span,
"arguments `PinnedDrop` and `Replace` are mutually exclusive",
));
}
}
let project_replace = match (project_replace_span, project_replace_value, replace) {
(None, _, None) => ProjReplace::None,
// If both `project_replace` and `Replace` are specified,
// We always prefer `project_replace`'s span,
(Some(span), Some(ident), _) => ProjReplace::Named { ident, span },
(Some(span), ..) | (None, _, Some(span)) => ProjReplace::Unnamed { span },
let project_replace = match (project_replace_span, project_replace_value) {
(None, _) => ProjReplace::None,
(Some(span), Some(ident)) => ProjReplace::Named { ident, span },
(Some(span), None) => ProjReplace::Unnamed { span },
};
let unpin_impl = match (unsafe_unpin, not_unpin) {
(None, None) => UnpinImpl::Default,
Expand Down Expand Up @@ -427,7 +419,7 @@ struct Context<'a> {
project: bool,
/// `project_ref` argument.
project_ref: bool,
/// `project_replace [= <ident>]` or `Replace` argument.
/// `project_replace [= <ident>]` argument.
project_replace: ProjReplace,
}

Expand Down
18 changes: 3 additions & 15 deletions tests/ui/pin_project/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ mod pin_item {
mod pin_project_argument {
use pin_project::pin_project;

#[pin_project(Replace)] //~ ERROR `Replace` argument was removed, use `project_replace` argument instead
struct RemovedReplace(#[pin] ());

#[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier
struct Unexpected1(#[pin] ());

Expand All @@ -106,9 +109,6 @@ mod pin_project_argument {
#[pin_project(PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument
struct DuplicatePinnedDrop(#[pin] ());

#[pin_project(Replace, Replace)] //~ ERROR duplicate `Replace` argument
struct DuplicateReplace(#[pin] ());

#[pin_project(UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument
struct DuplicateUnsafeUnpin(#[pin] ());

Expand Down Expand Up @@ -142,24 +142,12 @@ mod pin_project_argument {
#[pin_project(project_replace = A)] // Ok
struct ProjectReplaceWithoutReplace(#[pin] ());

#[pin_project(PinnedDrop, Replace)] //~ ERROR arguments `PinnedDrop` and `Replace` are mutually exclusive
struct PinnedDropWithReplace1(#[pin] ());

#[pin_project(Replace, UnsafeUnpin, PinnedDrop)] //~ ERROR arguments `PinnedDrop` and `Replace` are mutually exclusive
struct PinnedDropWithReplace2(#[pin] ());

#[pin_project(PinnedDrop, project_replace)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive
struct PinnedDropWithProjectReplace1(#[pin] ());

#[pin_project(project_replace, UnsafeUnpin, PinnedDrop)] //~ ERROR arguments `PinnedDrop` and `project_replace` are mutually exclusive
struct PinnedDropWithProjectReplace2(#[pin] ());

#[pin_project(project_replace, Replace)] // Ok
struct ProjectReplaceWithReplace1(#[pin] ());

#[pin_project(project_replace = B, Replace)] // Ok
struct ProjectReplaceWithReplace2(#[pin] ());

#[pin_project(UnsafeUnpin, !Unpin)] //~ ERROR arguments `UnsafeUnpin` and `!Unpin` are mutually exclusive
struct UnsafeUnpinWithNotUnpin1(#[pin] ());

Expand Down
Loading