Add very simple edition check to tidy; and add missing edition = 2018s.
This commit is contained in:
parent
8b94e9e918
commit
870efe34c8
6 changed files with 56 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
||||||
name = "example"
|
name = "example"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Hideki Sekine <sekineh@me.com>"]
|
authors = ["Hideki Sekine <sekineh@me.com>"]
|
||||||
# edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = "0.5.4"
|
cortex-m = "0.5.4"
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
// #![feature(stdsimd)]
|
// #![feature(stdsimd)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate cortex_m;
|
|
||||||
|
|
||||||
extern crate cortex_m_rt as rt;
|
|
||||||
extern crate cortex_m_semihosting as semihosting;
|
|
||||||
extern crate panic_halt;
|
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use cortex_m::asm;
|
use cortex_m::asm;
|
||||||
use rt::entry;
|
use cortex_m_rt::entry;
|
||||||
|
use cortex_m_semihosting as semihosting;
|
||||||
|
|
||||||
|
//FIXME: This imports the provided #[panic_handler].
|
||||||
|
#[allow(rust_2018_idioms)]
|
||||||
|
extern crate panic_halt;
|
||||||
|
|
||||||
entry!(main);
|
entry!(main);
|
||||||
|
|
||||||
|
@ -22,7 +20,7 @@ fn main() -> ! {
|
||||||
|
|
||||||
// write something through semihosting interface
|
// write something through semihosting interface
|
||||||
let mut hstdout = semihosting::hio::hstdout().unwrap();
|
let mut hstdout = semihosting::hio::hstdout().unwrap();
|
||||||
write!(hstdout, "x = {}\n", x);
|
let _ = write!(hstdout, "x = {}\n", x);
|
||||||
|
|
||||||
// exit from qemu
|
// exit from qemu
|
||||||
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);
|
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);
|
||||||
|
|
|
@ -6,6 +6,7 @@ license = 'MIT OR Apache-2.0'
|
||||||
description = """
|
description = """
|
||||||
Hack for the compiler's own build system
|
Hack for the compiler's own build system
|
||||||
"""
|
"""
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
45
src/tools/tidy/src/edition.rs
Normal file
45
src/tools/tidy/src/edition.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
//! Tidy check to ensure that crate `edition` is '2018'
|
||||||
|
//!
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn filter_dirs(path: &Path) -> bool {
|
||||||
|
// FIXME: just use super::filter_dirs after the submodules are updated.
|
||||||
|
if super::filter_dirs(path) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let skip = [
|
||||||
|
"src/doc/book/second-edition",
|
||||||
|
"src/doc/book/2018-edition",
|
||||||
|
"src/doc/book/ci/stable-check",
|
||||||
|
"src/doc/reference/stable-check",
|
||||||
|
];
|
||||||
|
skip.iter().any(|p| path.ends_with(p))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_edition_2018(mut line: &str) -> bool {
|
||||||
|
line = line.trim();
|
||||||
|
line == "edition = \"2018\"" || line == "edition = \'2018\'"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
|
super::walk(
|
||||||
|
path,
|
||||||
|
&mut |path| filter_dirs(path) || path.ends_with("src/test"),
|
||||||
|
&mut |entry, contents| {
|
||||||
|
let file = entry.path();
|
||||||
|
let filename = file.file_name().unwrap();
|
||||||
|
if filename != "Cargo.toml" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let has_edition = contents.lines().any(is_edition_2018);
|
||||||
|
if !has_edition {
|
||||||
|
tidy_error!(
|
||||||
|
bad,
|
||||||
|
"{} doesn't have `edition = \"2018\"` on a separate line",
|
||||||
|
file.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ pub mod style;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod features;
|
pub mod features;
|
||||||
pub mod cargo;
|
pub mod cargo;
|
||||||
|
pub mod edition;
|
||||||
pub mod pal;
|
pub mod pal;
|
||||||
pub mod deps;
|
pub mod deps;
|
||||||
pub mod extdeps;
|
pub mod extdeps;
|
||||||
|
|
|
@ -22,6 +22,7 @@ fn main() {
|
||||||
style::check(&path, &mut bad);
|
style::check(&path, &mut bad);
|
||||||
errors::check(&path, &mut bad);
|
errors::check(&path, &mut bad);
|
||||||
cargo::check(&path, &mut bad);
|
cargo::check(&path, &mut bad);
|
||||||
|
edition::check(&path, &mut bad);
|
||||||
let collected = features::check(&path, &mut bad, verbose);
|
let collected = features::check(&path, &mut bad, verbose);
|
||||||
pal::check(&path, &mut bad);
|
pal::check(&path, &mut bad);
|
||||||
unstable_book::check(&path, collected, &mut bad);
|
unstable_book::check(&path, collected, &mut bad);
|
||||||
|
|
Loading…
Add table
Reference in a new issue