Skip to content

Commit 8b0fb1e

Browse files
committed
2 parents 1fce376 + 281bd79 commit 8b0fb1e

File tree

11 files changed

+88
-29
lines changed

11 files changed

+88
-29
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.166
5+
* Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)*
6+
* New lints: [`explicit_write`], [`identity_conversion`], [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`], [`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`], [`transmute_int_to_float`]
7+
48
## 0.0.165
59
* Rust upgrade to rustc 1.22.0-nightly (0e6f4cf51 2017-09-27)
610
* New lint: [`mut_range_bound`]
@@ -505,6 +509,7 @@ All notable changes to this project will be documented in this file.
505509
[`explicit_counter_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_counter_loop
506510
[`explicit_into_iter_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_into_iter_loop
507511
[`explicit_iter_loop`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_iter_loop
512+
[`explicit_write`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#explicit_write
508513
[`extend_from_slice`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#extend_from_slice
509514
[`filter_map`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#filter_map
510515
[`filter_next`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#filter_next
@@ -516,19 +521,22 @@ All notable changes to this project will be documented in this file.
516521
[`forget_copy`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#forget_copy
517522
[`forget_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#forget_ref
518523
[`get_unwrap`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#get_unwrap
524+
[`identity_conversion`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#identity_conversion
519525
[`identity_op`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#identity_op
520526
[`if_let_redundant_pattern_matching`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
521527
[`if_let_some_result`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#if_let_some_result
522528
[`if_not_else`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#if_not_else
523529
[`if_same_then_else`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#if_same_then_else
524530
[`ifs_same_cond`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ifs_same_cond
531+
[`implicit_hasher`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#implicit_hasher
525532
[`inconsistent_digit_grouping`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
526533
[`indexing_slicing`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#indexing_slicing
527534
[`ineffective_bit_mask`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ineffective_bit_mask
528535
[`infinite_iter`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#infinite_iter
529536
[`inline_always`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inline_always
530537
[`int_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#int_plus_one
531538
[`integer_arithmetic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#integer_arithmetic
539+
[`invalid_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_ref
532540
[`invalid_regex`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_regex
533541
[`invalid_upcast_comparisons`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
534542
[`items_after_statements`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#items_after_statements
@@ -590,6 +598,7 @@ All notable changes to this project will be documented in this file.
590598
[`not_unsafe_ptr_arg_deref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
591599
[`ok_expect`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ok_expect
592600
[`op_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#op_ref
601+
[`option_map_or_none`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#option_map_or_none
593602
[`option_map_unwrap_or`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#option_map_unwrap_or
594603
[`option_map_unwrap_or_else`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#option_map_unwrap_or_else
595604
[`option_unwrap_used`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#option_unwrap_used
@@ -604,6 +613,8 @@ All notable changes to this project will be documented in this file.
604613
[`print_with_newline`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#print_with_newline
605614
[`ptr_arg`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ptr_arg
606615
[`pub_enum_variant_names`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#pub_enum_variant_names
616+
[`range_minus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_minus_one
617+
[`range_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_plus_one
607618
[`range_step_by_zero`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_step_by_zero
608619
[`range_zip_with_len`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_zip_with_len
609620
[`redundant_closure`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_closure
@@ -637,6 +648,9 @@ All notable changes to this project will be documented in this file.
637648
[`temporary_cstring_as_ptr`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
638649
[`too_many_arguments`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#too_many_arguments
639650
[`toplevel_ref_arg`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#toplevel_ref_arg
651+
[`transmute_int_to_bool`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#transmute_int_to_bool
652+
[`transmute_int_to_char`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#transmute_int_to_char
653+
[`transmute_int_to_float`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#transmute_int_to_float
640654
[`transmute_ptr_to_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref
641655
[`trivial_regex`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#trivial_regex
642656
[`type_complexity`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#type_complexity

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.165"
3+
version = "0.0.166"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -37,7 +37,7 @@ path = "src/driver.rs"
3737

3838
[dependencies]
3939
# begin automatic update
40-
clippy_lints = { version = "0.0.165", path = "clippy_lints" }
40+
clippy_lints = { version = "0.0.166", path = "clippy_lints" }
4141
# end automatic update
4242
cargo_metadata = "0.2"
4343

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.165"
4+
version = "0.0.166"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",

clippy_lints/src/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7171
};
7272

7373
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
74-
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables).consume_body(body);
74+
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
7575

7676
for node in v.set {
7777
span_lint(

clippy_lints/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub mod eq_op;
9292
pub mod escape;
9393
pub mod eta_reduction;
9494
pub mod eval_order_dependence;
95+
pub mod explicit_write;
9596
pub mod format;
9697
pub mod formatting;
9798
pub mod functions;
@@ -147,7 +148,6 @@ pub mod serde_api;
147148
pub mod shadow;
148149
pub mod should_assert_eq;
149150
pub mod strings;
150-
pub mod explicit_write;
151151
pub mod swap;
152152
pub mod temporary_assignment;
153153
pub mod transmute;
@@ -357,7 +357,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
357357
if_not_else::IF_NOT_ELSE,
358358
infinite_iter::MAYBE_INFINITE_ITER,
359359
int_plus_one::INT_PLUS_ONE,
360-
invalid_ref::INVALID_REF,
361360
items_after_statements::ITEMS_AFTER_STATEMENTS,
362361
matches::SINGLE_MATCH_ELSE,
363362
mem_forget::MEM_FORGET,
@@ -375,6 +374,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
375374
non_expressive_names::SIMILAR_NAMES,
376375
print::PRINT_STDOUT,
377376
print::USE_DEBUG,
377+
ranges::RANGE_PLUS_ONE,
378378
shadow::SHADOW_REUSE,
379379
shadow::SHADOW_SAME,
380380
shadow::SHADOW_UNRELATED,
@@ -434,6 +434,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
434434
eta_reduction::REDUNDANT_CLOSURE,
435435
eval_order_dependence::DIVERGING_SUB_EXPRESSION,
436436
eval_order_dependence::EVAL_ORDER_DEPENDENCE,
437+
explicit_write::EXPLICIT_WRITE,
437438
format::USELESS_FORMAT,
438439
formatting::POSSIBLE_MISSING_COMMA,
439440
formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
@@ -444,6 +445,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
444445
identity_op::IDENTITY_OP,
445446
if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING,
446447
infinite_iter::INFINITE_ITER,
448+
invalid_ref::INVALID_REF,
447449
is_unit_expr::UNIT_EXPR,
448450
large_enum_variant::LARGE_ENUM_VARIANT,
449451
len_zero::LEN_WITHOUT_IS_EMPTY,
@@ -488,6 +490,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
488490
methods::ITER_SKIP_NEXT,
489491
methods::NEW_RET_NO_SELF,
490492
methods::OK_EXPECT,
493+
methods::OPTION_MAP_OR_NONE,
491494
methods::OR_FUN_CALL,
492495
methods::SEARCH_IS_SOME,
493496
methods::SHOULD_IMPLEMENT_TRAIT,
@@ -537,6 +540,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
537540
ptr::MUT_FROM_REF,
538541
ptr::PTR_ARG,
539542
ranges::ITERATOR_STEP_BY_ZERO,
543+
ranges::RANGE_MINUS_ONE,
540544
ranges::RANGE_ZIP_WITH_LEN,
541545
reference::DEREF_ADDROF,
542546
regex::INVALID_REGEX,
@@ -547,17 +551,16 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
547551
serde_api::SERDE_API_MISUSE,
548552
should_assert_eq::SHOULD_ASSERT_EQ,
549553
strings::STRING_LIT_AS_BYTES,
550-
explicit_write::EXPLICIT_WRITE,
551554
swap::ALMOST_SWAPPED,
552555
swap::MANUAL_SWAP,
553556
temporary_assignment::TEMPORARY_ASSIGNMENT,
554557
transmute::CROSSPOINTER_TRANSMUTE,
558+
transmute::TRANSMUTE_INT_TO_BOOL,
559+
transmute::TRANSMUTE_INT_TO_CHAR,
560+
transmute::TRANSMUTE_INT_TO_FLOAT,
555561
transmute::TRANSMUTE_PTR_TO_REF,
556562
transmute::USELESS_TRANSMUTE,
557563
transmute::WRONG_TRANSMUTE,
558-
transmute::TRANSMUTE_INT_TO_CHAR,
559-
transmute::TRANSMUTE_INT_TO_BOOL,
560-
transmute::TRANSMUTE_INT_TO_FLOAT,
561564
types::ABSURD_EXTREME_COMPARISONS,
562565
types::BORROWED_BOX,
563566
types::BOX_VEC,

clippy_lints/src/loops.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,14 @@ fn get_indexed_assignments<'a, 'tcx>(
749749
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
750750
if let Expr_::ExprAssign(ref lhs, ref rhs) = e.node {
751751
match (get_fixed_offset_var(cx, lhs, var), fetch_cloned_fixed_offset_var(cx, rhs, var)) {
752-
(Some(offset_left), Some(offset_right)) => Some((offset_left, offset_right)),
752+
(Some(offset_left), Some(offset_right)) => {
753+
// Source and destination must be different
754+
if offset_left.var_name != offset_right.var_name {
755+
Some((offset_left, offset_right))
756+
} else {
757+
None
758+
}
759+
},
753760
_ => None,
754761
}
755762
} else {
@@ -1390,7 +1397,7 @@ fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: &[Option<NodeId>
13901397
let mut delegate = MutateDelegate { node_id_low: bound_ids[0], node_id_high: bound_ids[1], span_low: None, span_high: None };
13911398
let def_id = def_id::DefId::local(body.hir_id.owner);
13921399
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
1393-
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables).walk_expr(body);
1400+
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(body);
13941401
delegate.mutation_span()
13951402
}
13961403

clippy_lints/src/methods.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -821,18 +821,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
821821
or_has_args: bool,
822822
span: Span,
823823
) {
824-
// don't lint for constant values
825-
// FIXME: can we `expect` here instead of match?
826-
let promotable = cx.tcx
827-
.rvalue_promotable_to_static
828-
.borrow()
829-
.get(&arg.id)
830-
.cloned()
831-
.unwrap_or(true);
832-
if promotable {
833-
return;
834-
}
835-
836824
// (path, fn_has_argument, methods, suffix)
837825
let know_types: &[(&[_], _, &[_], _)] = &[
838826
(&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
@@ -841,6 +829,21 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
841829
(&paths::RESULT, true, &["or", "unwrap_or"], "else"),
842830
];
843831

832+
// early check if the name is one we care about
833+
if know_types.iter().all(|k| !k.2.contains(&name)) {
834+
return;
835+
}
836+
837+
// don't lint for constant values
838+
// FIXME: can we `expect` here instead of match?
839+
let owner_def = cx.tcx.hir.get_parent_did(arg.id);
840+
let promotable = cx.tcx
841+
.rvalue_promotable_map(owner_def)
842+
[&arg.hir_id.local_id];
843+
if promotable {
844+
return;
845+
}
846+
844847
let self_ty = cx.tables.expr_ty(self_expr);
845848

846849
let (fn_has_arguments, poss, suffix) = if let Some(&(_, fn_has_arguments, poss, suffix)) =

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
108108
} = {
109109
let mut ctx = MovedVariablesCtxt::new(cx);
110110
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
111-
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables).consume_body(body);
111+
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
112112
ctx
113113
};
114114

@@ -121,6 +121,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
121121
.zip(&body.arguments)
122122
.enumerate()
123123
{
124+
// All spans generated from a proc-macro invocation are the same...
125+
if span == input.span {
126+
return;
127+
}
128+
124129
// * Exclude a type that is specifically bounded by `Borrow`.
125130
// * Exclude a type whose reference also fulfills its bound.
126131
// (e.g. `std::convert::AsRef`, `serde::Serialize`)

mini-macro/src/lib.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
#![feature(plugin_registrar, rustc_private)]
1+
#![feature(plugin_registrar, rustc_private, quote)]
22

33
extern crate rustc_plugin;
44
extern crate syntax;
55

6+
use rustc_plugin::Registry;
7+
use syntax::ast::MetaItem;
68
use syntax::codemap::Span;
7-
use syntax::tokenstream::TokenTree;
8-
use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
9+
use syntax::ext::base::{Annotatable, ExtCtxt, MacEager, MacResult, SyntaxExtension};
910
use syntax::ext::build::AstBuilder; // trait for expr_usize
10-
use rustc_plugin::Registry;
11+
use syntax::symbol::Symbol;
12+
use syntax::tokenstream::TokenTree;
1113

1214
fn expand_macro(cx: &mut ExtCtxt, sp: Span, _: &[TokenTree]) -> Box<MacResult + 'static> {
1315
let e = cx.expr_usize(sp, 42);
1416
let e = cx.expr_mut_addr_of(sp, e);
1517
MacEager::expr(cx.expr_mut_addr_of(sp, e))
1618
}
1719

20+
fn expand_attr_macro(cx: &mut ExtCtxt, _: Span, _: &MetaItem, annotated: Annotatable) -> Vec<Annotatable> {
21+
vec![
22+
Annotatable::Item(
23+
quote_item!(
24+
cx,
25+
#[allow(unused)] fn needless_take_by_value(s: String) { println!("{}", s.len()); }
26+
).unwrap()
27+
),
28+
annotated,
29+
]
30+
}
31+
1832
#[plugin_registrar]
1933
pub fn plugin_registrar(reg: &mut Registry) {
2034
reg.register_macro("mini_macro", expand_macro);
35+
reg.register_syntax_extension(
36+
Symbol::intern("mini_macro_attr"),
37+
SyntaxExtension::MultiModifier(Box::new(expand_attr_macro)),
38+
);
2139
}

tests/run-pass/procedural_macro.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![plugin(clippy_mini_macro_test)]
33

44
#[deny(warnings)]
5+
#[mini_macro_attr]
56
fn main() {
67
let _ = mini_macro!();
78
}

0 commit comments

Comments
 (0)