Skip to content

Commit 16e0c28

Browse files
Merge pull request #34 from LukasKalbertodt/improve-travis
Improve Travis-CI config, fix warning and update to newest nightly
2 parents ce3ff8d + 0f63c85 commit 16e0c28

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

.travis.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
language: rust
2-
rust:
3-
- nightly
42

5-
script:
6-
- cargo build --verbose
7-
- cargo test --verbose
8-
- cargo build --verbose --features=nightly
9-
- cargo test --verbose --features=nightly
3+
matrix:
4+
include:
5+
- name: "Build & test on nightly WITH nightly feature"
6+
rust: nightly
7+
script:
8+
- cargo build --verbose --features=nightly || travis_terminate 1
9+
- cargo test --verbose --features=nightly || travis_terminate 1
10+
- name: "Build & test on nightly WITHOUT nightly feature"
11+
rust: nightly
12+
script:
13+
- cargo build --verbose || travis_terminate 1
14+
- cargo test --verbose || travis_terminate 1
15+
- name: "Build on beta"
16+
rust: beta
17+
script: cargo build --verbose
1018

1119
env:
12-
- RUST_FLAGS="--deny warnings"
13-
14-
cache: cargo
20+
global:
21+
- RUSTFLAGS="--deny warnings"

src/gen.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,39 @@ fn gen_method_item(
430430
// Generate the list of argument used to call the method.
431431
let args = get_arg_list(sig.decl.inputs.iter())?;
432432

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

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

458488
// `&self` or `&mut self` receiver
459489
SelfType::Ref | SelfType::Mut => {
460490
// The proxy type could be anything in the `Ref` case, and `&mut`
461491
// or Box in the `Mut` case.
462-
quote! { (*self).#name#generic_types(#args) }
492+
quote! { (*self).#name #generic_types(#args) }
463493
}
464494
};
465495

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
//! references, some common smart pointers and closures.
33
44

5-
#![cfg_attr(feature = "nightly", feature(proc_macro_diagnostic, proc_macro_span))]
5+
#![cfg_attr(
6+
feature = "nightly",
7+
feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)
8+
)]
69

710
extern crate proc_macro;
811
#[macro_use]

tests/util/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ pub(crate) fn get_dep_path() -> PathBuf {
2121
// Obtain the build plan from `cargo build`. This JSON plan will tell us
2222
// several things, including the path of the output of `auto_impl` (usually
2323
// an .so file on Linux).
24-
let output = Command::new(env!("CARGO"))
25-
.args(&["build", "-Z", "unstable-options", "--build-plan"])
26-
.stderr(Stdio::inherit())
27-
.output()
28-
.expect("failed to run `cargo build`");
24+
let mut command = Command::new(env!("CARGO"));
25+
command.args(&["build", "-Z", "unstable-options", "--build-plan"]);
26+
command.stderr(Stdio::inherit());
27+
28+
#[cfg(feature = "nightly")]
29+
command.arg("--features=nightly");
30+
31+
let output = command.output().expect("failed to run `cargo build`");
2932

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

0 commit comments

Comments
 (0)