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 all 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
17 changes: 10 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.0.136 - 2017-05-26
## 0.0.137 — 2017-06-05
* Update to *rustc 1.19.0-nightly (6684d176c 2017-06-03)*

## 0.0.136 — 2017—05—26
* Update to *rustc 1.19.0-nightly (557967766 2017-05-26)*

## 0.0.135 - 2017-05-24
## 0.0.135 2017—05—24
* Update to *rustc 1.19.0-nightly (5b13bff52 2017-05-23)*

## 0.0.134 - 2017-05-19
## 0.0.134 2017—05—19
* Update to *rustc 1.19.0-nightly (0ed1ec9f9 2017-05-18)*

## 0.0.133 - 2017-05-14
## 0.0.133 2017—05—14
* Update to *rustc 1.19.0-nightly (826d8f385 2017-05-13)*

## 0.0.132 - 2017-05-05
## 0.0.132 2017—05—05
* Fix various bugs and some ices

## 0.0.131 - 2017-05-04
## 0.0.131 2017—05—04
* Update to *rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)*

## 0.0.130 - 2017-05-03
## 0.0.130 2017—05—03
* Update to *rustc 1.19.0-nightly (6a5fc9eec 2017-05-02)*

## 0.0.129 — 2017-05-01
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.136"
version = "0.0.137"
authors = [
"Manish Goregaokar <[email protected]>",
"Andre Bogus <[email protected]>",
Expand Down Expand Up @@ -31,7 +31,7 @@ test = false

[dependencies]
# begin automatic update
clippy_lints = { version = "0.0.136", path = "clippy_lints" }
clippy_lints = { version = "0.0.137", path = "clippy_lints" }
# end automatic update
cargo_metadata = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clippy_lints"
# begin automatic update
version = "0.0.136"
version = "0.0.137"
# end automatic update
authors = [
"Manish Goregaokar <[email protected]>",
Expand Down
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
97 changes: 34 additions & 63 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use rustc::lint::*;
use rustc::middle::expr_use_visitor::*;
use rustc::middle::mem_categorization::{cmt, Categorization};
use rustc::ty;
use rustc::ty::layout::TargetDataLayout;
use rustc::traits::Reveal;
use rustc::util::nodemap::NodeSet;
use syntax::ast::NodeId;
use syntax::codemap::Span;
Expand Down Expand Up @@ -46,8 +44,7 @@ fn is_non_trait_box(ty: ty::Ty) -> bool {
struct EscapeDelegate<'a, 'tcx: 'a> {
set: NodeSet,
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
tables: &'a ty::TypeckTables<'tcx>,
target: TargetDataLayout,
param_env: ty::ParamEnv<'tcx>,
too_large_for_stack: u64,
}

Expand All @@ -67,23 +64,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
_: Span,
node_id: NodeId
) {
// we store the infcx because it is expensive to recreate
// the context each time.
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
let param_env = cx.tcx.param_env(fn_def_id).reveal_all();
let mut v = EscapeDelegate {
set: NodeSet(),
tcx: cx.tcx,
tables: cx.tables,
target: TargetDataLayout::parse(cx.sess()),
param_env: param_env,
too_large_for_stack: self.too_large_for_stack,
};

let infcx = cx.tcx.borrowck_fake_infer_ctxt(body.id());
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);
cx.tcx.infer_ctxt(body.id()).enter(|infcx| {
let region_maps = &cx.tcx.region_maps(fn_def_id);
let mut vis = ExprUseVisitor::new(&mut v, region_maps, &infcx, param_env);
vis.consume_body(body);
}
});

for node in v.set {
span_lint(cx,
Expand All @@ -94,14 +88,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}
}

impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
impl<'a, 'gcx: 'tcx, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'gcx> {
fn consume(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, mode: ConsumeMode) {
if let Categorization::Local(lid) = cmt.cat {
if self.set.contains(&lid) {
if let Move(DirectRefMove) = mode {
// moved out or in. clearly can't be localized
self.set.remove(&lid);
}
if let Move(DirectRefMove) = mode {
// moved out or in. clearly can't be localized
self.set.remove(&lid);
}
}
}
Expand Down Expand Up @@ -149,49 +141,30 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}
fn borrow(
&mut self,
borrow_id: NodeId,
_: NodeId,
_: Span,
cmt: cmt<'tcx>,
_: ty::Region,
_: ty::BorrowKind,
loan_cause: LoanCause
) {
use rustc::ty::adjustment::Adjust;

if let Categorization::Local(lid) = cmt.cat {
if self.set.contains(&lid) {
if let Some(&Adjust::DerefRef { autoderefs, .. }) =
self.tables
.adjustments
.get(&borrow_id)
.map(|a| &a.kind) {
if LoanCause::AutoRef == loan_cause {
// x.foo()
if autoderefs == 0 {
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, .. }) =
self.tables
.adjustments
.get(&self.tcx
.hir
.get_parent_node(borrow_id))
.map(|a| &a.kind) {
if autoderefs <= 1 {
// foo(&x) where no extra autoreffing is happening
self.set.remove(&lid);
}
}
match loan_cause {
// x.foo()
// Used without autodereffing (i.e. x.clone())
LoanCause::AutoRef |

} else if LoanCause::MatchDiscriminant == loan_cause {
self.set.remove(&lid); // `match x` can move
// &x
// foo(&x) where no extra autoreffing is happening
LoanCause::AddrOf |

// `match x` can move
LoanCause::MatchDiscriminant => {
self.set.remove(&lid);
}

// do nothing for matches, etc. These can't escape
_ => {}
}
}
}
Expand All @@ -200,19 +173,17 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}

impl<'a, 'tcx: 'a> EscapeDelegate<'a, 'tcx> {
fn is_large_box(&self, ty: ty::Ty<'tcx>) -> bool {
fn is_large_box(&self, ty: ty::Ty) -> bool {
// Large types need to be boxed to avoid stack
// 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) {
let size = layout.size(&self.target);
size.bytes() > self.too_large_for_stack
} else {
false
})
} else {
false
if let Some(inner) = self.tcx.lift(&ty.boxed_ty()) {
if let Ok(layout) = inner.layout(self.tcx, self.param_env) {
return layout.size(self.tcx).bytes() > self.too_large_for_stack;
}
}
}

false
}
}
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
5 changes: 2 additions & 3 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc::hir::intravisit;
use rustc::hir;
use rustc::ty;
use rustc::lint::*;
use std::collections::HashSet;
use syntax::ast;
Expand Down Expand Up @@ -184,8 +183,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
13 changes: 6 additions & 7 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc::lint::*;
use rustc::middle::const_val::ConstVal;
use rustc::middle::region::CodeExtent;
use rustc::ty;
use rustc::ty::subst::Subst;
use rustc_const_eval::ConstContext;
use std::collections::HashMap;
use syntax::ast;
Expand Down Expand Up @@ -676,13 +677,11 @@ 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 def_id = cx.tables.type_dependent_defs[&arg.id].def_id();
let substs = cx.tables.node_substs(arg.id);
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);

let fn_arg_tys = method_type.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
19 changes: 8 additions & 11 deletions clippy_lints/src/mut_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc::lint::*;
use rustc::ty::{TypeAndMut, TypeVariants, MethodCall, TyS};
use rustc::ty::{TypeAndMut, TypeVariants, TyS};
use rustc::ty::subst::Subst;
use rustc::hir::*;
use utils::span_lint;

Expand Down Expand Up @@ -34,24 +35,20 @@ impl LintPass for UnnecessaryMutPassed {

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
let borrowed_table = cx.tables;
match e.node {
ExprCall(ref fn_expr, ref arguments) => {
let function_type = borrowed_table.node_types
.get(&fn_expr.id)
.expect("A function with an unknown type is called. If this happened, the compiler would have \
aborted the compilation long ago");
if let ExprPath(ref path) = fn_expr.node {
check_arguments(cx,
arguments,
function_type,
cx.tables.expr_ty(fn_expr),
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)));
}
},
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 = cx.tables.type_dependent_defs[&e.id].def_id();
let substs = cx.tables.node_substs(e.id);
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
check_arguments(cx, arguments, method_type, &name.node.as_str())
},
_ => (),
}
Expand All @@ -71,7 +68,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
10 changes: 7 additions & 3 deletions clippy_lints/src/needless_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use rustc::lint::*;
use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingMode};
use rustc::ty;
use rustc::ty::adjustment::{Adjustment, Adjust};
use utils::{span_lint, in_macro};

/// **What it does:** Checks for address of operations (`&`) that are going to
Expand Down Expand Up @@ -41,9 +42,12 @@ 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.

cx.tables.adjustments.get(&e.id).map(|a| &a.kind) {
if autoderefs > 1 && autoref.is_some() {
for adj3 in cx.tables.expr_adjustments(e).windows(3) {
if let [
Adjustment { kind: Adjust::Deref(_), .. },
Adjustment { kind: Adjust::Deref(_), .. },
Adjustment { kind: Adjust::Borrow(_), .. }
] = *adj3 {
span_lint(cx,
NEEDLESS_BORROW,
e.span,
Expand Down
Loading