mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-12 23:13:15 +00:00
Merge branch 'master' into fix-3078
This commit is contained in:
commit
c6074a94b9
@ -59,9 +59,5 @@ derive-new = "0.5"
|
||||
# for more information.
|
||||
rustc-workspace-hack = "1.0.0"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.2.2"
|
||||
ansi_term = "0.11"
|
||||
|
||||
[features]
|
||||
debugging = []
|
||||
|
87
build.rs
87
build.rs
@ -13,98 +13,11 @@
|
||||
//! This build script was originally taken from the Rocket web framework:
|
||||
//! https://github.com/SergioBenitez/Rocket
|
||||
|
||||
use ansi_term::Colour::Red;
|
||||
use rustc_version::{version_meta, version_meta_for, Channel, Version, VersionMeta};
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
check_rustc_version();
|
||||
|
||||
// Forward the profile to the main compilation
|
||||
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
|
||||
// Don't rebuild even if nothing changed
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
}
|
||||
|
||||
fn check_rustc_version() {
|
||||
let string = include_str!("min_version.txt");
|
||||
let min_version_meta = version_meta_for(string).expect("Could not parse version string in min_version.txt");
|
||||
let current_version_meta = version_meta().expect("Could not retrieve current rustc version information from ENV");
|
||||
|
||||
let min_version = min_version_meta.clone().semver;
|
||||
let min_date_str = min_version_meta
|
||||
.clone()
|
||||
.commit_date
|
||||
.expect("min_version.txt does not contain a rustc commit date");
|
||||
|
||||
// Dev channel (rustc built from git) does not have any date or commit information in rustc -vV
|
||||
// `current_version_meta.commit_date` would crash, so we return early here.
|
||||
if current_version_meta.channel == Channel::Dev {
|
||||
return;
|
||||
}
|
||||
|
||||
let current_version = current_version_meta.clone().semver;
|
||||
let current_date_str = current_version_meta
|
||||
.clone()
|
||||
.commit_date
|
||||
.expect("current rustc version information does not contain a rustc commit date");
|
||||
|
||||
let print_version_err = |version: &Version, date: &str| {
|
||||
eprintln!(
|
||||
"> {} {}. {} {}.\n",
|
||||
"Installed rustc version is:",
|
||||
format!("{} ({})", version, date),
|
||||
"Minimum required rustc version:",
|
||||
format!("{} ({})", min_version, min_date_str)
|
||||
);
|
||||
};
|
||||
|
||||
if !correct_channel(¤t_version_meta) {
|
||||
eprintln!(
|
||||
"\n{} {}",
|
||||
Red.bold().paint("error:"),
|
||||
"Clippy requires a nightly version of Rust."
|
||||
);
|
||||
print_version_err(¤t_version, &*current_date_str);
|
||||
eprintln!(
|
||||
"{}{}{}",
|
||||
"See the README (", "https://github.com/rust-lang-nursery/rust-clippy#usage", ") for more information."
|
||||
);
|
||||
panic!("Aborting compilation due to incompatible compiler.")
|
||||
}
|
||||
|
||||
let current_date = str_to_ymd(¤t_date_str).unwrap();
|
||||
let min_date = str_to_ymd(&min_date_str).unwrap();
|
||||
|
||||
if current_date < min_date {
|
||||
eprintln!(
|
||||
"\n{} {}",
|
||||
Red.bold().paint("error:"),
|
||||
"Clippy does not support this version of rustc nightly."
|
||||
);
|
||||
eprintln!(
|
||||
"> {}{}{}",
|
||||
"Use `", "rustup update", "` or your preferred method to update Rust."
|
||||
);
|
||||
print_version_err(¤t_version, &*current_date_str);
|
||||
panic!("Aborting compilation due to incompatible compiler.")
|
||||
}
|
||||
}
|
||||
|
||||
fn correct_channel(version_meta: &VersionMeta) -> bool {
|
||||
match version_meta.channel {
|
||||
Channel::Stable | Channel::Beta => false,
|
||||
Channel::Nightly | Channel::Dev => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a string of %Y-%m-%d to a single u32 maintaining ordering.
|
||||
fn str_to_ymd(ymd: &str) -> Option<u32> {
|
||||
let ymd: Vec<u32> = ymd.split("-").filter_map(|s| s.parse::<u32>().ok()).collect();
|
||||
if ymd.len() != 3 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (y, m, d) = (ymd[0], ymd[1], ymd[2]);
|
||||
Some((y << 9) | (m << 5) | d)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#![feature(range_contains)]
|
||||
#![allow(unknown_lints, shadow_reuse, missing_docs_in_private_items)]
|
||||
#![recursion_limit = "256"]
|
||||
#![feature(iterator_find_map)]
|
||||
#![feature(macro_at_most_once_rep)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
@ -635,6 +634,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||
question_mark::QUESTION_MARK,
|
||||
ranges::ITERATOR_STEP_BY_ZERO,
|
||||
ranges::RANGE_MINUS_ONE,
|
||||
ranges::RANGE_PLUS_ONE,
|
||||
ranges::RANGE_ZIP_WITH_LEN,
|
||||
redundant_field_names::REDUNDANT_FIELD_NAMES,
|
||||
reference::DEREF_ADDROF,
|
||||
@ -756,7 +756,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||
ptr::CMP_NULL,
|
||||
ptr::PTR_ARG,
|
||||
question_mark::QUESTION_MARK,
|
||||
ranges::RANGE_MINUS_ONE,
|
||||
redundant_field_names::REDUNDANT_FIELD_NAMES,
|
||||
regex::REGEX_MACRO,
|
||||
regex::TRIVIAL_REGEX,
|
||||
@ -816,6 +815,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||
overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
|
||||
partialeq_ne_impl::PARTIALEQ_NE_IMPL,
|
||||
precedence::PRECEDENCE,
|
||||
ranges::RANGE_MINUS_ONE,
|
||||
ranges::RANGE_PLUS_ONE,
|
||||
ranges::RANGE_ZIP_WITH_LEN,
|
||||
reference::DEREF_ADDROF,
|
||||
reference::REF_IN_DEREF,
|
||||
@ -921,7 +922,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
|
||||
fallible_impl_from::FALLIBLE_IMPL_FROM,
|
||||
mutex_atomic::MUTEX_INTEGER,
|
||||
needless_borrow::NEEDLESS_BORROW,
|
||||
ranges::RANGE_PLUS_ONE,
|
||||
unwrap::PANICKING_UNWRAP,
|
||||
unwrap::UNNECESSARY_UNWRAP,
|
||||
]);
|
||||
|
@ -21,7 +21,7 @@ use crate::utils::sugg::DiagnosticBuilderExt;
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// ```rust
|
||||
/// struct Foo(Bar);
|
||||
///
|
||||
/// impl Foo {
|
||||
@ -63,7 +63,7 @@ declare_clippy_lint! {
|
||||
///
|
||||
/// **Example:**
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// ```rust
|
||||
/// struct Foo;
|
||||
///
|
||||
/// impl Foo {
|
||||
|
@ -57,7 +57,7 @@ declare_clippy_lint! {
|
||||
/// ```
|
||||
declare_clippy_lint! {
|
||||
pub RANGE_PLUS_ONE,
|
||||
nursery,
|
||||
complexity,
|
||||
"`x..(y+1)` reads better as `x..=y`"
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ declare_clippy_lint! {
|
||||
/// ```
|
||||
declare_clippy_lint! {
|
||||
pub RANGE_MINUS_ONE,
|
||||
style,
|
||||
complexity,
|
||||
"`x..=(y-1)` reads better as `x..y`"
|
||||
}
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
rustc 1.28.0-nightly (e3bf634e0 2018-06-28)
|
||||
binary: rustc
|
||||
commit-hash: e3bf634e060bc2f8665878288bcea02008ca346e
|
||||
commit-date: 2018-06-28
|
||||
host: x86_64-unknown-linux-gnu
|
||||
release: 1.28.0-nightly
|
||||
LLVM version: 6.0
|
222
src/driver.rs
222
src/driver.rs
@ -13,125 +13,123 @@ fn show_version() {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
use std::env;
|
||||
exit(rustc_driver::run(move || {
|
||||
use std::env;
|
||||
|
||||
if std::env::args().any(|a| a == "--version" || a == "-V") {
|
||||
show_version();
|
||||
return;
|
||||
}
|
||||
|
||||
let sys_root = option_env!("SYSROOT")
|
||||
.map(String::from)
|
||||
.or_else(|| std::env::var("SYSROOT").ok())
|
||||
.or_else(|| {
|
||||
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
||||
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
||||
home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
|
||||
})
|
||||
.or_else(|| {
|
||||
Command::new("rustc")
|
||||
.arg("--print")
|
||||
.arg("sysroot")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|out| String::from_utf8(out.stdout).ok())
|
||||
.map(|s| s.trim().to_owned())
|
||||
})
|
||||
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
|
||||
|
||||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
|
||||
// We're invoking the compiler programmatically, so we ignore this/
|
||||
let mut orig_args: Vec<String> = env::args().collect();
|
||||
if orig_args.len() <= 1 {
|
||||
std::process::exit(1);
|
||||
}
|
||||
if orig_args[1] == "rustc" {
|
||||
// we still want to be able to invoke it normally though
|
||||
orig_args.remove(1);
|
||||
}
|
||||
// this conditional check for the --sysroot flag is there so users can call
|
||||
// `clippy_driver` directly
|
||||
// without having to pass --sysroot or anything
|
||||
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
|
||||
orig_args.clone()
|
||||
} else {
|
||||
orig_args
|
||||
.clone()
|
||||
.into_iter()
|
||||
.chain(Some("--sysroot".to_owned()))
|
||||
.chain(Some(sys_root))
|
||||
.collect()
|
||||
};
|
||||
|
||||
// this check ensures that dependencies are built but not linted and the final
|
||||
// crate is
|
||||
// linted but not built
|
||||
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true")
|
||||
|| orig_args.iter().any(|s| s == "--emit=dep-info,metadata");
|
||||
|
||||
if clippy_enabled {
|
||||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
||||
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
|
||||
args.extend(
|
||||
extra_args
|
||||
.split("__CLIPPY_HACKERY__")
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(str::to_owned),
|
||||
);
|
||||
if std::env::args().any(|a| a == "--version" || a == "-V") {
|
||||
show_version();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
let mut controller = CompileController::basic();
|
||||
if clippy_enabled {
|
||||
controller.after_parse.callback = Box::new(move |state| {
|
||||
let mut registry = rustc_plugin::registry::Registry::new(
|
||||
state.session,
|
||||
state
|
||||
.krate
|
||||
.as_ref()
|
||||
.expect(
|
||||
"at this compilation stage \
|
||||
the crate must be parsed",
|
||||
)
|
||||
.span,
|
||||
);
|
||||
registry.args_hidden = Some(Vec::new());
|
||||
let sys_root = option_env!("SYSROOT")
|
||||
.map(String::from)
|
||||
.or_else(|| std::env::var("SYSROOT").ok())
|
||||
.or_else(|| {
|
||||
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
||||
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
||||
home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
|
||||
})
|
||||
.or_else(|| {
|
||||
Command::new("rustc")
|
||||
.arg("--print")
|
||||
.arg("sysroot")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|out| String::from_utf8(out.stdout).ok())
|
||||
.map(|s| s.trim().to_owned())
|
||||
})
|
||||
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
|
||||
|
||||
let conf = clippy_lints::read_conf(®istry);
|
||||
clippy_lints::register_plugins(&mut registry, &conf);
|
||||
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
|
||||
// We're invoking the compiler programmatically, so we ignore this/
|
||||
let mut orig_args: Vec<String> = env::args().collect();
|
||||
if orig_args.len() <= 1 {
|
||||
std::process::exit(1);
|
||||
}
|
||||
if orig_args[1] == "rustc" {
|
||||
// we still want to be able to invoke it normally though
|
||||
orig_args.remove(1);
|
||||
}
|
||||
// this conditional check for the --sysroot flag is there so users can call
|
||||
// `clippy_driver` directly
|
||||
// without having to pass --sysroot or anything
|
||||
let mut args: Vec<String> = if orig_args.iter().any(|s| s == "--sysroot") {
|
||||
orig_args.clone()
|
||||
} else {
|
||||
orig_args
|
||||
.clone()
|
||||
.into_iter()
|
||||
.chain(Some("--sysroot".to_owned()))
|
||||
.chain(Some(sys_root))
|
||||
.collect()
|
||||
};
|
||||
|
||||
let rustc_plugin::registry::Registry {
|
||||
early_lint_passes,
|
||||
late_lint_passes,
|
||||
lint_groups,
|
||||
llvm_passes,
|
||||
attributes,
|
||||
..
|
||||
} = registry;
|
||||
let sess = &state.session;
|
||||
let mut ls = sess.lint_store.borrow_mut();
|
||||
for pass in early_lint_passes {
|
||||
ls.register_early_pass(Some(sess), true, pass);
|
||||
}
|
||||
for pass in late_lint_passes {
|
||||
ls.register_late_pass(Some(sess), true, pass);
|
||||
// this check ensures that dependencies are built but not linted and the final
|
||||
// crate is
|
||||
// linted but not built
|
||||
let clippy_enabled = env::var("CLIPPY_TESTS").ok().map_or(false, |val| val == "true")
|
||||
|| orig_args.iter().any(|s| s == "--emit=dep-info,metadata");
|
||||
|
||||
if clippy_enabled {
|
||||
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]);
|
||||
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
|
||||
args.extend(
|
||||
extra_args
|
||||
.split("__CLIPPY_HACKERY__")
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(str::to_owned),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (name, to) in lint_groups {
|
||||
ls.register_group(Some(sess), true, name, to);
|
||||
}
|
||||
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
|
||||
let mut controller = CompileController::basic();
|
||||
if clippy_enabled {
|
||||
controller.after_parse.callback = Box::new(move |state| {
|
||||
let mut registry = rustc_plugin::registry::Registry::new(
|
||||
state.session,
|
||||
state
|
||||
.krate
|
||||
.as_ref()
|
||||
.expect(
|
||||
"at this compilation stage \
|
||||
the crate must be parsed",
|
||||
)
|
||||
.span,
|
||||
);
|
||||
registry.args_hidden = Some(Vec::new());
|
||||
|
||||
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
|
||||
sess.plugin_attributes.borrow_mut().extend(attributes);
|
||||
});
|
||||
}
|
||||
controller.compilation_done.stop = Compilation::Stop;
|
||||
let conf = clippy_lints::read_conf(®istry);
|
||||
clippy_lints::register_plugins(&mut registry, &conf);
|
||||
|
||||
if rustc_driver::run_compiler(&args, Box::new(controller), None, None)
|
||||
.0
|
||||
.is_err()
|
||||
{
|
||||
exit(101);
|
||||
}
|
||||
let rustc_plugin::registry::Registry {
|
||||
early_lint_passes,
|
||||
late_lint_passes,
|
||||
lint_groups,
|
||||
llvm_passes,
|
||||
attributes,
|
||||
..
|
||||
} = registry;
|
||||
let sess = &state.session;
|
||||
let mut ls = sess.lint_store.borrow_mut();
|
||||
for pass in early_lint_passes {
|
||||
ls.register_early_pass(Some(sess), true, pass);
|
||||
}
|
||||
for pass in late_lint_passes {
|
||||
ls.register_late_pass(Some(sess), true, pass);
|
||||
}
|
||||
|
||||
for (name, to) in lint_groups {
|
||||
ls.register_group(Some(sess), true, name, to);
|
||||
}
|
||||
clippy_lints::register_pre_expansion_lints(sess, &mut ls, &conf);
|
||||
|
||||
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
|
||||
sess.plugin_attributes.borrow_mut().extend(attributes);
|
||||
});
|
||||
}
|
||||
controller.compilation_done.stop = Compilation::Stop;
|
||||
|
||||
let args = args;
|
||||
rustc_driver::run_compiler(&args, Box::new(controller), None, None)
|
||||
}) as i32)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user