-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
let mut vis = ExprUseVisitor::new(&mut v, region_maps, &infcx, param_env); | ||
vis.consume_body(body); | ||
} | ||
|
||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
@@ -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 { | ||
|
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; | ||
|
||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
_ => (), | ||
} | ||
|
@@ -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)); | ||
} | ||
}, | ||
_ => (), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, .. }) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 { | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this TODO removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iirc you told me on IRC that this impl is pretty sensible ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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())) | ||
} |
There was a problem hiding this comment.
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 useborrowck_fake_infer_ctxt
. It's literally a hack forborrowck
. Bad for everything else.