Skip to content

Hacky rustup #3905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
[dev-dependencies]
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
cargo_metadata = "0.7.1"
compiletest_rs = "0.3.19"
compiletest_rs = { version = "=0.3.19", features = ["tmp", "stable"] }
libtest = "0.0.1"
lazy_static = "1.0"
serde_derive = "1.0"
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl LintPass for AttrPass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident_str() {
match ident {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
"allow" | "warn" | "deny" | "forbid" => {
check_clippy_lint_names(cx, items);
},
Expand Down Expand Up @@ -242,8 +242,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {

for attr in &item.attrs {
if let Some(lint_list) = &attr.meta_item_list() {
if let Some(ident) = attr.ident_str() {
match ident {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
"allow" | "warn" | "deny" | "forbid" => {
// whitelist `unused_imports` and `deprecated` for `use` items
// and `unused_imports` for `extern crate` items with `macro_use`
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/enum_glob_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ impl LintPass for EnumGlobUse {

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) {
let map = cx.tcx.hir();
// only check top level `use` statements
for item in &m.item_ids {
self.lint_item(cx, cx.tcx.hir().expect_item(item.id));
self.lint_item(cx, map.expect_item(map.hir_to_node_id(item.id)));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
self.collect_anonymous_lifetimes(path, ty);
},
TyKind::Def(item, _) => {
if let ItemKind::Existential(ref exist_ty) = self.cx.tcx.hir().expect_item(item.id).node {
let map = self.cx.tcx.hir();
if let ItemKind::Existential(ref exist_ty) = map.expect_item(map.hir_to_node_id(item.id)).node {
for bound in &exist_ty.bounds {
if let GenericBound::Outlives(_) = *bound {
self.record(&None);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
for pat in &arm.pats {
if let PatKind::Path(ref path) = pat.deref().node {
if let QPath::Resolved(_, p) = path {
missing_variants.retain(|e| e.did != p.def.def_id());
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
}
} else if let PatKind::TupleStruct(ref path, ..) = pat.deref().node {
if let QPath::Resolved(_, p) = path {
missing_variants.retain(|e| e.did != p.def.def_id());
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
}
}
}
Expand All @@ -539,7 +539,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
String::new()
};
// This path assumes that the enum type is imported into scope.
format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.did), suffix)
format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.def_id), suffix)
})
.collect();

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl MissingDoc {
if let Some(meta) = meta;
if let MetaItemKind::List(list) = meta.node;
if let Some(meta) = list.get(0);
if let Some(name) = meta.ident_str();
if let Some(name) = meta.ident();
then {
name == "include"
name.as_str() == "include"
} else {
false
}
Expand Down
11 changes: 5 additions & 6 deletions clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
};

if let Some(trait_def_id) = trait_def_id {
if cx.tcx.hir().as_local_node_id(trait_def_id).is_some() {
if !cx.access_levels.is_exported(impl_item.hir_id) {
// If a trait is being implemented for an item, and the
// trait is not exported, we don't need #[inline]
return;
}
if cx.tcx.hir().as_local_node_id(trait_def_id).is_some() && !cx.access_levels.is_exported(impl_item.hir_id)
{
// If a trait is being implemented for an item, and the
// trait is not exported, we don't need #[inline]
return;
}
}

Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
if let ExprKind::Path(ref qpath) = callee.node {
let def = cx.tables.qpath_def(qpath, callee.hir_id);
match def {
Def::Struct(..) | Def::Variant(..) | Def::StructCtor(..) | Def::VariantCtor(..) => {
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) => {
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
},
_ => false,
Expand Down Expand Up @@ -166,9 +166,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
if let ExprKind::Path(ref qpath) = callee.node {
let def = cx.tables.qpath_def(qpath, callee.hir_id);
match def {
Def::Struct(..) | Def::Variant(..) | Def::StructCtor(..) | Def::VariantCtor(..)
if !has_drop(cx, cx.tables.expr_ty(expr)) =>
{
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) if !has_drop(cx, cx.tables.expr_ty(expr)) => {
Some(args.iter().collect())
},
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Pass {
},
ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr),
ExprKind::Path(ref qp) => {
if let Def::VariantCtor(def_id, _) = cx.tables.qpath_def(qp, expression.hir_id) {
if let Def::Ctor(def_id, def::CtorOf::Variant, _) = cx.tables.qpath_def(qp, expression.hir_id) {
return match_def_path(cx.tcx, def_id, &OPTION_NONE);
}

Expand Down
13 changes: 9 additions & 4 deletions clippy_lints/src/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,30 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}) = higher::range(cx, expr);
if let Some(y) = y_plus_one(end);
then {
let span = expr.span
.ctxt()
.outer()
.expn_info()
.map_or(expr.span, |info| info.call_site);
span_lint_and_then(
cx,
RANGE_PLUS_ONE,
expr.span,
span,
"an inclusive range would be more readable",
|db| {
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
let end = Sugg::hir(cx, y, "y");
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
if let Some(is_wrapped) = &snippet_opt(cx, span) {
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
db.span_suggestion(
expr.span,
span,
"use",
format!("({}..={})", start, end),
Applicability::MaybeIncorrect,
);
} else {
db.span_suggestion(
expr.span,
span,
"use",
format!("{}..={}", start, end),
Applicability::MachineApplicable, // snippet
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ impl LintPass for CharLitAsU8 {

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
use syntax::ast::{LitKind, UintTy};
use syntax::ast::LitKind;

if let ExprKind::Cast(ref e, _) = expr.node {
if let ExprKind::Lit(ref l) = e.node {
Expand Down Expand Up @@ -1818,7 +1818,6 @@ impl Ord for FullInt {

fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(FullInt, FullInt)> {
use std::*;
use syntax::ast::{IntTy, UintTy};

if let ExprKind::Cast(ref cast_exp, _) = expr.node {
let pre_cast_ty = cx.tables.expr_ty(cast_exp);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
if path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfUpper.name() {
if self.item_path.def == path.def {
span_use_self_lint(self.cx, path);
} else if let Def::StructCtor(ctor_did, CtorKind::Fn) = path.def {
} else if let Def::Ctor(ctor_did, def::CtorOf::Struct, CtorKind::Fn) = path.def {
if self.item_path.def.opt_def_id() == self.cx.tcx.parent(ctor_did) {
span_use_self_lint(self.cx, path);
}
Expand Down
10 changes: 8 additions & 2 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc::hir::def::Def;
use rustc::hir::def_id::CrateNum;
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
use rustc::hir::map::DisambiguatedDefPathData;
use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
use rustc::hir::Node;
use rustc::hir::*;
use rustc::lint::{LateContext, Level, Lint, LintContext};
Expand Down Expand Up @@ -178,6 +178,12 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?;

// Skip `::{{constructor}}` on tuple/unit structs.
if let DefPathData::Ctor = disambiguated_data.data {
return Ok(path);
}

path.push(disambiguated_data.data.as_interned_str().as_str());
Ok(path)
}
Expand Down Expand Up @@ -863,7 +869,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool {
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool {
matches!(
cx.tables.qpath_def(qpath, id),
def::Def::Variant(..) | def::Def::VariantCtor(..)
def::Def::Variant(..) | def::Def::Ctor(_, def::CtorOf::Variant, _)
)
}

Expand Down
5 changes: 5 additions & 0 deletions clippy_lints/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
then {
// report the error around the `vec!` not inside `<std macros>:`
let span = arg.span
.ctxt()
.outer()
.expn_info()
.map(|info| info.call_site)
.expect("unable to get call_site")
.ctxt()
.outer()
.expn_info()
Expand Down
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
ls.register_early_pass(Some(sess), true, false, pass);
}
for pass in late_lint_passes {
ls.register_late_pass(Some(sess), true, pass);
ls.register_late_pass(Some(sess), true, false, false, pass);
}

for (name, (to, deprecated_name)) in lint_groups {
Expand Down
47 changes: 38 additions & 9 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(test)]

use compiletest_rs as compiletest;
extern crate test;
use libtest::TestDescAndFn;

use std::env::{set_var, var};
use std::ffi::OsStr;
Expand Down Expand Up @@ -74,15 +74,12 @@ fn run_mode(mode: &str, dir: PathBuf) {
compiletest::run_tests(&cfg);
}

fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDescAndFn>) -> Result<bool, io::Error> {
#[warn(clippy::identity_conversion)]
fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<TestDescAndFn>) -> Result<bool, io::Error> {
let mut result = true;
let opts = compiletest::test_opts(config);
for dir in fs::read_dir(&config.src_base)? {
let dir = dir?;
if !dir.file_type()?.is_dir() {
continue;
}
let dir_path = dir.path();
let dir_path = dir.unwrap().path();
set_var("CARGO_MANIFEST_DIR", &dir_path);
for file in fs::read_dir(&dir_path)? {
let file = file?;
Expand All @@ -101,9 +98,25 @@ fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDesc
let test_name = compiletest::make_test_name(&config, &paths);
let index = tests
.iter()
.position(|test| test.desc.name == test_name)
.position(|test| test.desc.name.to_string() == test_name.to_string())
.expect("The test should be in there");
result &= test::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
let opts = libtest::TestOpts {
list: opts.list,
filter: opts.filter.clone(),
filter_exact: opts.filter_exact,
exclude_should_panic: Default::default(),
run_ignored: libtest::RunIgnored::No,
run_tests: opts.run_tests,
bench_benchmarks: opts.bench_benchmarks,
logfile: opts.logfile.clone(),
nocapture: opts.nocapture,
color: libtest::ColorConfig::AutoColor,
format: libtest::OutputFormat::Pretty,
test_threads: opts.test_threads,
skip: opts.skip.clone(),
options: libtest::Options::new(),
};
result &= libtest::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
}
}
Ok(result)
Expand All @@ -114,6 +127,22 @@ fn run_ui_toml() {
let config = config("ui", path);
let tests = compiletest::make_tests(&config);

let tests = tests
.into_iter()
.map(|test| {
libtest::TestDescAndFn {
desc: libtest::TestDesc {
name: libtest::TestName::DynTestName(test.desc.name.to_string()),
ignore: test.desc.ignore,
allow_fail: test.desc.allow_fail,
should_panic: libtest::ShouldPanic::No,
},
// oli obk giving up
testfn: unsafe { std::mem::transmute(test.testfn) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put up an issue about this, there's probably someone who already knows how to write it without transmute right? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think oli-obk meant opening issues only for broken tests, it's probably not possible to avoid transumte until libtest gets fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. It's just one line though, it doesn't seem that bad right?

}
})
.collect();

let res = run_ui_toml_tests(&config, tests);
match res {
Ok(true) => {},
Expand Down
Loading