From 665cf9622107144ad2b6415d1ff5d81999d42ae3 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Fri, 11 May 2018 08:37:48 +0200 Subject: [PATCH 1/3] Rustup to 2018-05-11 --- clippy_lints/src/consts.rs | 2 +- clippy_lints/src/loops.rs | 16 +++++++-------- clippy_lints/src/map_clone.rs | 4 ++-- clippy_lints/src/methods.rs | 12 ++++++------ clippy_lints/src/mut_mut.rs | 6 ++---- clippy_lints/src/mut_reference.rs | 6 ++---- clippy_lints/src/needless_borrow.rs | 8 ++++---- clippy_lints/src/ptr.rs | 6 ++---- clippy_lints/src/transmute.rs | 30 ++++++++++++++++------------- clippy_lints/src/utils/mod.rs | 4 ++-- clippy_lints/src/vec.rs | 4 ++-- 11 files changed, 48 insertions(+), 50 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 675342645b89..3668f5232930 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -426,7 +426,7 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<' _ => None, }, ConstVal::Value(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(n))) => match result.ty.sty { - ty::TyRef(_, tam) => match tam.ty.sty { + ty::TyRef(_, tam, _) => match tam.sty { ty::TyStr => { let alloc = tcx .interpret_interner diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 87ea98533c32..50e6e4c3b3f7 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -743,7 +743,7 @@ struct FixedOffsetVar { fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty) -> bool { let is_slice = match ty.sty { - ty::TyRef(_, ref subty) => is_slice_like(cx, subty.ty), + ty::TyRef(_, subty, _) => is_slice_like(cx, subty), ty::TySlice(..) | ty::TyArray(..) => true, _ => false, }; @@ -1365,9 +1365,9 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( if pat.len() == 2 { let arg_span = arg.span; let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).sty { - ty::TyRef(_, ref tam) => match (&pat[0].node, &pat[1].node) { - (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", tam.ty, tam.mutbl), - (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", tam.ty, MutImmutable), + ty::TyRef(_, ty, mutbl) => match (&pat[0].node, &pat[1].node) { + (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl), + (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, MutImmutable), _ => return, }, _ => return, @@ -1705,8 +1705,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { for expr in args { let ty = self.cx.tables.expr_ty_adjusted(expr); self.prefer_mutable = false; - if let ty::TyRef(_, mutbl) = ty.sty { - if mutbl.mutbl == MutMutable { + if let ty::TyRef(_, _, mutbl) = ty.sty { + if mutbl == MutMutable { self.prefer_mutable = true; } } @@ -1717,8 +1717,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; - if let ty::TyRef(_, mutbl) = ty.sty { - if mutbl.mutbl == MutMutable { + if let ty::TyRef(_, _, mutbl) = ty.sty { + if mutbl == MutMutable { self.prefer_mutable = true; } } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 23d3c8d433d3..3a473ba47753 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -51,8 +51,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { walk_ptrs_ty_depth(cx.tables.pat_ty(&first_arg.pat)).1 == 1 { // the argument is not an &mut T - if let ty::TyRef(_, tam) = ty.sty { - if tam.mutbl == MutImmutable { + if let ty::TyRef(_, _, mutbl) = ty.sty { + if mutbl == MutImmutable { span_help_and_lint(cx, MAP_CLONE, expr.span, &format!( "you seem to be using .map() to clone the contents of an {}, consider \ using `.cloned()`", type_name), diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 423be2106d16..212310a0f2a5 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -749,7 +749,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } match self_ty.sty { - ty::TyRef(_, ty) if ty.ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS { + ty::TyRef(_, ty, _) if ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS { if method_call.name == method && args.len() > pos { lint_single_char_pattern(cx, expr, &args[pos]); } @@ -967,8 +967,8 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name: /// Checks for the `CLONE_ON_COPY` lint. fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) { let ty = cx.tables.expr_ty(expr); - if let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = arg_ty.sty { - if let ty::TyRef(_, ty::TypeAndMut { ty: innermost, .. }) = inner.sty { + if let ty::TyRef(_, inner, _) = arg_ty.sty { + if let ty::TyRef(_, innermost, _) = inner.sty { span_lint_and_then( cx, CLONE_DOUBLE_REF, @@ -978,7 +978,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t |db| if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) { let mut ty = innermost; let mut n = 0; - while let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = ty.sty { + while let ty::TyRef(_, inner, _) = ty.sty { ty = inner; n += 1; } @@ -1300,7 +1300,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option may_slice(cx, ty.boxed_ty()), ty::TyAdt(..) => match_type(cx, ty, &paths::VEC), ty::TyArray(_, size) => size.val.to_raw_bits().expect("array length") < 32, - ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => may_slice(cx, inner), + ty::TyRef(_, inner, _) => may_slice(cx, inner), _ => false, } } @@ -1315,7 +1315,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option sugg::Sugg::hir_opt(cx, expr), ty::TyAdt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => sugg::Sugg::hir_opt(cx, expr), - ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => if may_slice(cx, inner) { + ty::TyRef(_, inner, _) => if may_slice(cx, inner) { sugg::Sugg::hir_opt(cx, expr) } else { None diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 13c1c930a055..129f022606ad 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -72,10 +72,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { ); } else if let ty::TyRef( _, - ty::TypeAndMut { - mutbl: hir::MutMutable, - .. - }, + _, + _, ) = self.cx.tables.expr_ty(e).sty { span_lint( diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 5e60ff624a18..a59909c48c89 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -63,10 +63,8 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ match parameter.sty { ty::TyRef( _, - ty::TypeAndMut { - mutbl: MutImmutable, - .. - }, + _, + _, ) | ty::TyRawPtr(ty::TypeAndMut { mutbl: MutImmutable, diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 4a6d825130ff..7fdef19f183c 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { } if_chain! { if let PatKind::Binding(BindingAnnotation::Ref, _, name, _) = pat.node; - if let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty; - if tam.mutbl == MutImmutable; - if let ty::TyRef(_, ref tam) = tam.ty.sty; + if let ty::TyRef(_, tam, mutbl) = cx.tables.pat_ty(pat).sty; + if mutbl == MutImmutable; + if let ty::TyRef(_, _, mutbl) = tam.sty; // only lint immutable refs, because borrowed `&mut T` cannot be moved out - if tam.mutbl == MutImmutable; + if mutbl == MutImmutable; then { span_lint_and_then( cx, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 17f46f78baa9..fb9369c78a02 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -152,10 +152,8 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() { if let ty::TyRef( _, - ty::TypeAndMut { - ty, - mutbl: MutImmutable, - }, + ty, + _ ) = ty.sty { if match_type(cx, ty, &paths::VEC) { diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 63ea96bbceac..4ee0a77f5491 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -229,16 +229,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { e.span, &format!("transmute from a type (`{}`) to itself", from_ty), ), - (&ty::TyRef(_, rty), &ty::TyRawPtr(ptr_ty)) => span_lint_and_then( + (&ty::TyRef(_, rty, rty_mutbl), &ty::TyRawPtr(ptr_ty)) => span_lint_and_then( cx, USELESS_TRANSMUTE, e.span, "transmute from a reference to a pointer", |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg = if ptr_ty == rty { + let rty_and_mut = ty::TypeAndMut { ty: rty, mutbl: rty_mutbl }; + + let sugg = if ptr_ty == rty_and_mut { arg.as_ty(to_ty) } else { - arg.as_ty(cx.tcx.mk_ptr(rty)).as_ty(to_ty) + arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty) }; db.span_suggestion(e.span, "try", sugg.to_string()); @@ -284,7 +286,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { to_ty ), ), - (&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty)) => span_lint_and_then( + (&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty, mutbl)) => span_lint_and_then( cx, TRANSMUTE_PTR_TO_REF, e.span, @@ -296,16 +298,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { ), |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let (deref, cast) = if to_ref_ty.mutbl == Mutability::MutMutable { + let (deref, cast) = if mutbl == Mutability::MutMutable { ("&mut *", "*mut") } else { ("&*", "*const") }; - let arg = if from_pty.ty == to_ref_ty.ty { + let arg = if from_pty.ty == to_ref_ty { arg } else { - arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty.ty))) + arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty))) }; db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string()); @@ -331,13 +333,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { ); }, ), - (&ty::TyRef(_, ref ref_from), &ty::TyRef(_, ref ref_to)) => { + (&ty::TyRef(_, ty_from, from_mutbl), &ty::TyRef(_, ty_to, to_mutbl)) => { if_chain! { - if let (&ty::TySlice(slice_ty), &ty::TyStr) = (&ref_from.ty.sty, &ref_to.ty.sty); + if let (&ty::TySlice(slice_ty), &ty::TyStr) = (&ty_from.sty, &ty_to.sty); if let ty::TyUint(ast::UintTy::U8) = slice_ty.sty; - if ref_from.mutbl == ref_to.mutbl; + if from_mutbl == to_mutbl; then { - let postfix = if ref_from.mutbl == Mutability::MutMutable { + let postfix = if from_mutbl == Mutability::MutMutable { "_mut" } else { "" @@ -367,8 +369,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { e.span, "transmute from a reference to a reference", |db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { - let sugg_paren = arg.as_ty(cx.tcx.mk_ptr(*ref_from)).as_ty(cx.tcx.mk_ptr(*ref_to)); - let sugg = if ref_to.mutbl == Mutability::MutMutable { + let ty_from_and_mut = ty::TypeAndMut { ty: ty_from, mutbl: from_mutbl }; + let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: to_mutbl }; + let sugg_paren = arg.as_ty(cx.tcx.mk_ptr(ty_from_and_mut)).as_ty(cx.tcx.mk_ptr(ty_to_and_mut)); + let sugg = if to_mutbl == Mutability::MutMutable { sugg_paren.mut_addr_deref() } else { sugg_paren.addr_deref() diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 9234926d534c..bc50eb2ac202 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -674,7 +674,7 @@ pub fn walk_ptrs_hir_ty(ty: &hir::Ty) -> &hir::Ty { /// Return the base type for references and raw pointers. pub fn walk_ptrs_ty(ty: Ty) -> Ty { match ty.sty { - ty::TyRef(_, ref tm) => walk_ptrs_ty(tm.ty), + ty::TyRef(_, ty, _) => walk_ptrs_ty(ty), _ => ty, } } @@ -684,7 +684,7 @@ pub fn walk_ptrs_ty(ty: Ty) -> Ty { pub fn walk_ptrs_ty_depth(ty: Ty) -> (Ty, usize) { fn inner(ty: Ty, depth: usize) -> (Ty, usize) { match ty.sty { - ty::TyRef(_, ref tm) => inner(tm.ty, depth + 1), + ty::TyRef(_, ty, _) => inner(ty, depth + 1), _ => (ty, depth), } } diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index c98cd8719f10..d5ed4cb712d5 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -35,8 +35,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { // search for `&vec![_]` expressions where the adjusted type is `&[_]` if_chain! { - if let ty::TyRef(_, ref ty) = cx.tables.expr_ty_adjusted(expr).sty; - if let ty::TySlice(..) = ty.ty.sty; + if let ty::TyRef(_, ty, _) = cx.tables.expr_ty_adjusted(expr).sty; + if let ty::TySlice(..) = ty.sty; if let ExprAddrOf(_, ref addressee) = expr.node; if let Some(vec_args) = higher::vec_macro(cx, addressee); then { From 39c0f575f2b291d683639afe4b016394d5c242bd Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 11 May 2018 09:50:29 +0200 Subject: [PATCH 2/3] Reintroduce the lost (im)mutability checks --- clippy_lints/src/mut_mut.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/mut_mut.rs b/clippy_lints/src/mut_mut.rs index 129f022606ad..501959e0f623 100644 --- a/clippy_lints/src/mut_mut.rs +++ b/clippy_lints/src/mut_mut.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> { } else if let ty::TyRef( _, _, - _, + hir::MutMutable, ) = self.cx.tables.expr_ty(e).sty { span_lint( diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index a59909c48c89..1184433c4dde 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -64,7 +64,7 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ ty::TyRef( _, _, - _, + MutImmutable, ) | ty::TyRawPtr(ty::TypeAndMut { mutbl: MutImmutable, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index fb9369c78a02..240b93e57299 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -153,7 +153,7 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< if let ty::TyRef( _, ty, - _ + MutImmutable ) = ty.sty { if match_type(cx, ty, &paths::VEC) { From 6baca22e27a58bf493fe4c2b509a899fbe8d46c4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 11 May 2018 09:56:57 +0200 Subject: [PATCH 3/3] Version bump --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 2 +- min_version.txt | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e27e76ef7daf..6bde6136f51a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.198 +* Rustup to *rustc 1.27.0-nightly (acd3871ba 2018-05-10)* + ## 0.0.197 * Rustup to *rustc 1.27.0-nightly (428ea5f6b 2018-05-06)* diff --git a/Cargo.toml b/Cargo.toml index 1a924bc7cf10..03d56de37cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.197" +version = "0.0.198" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -37,7 +37,7 @@ path = "src/driver.rs" [dependencies] # begin automatic update -clippy_lints = { version = "0.0.197", path = "clippy_lints" } +clippy_lints = { version = "0.0.198", path = "clippy_lints" } # end automatic update regex = "0.2" semver = "0.9" diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 8e0e2633c4f3..2b647359618a 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.197" +version = "0.0.198" # end automatic update authors = [ "Manish Goregaokar ", diff --git a/min_version.txt b/min_version.txt index b901c8ec520e..a2e0b6f1933a 100644 --- a/min_version.txt +++ b/min_version.txt @@ -1,7 +1,7 @@ -rustc 1.27.0-nightly (e82261dfb 2018-05-03) +rustc 1.27.0-nightly (acd3871ba 2018-05-10) binary: rustc -commit-hash: e82261dfbb5feaa2d28d2b138f4aabb2aa52c94b -commit-date: 2018-05-03 +commit-hash: acd3871ba17316419c644e17547887787628ec2f +commit-date: 2018-05-10 host: x86_64-unknown-linux-gnu release: 1.27.0-nightly LLVM version: 6.0