Skip to content

Improve Travis-CI config, fix warning and update to newest nightly #34

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

Merged
merged 5 commits into from
Oct 5, 2018
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
27 changes: 17 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
language: rust
rust:
- nightly

script:
- cargo build --verbose
- cargo test --verbose
- cargo build --verbose --features=nightly
- cargo test --verbose --features=nightly
matrix:
include:
- name: "Build & test on nightly WITH nightly feature"
rust: nightly
script:
- cargo build --verbose --features=nightly || travis_terminate 1
- cargo test --verbose --features=nightly || travis_terminate 1
- name: "Build & test on nightly WITHOUT nightly feature"
rust: nightly
script:
- cargo build --verbose || travis_terminate 1
- cargo test --verbose || travis_terminate 1
- name: "Build on beta"
rust: beta
script: cargo build --verbose

env:
- RUST_FLAGS="--deny warnings"

cache: cargo
global:
- RUSTFLAGS="--deny warnings"
40 changes: 35 additions & 5 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,39 @@ fn gen_method_item(
// Generate the list of argument used to call the method.
let args = get_arg_list(sig.decl.inputs.iter())?;

// Builds turbofish with generic types
let (_, generic_types, _) = sig.decl.generics.split_for_impl();
let generic_types = generic_types.as_turbofish();
// Build the turbofish type parameters. We need to pass type parameters
// explicitly as they cannot be inferred in all cases (e.g. something like
// `mem::size_of`). However, we don't explicitly specify lifetime
// parameters. Most lifetime parameters are so called late-bound lifetimes
// (ones that stick to input parameters) and Rust prohibits us from
// specifying late-bound lifetimes explicitly (which is not a problem,
// because those can always be correctly inferred). It would be possible to
// explicitly specify early-bound lifetimes, but this is hardly useful.
// Early-bound lifetimes are lifetimes that are only attached to the return
// type. Something like:
//
// fn foo<'a>() -> &'a i32
//
// It's hard to imagine how such a function would even work. So since those
// functions are really rare and special, we won't support them. In
// particular, for us to determine if a lifetime parameter is early- or
// late-bound would be *really* difficult.
//
// So we just specify type parameters. In the future, however, we need to
// add support for const parameters. But those are not remotely stable yet,
// so we can wait a bit still.
let generic_types = sig.decl.generics
.type_params()
.map(|param| {
let name = &param.ident;
quote! { #name , }
})
.collect::<TokenStream2>();
let generic_types = if generic_types.is_empty() {
generic_types
} else {
quote ! { ::<#generic_types> }
};

// Generate the body of the function. This mainly depends on the self type,
// but also on the proxy type.
Expand All @@ -452,14 +482,14 @@ fn gen_method_item(
// Receiver `self` (by value)
SelfType::Value => {
// The proxy type is a Box.
quote! { (*self).#name#generic_types(#args) }
quote! { (*self).#name #generic_types(#args) }
}

// `&self` or `&mut self` receiver
SelfType::Ref | SelfType::Mut => {
// The proxy type could be anything in the `Ref` case, and `&mut`
// or Box in the `Mut` case.
quote! { (*self).#name#generic_types(#args) }
quote! { (*self).#name #generic_types(#args) }
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//! references, some common smart pointers and closures.


#![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic, proc_macro_span))]
#![cfg_attr(
feature = "nightly",
feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)
)]

extern crate proc_macro;
#[macro_use]
Expand Down
13 changes: 8 additions & 5 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ pub(crate) fn get_dep_path() -> PathBuf {
// Obtain the build plan from `cargo build`. This JSON plan will tell us
// several things, including the path of the output of `auto_impl` (usually
// an .so file on Linux).
let output = Command::new(env!("CARGO"))
.args(&["build", "-Z", "unstable-options", "--build-plan"])
.stderr(Stdio::inherit())
.output()
.expect("failed to run `cargo build`");
let mut command = Command::new(env!("CARGO"));
command.args(&["build", "-Z", "unstable-options", "--build-plan"]);
command.stderr(Stdio::inherit());

#[cfg(feature = "nightly")]
command.arg("--features=nightly");

let output = command.output().expect("failed to run `cargo build`");

if !output.status.success() {
panic!("failed to run `cargo build`");
Expand Down