Skip to content

Commit 34457fb

Browse files
committed
Auto merge of #4388 - flip1995:rustup, r=phansch
Rustup Supersedes #4387 and #4385 This removes tests with the `try!` macro in them completely. There is no need for Clippy to support the `try!` macro, since it is deprecated now. [`StmtKind`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/enum.StmtKind.html) got a new variant [`Semi`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/enum.StmtKind.html#variant.Semi), which Just Works with the `author` lint. Nice. changelog: none
2 parents d829d9f + 87fa2d9 commit 34457fb

16 files changed

+43
-56
lines changed

clippy_lints/src/enum_clike.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
4343
if cx.tcx.data_layout.pointer_size.bits() != 64 {
4444
return;
4545
}
46-
if let ItemKind::Enum(ref def, _) = item.node {
46+
if let ItemKind::Enum(def, _) = &item.node {
4747
for var in &def.variants {
48-
let variant = &var.node;
49-
if let Some(ref anon_const) = variant.disr_expr {
48+
if let Some(anon_const) = &var.disr_expr {
5049
let param_env = ty::ParamEnv::empty();
5150
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
5251
let substs = InternalSubsts::identity_for_item(cx.tcx.global_tcx(), def_id);

clippy_lints/src/enum_variants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl_lint_pass!(EnumVariantNames => [
123123
]);
124124

125125
fn var2str(var: &Variant) -> LocalInternedString {
126-
var.node.ident.as_str()
126+
var.ident.as_str()
127127
}
128128

129129
/// Returns the number of chars that match from the start

clippy_lints/src/large_enum_variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
8585
"large size difference between variants",
8686
|db| {
8787
if variant.fields.len() == 1 {
88-
let span = match def.variants[i].node.data {
88+
let span = match def.variants[i].data {
8989
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => {
9090
fields[0].ty.span
9191
},

clippy_lints/src/missing_doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
197197
}
198198

199199
fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, v: &'tcx hir::Variant, _: &hir::Generics) {
200-
self.check_missing_docs_attrs(cx, &v.node.attrs, v.span, "a variant");
200+
self.check_missing_docs_attrs(cx, &v.attrs, v.span, "a variant");
201201
}
202202
}

clippy_lints/src/utils/author.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author {
9191
}
9292

9393
fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx hir::Variant, generics: &hir::Generics) {
94-
if !has_attr(cx.sess(), &var.node.attrs) {
94+
if !has_attr(cx.sess(), &var.attrs) {
9595
return;
9696
}
9797
prelude();

tests/ui/author/blocks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(stmt_expr_attributes)]
2+
#![allow(redundant_semicolon)]
23

34
#[rustfmt::skip]
45
fn main() {

tests/ui/author/blocks.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
error: statement with no effect
2-
--> $DIR/blocks.rs:14:5
2+
--> $DIR/blocks.rs:8:9
33
|
4-
LL | -x;
5-
| ^^^
4+
LL | ;;;;
5+
| ^^^^
66
|
77
= note: `-D clippy::no-effect` implied by `-D warnings`
88

9-
error: aborting due to previous error
9+
error: statement with no effect
10+
--> $DIR/blocks.rs:15:5
11+
|
12+
LL | -x;
13+
| ^^^
14+
15+
error: aborting due to 2 previous errors
1016

tests/ui/author/blocks.stdout

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
if_chain! {
22
if let ExprKind::Block(ref block) = expr.node;
33
if let Some(trailing_expr) = &block.expr;
4-
if block.stmts.len() == 0;
4+
if block.stmts.len() == 1;
5+
if let StmtKind::Semi(ref e, _) = block.stmts[0].node
6+
if let ExprKind::Tup(ref elements) = e.node;
7+
if elements.len() == 0;
58
then {
69
// report your lint here
710
}

tests/ui/cognitive_complexity.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ fn try_() -> Result<i32, &'static str> {
322322

323323
#[clippy::cognitive_complexity = "0"]
324324
fn try_again() -> Result<i32, &'static str> {
325-
let _ = r#try!(Ok(42));
326-
let _ = r#try!(Ok(43));
327-
let _ = r#try!(Ok(44));
328-
let _ = r#try!(Ok(45));
329-
let _ = r#try!(Ok(46));
330-
let _ = r#try!(Ok(47));
331-
let _ = r#try!(Ok(48));
332-
let _ = r#try!(Ok(49));
325+
let _ = Ok(42)?;
326+
let _ = Ok(43)?;
327+
let _ = Ok(44)?;
328+
let _ = Ok(45)?;
329+
let _ = Ok(46)?;
330+
let _ = Ok(47)?;
331+
let _ = Ok(48)?;
332+
let _ = Ok(49)?;
333333
match 5 {
334334
5 => Ok(5),
335335
_ => return Err("bla"),

tests/ui/cognitive_complexity.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ error: the function has a cognitive complexity of 1
230230
--> $DIR/cognitive_complexity.rs:324:1
231231
|
232232
LL | / fn try_again() -> Result<i32, &'static str> {
233-
LL | | let _ = r#try!(Ok(42));
234-
LL | | let _ = r#try!(Ok(43));
235-
LL | | let _ = r#try!(Ok(44));
233+
LL | | let _ = Ok(42)?;
234+
LL | | let _ = Ok(43)?;
235+
LL | | let _ = Ok(44)?;
236236
... |
237237
LL | | }
238238
LL | | }

tests/ui/if_same_then_else.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ fn if_same_then_else() -> Result<&'static str, ()> {
215215
};
216216

217217
if true {
218-
r#try!(Ok("foo"));
218+
Ok("foo")?;
219219
} else {
220220
//~ ERROR same body as `if` block
221-
r#try!(Ok("foo"));
221+
Ok("foo")?;
222222
}
223223

224224
if true {

tests/ui/if_same_then_else.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ error: this `if` has identical blocks
197197
LL | } else {
198198
| ____________^
199199
LL | | //~ ERROR same body as `if` block
200-
LL | | r#try!(Ok("foo"));
200+
LL | | Ok("foo")?;
201201
LL | | }
202202
| |_____^
203203
|
@@ -206,7 +206,7 @@ note: same as this
206206
|
207207
LL | if true {
208208
| _____________^
209-
LL | | r#try!(Ok("foo"));
209+
LL | | Ok("foo")?;
210210
LL | | } else {
211211
| |_____^
212212

tests/ui/redundant_closure_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ fn main() {
1919
#[allow(clippy::needless_return)]
2020
(|| return 2)();
2121
(|| -> Option<i32> { None? })();
22-
(|| -> Result<i32, i32> { r#try!(Err(2)) })();
22+
(|| -> Result<i32, i32> { Err(2)? })();
2323
}

tests/ui/swap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::all)]
2-
#![allow(clippy::blacklisted_name, unused_assignments)]
2+
#![allow(clippy::blacklisted_name, clippy::no_effect, redundant_semicolon, unused_assignments)]
33

44
struct Foo(u32);
55

tests/ui/unused_io_amount.rs

-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33

44
use std::io;
55

6-
fn try_macro<T: io::Read + io::Write>(s: &mut T) -> io::Result<()> {
7-
r#try!(s.write(b"test"));
8-
let mut buf = [0u8; 4];
9-
r#try!(s.read(&mut buf));
10-
Ok(())
11-
}
12-
136
fn question_mark<T: io::Read + io::Write>(s: &mut T) -> io::Result<()> {
147
s.write(b"test")?;
158
let mut buf = [0u8; 4];

tests/ui/unused_io_amount.stderr

+5-20
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,28 @@
11
error: handle written amount returned or use `Write::write_all` instead
22
--> $DIR/unused_io_amount.rs:7:5
33
|
4-
LL | r#try!(s.write(b"test"));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | s.write(b"test")?;
5+
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::unused-io-amount` implied by `-D warnings`
8-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
98

109
error: handle read amount returned or use `Read::read_exact` instead
1110
--> $DIR/unused_io_amount.rs:9:5
1211
|
13-
LL | r#try!(s.read(&mut buf));
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
17-
18-
error: handle written amount returned or use `Write::write_all` instead
19-
--> $DIR/unused_io_amount.rs:14:5
20-
|
21-
LL | s.write(b"test")?;
22-
| ^^^^^^^^^^^^^^^^^
23-
24-
error: handle read amount returned or use `Read::read_exact` instead
25-
--> $DIR/unused_io_amount.rs:16:5
26-
|
2712
LL | s.read(&mut buf)?;
2813
| ^^^^^^^^^^^^^^^^^
2914

3015
error: handle written amount returned or use `Write::write_all` instead
31-
--> $DIR/unused_io_amount.rs:21:5
16+
--> $DIR/unused_io_amount.rs:14:5
3217
|
3318
LL | s.write(b"test").unwrap();
3419
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3520

3621
error: handle read amount returned or use `Read::read_exact` instead
37-
--> $DIR/unused_io_amount.rs:23:5
22+
--> $DIR/unused_io_amount.rs:16:5
3823
|
3924
LL | s.read(&mut buf).unwrap();
4025
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4126

42-
error: aborting due to 6 previous errors
27+
error: aborting due to 4 previous errors
4328

0 commit comments

Comments
 (0)