Skip to content

Commit

Permalink
Check that we don't use any unstable features.
Browse files Browse the repository at this point in the history
We need to track Rust master, but don't want to cover unstable things.
As such, a new lint, `stable-check`, is added.

The second edition was already lint clean, but the first needed some
tweaks:

1. The closures chapter was showing off details of the closure traits,
   so just don't do that.
2. The FFI chapter was using internal libc to compile the tests, so just
   don't compile them anymore.
3. The compiler plugins chapter was vestigial and was moved to the
   unstable book.

Fixes rust-lang#558
  • Loading branch information
steveklabnik committed Mar 23, 2017
1 parent dba7772 commit 59f76f1
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 294 deletions.
8 changes: 8 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ set -e

export PATH=$PATH:/home/travis/.cargo/bin;

# feature check
cd ci/stable-check

cargo run -- ../../first-edition/src
cargo run -- ../../second-edition/src

cd ../..

# tests for the second edition

cd second-edition
Expand Down
4 changes: 4 additions & 0 deletions ci/stable-check/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ci/stable-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "stable-check"
version = "0.1.0"
authors = ["steveklabnik <steve@steveklabnik.com>"]

[dependencies]
70 changes: 70 additions & 0 deletions ci/stable-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::env;
use std::fmt;
use std::fs;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::path::Path;

fn main() {
let arg = env::args().nth(1).unwrap_or_else(|| {
println!("Please pass a src directory as the first argument");
std::process::exit(1);
});

match check_directory(&Path::new(&arg)) {
Ok(()) => println!("passed!"),
Err(e) => {
println!("Error: {}", e);
std::process::exit(1);
}
}

}

enum Error {
Io(io::Error),
LintFailure(String),
}

impl From<io::Error> for Error {
fn from(e: io::Error) -> Error {
Error::Io(e)
}
}

impl From<String> for Error {
fn from(e: String) -> Error {
Error::LintFailure(e)
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&Error::Io(ref e) => write!(f, "I/O error: {}", e),
&Error::LintFailure(ref e) => write!(f, "Lint failed: {}", e),
}
}
}

fn check_directory(dir: &Path) -> Result<(), Error> {
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();

if path.is_dir() {
continue;
}

let mut file = File::open(&path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

if contents.contains("#![feature") {
return Err(Error::LintFailure(format!("Feature flag found in {:?}", path)));
}
}

Ok(())
}
23 changes: 4 additions & 19 deletions first-edition/src/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,26 +222,11 @@ operator. From this, everything else clicks into place. In Rust, we use the
trait system to overload operators. Calling functions is no different. We have
three separate traits to overload with:

```rust
# #![feature(unboxed_closures)]
# mod foo {
pub trait Fn<Args> : FnMut<Args> {
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
}

pub trait FnMut<Args> : FnOnce<Args> {
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
}

pub trait FnOnce<Args> {
type Output;

extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
# }
```
* `Fn`
* `FnMut`
* `FnOnce`

You’ll notice a few differences between these traits, but a big one is `self`:
There are a few differences between these traits, but a big one is `self`:
`Fn` takes `&self`, `FnMut` takes `&mut self`, and `FnOnce` takes `self`. This
covers all three kinds of `self` via the usual method call syntax. But we’ve
split them up into three traits, rather than having a single one. This gives us
Expand Down
253 changes: 0 additions & 253 deletions first-edition/src/compiler-plugins.md

This file was deleted.

Loading

0 comments on commit 59f76f1

Please sign in to comment.