Skip to content

Commit 992d88a

Browse files
authored
Merge pull request #1977 from rust-lang-nursery/panic
Fix a panic and a false positive
2 parents cf1fc5d + 2430e06 commit 992d88a

21 files changed

+69
-70
lines changed

CHANGELOG.md

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

4+
## 0.0.154
5+
* Fix [`use_self`] triggering inside derives
6+
47
## 0.0.153
58
* Update to *rustc 1.21.0-nightly (8c303ed87 2017-08-20)*
69
* New lint: [`use_self`]

clippy_lints/src/blacklisted_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub struct BlackListedName {
2626
}
2727

2828
impl BlackListedName {
29-
pub fn new(blacklist: Vec<String>) -> BlackListedName {
30-
BlackListedName { blacklist: blacklist }
29+
pub fn new(blacklist: Vec<String>) -> Self {
30+
Self { blacklist: blacklist }
3131
}
3232
}
3333

clippy_lints/src/consts.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum FloatWidth {
2323
}
2424

2525
impl From<FloatTy> for FloatWidth {
26-
fn from(ty: FloatTy) -> FloatWidth {
26+
fn from(ty: FloatTy) -> Self {
2727
match ty {
2828
FloatTy::F32 => FloatWidth::F32,
2929
FloatTy::F64 => FloatWidth::F64,
@@ -55,7 +55,7 @@ pub enum Constant {
5555
}
5656

5757
impl PartialEq for Constant {
58-
fn eq(&self, other: &Constant) -> bool {
58+
fn eq(&self, other: &Self) -> bool {
5959
match (self, other) {
6060
(&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => ls == rs && l_sty == r_sty,
6161
(&Constant::Binary(ref l), &Constant::Binary(ref r)) => l == r,
@@ -123,7 +123,7 @@ impl Hash for Constant {
123123
}
124124

125125
impl PartialOrd for Constant {
126-
fn partial_cmp(&self, other: &Constant) -> Option<Ordering> {
126+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
127127
match (self, other) {
128128
(&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => {
129129
if l_sty == r_sty {
@@ -297,7 +297,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
297297
};
298298
let param_env = self.param_env.and((def_id, substs));
299299
if let Some((def_id, substs)) = lookup_const_by_id(self.tcx, param_env) {
300-
let mut cx = ConstEvalLateContext {
300+
let mut cx = Self {
301301
tcx: self.tcx,
302302
tables: self.tcx.typeck_tables_of(def_id),
303303
needed_resolution: false,

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct CyclomaticComplexity {
3131

3232
impl CyclomaticComplexity {
3333
pub fn new(limit: u64) -> Self {
34-
CyclomaticComplexity { limit: LimitStack::new(limit) }
34+
Self { limit: LimitStack::new(limit) }
3535
}
3636
}
3737

clippy_lints/src/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Doc {
3737

3838
impl Doc {
3939
pub fn new(valid_idents: Vec<String>) -> Self {
40-
Doc { valid_idents: valid_idents }
40+
Self { valid_idents: valid_idents }
4141
}
4242
}
4343

@@ -62,7 +62,7 @@ struct Parser<'a> {
6262
}
6363

6464
impl<'a> Parser<'a> {
65-
fn new(parser: pulldown_cmark::Parser<'a>) -> Parser<'a> {
65+
fn new(parser: pulldown_cmark::Parser<'a>) -> Self {
6666
Self { parser: parser }
6767
}
6868
}

clippy_lints/src/enum_variants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub struct EnumVariantNames {
104104
}
105105

106106
impl EnumVariantNames {
107-
pub fn new(threshold: u64) -> EnumVariantNames {
108-
EnumVariantNames {
107+
pub fn new(threshold: u64) -> Self {
108+
Self {
109109
modules: Vec::new(),
110110
threshold: threshold,
111111
}

clippy_lints/src/functions.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::hir::intravisit;
22
use rustc::hir;
33
use rustc::lint::*;
4+
use rustc::ty;
45
use std::collections::HashSet;
56
use syntax::ast;
67
use syntax::abi::Abi;
@@ -58,8 +59,8 @@ pub struct Functions {
5859
}
5960

6061
impl Functions {
61-
pub fn new(threshold: u64) -> Functions {
62-
Functions { threshold: threshold }
62+
pub fn new(threshold: u64) -> Self {
63+
Self { threshold: threshold }
6364
}
6465
}
6566

@@ -150,9 +151,11 @@ impl<'a, 'tcx> Functions {
150151
.collect::<HashSet<_>>();
151152

152153
if !raw_ptrs.is_empty() {
154+
let tables = cx.tcx.body_tables(body.id());
153155
let mut v = DerefVisitor {
154156
cx: cx,
155157
ptrs: raw_ptrs,
158+
tables,
156159
};
157160

158161
hir::intravisit::walk_expr(&mut v, expr);
@@ -172,13 +175,14 @@ fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::def_id::DefId> {
172175
struct DerefVisitor<'a, 'tcx: 'a> {
173176
cx: &'a LateContext<'a, 'tcx>,
174177
ptrs: HashSet<hir::def_id::DefId>,
178+
tables: &'a ty::TypeckTables<'tcx>,
175179
}
176180

177181
impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
178182
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
179183
match expr.node {
180184
hir::ExprCall(ref f, ref args) => {
181-
let ty = self.cx.tables.expr_ty(f);
185+
let ty = self.tables.expr_ty(f);
182186

183187
if type_is_unsafe_function(self.cx, ty) {
184188
for arg in args {
@@ -187,7 +191,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
187191
}
188192
},
189193
hir::ExprMethodCall(_, _, ref args) => {
190-
let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id();
194+
let def_id = self.tables.type_dependent_defs()[expr.hir_id].def_id();
191195
let base_type = self.cx.tcx.type_of(def_id);
192196

193197
if type_is_unsafe_function(self.cx, base_type) {

clippy_lints/src/large_enum_variant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct LargeEnumVariant {
3434

3535
impl LargeEnumVariant {
3636
pub fn new(maximum_size_difference_allowed: u64) -> Self {
37-
LargeEnumVariant { maximum_size_difference_allowed: maximum_size_difference_allowed }
37+
Self { maximum_size_difference_allowed: maximum_size_difference_allowed }
3838
}
3939
}
4040

clippy_lints/src/lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ struct RefVisitor<'a, 'tcx: 'a> {
254254
}
255255

256256
impl<'v, 't> RefVisitor<'v, 't> {
257-
fn new(cx: &'v LateContext<'v, 't>) -> RefVisitor<'v, 't> {
258-
RefVisitor {
257+
fn new(cx: &'v LateContext<'v, 't>) -> Self {
258+
Self {
259259
cx: cx,
260260
lts: Vec::new(),
261261
abort: false,

clippy_lints/src/literal_digit_grouping.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct DigitInfo<'a> {
9595
}
9696

9797
impl<'a> DigitInfo<'a> {
98-
pub fn new(lit: &str, float: bool) -> DigitInfo {
98+
pub fn new(lit: &'a str, float: bool) -> Self {
9999
// Determine delimiter for radix prefix, if present, and radix.
100100
let radix = if lit.starts_with("0x") {
101101
Radix::Hexadecimal
@@ -120,7 +120,7 @@ impl<'a> DigitInfo<'a> {
120120
if !float && (d == 'i' || d == 'u') || float && d == 'f' {
121121
let suffix_start = if last_d == '_' { d_idx - 1 } else { d_idx };
122122
let (digits, suffix) = sans_prefix.split_at(suffix_start);
123-
return DigitInfo {
123+
return Self {
124124
digits: digits,
125125
radix: radix,
126126
prefix: prefix,
@@ -132,7 +132,7 @@ impl<'a> DigitInfo<'a> {
132132
}
133133

134134
// No suffix found
135-
DigitInfo {
135+
Self {
136136
digits: sans_prefix,
137137
radix: radix,
138138
prefix: prefix,
@@ -257,7 +257,7 @@ impl LiteralDigitGrouping {
257257
char::to_digit(firstch, 10).is_some()
258258
], {
259259
let digit_info = DigitInfo::new(&src, false);
260-
let _ = LiteralDigitGrouping::do_lint(digit_info.digits).map_err(|warning_type| {
260+
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
261261
warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)
262262
});
263263
}}
@@ -278,14 +278,14 @@ impl LiteralDigitGrouping {
278278

279279
// Lint integral and fractional parts separately, and then check consistency of digit
280280
// groups if both pass.
281-
let _ = LiteralDigitGrouping::do_lint(parts[0])
281+
let _ = Self::do_lint(parts[0])
282282
.map(|integral_group_size| {
283283
if parts.len() > 1 {
284284
// Lint the fractional part of literal just like integral part, but reversed.
285285
let fractional_part = &parts[1].chars().rev().collect::<String>();
286-
let _ = LiteralDigitGrouping::do_lint(fractional_part)
286+
let _ = Self::do_lint(fractional_part)
287287
.map(|fractional_group_size| {
288-
let consistent = LiteralDigitGrouping::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len());
288+
let consistent = Self::parts_consistent(integral_group_size, fractional_group_size, parts[0].len(), parts[1].len());
289289
if !consistent {
290290
WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(), cx, &lit.span);
291291
}

0 commit comments

Comments
 (0)