Skip to content

Commit

Permalink
How to NOT solve rust-lang#2788
Browse files Browse the repository at this point in the history
Seriously this workaround is terrible, don't merge it
  • Loading branch information
mati865 committed May 23, 2018
1 parent 3c6503e commit c5de91c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
op.node,
cx,
ty,
rty,
rty.into(),
Add: BiAdd,
Sub: BiSub,
Mul: BiMul,
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
ty::TyRef(_, tam, _) => match tam.sty {
ty::TyStr => {
let alloc = tcx
.interpret_interner
.get_alloc(ptr.alloc_id)
.unwrap();
.alloc_map
.lock()
.unwrap_memory(ptr.alloc_id);
let offset = ptr.offset.bytes() as usize;
let n = n as usize;
String::from_utf8(alloc.bytes[offset..(offset + n)].to_owned()).ok().map(Constant::Str)
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
if let ItemEnum(ref def, _) = item.node {
for var in &def.variants {
let variant = &var.node;
if let Some(body_id) = variant.disr_expr {
if let Some(ref anon_const) = variant.disr_expr {
let param_env = ty::ParamEnv::empty();
let did = cx.tcx.hir.body_owner_def_id(body_id);
let did = cx.tcx.hir.body_owner_def_id(anon_const.body);
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), did);
let instance = ty::Instance::new(did, substs);
let cid = GlobalId {
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
let lcpy = is_copy(cx, lty);
let rcpy = is_copy(cx, rty);
// either operator autorefs or both args are copyable
if (requires_ref || (lcpy && rcpy)) && implements_trait(cx, lty, trait_id, &[rty]) {
if (requires_ref || (lcpy && rcpy)) && implements_trait(cx, lty, trait_id, &[rty.into()]) {
span_lint_and_then(
cx,
OP_REF,
Expand All @@ -106,12 +106,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
);
},
)
} else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
} else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) {
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(left.span, "use the left value directly", lsnip);
})
} else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
} else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) {
span_lint_and_then(
cx,
OP_REF,
Expand All @@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
(&ExprAddrOf(_, ref l), _) => {
let lty = cx.tables.expr_ty(l);
let lcpy = is_copy(cx, lty);
if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right).into()]) {
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
let lsnip = snippet(cx, l.span, "...").to_string();
db.span_suggestion(left.span, "use the left value directly", lsnip);
Expand All @@ -139,7 +139,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
(_, &ExprAddrOf(_, ref r)) => {
let rty = cx.tables.expr_ty(r);
let rcpy = is_copy(cx, rty);
if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty.into()]) {
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
let rsnip = snippet(cx, r.span, "...").to_string();
db.span_suggestion(right.span, "use the right value directly", rsnip);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) {
// *arg impls PartialEq<other>
if !arg_ty
.builtin_deref(true)
.map_or(false, |tam| implements_trait(cx, tam.ty, partial_eq_trait_id, &[other_ty]))
.map_or(false, |tam| implements_trait(cx, tam.ty, partial_eq_trait_id, &[other_ty.into()]))
// arg impls PartialEq<*other>
&& !other_ty
.builtin_deref(true)
.map_or(false, |tam| implements_trait(cx, arg_ty, partial_eq_trait_id, &[tam.ty]))
.map_or(false, |tam| implements_trait(cx, arg_ty, partial_eq_trait_id, &[tam.ty.into()]))
// arg impls PartialEq<other>
&& !implements_trait(cx, arg_ty, partial_eq_trait_id, &[other_ty])
&& !implements_trait(cx, arg_ty, partial_eq_trait_id, &[other_ty.into()])
{
return;
}
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
cx,
cx.tcx.mk_imm_ref(&RegionKind::ReErased, ty),
t.def_id(),
&t.skip_binder().input_types().skip(1).collect::<Vec<_>>(),
// What an ugly abomination
&t.skip_binder().input_types().skip(1).collect::<Vec<_>>()

This comment has been minimized.

Copy link
@oli-obk

oli-obk May 23, 2018

you can remove the .collect::<Vec<_>>().into_iter() in the middle and everything should work.

This comment has been minimized.

Copy link
@mati865

mati865 May 23, 2018

Author Owner

I wasn't even thinking about it, just made it build with least effort.
I'll tweak few other things before opening PR.

.into_iter().map(|ty| ty.into()).collect::<Vec<_>>(),
)
}),
)
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings:
fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut Vec<(Name, Span)>) {
match ty.node {
TySlice(ref sty) => check_ty(cx, sty, bindings),
TyArray(ref fty, body_id) => {
TyArray(ref fty, ref body_id) => {
check_ty(cx, fty, bindings);
check_expr(cx, &cx.tcx.hir.body(body_id).value, bindings);
check_expr(cx, &cx.tcx.hir.body(body_id.body).value, bindings);
},
TyPtr(MutTy { ty: ref mty, .. }) | TyRptr(_, MutTy { ty: ref mty, .. }) => check_ty(cx, mty, bindings),
TyTup(ref tup) => for t in tup {
check_ty(cx, t, bindings)
},
TyTypeof(body_id) => check_expr(cx, &cx.tcx.hir.body(body_id).value, bindings),
TyTypeof(ref body_id) => check_expr(cx, &cx.tcx.hir.body(body_id.body).value, bindings),
_ => (),
}
}
Expand Down
30 changes: 15 additions & 15 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
(&ExprMethodCall(ref l_path, _, ref l_args), &ExprMethodCall(ref r_path, _, ref r_args)) => {
!self.ignore_fn && l_path == r_path && self.eq_exprs(l_args, r_args)
},
(&ExprRepeat(ref le, ll_id), &ExprRepeat(ref re, rl_id)) => {
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id));
let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id).value);
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id));
let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id).value);
(&ExprRepeat(ref le, ref ll_id), &ExprRepeat(ref re, ref rl_id)) => {
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);

self.eq_expr(le, re) && ll == rl
},
Expand Down Expand Up @@ -234,16 +234,16 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
match (&left.node, &right.node) {
(&TySlice(ref l_vec), &TySlice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
(&TyArray(ref lt, ll_id), &TyArray(ref rt, rl_id)) => {
(&TyArray(ref lt, ref ll_id), &TyArray(ref rt, ref rl_id)) => {
let full_table = self.tables;

let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id));
self.tables = self.cx.tcx.body_tables(ll_id);
let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id).value);
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
self.tables = self.cx.tcx.body_tables(ll_id.body);
let ll = celcx.expr(&self.cx.tcx.hir.body(ll_id.body).value);

let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id));
self.tables = self.cx.tcx.body_tables(rl_id);
let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id).value);
let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(rl_id.body));
self.tables = self.cx.tcx.body_tables(rl_id.body);
let rl = celcx.expr(&self.cx.tcx.hir.body(rl_id.body).value);

let eq_ty = self.eq_ty(lt, rt);
self.tables = full_table;
Expand Down Expand Up @@ -474,13 +474,13 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
self.hash_name(&path.name);
self.hash_exprs(args);
},
ExprRepeat(ref e, l_id) => {
ExprRepeat(ref e, ref l_id) => {
let c: fn(_, _) -> _ = ExprRepeat;
c.hash(&mut self.s);
self.hash_expr(e);
let full_table = self.tables;
self.tables = self.cx.tcx.body_tables(l_id);
self.hash_expr(&self.cx.tcx.hir.body(l_id).value);
self.tables = self.cx.tcx.body_tables(l_id.body);
self.hash_expr(&self.cx.tcx.hir.body(l_id.body).value);
self.tables = full_table;
},
ExprRet(ref e) => {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) {
print_expr(cx, base, indent + 1);
}
},
hir::ExprRepeat(ref val, body_id) => {
hir::ExprRepeat(ref val, ref anon_const) => {
println!("{}Repeat", ind);
println!("{}value:", ind);
print_expr(cx, val, indent + 1);
println!("{}repeat count:", ind);
print_expr(cx, &cx.tcx.hir.body(body_id).value, indent + 1);
print_expr(cx, &cx.tcx.hir.body(anon_const.body).value, indent + 1);
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::hir::map::Node;
use rustc::lint::{LateContext, Level, Lint, LintContext};
use rustc::session::Session;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}};
use rustc::ty::{self, Ty, TyCtxt, layout::{self, IntegerExt}, subst::Kind};
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart};
use std::borrow::Cow;
use std::env;
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn implements_trait<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
ty: Ty<'tcx>,
trait_id: DefId,
ty_params: &[Ty<'tcx>],
ty_params: &[Kind<'tcx>],
) -> bool {
let ty = cx.tcx.erase_regions(&ty);
let obligation =
Expand Down

1 comment on commit c5de91c

@oli-obk
Copy link

Choose a reason for hiding this comment

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

other than the nit, lgtm! Would you be so kind and open a PR?

Please sign in to comment.