Skip to content

Commit

Permalink
Do not display UnpinStruct in the document by default
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 4, 2019
1 parent 7da8926 commit 703dbb4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 52 deletions.
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
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
1 change: 0 additions & 1 deletion pin-project-internal/src/pin_project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ impl Context {
{
proc_macro::Span::def_site().into()
}

#[cfg(not(proc_macro_def_site))]
{
Span::call_site()
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

0 comments on commit 703dbb4

Please sign in to comment.