Skip to content

Commit d020565

Browse files
committed
Hacky rustup
1 parent 61aa5c9 commit d020565

16 files changed

+91
-123
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/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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,31 @@ 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(|info| info.call_site)
165+
.unwrap_or(expr.span);
160166
span_lint_and_then(
161167
cx,
162168
RANGE_PLUS_ONE,
163-
expr.span,
169+
span,
164170
"an inclusive range would be more readable",
165171
|db| {
166172
let start = start.map_or(String::new(), |x| Sugg::hir(cx, x, "x").to_string());
167173
let end = Sugg::hir(cx, y, "y");
168-
if let Some(is_wrapped) = &snippet_opt(cx, expr.span) {
174+
if let Some(is_wrapped) = &snippet_opt(cx, span) {
169175
if is_wrapped.starts_with('(') && is_wrapped.ends_with(')') {
170176
db.span_suggestion(
171-
expr.span,
177+
span,
172178
"use",
173179
format!("({}..={})", start, end),
174180
Applicability::MaybeIncorrect,
175181
);
176182
} else {
177183
db.span_suggestion(
178-
expr.span,
184+
span,
179185
"use",
180186
format!("{}..={}", start, end),
181187
Applicability::MachineApplicable, // snippet

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool {
863863
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool {
864864
matches!(
865865
cx.tables.qpath_def(qpath, id),
866-
def::Def::Variant(..) | def::Def::VariantCtor(..)
866+
def::Def::Variant(..) | def::Def::Ctor(_, def::CtorOf::Variant, _)
867867
)
868868
}
869869

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()

tests/compile-test.rs

Lines changed: 37 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,11 @@ 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+
fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<TestDescAndFn>) -> Result<bool, io::Error> {
7878
let mut result = true;
7979
let opts = compiletest::test_opts(config);
8080
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();
81+
let dir_path = dir.unwrap().path();
8682
set_var("CARGO_MANIFEST_DIR", &dir_path);
8783
for file in fs::read_dir(&dir_path)? {
8884
let file = file?;
@@ -101,9 +97,25 @@ fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDesc
10197
let test_name = compiletest::make_test_name(&config, &paths);
10298
let index = tests
10399
.iter()
104-
.position(|test| test.desc.name == test_name)
100+
.position(|test| test.desc.name.to_string() == test_name.to_string())
105101
.expect("The test should be in there");
106-
result &= test::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
102+
let opts = libtest::TestOpts {
103+
list: opts.list.clone(),
104+
filter: opts.filter.clone(),
105+
filter_exact: opts.filter_exact.clone(),
106+
exclude_should_panic: Default::default(),
107+
run_ignored: libtest::RunIgnored::No,
108+
run_tests: opts.run_tests.clone(),
109+
bench_benchmarks: opts.bench_benchmarks.clone(),
110+
logfile: opts.logfile.clone(),
111+
nocapture: opts.nocapture,
112+
color: libtest::ColorConfig::AutoColor,
113+
format: libtest::OutputFormat::Pretty,
114+
test_threads: opts.test_threads,
115+
skip: opts.skip.clone(),
116+
options: libtest::Options::new(),
117+
};
118+
result &= libtest::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
107119
}
108120
}
109121
Ok(result)
@@ -114,6 +126,22 @@ fn run_ui_toml() {
114126
let config = config("ui", path);
115127
let tests = compiletest::make_tests(&config);
116128

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

tests/ui/for_loop.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,83 +198,83 @@ error: it is more concise to loop over references to containers instead of using
198198
--> $DIR/for_loop.rs:170:15
199199
|
200200
LL | for _v in vec.iter() {}
201-
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
201+
| ^^^^^^^^^^
202202
|
203203
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
204204

205205
error: it is more concise to loop over references to containers instead of using explicit iteration methods
206206
--> $DIR/for_loop.rs:172:15
207207
|
208208
LL | for _v in vec.iter_mut() {}
209-
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
209+
| ^^^^^^^^^^^^^^
210210

211211
error: it is more concise to loop over containers instead of using explicit iteration methods`
212212
--> $DIR/for_loop.rs:175:15
213213
|
214214
LL | for _v in out_vec.into_iter() {}
215-
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
215+
| ^^^^^^^^^^^^^^^^^^^
216216
|
217217
= note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
218218

219219
error: it is more concise to loop over references to containers instead of using explicit iteration methods
220220
--> $DIR/for_loop.rs:178:15
221221
|
222222
LL | for _v in array.into_iter() {}
223-
| ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`
223+
| ^^^^^^^^^^^^^^^^^
224224

225225
error: it is more concise to loop over references to containers instead of using explicit iteration methods
226226
--> $DIR/for_loop.rs:183:15
227227
|
228228
LL | for _v in [1, 2, 3].iter() {}
229-
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
229+
| ^^^^^^^^^^^^^^^^
230230

231231
error: it is more concise to loop over references to containers instead of using explicit iteration methods
232232
--> $DIR/for_loop.rs:187:15
233233
|
234234
LL | for _v in [0; 32].iter() {}
235-
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
235+
| ^^^^^^^^^^^^^^
236236

237237
error: it is more concise to loop over references to containers instead of using explicit iteration methods
238238
--> $DIR/for_loop.rs:192:15
239239
|
240240
LL | for _v in ll.iter() {}
241-
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
241+
| ^^^^^^^^^
242242

243243
error: it is more concise to loop over references to containers instead of using explicit iteration methods
244244
--> $DIR/for_loop.rs:195:15
245245
|
246246
LL | for _v in vd.iter() {}
247-
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
247+
| ^^^^^^^^^
248248

249249
error: it is more concise to loop over references to containers instead of using explicit iteration methods
250250
--> $DIR/for_loop.rs:198:15
251251
|
252252
LL | for _v in bh.iter() {}
253-
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
253+
| ^^^^^^^^^
254254

255255
error: it is more concise to loop over references to containers instead of using explicit iteration methods
256256
--> $DIR/for_loop.rs:201:15
257257
|
258258
LL | for _v in hm.iter() {}
259-
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
259+
| ^^^^^^^^^
260260

261261
error: it is more concise to loop over references to containers instead of using explicit iteration methods
262262
--> $DIR/for_loop.rs:204:15
263263
|
264264
LL | for _v in bt.iter() {}
265-
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
265+
| ^^^^^^^^^
266266

267267
error: it is more concise to loop over references to containers instead of using explicit iteration methods
268268
--> $DIR/for_loop.rs:207:15
269269
|
270270
LL | for _v in hs.iter() {}
271-
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
271+
| ^^^^^^^^^
272272

273273
error: it is more concise to loop over references to containers instead of using explicit iteration methods
274274
--> $DIR/for_loop.rs:210:15
275275
|
276276
LL | for _v in bs.iter() {}
277-
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
277+
| ^^^^^^^^^
278278

279279
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
280280
--> $DIR/for_loop.rs:212:15

tests/ui/into_iter_on_ref.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
for _ in &[1, 2, 3] {}
1111
for _ in vec![X, X] {}
1212
for _ in &vec![X, X] {}
13-
for _ in [1, 2, 3].iter() {} //~ ERROR equivalent to .iter()
13+
for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
1414

1515
let _ = [1, 2, 3].iter(); //~ ERROR equivalent to .iter()
1616
let _ = vec![1, 2, 3].into_iter();

tests/ui/into_iter_on_ref.stderr

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
error: this .into_iter() call is equivalent to .iter() and will not move the array
2-
--> $DIR/into_iter_on_ref.rs:13:24
2+
--> $DIR/into_iter_on_ref.rs:15:23
33
|
4-
LL | for _ in [1, 2, 3].into_iter() {} //~ ERROR equivalent to .iter()
5-
| ^^^^^^^^^ help: call directly: `iter`
4+
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
5+
| ^^^^^^^^^ help: call directly: `iter`
66
|
77
note: lint level defined here
88
--> $DIR/into_iter_on_ref.rs:4:9
99
|
1010
LL | #![deny(clippy::into_iter_on_array)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: this .into_iter() call is equivalent to .iter() and will not move the array
14-
--> $DIR/into_iter_on_ref.rs:15:23
15-
|
16-
LL | let _ = [1, 2, 3].into_iter(); //~ ERROR equivalent to .iter()
17-
| ^^^^^^^^^ help: call directly: `iter`
18-
1913
error: this .into_iter() call is equivalent to .iter() and will not move the Vec
2014
--> $DIR/into_iter_on_ref.rs:17:30
2115
|
@@ -174,5 +168,5 @@ error: this .into_iter() call is equivalent to .iter() and will not move the Pat
174168
LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
175169
| ^^^^^^^^^ help: call directly: `iter`
176170

177-
error: aborting due to 28 previous errors
171+
error: aborting due to 27 previous errors
178172

0 commit comments

Comments
 (0)