Skip to content

Commit 027a659

Browse files
committed
Auto merge of #3905 - rust-lang:compiletest, r=<try>
Hacky rustup This gets our tests back working, but we now are calling `transmute` in the compiletest code. Also I couldn't quickly figure out some test failures and won't have time to get to them until thursday, if someone could take them over that would be great (maybe just merge this PR and open issues for all failures and start addressing them?)
2 parents 61aa5c9 + 4192779 commit 027a659

23 files changed

+114
-74
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
4747
[dev-dependencies]
4848
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
4949
cargo_metadata = "0.7.1"
50-
compiletest_rs = "0.3.19"
50+
compiletest_rs = { version = "=0.3.19", features = ["tmp", "stable"] }
51+
libtest = "0.0.1"
5152
lazy_static = "1.0"
5253
serde_derive = "1.0"
5354
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }

clippy_lints/src/attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl LintPass for AttrPass {
208208
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
209209
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
210210
if let Some(items) = &attr.meta_item_list() {
211-
if let Some(ident) = attr.ident_str() {
212-
match ident {
211+
if let Some(ident) = attr.ident() {
212+
match &*ident.as_str() {
213213
"allow" | "warn" | "deny" | "forbid" => {
214214
check_clippy_lint_names(cx, items);
215215
},
@@ -242,8 +242,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
242242

243243
for attr in &item.attrs {
244244
if let Some(lint_list) = &attr.meta_item_list() {
245-
if let Some(ident) = attr.ident_str() {
246-
match ident {
245+
if let Some(ident) = attr.ident() {
246+
match &*ident.as_str() {
247247
"allow" | "warn" | "deny" | "forbid" => {
248248
// whitelist `unused_imports` and `deprecated` for `use` items
249249
// and `unused_imports` for `extern crate` items with `macro_use`

clippy_lints/src/enum_glob_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ impl LintPass for EnumGlobUse {
3939

4040
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
4141
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) {
42+
let map = cx.tcx.hir();
4243
// only check top level `use` statements
4344
for item in &m.item_ids {
44-
self.lint_item(cx, cx.tcx.hir().expect_item(item.id));
45+
self.lint_item(cx, map.expect_item(map.hir_to_node_id(item.id)));
4546
}
4647
}
4748
}

clippy_lints/src/lifetimes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
356356
self.collect_anonymous_lifetimes(path, ty);
357357
},
358358
TyKind::Def(item, _) => {
359-
if let ItemKind::Existential(ref exist_ty) = self.cx.tcx.hir().expect_item(item.id).node {
359+
let map = self.cx.tcx.hir();
360+
if let ItemKind::Existential(ref exist_ty) = map.expect_item(map.hir_to_node_id(item.id)).node {
360361
for bound in &exist_ty.bounds {
361362
if let GenericBound::Outlives(_) = *bound {
362363
self.record(&None);

clippy_lints/src/matches.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
516516
for pat in &arm.pats {
517517
if let PatKind::Path(ref path) = pat.deref().node {
518518
if let QPath::Resolved(_, p) = path {
519-
missing_variants.retain(|e| e.did != p.def.def_id());
519+
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
520520
}
521521
} else if let PatKind::TupleStruct(ref path, ..) = pat.deref().node {
522522
if let QPath::Resolved(_, p) = path {
523-
missing_variants.retain(|e| e.did != p.def.def_id());
523+
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
524524
}
525525
}
526526
}
@@ -539,7 +539,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
539539
String::new()
540540
};
541541
// This path assumes that the enum type is imported into scope.
542-
format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.did), suffix)
542+
format!("{}{}{}", ident_str, cx.tcx.def_path_str(v.def_id), suffix)
543543
})
544544
.collect();
545545

clippy_lints/src/missing_doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ impl MissingDoc {
5858
if let Some(meta) = meta;
5959
if let MetaItemKind::List(list) = meta.node;
6060
if let Some(meta) = list.get(0);
61-
if let Some(name) = meta.ident_str();
61+
if let Some(name) = meta.ident();
6262
then {
63-
name == "include"
63+
name.as_str() == "include"
6464
} else {
6565
false
6666
}

clippy_lints/src/missing_inline.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
162162
};
163163

164164
if let Some(trait_def_id) = trait_def_id {
165-
if cx.tcx.hir().as_local_node_id(trait_def_id).is_some() {
166-
if !cx.access_levels.is_exported(impl_item.hir_id) {
167-
// If a trait is being implemented for an item, and the
168-
// trait is not exported, we don't need #[inline]
169-
return;
170-
}
165+
if cx.tcx.hir().as_local_node_id(trait_def_id).is_some() && !cx.access_levels.is_exported(impl_item.hir_id)
166+
{
167+
// If a trait is being implemented for an item, and the
168+
// trait is not exported, we don't need #[inline]
169+
return;
171170
}
172171
}
173172

clippy_lints/src/no_effect.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
7272
if let ExprKind::Path(ref qpath) = callee.node {
7373
let def = cx.tables.qpath_def(qpath, callee.hir_id);
7474
match def {
75-
Def::Struct(..) | Def::Variant(..) | Def::StructCtor(..) | Def::VariantCtor(..) => {
75+
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) => {
7676
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
7777
},
7878
_ => false,
@@ -166,9 +166,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
166166
if let ExprKind::Path(ref qpath) = callee.node {
167167
let def = cx.tables.qpath_def(qpath, callee.hir_id);
168168
match def {
169-
Def::Struct(..) | Def::Variant(..) | Def::StructCtor(..) | Def::VariantCtor(..)
170-
if !has_drop(cx, cx.tables.expr_ty(expr)) =>
171-
{
169+
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) if !has_drop(cx, cx.tables.expr_ty(expr)) => {
172170
Some(args.iter().collect())
173171
},
174172
_ => None,

clippy_lints/src/question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Pass {
128128
},
129129
ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr),
130130
ExprKind::Path(ref qp) => {
131-
if let Def::VariantCtor(def_id, _) = cx.tables.qpath_def(qp, expression.hir_id) {
131+
if let Def::Ctor(def_id, def::CtorOf::Variant, _) = cx.tables.qpath_def(qp, expression.hir_id) {
132132
return match_def_path(cx.tcx, def_id, &OPTION_NONE);
133133
}
134134

clippy_lints/src/ranges.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,30 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
157157
}) = higher::range(cx, expr);
158158
if let Some(y) = y_plus_one(end);
159159
then {
160+
let span = expr.span
161+
.ctxt()
162+
.outer()
163+
.expn_info()
164+
.map_or(expr.span, |info| info.call_site);
160165
span_lint_and_then(
161166
cx,
162167
RANGE_PLUS_ONE,
163-
expr.span,
168+
span,
164169
"an inclusive range would be more readable",
165170
|db| {
166171
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
167172
let end = Sugg::hir(cx, y, "y");
168-
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
173+
if let Some(is_wrapped) = &snippet_opt(cx, span) {
169174
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
170175
db.span_suggestion(
171-
expr.span,
176+
span,
172177
"use",
173178
format!("({}..={})", start, end),
174179
Applicability::MaybeIncorrect,
175180
);
176181
} else {
177182
db.span_suggestion(
178-
expr.span,
183+
span,
179184
"use",
180185
format!("{}..={}", start, end),
181186
Applicability::MachineApplicable, // snippet

clippy_lints/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ impl LintPass for CharLitAsU8 {
15331533

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

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

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

18231822
if let ExprKind::Cast(ref cast_exp, _) = expr.node {
18241823
let pre_cast_ty = cx.tables.expr_ty(cast_exp);

clippy_lints/src/use_self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
233233
if path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfUpper.name() {
234234
if self.item_path.def == path.def {
235235
span_use_self_lint(self.cx, path);
236-
} else if let Def::StructCtor(ctor_did, CtorKind::Fn) = path.def {
236+
} else if let Def::Ctor(ctor_did, def::CtorOf::Struct, CtorKind::Fn) = path.def {
237237
if self.item_path.def.opt_def_id() == self.cx.tcx.parent(ctor_did) {
238238
span_use_self_lint(self.cx, path);
239239
}

clippy_lints/src/utils/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::hir::def::Def;
2727
use rustc::hir::def_id::CrateNum;
2828
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
2929
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
30-
use rustc::hir::map::DisambiguatedDefPathData;
30+
use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
3131
use rustc::hir::Node;
3232
use rustc::hir::*;
3333
use rustc::lint::{LateContext, Level, Lint, LintContext};
@@ -178,6 +178,12 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
178178
disambiguated_data: &DisambiguatedDefPathData,
179179
) -> Result<Self::Path, Self::Error> {
180180
let mut path = print_prefix(self)?;
181+
182+
// Skip `::{{constructor}}` on tuple/unit structs.
183+
if let DefPathData::Ctor = disambiguated_data.data {
184+
return Ok(path);
185+
}
186+
181187
path.push(disambiguated_data.data.as_interned_str().as_str());
182188
Ok(path)
183189
}
@@ -863,7 +869,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool {
863869
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool {
864870
matches!(
865871
cx.tables.qpath_def(qpath, id),
866-
def::Def::Variant(..) | def::Def::VariantCtor(..)
872+
def::Def::Variant(..) | def::Def::Ctor(_, def::CtorOf::Variant, _)
867873
)
868874
}
869875

clippy_lints/src/vec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5959
then {
6060
// report the error around the `vec!` not inside `<std macros>:`
6161
let span = arg.span
62+
.ctxt()
63+
.outer()
64+
.expn_info()
65+
.map(|info| info.call_site)
66+
.expect("unable to get call_site")
6267
.ctxt()
6368
.outer()
6469
.expn_info()

src/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
9393
ls.register_early_pass(Some(sess), true, false, pass);
9494
}
9595
for pass in late_lint_passes {
96-
ls.register_late_pass(Some(sess), true, pass);
96+
ls.register_late_pass(Some(sess), true, false, false, pass);
9797
}
9898

9999
for (name, (to, deprecated_name)) in lint_groups {

tests/compile-test.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(test)]
22

33
use compiletest_rs as compiletest;
4-
extern crate test;
4+
use libtest::TestDescAndFn;
55

66
use std::env::{set_var, var};
77
use std::ffi::OsStr;
@@ -74,15 +74,12 @@ fn run_mode(mode: &str, dir: PathBuf) {
7474
compiletest::run_tests(&cfg);
7575
}
7676

77-
fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDescAndFn>) -> Result<bool, io::Error> {
77+
#[warn(clippy::identity_conversion)]
78+
fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<TestDescAndFn>) -> Result<bool, io::Error> {
7879
let mut result = true;
7980
let opts = compiletest::test_opts(config);
8081
for dir in fs::read_dir(&config.src_base)? {
81-
let dir = dir?;
82-
if !dir.file_type()?.is_dir() {
83-
continue;
84-
}
85-
let dir_path = dir.path();
82+
let dir_path = dir.unwrap().path();
8683
set_var("CARGO_MANIFEST_DIR", &dir_path);
8784
for file in fs::read_dir(&dir_path)? {
8885
let file = file?;
@@ -101,9 +98,25 @@ fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDesc
10198
let test_name = compiletest::make_test_name(&config, &paths);
10299
let index = tests
103100
.iter()
104-
.position(|test| test.desc.name == test_name)
101+
.position(|test| test.desc.name.to_string() == test_name.to_string())
105102
.expect("The test should be in there");
106-
result &= test::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
103+
let opts = libtest::TestOpts {
104+
list: opts.list,
105+
filter: opts.filter.clone(),
106+
filter_exact: opts.filter_exact,
107+
exclude_should_panic: Default::default(),
108+
run_ignored: libtest::RunIgnored::No,
109+
run_tests: opts.run_tests,
110+
bench_benchmarks: opts.bench_benchmarks,
111+
logfile: opts.logfile.clone(),
112+
nocapture: opts.nocapture,
113+
color: libtest::ColorConfig::AutoColor,
114+
format: libtest::OutputFormat::Pretty,
115+
test_threads: opts.test_threads,
116+
skip: opts.skip.clone(),
117+
options: libtest::Options::new(),
118+
};
119+
result &= libtest::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
107120
}
108121
}
109122
Ok(result)
@@ -114,6 +127,22 @@ fn run_ui_toml() {
114127
let config = config("ui", path);
115128
let tests = compiletest::make_tests(&config);
116129

130+
let tests = tests
131+
.into_iter()
132+
.map(|test| {
133+
libtest::TestDescAndFn {
134+
desc: libtest::TestDesc {
135+
name: libtest::TestName::DynTestName(test.desc.name.to_string()),
136+
ignore: test.desc.ignore,
137+
allow_fail: test.desc.allow_fail,
138+
should_panic: libtest::ShouldPanic::No,
139+
},
140+
// oli obk giving up
141+
testfn: unsafe { std::mem::transmute(test.testfn) },
142+
}
143+
})
144+
.collect();
145+
117146
let res = run_ui_toml_tests(&config, tests);
118147
match res {
119148
Ok(true) => {},

0 commit comments

Comments
 (0)