Skip to content

Try to fix compilation error on rustc 1.19.0-nightly 4ed2edaaf #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
match def {
Def::Const(def_id) |
Def::AssociatedConst(def_id) => {
let substs = self.tables
.node_id_item_substs(id)
.unwrap_or_else(|| self.tcx.intern_substs(&[]));
let substs = self.tables.node_substs(id);
let substs = if self.substs.is_empty() {
substs
} else {
Expand Down
14 changes: 8 additions & 6 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
let region_maps = &cx.tcx.region_maps(fn_def_id);
{
let mut vis = ExprUseVisitor::new(&mut v, region_maps, &infcx);
let def_id = cx.tcx.hir.body_owner_def_id(body.id());
let param_env = cx.tcx.param_env(def_id);
Copy link
Member

Choose a reason for hiding this comment

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

You can pass fn_def_id. Also, never use borrowck_fake_infer_ctxt. It's literally a hack for borrowck. Bad for everything else.

let mut vis = ExprUseVisitor::new(&mut v, region_maps, &infcx, param_env);
vis.consume_body(body);
}

Expand Down Expand Up @@ -160,29 +162,29 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {

if let Categorization::Local(lid) = cmt.cat {
if self.set.contains(&lid) {
if let Some(&Adjust::DerefRef { autoderefs, .. }) =
if let Some(&Adjust::Deref(ref overloaded)) =
self.tables
.adjustments
.get(&borrow_id)
.map(|a| &a.kind) {
if LoanCause::AutoRef == loan_cause {
// x.foo()
if autoderefs == 0 {
if overloaded == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Adjust::Deref related codes are not fixed yet. I am not sure how to fix it as I am a newbie to rustc internals.

Copy link
Member

Choose a reason for hiding this comment

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

This one checks for no deref adjustments.

self.set.remove(&lid); // Used without autodereffing (i.e. x.clone())
}
} else {
span_bug!(cmt.span, "Unknown adjusted AutoRef");
}
} else if LoanCause::AddrOf == loan_cause {
// &x
if let Some(&Adjust::DerefRef { autoderefs, .. }) =
if let Some(&Adjust::Deref(ref overloaded)) =
self.tables
.adjustments
.get(&self.tcx
.hir
.get_parent_node(borrow_id))
.map(|a| &a.kind) {
if autoderefs <= 1 {
if overloaded <= 1 {
// foo(&x) where no extra autoreffing is happening
Copy link
Member

Choose a reason for hiding this comment

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

This check is weird, since it doesn't check for an autoref. Either way, it wants at most one deref adjustment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there were false posived when generics are involved. But I don't remember the details. Please add a FIXME(oli-obk) so I'll check it again in the future

self.set.remove(&lid);
}
Expand All @@ -205,7 +207,7 @@ impl<'a, 'tcx: 'a> EscapeDelegate<'a, 'tcx> {
// overflows.
if ty.is_box() {
let inner = ty.boxed_ty();
self.tcx.infer_ctxt((), Reveal::All).enter(|infcx| if let Ok(layout) = inner.layout(&infcx) {
self.tcx.infer_ctxt(()).enter(|infcx| if let Ok(layout) = inner.layout(&infcx) {
let size = layout.size(&self.target);
size.bytes() > self.too_large_for_stack
} else {
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/eval_order_dependence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
}
},
ExprMethodCall(..) => {
let method_call = ty::MethodCall::expr(e.id);
let borrowed_table = self.cx.tables;
let method_type = borrowed_table.method_map.get(&method_call).expect("This should never happen.");
let result_ty = method_type.ty.fn_ret();
if let ty::TyNever = self.cx.tcx.erase_late_bound_regions(&result_ty).sty {
if borrowed_table.expr_ty(e).is_never() {
self.report_diverging_sub_expr(e);
}
},
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
}
},
hir::ExprMethodCall(_, _, ref args) => {
let method_call = ty::MethodCall::expr(expr.id);
let base_type = self.cx.tables.method_map[&method_call].ty;
let def_id = self.cx.tables.type_dependent_defs[&expr.id].def_id();
let base_type = self.cx.tcx.type_of(def_id);

if type_is_unsafe_function(base_type) {
for arg in args {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItemRef]
{
let did = cx.tcx.hir.local_def_id(item.id.node_id);
let impl_ty = cx.tcx.type_of(did);
impl_ty.fn_args().skip_binder().len() == 1
impl_ty.fn_sig().inputs().skip_binder().len() == 1
}
} else {
false
Expand All @@ -122,7 +122,7 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
{
let did = cx.tcx.hir.local_def_id(item.id.node_id);
let impl_ty = cx.tcx.type_of(did);
impl_ty.fn_args().skip_binder().len() == 1
impl_ty.fn_sig().inputs().skip_binder().len() == 1
}
} else {
false
Expand Down
9 changes: 2 additions & 7 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,8 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
lint_iter_method(cx, args, arg, &method_name);
}
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
let method_call = ty::MethodCall::expr(arg.id);
let fn_ty = cx.tables
.method_map
.get(&method_call)
.map(|method_callee| method_callee.ty)
.expect("method calls need an entry in the method map");
let fn_arg_tys = fn_ty.fn_args();
let fn_ty = cx.tables.expr_ty(arg);
let fn_arg_tys = fn_ty.fn_sig().inputs();
assert_eq!(fn_arg_tys.skip_binder().len(), 1);
if fn_arg_tys.skip_binder()[0].is_region_ptr() {
lint_iter_method(cx, args, arg, &method_name);
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/mut_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::lint::*;
use rustc::ty::{TypeAndMut, TypeVariants, MethodCall, TyS};
use rustc::ty::{TypeAndMut, TypeVariants, TyS};
use rustc::hir::*;
use utils::span_lint;

Expand Down Expand Up @@ -49,9 +49,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
}
},
ExprMethodCall(ref name, _, ref arguments) => {
let method_call = MethodCall::expr(e.id);
let method_type = borrowed_table.method_map.get(&method_call).expect("This should never happen.");
check_arguments(cx, arguments, method_type.ty, &name.node.as_str())
let def_id = borrowed_table.type_dependent_defs[&e.id].def_id();
let method_type = cx.tcx.type_of(def_id);
check_arguments(cx, arguments, method_type, &name.node.as_str())
Copy link
Member

Choose a reason for hiding this comment

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

expr_ty(e) gives you the returned type not the method type (which you have to get from its DefId now).

},
_ => (),
}
Expand All @@ -71,7 +71,7 @@ fn check_arguments(cx: &LateContext, arguments: &[Expr], type_definition: &TyS,
span_lint(cx,
UNNECESSARY_MUT_PASSED,
argument.span,
&format!("The function/method \"{}\" doesn't need a mutable reference", name));
&format!("The function/method `{}` doesn't need a mutable reference", name));
}
},
_ => (),
Expand Down
14 changes: 6 additions & 8 deletions clippy_lints/src/needless_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
}
if let ExprAddrOf(MutImmutable, ref inner) = e.node {
if let ty::TyRef(..) = cx.tables.expr_ty(inner).sty {
if let Some(&ty::adjustment::Adjust::DerefRef { autoderefs, autoref, .. }) =
Copy link
Member

Choose a reason for hiding this comment

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

What you have now instead is a vector of adjustments, each autoderef is now one entry in that vector, and autoref is another entry. So this check looks for an autoref that is preceded by 2 or more derefs.

if let Some(&ty::adjustment::Adjust::Deref(Some(_))) =
cx.tables.adjustments.get(&e.id).map(|a| &a.kind) {
if autoderefs > 1 && autoref.is_some() {
span_lint(cx,
NEEDLESS_BORROW,
e.span,
"this expression borrows a reference that is immediately dereferenced by the \
compiler");
}
span_lint(cx,
NEEDLESS_BORROW,
e.span,
"this expression borrows a reference that is immediately dereferenced by the \
compiler");
}
}
}
Expand Down
25 changes: 8 additions & 17 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,8 @@ pub fn match_type(cx: &LateContext, ty: ty::Ty, path: &[&str]) -> bool {

/// Check if the method call given in `expr` belongs to given type.
pub fn match_impl_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool {
let method_call = ty::MethodCall::expr(expr.id);

let trt_id = cx.tables
.method_map
.get(&method_call)
.and_then(|callee| cx.tcx.impl_of_method(callee.def_id));
let method_call = cx.tables.type_dependent_defs[&expr.id];
let trt_id = cx.tcx.impl_of_method(method_call.def_id());
if let Some(trt_id) = trt_id {
match_def_path(cx.tcx, trt_id, path)
} else {
Expand All @@ -199,12 +195,8 @@ pub fn match_impl_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool {

/// Check if the method call given in `expr` belongs to given trait.
pub fn match_trait_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool {
let method_call = ty::MethodCall::expr(expr.id);

let trt_id = cx.tables
.method_map
.get(&method_call)
.and_then(|callee| cx.tcx.trait_of_item(callee.def_id));
let method_call = cx.tables.type_dependent_defs[&expr.id];
let trt_id = cx.tcx.trait_of_item(method_call.def_id());
if let Some(trt_id) = trt_id {
match_def_path(cx.tcx, trt_id, path)
} else {
Expand Down Expand Up @@ -267,7 +259,6 @@ pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool {
}

/// Get the definition associated to a path.
/// TODO: investigate if there is something more efficient for that.
Copy link
Member

Choose a reason for hiding this comment

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

Why was this TODO removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Iirc you told me on IRC that this impl is pretty sensible ;)

Copy link
Member

Choose a reason for hiding this comment

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

Oh was this you?

pub fn path_to_def(cx: &LateContext, path: &[&str]) -> Option<def::Def> {
let cstore = &cx.tcx.sess.cstore;

Expand Down Expand Up @@ -327,9 +318,9 @@ pub fn implements_trait<'a, 'tcx>(
) -> bool {
let ty = cx.tcx.erase_regions(&ty);
let mut b = if let Some(id) = parent_node_id {
cx.tcx.infer_ctxt(BodyId { node_id: id }, Reveal::All)
cx.tcx.infer_ctxt(BodyId { node_id: id })
} else {
cx.tcx.infer_ctxt((), Reveal::All)
cx.tcx.infer_ctxt(())
};
b.enter(|infcx| {
let obligation = cx.tcx.predicate_for_trait_def(traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
Expand Down Expand Up @@ -788,7 +779,7 @@ pub fn same_tys<'a, 'tcx>(
parameter_item: DefId
) -> bool {
let parameter_env = cx.tcx.param_env(parameter_item);
cx.tcx.infer_ctxt(parameter_env, Reveal::All).enter(|infcx| {
cx.tcx.infer_ctxt(parameter_env).enter(|infcx| {
let substs = Substs::identity_for_item(cx.tcx, parameter_item);
let new_a = a.subst(infcx.tcx, substs);
let new_b = b.subst(infcx.tcx, substs);
Expand Down Expand Up @@ -971,6 +962,6 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {

pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Option<u64> {
cx.tcx
.infer_ctxt((), Reveal::All)
.infer_ctxt(())
.enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()))
}