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

Do not display UnpinStruct in the document by default #71

Merged
merged 2 commits into from
Sep 4, 2019
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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
toolchain: nightly
- script: |
cargo clean
RUSTFLAGS='--cfg compiletest' cargo test -p pin-project --all-features --test compiletest
RUSTFLAGS='--cfg compiletest --cfg pin_project_show_unpin_struct' cargo test -p pin-project --all-features --test compiletest
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc #35 It becomes even more complicated :(

displayName: compiletest

- job: clippy
Expand Down
3 changes: 0 additions & 3 deletions pin-project-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ lazy_static = { version = "1.3", optional = true }

[dev-dependencies]
pin-project = { version = "0.4.0-alpha.8", path = ".." }

[build-dependencies]
rustc_version = "0.2.3"
45 changes: 14 additions & 31 deletions pin-project-internal/build.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
// Based on https://stackoverflow.com/a/49250753/1290530

use std::env;

use rustc_version::{version_meta, Channel};

fn main() {
// Set cfg flags depending on release channel
match version_meta().unwrap().channel {
// Enable our feature on nightly, or when using a
// locally build rustc.
//
// This is intended to avoid the issue that cannot know the actual
// trait implementation bounds of the `Unpin` implementation from the
// document of generated code.
// See [taiki-e/pin-project#53] and [rust-lang/rust#63281] for more details.
//
// [taiki-e/pin-project#53]: https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867
// [rust-lang/rust#63281]: https://github.com/rust-lang/rust/issues/63281
//
// You can opt-out of this in one of the followg ways:
// * Use `--cfg pin_project_stable_docs` in RUSTFLAGS.
// ```toml
// # in Cargo.toml
// [package.metadata.docs.rs]
// rustdoc-args = ["--cfg", "pin_project_stable_docs"]
// ```
// * Use `-Zallow-features` in RUSTFLAGS to disallow unstable features.
Channel::Nightly | Channel::Dev
if feature_allowed("proc_macro_def_site") && !cfg!(pin_project_stable_docs) =>
{
println!("cargo:rustc-cfg=proc_macro_def_site");
}
_ => {}
// While this crate supports stable Rust, it currently requires
// nightly Rust in order for rustdoc to correctly document auto-generated
// `Unpin` impls. This does not affect the runtime functionality of this crate,
// nor does it affect the safety of the api provided by this crate.
//
// This is disabled by default and can be enabled using
// `--cfg pin_project_show_unpin_struct` in RUSTFLAGS.
//
// Refs:
// * https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867
// * https://github.com/taiki-e/pin-project/pull/70
// * https://github.com/rust-lang/rust/issues/63281
if cfg!(pin_project_show_unpin_struct) && feature_allowed("proc_macro_def_site") {
println!("cargo:rustc-cfg=proc_macro_def_site");
}
}

Expand Down
8 changes: 6 additions & 2 deletions pin-project-internal/src/pin_project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,17 @@ impl Context {
{
proc_macro::Span::def_site().into()
}

#[cfg(not(proc_macro_def_site))]
{
Span::call_site()
}
};

let struct_ident = format_ident!("__UnpinStruct{}", orig_ident, span = make_span());
let struct_ident = if cfg!(proc_macro_def_site) {
format_ident!("UnpinStruct{}", orig_ident, span = make_span())
} else {
format_ident!("__UnpinStruct{}", orig_ident)
};
let always_unpin_ident = format_ident!("AlwaysUnpin{}", orig_ident, span = make_span());

// Generate a field in our new struct for every
Expand Down Expand Up @@ -292,6 +295,7 @@ impl Context {
///
/// [taiki-e/pin-project#53]: https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867
/// [rust-lang/rust#63281]: https://github.com/rust-lang/rust/issues/63281
#[allow(dead_code)]
#vis struct #struct_ident #full_generics #where_clause {
__pin_project_use_generics: #always_unpin_ident <(#(#type_params),*)>,

Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
//! * [`pinned_drop`] - An attribute for annotating a function that implements `Drop`.
//! * [`project`] - An attribute to support pattern matching.
//!
//! NOTE: While this crate supports stable Rust, it currently requires
//! nightly Rust in order for rustdoc to correctly document auto-generated
//! `Unpin` impls. This does not affect the runtime functionality of this crate,
//! nor does it affect the safety of the api provided by this crate.
//!
//!
//! ## Examples
//!
//! [`pin_project`] attribute creates a projection struct covering all the fields.
Expand Down
1 change: 1 addition & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(compiletest)]
#![cfg(pin_project_show_unpin_struct)]
#![cfg(feature = "project_attr")]
#![warn(rust_2018_idioms, single_use_lifetimes)]

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/pin_project/proper_unpin.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
error[E0277]: the trait bound `T: std::marker::Unpin` is not satisfied in `__UnpinStructFoo<T, U>`
error[E0277]: the trait bound `T: std::marker::Unpin` is not satisfied in `UnpinStructFoo<T, U>`
--> $DIR/proper_unpin.rs:20:5
|
17 | fn is_unpin<T: Unpin>() {}
| ----------------------- required by `is_unpin`
...
20 | is_unpin::<Foo<T, U>>(); //~ ERROR E0277
| ^^^^^^^^^^^^^^^^^^^^^ within `__UnpinStructFoo<T, U>`, the trait `std::marker::Unpin` is not implemented for `T`
| ^^^^^^^^^^^^^^^^^^^^^ within `UnpinStructFoo<T, U>`, the trait `std::marker::Unpin` is not implemented for `T`
|
= help: consider adding a `where T: std::marker::Unpin` bound
= note: required because it appears within the type `Inner<T>`
= note: required because it appears within the type `__UnpinStructFoo<T, U>`
= note: required because it appears within the type `UnpinStructFoo<T, U>`
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<T, U>`

error: aborting due to previous error
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pin_project/unpin_sneaky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ struct Foo {
inner: u8,
}

impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321
impl Unpin for UnpinStructFoo {} //~ ERROR E0412,E0321

fn main() {}
12 changes: 6 additions & 6 deletions tests/ui/pin_project/unpin_sneaky.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error[E0412]: cannot find type `__UnpinStructFoo` in this scope
error[E0412]: cannot find type `UnpinStructFoo` in this scope
--> $DIR/unpin_sneaky.rs:11:16
|
11 | impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321
| ^^^^^^^^^^^^^^^^ not found in this scope
11 | impl Unpin for UnpinStructFoo {} //~ ERROR E0412,E0321
| ^^^^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
|
3 | use crate::__UnpinStructFoo;
3 | use crate::UnpinStructFoo;
|

error[E0321]: cross-crate traits with a default impl, like `std::marker::Unpin`, can only be implemented for a struct/enum type, not `[type error]`
--> $DIR/unpin_sneaky.rs:11:1
|
11 | impl Unpin for __UnpinStructFoo {} //~ ERROR E0412,E0321
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
11 | impl Unpin for UnpinStructFoo {} //~ ERROR E0412,E0321
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type

error: aborting due to 2 previous errors

Expand Down