Skip to content

Commit 2c0e220

Browse files
authored
Rollup merge of rust-lang#63087 - crlf0710:tidy_2018, r=Mark-Simulacrum
Add very simple edition check to tidy. Fixes rust-lang#58099.
2 parents 2575e53 + 870efe3 commit 2c0e220

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

src/test/run-make/thumb-none-qemu/example/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "example"
33
version = "0.1.0"
44
authors = ["Hideki Sekine <[email protected]>"]
5-
# edition = "2018"
5+
edition = "2018"
66

77
[dependencies]
88
cortex-m = "0.5.4"

src/test/run-make/thumb-none-qemu/example/src/main.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// #![feature(stdsimd)]
22
#![no_main]
33
#![no_std]
4-
5-
extern crate cortex_m;
6-
7-
extern crate cortex_m_rt as rt;
8-
extern crate cortex_m_semihosting as semihosting;
9-
extern crate panic_halt;
10-
114
use core::fmt::Write;
125
use cortex_m::asm;
13-
use rt::entry;
6+
use cortex_m_rt::entry;
7+
use cortex_m_semihosting as semihosting;
8+
9+
//FIXME: This imports the provided #[panic_handler].
10+
#[allow(rust_2018_idioms)]
11+
extern crate panic_halt;
1412

1513
entry!(main);
1614

@@ -22,7 +20,7 @@ fn main() -> ! {
2220

2321
// write something through semihosting interface
2422
let mut hstdout = semihosting::hio::hstdout().unwrap();
25-
write!(hstdout, "x = {}\n", x);
23+
let _ = write!(hstdout, "x = {}\n", x);
2624

2725
// exit from qemu
2826
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);

src/tools/rustc-std-workspace-alloc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ license = 'MIT OR Apache-2.0'
66
description = """
77
Hack for the compiler's own build system
88
"""
9+
edition = "2018"
910

1011
[lib]
1112
path = "lib.rs"

src/tools/tidy/src/edition.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! Tidy check to ensure that crate `edition` is '2018'
2+
//!
3+
4+
use std::path::Path;
5+
6+
fn filter_dirs(path: &Path) -> bool {
7+
// FIXME: just use super::filter_dirs after the submodules are updated.
8+
if super::filter_dirs(path) {
9+
return true;
10+
}
11+
let skip = [
12+
"src/doc/book/second-edition",
13+
"src/doc/book/2018-edition",
14+
"src/doc/book/ci/stable-check",
15+
"src/doc/reference/stable-check",
16+
];
17+
skip.iter().any(|p| path.ends_with(p))
18+
}
19+
20+
fn is_edition_2018(mut line: &str) -> bool {
21+
line = line.trim();
22+
line == "edition = \"2018\"" || line == "edition = \'2018\'"
23+
}
24+
25+
pub fn check(path: &Path, bad: &mut bool) {
26+
super::walk(
27+
path,
28+
&mut |path| filter_dirs(path) || path.ends_with("src/test"),
29+
&mut |entry, contents| {
30+
let file = entry.path();
31+
let filename = file.file_name().unwrap();
32+
if filename != "Cargo.toml" {
33+
return;
34+
}
35+
let has_edition = contents.lines().any(is_edition_2018);
36+
if !has_edition {
37+
tidy_error!(
38+
bad,
39+
"{} doesn't have `edition = \"2018\"` on a separate line",
40+
file.display()
41+
);
42+
}
43+
},
44+
);
45+
}

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod style;
3434
pub mod errors;
3535
pub mod features;
3636
pub mod cargo;
37+
pub mod edition;
3738
pub mod pal;
3839
pub mod deps;
3940
pub mod extdeps;

src/tools/tidy/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
style::check(&path, &mut bad);
2323
errors::check(&path, &mut bad);
2424
cargo::check(&path, &mut bad);
25+
edition::check(&path, &mut bad);
2526
let collected = features::check(&path, &mut bad, verbose);
2627
pal::check(&path, &mut bad);
2728
unstable_book::check(&path, collected, &mut bad);

0 commit comments

Comments
 (0)