Skip to content

Commit f1b9ddc

Browse files
committed
Merge remote-tracking branch 'upstream/master' into clippy--all
2 parents 6c66589 + 66346b2 commit f1b9ddc

23 files changed

+839
-454
lines changed

CHANGELOG.md

+215-210
Large diffs are not rendered by default.

CONTRIBUTING.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ High level approach:
1515

1616
All issues on Clippy are mentored, if you want help with a bug just ask @Manishearth, @llogiq, @mcarton or @oli-obk.
1717

18-
Some issues are easier than others. The [E-easy](https://github.com/Manishearth/rust-clippy/labels/E-easy)
18+
Some issues are easier than others. The [E-easy](https://github.com/rust-lang-nursery/rust-clippy/labels/E-easy)
1919
label can be used to find the easy issues. If you want to work on an issue, please leave a comment
2020
so that we can assign it to you!
2121

22-
Issues marked [T-AST](https://github.com/Manishearth/rust-clippy/labels/T-AST) involve simple
22+
Issues marked [T-AST](https://github.com/rust-lang-nursery/rust-clippy/labels/T-AST) involve simple
2323
matching of the syntax tree structure, and are generally easier than
24-
[T-middle](https://github.com/Manishearth/rust-clippy/labels/T-middle) issues, which involve types
24+
[T-middle](https://github.com/rust-lang-nursery/rust-clippy/labels/T-middle) issues, which involve types
2525
and resolved paths.
2626

27-
Issues marked [E-medium](https://github.com/Manishearth/rust-clippy/labels/E-medium) are generally
27+
Issues marked [E-medium](https://github.com/rust-lang-nursery/rust-clippy/labels/E-medium) are generally
2828
pretty easy too, though it's recommended you work on an E-easy issue first. They are mostly classified
2929
as `E-medium`, since they might be somewhat involved code wise, but not difficult per-se.
3030

@@ -38,7 +38,7 @@ how this syntax structure is encoded in the AST, it is recommended to run `rustc
3838
example of the structure and compare with the
3939
[nodes in the AST docs](http://manishearth.github.io/rust-internals-docs/syntax/ast/). Usually
4040
the lint will end up to be a nested series of matches and ifs,
41-
[like so](https://github.com/Manishearth/rust-clippy/blob/de5ccdfab68a5e37689f3c950ed1532ba9d652a0/src/misc.rs#L34).
41+
[like so](https://github.com/rust-lang-nursery/rust-clippy/blob/de5ccdfab68a5e37689f3c950ed1532ba9d652a0/src/misc.rs#L34).
4242

4343
T-middle issues can be more involved and require verifying types. The
4444
[`ty`](http://manishearth.github.io/rust-internals-docs/rustc/ty) module contains a

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.152"
3+
version = "0.0.153"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -9,15 +9,15 @@ authors = [
99
"Oliver Schneider <[email protected]>"
1010
]
1111
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
12-
repository = "https://github.com/Manishearth/rust-clippy"
12+
repository = "https://github.com/rust-lang-nursery/rust-clippy"
1313
readme = "README.md"
1414
license = "MPL-2.0"
1515
keywords = ["clippy", "lint", "plugin"]
1616
categories = ["development-tools", "development-tools::cargo-plugins"]
1717

1818
[badges]
19-
travis-ci = { repository = "Manishearth/rust-clippy" }
20-
appveyor = { repository = "Manishearth/rust-clippy" }
19+
travis-ci = { repository = "rust-lang-nursery/rust-clippy" }
20+
appveyor = { repository = "rust-lang-nursery/rust-clippy" }
2121

2222
[lib]
2323
name = "clippy"
@@ -31,7 +31,7 @@ path = "src/main.rs"
3131

3232
[dependencies]
3333
# begin automatic update
34-
clippy_lints = { version = "0.0.152", path = "clippy_lints" }
34+
clippy_lints = { version = "0.0.153", path = "clippy_lints" }
3535
# end automatic update
3636
cargo_metadata = "0.2"
3737

PUBLISH.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Steps to publish a new clippy version
1212
- `git pull`.
1313
- `git tag -s v0.0.X -m "v0.0.X"`.
1414
- `git push --tags`.
15-
- `git clone [email protected]:Manishearth/rust-clippy.wiki.git ../rust-clippy.wiki`
15+
- `git clone [email protected]:rust-lang-nursery/rust-clippy.wiki.git ../rust-clippy.wiki`
1616
- `./util/update_wiki.py`
1717
- `cd ../rust-clippy.wiki`
1818
- `git add *`

README.md

+215-214
Large diffs are not rendered by default.

clippy_lints/Cargo.toml

+2-2
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.152"
4+
version = "0.0.153"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",
@@ -10,7 +10,7 @@ authors = [
1010
"Martin Carton <[email protected]>"
1111
]
1212
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
13-
repository = "https://github.com/Manishearth/rust-clippy"
13+
repository = "https://github.com/rust-lang-nursery/rust-clippy"
1414
readme = "README.md"
1515
license = "MPL-2.0"
1616
keywords = ["clippy", "lint", "plugin"]

clippy_lints/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
This crate contains Clippy lints. For the main crate, check
22
[*cargo.io*](https://crates.io/crates/clippy) or
3-
[GitHub](https://github.com/Manishearth/rust-clippy).
3+
[GitHub](https://github.com/rust-lang-nursery/rust-clippy).

clippy_lints/src/copies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ declare_lint! {
6767
/// [using `|`](https://doc.rust-lang.org/book/patterns.html#multiple-patterns).
6868
///
6969
/// **Known problems:** False positive possible with order dependent `match`
70-
/// (see issue [#860](https://github.com/Manishearth/rust-clippy/issues/860)).
70+
/// (see issue [#860](https://github.com/rust-lang-nursery/rust-clippy/issues/860)).
7171
///
7272
/// **Example:**
7373
/// ```rust,ignore

clippy_lints/src/doc.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
109109
if comment.starts_with("/*") {
110110
let doc = &comment[3..comment.len() - 2];
111111
let mut sizes = vec![];
112-
112+
let mut contains_initial_stars = false;
113113
for line in doc.lines() {
114114
let offset = line.as_ptr() as usize - comment.as_ptr() as usize;
115115
debug_assert_eq!(offset as u32 as usize, offset);
116-
116+
contains_initial_stars |= line.trim_left().starts_with('*');
117117
// +1 for the newline
118118
sizes.push((
119119
line.len() + 1,
@@ -123,8 +123,25 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
123123
},
124124
));
125125
}
126-
127-
return (doc.to_string(), sizes);
126+
if !contains_initial_stars {
127+
return (doc.to_string(), sizes);
128+
}
129+
// remove the initial '*'s if any
130+
let mut no_stars = String::with_capacity(doc.len());
131+
for line in doc.lines() {
132+
let mut chars = line.chars();
133+
while let Some(c) = chars.next() {
134+
if c.is_whitespace() {
135+
no_stars.push(c);
136+
} else {
137+
no_stars.push(if c == '*' { ' ' } else { c });
138+
break;
139+
}
140+
}
141+
no_stars.push_str(chars.as_str());
142+
no_stars.push('\n');
143+
}
144+
return (no_stars, sizes);
128145
}
129146

130147
panic!("not a doc-comment: {}", comment);

clippy_lints/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub mod unicode;
148148
pub mod unsafe_removed_from_name;
149149
pub mod unused_io_amount;
150150
pub mod unused_label;
151+
pub mod use_self;
151152
pub mod vec;
152153
pub mod zero_div_zero;
153154
// end lints modules, do not remove this comment, it’s used in `update_lints`
@@ -319,6 +320,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
319320
reg.register_late_lint_pass(box should_assert_eq::ShouldAssertEq);
320321
reg.register_late_lint_pass(box needless_pass_by_value::NeedlessPassByValue);
321322
reg.register_early_lint_pass(box literal_digit_grouping::LiteralDigitGrouping);
323+
reg.register_late_lint_pass(box use_self::UseSelf);
322324

323325
reg.register_lint_group("clippy_restrictions", vec![
324326
arithmetic::FLOAT_ARITHMETIC,
@@ -363,6 +365,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
363365
types::INVALID_UPCAST_COMPARISONS,
364366
unicode::NON_ASCII_LITERAL,
365367
unicode::UNICODE_NOT_NFC,
368+
use_self::USE_SELF,
366369
]);
367370

368371
reg.register_lint_group("clippy_internal", vec![

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
11241124
/// will mistakenly imply that it is possible for `x` to be outside the range of
11251125
/// `u8`.
11261126
///
1127-
/// **Known problems:** https://github.com/Manishearth/rust-clippy/issues/886
1127+
/// **Known problems:** https://github.com/rust-lang-nursery/rust-clippy/issues/886
11281128
///
11291129
/// **Example:**
11301130
/// ```rust

clippy_lints/src/use_self.rs

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
use rustc::lint::{LintArray, LateLintPass, LateContext, LintPass};
2+
use rustc::hir::*;
3+
use rustc::hir::intravisit::{Visitor, walk_path, NestedVisitorMap};
4+
use utils::span_lint_and_then;
5+
use syntax::ast::NodeId;
6+
use syntax_pos::symbol::keywords::SelfType;
7+
8+
/// **What it does:** Checks for unnecessary repetition of structure name when a
9+
/// replacement with `Self` is applicable.
10+
///
11+
/// **Why is this bad?** Unnecessary repetition. Mixed use of `Self` and struct name
12+
/// feels inconsistent.
13+
///
14+
/// **Known problems:** None.
15+
///
16+
/// **Example:**
17+
/// ```rust
18+
/// struct Foo {}
19+
/// impl Foo {
20+
/// fn new() -> Foo {
21+
/// Foo {}
22+
/// }
23+
/// }
24+
/// ```
25+
/// could be
26+
/// ```
27+
/// struct Foo {}
28+
/// impl Foo {
29+
/// fn new() -> Self {
30+
/// Self {}
31+
/// }
32+
/// }
33+
/// ```
34+
declare_lint! {
35+
pub USE_SELF,
36+
Allow,
37+
"Unnecessary structure name repetition whereas `Self` is applicable"
38+
}
39+
40+
#[derive(Copy, Clone, Default)]
41+
pub struct UseSelf;
42+
43+
impl LintPass for UseSelf {
44+
fn get_lints(&self) -> LintArray {
45+
lint_array!(USE_SELF)
46+
}
47+
}
48+
49+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
50+
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
51+
if_let_chain!([
52+
let ItemImpl(.., ref item_type, ref refs) = item.node,
53+
let Ty_::TyPath(QPath::Resolved(_, ref item_path)) = item_type.node,
54+
], {
55+
let visitor = &mut UseSelfVisitor {
56+
item_path: item_path,
57+
cx: cx,
58+
};
59+
for impl_item_ref in refs {
60+
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
61+
}
62+
})
63+
}
64+
}
65+
66+
struct UseSelfVisitor<'a, 'tcx: 'a> {
67+
item_path: &'a Path,
68+
cx: &'a LateContext<'a, 'tcx>,
69+
}
70+
71+
impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
72+
fn visit_path(&mut self, path: &'tcx Path, _id: NodeId) {
73+
if self.item_path.def == path.def &&
74+
path.segments
75+
.last()
76+
.expect("segments should be composed of at least 1 element")
77+
.name != SelfType.name() {
78+
span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| {
79+
db.span_suggestion(path.span,
80+
"use the applicable keyword",
81+
"Self".to_owned());
82+
});
83+
}
84+
85+
walk_path(self, path);
86+
}
87+
88+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
89+
NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir)
90+
}
91+
}

clippy_lints/src/utils/higher.rs

+23
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,36 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
114114

115115
/// Checks if a `let` decl is from a `for` loop desugaring.
116116
pub fn is_from_for_desugar(decl: &hir::Decl) -> bool {
117+
// This will detect plain for-loops without an actual variable binding:
118+
//
119+
// ```
120+
// for x in some_vec {
121+
// // do stuff
122+
// }
123+
// ```
117124
if_let_chain! {[
118125
let hir::DeclLocal(ref loc) = decl.node,
119126
let Some(ref expr) = loc.init,
120127
let hir::ExprMatch(_, _, hir::MatchSource::ForLoopDesugar) = expr.node,
121128
], {
122129
return true;
123130
}}
131+
132+
// This detects a variable binding in for loop to avoid `let_unit_value`
133+
// lint (see issue #1964).
134+
//
135+
// ```
136+
// for _ in vec![()] {
137+
// // anything
138+
// }
139+
// ```
140+
if_let_chain! {[
141+
let hir::DeclLocal(ref loc) = decl.node,
142+
let hir::LocalSource::ForLoopDesugar = loc.source,
143+
], {
144+
return true;
145+
}}
146+
124147
false
125148
}
126149

clippy_lints/src/utils/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::mem;
1616
use std::str::FromStr;
1717
use syntax::ast::{self, LitKind};
1818
use syntax::attr;
19-
use syntax::codemap::{ExpnFormat, ExpnInfo, Span, DUMMY_SP};
19+
use syntax::codemap::{CompilerDesugaringKind, ExpnFormat, ExpnInfo, Span, DUMMY_SP};
2020
use syntax::errors::DiagnosticBuilder;
2121
use syntax::ptr::P;
2222
use syntax::symbol::keywords;
@@ -114,7 +114,7 @@ pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
114114
pub fn in_macro(span: Span) -> bool {
115115
span.ctxt.outer().expn_info().map_or(false, |info| {
116116
match info.callee.format {// don't treat range expressions desugared to structs as "in_macro"
117-
ExpnFormat::CompilerDesugaring(name) => name != "...",
117+
ExpnFormat::CompilerDesugaring(kind) => kind != CompilerDesugaringKind::DotFill,
118118
_ => true,
119119
}
120120
})
@@ -537,7 +537,7 @@ impl<'a> DiagnosticWrapper<'a> {
537537
fn wiki_link(&mut self, lint: &'static Lint) {
538538
if env::var("CLIPPY_DISABLE_WIKI_LINKS").is_err() {
539539
self.0.help(&format!(
540-
"for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}",
540+
"for further information visit https://github.com/rust-lang-nursery/rust-clippy/wiki#{}",
541541
lint.name_lower()
542542
));
543543
}

mini-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors = [
1010
]
1111
license = "MPL-2.0"
1212
description = "A macro to test clippy's procedural macro checks"
13-
repository = "https://github.com/Manishearth/rust-clippy"
13+
repository = "https://github.com/rust-lang-nursery/rust-clippy"
1414

1515
[lib]
1616
name = "clippy_mini_macro_test"

tests/ui/doc.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn test_units() {
5050
}
5151

5252
/// This test has [a link_with_underscores][chunked-example] inside it. See #823.
53-
/// See also [the issue tracker](https://github.com/Manishearth/rust-clippy/search?q=doc_markdown&type=Issues)
53+
/// See also [the issue tracker](https://github.com/rust-lang-nursery/rust-clippy/search?q=doc_markdown&type=Issues)
5454
/// on GitHub (which is a camel-cased word, but is OK). And here is another [inline link][inline_link].
5555
/// It can also be [inline_link2].
5656
///
@@ -142,7 +142,7 @@ fn four_quotes() {
142142
/// See [NIST SP 800-56A, revision 2].
143143
///
144144
/// [NIST SP 800-56A, revision 2]:
145-
/// https://github.com/Manishearth/rust-clippy/issues/902#issuecomment-261919419
145+
/// https://github.com/rust-lang-nursery/rust-clippy/issues/902#issuecomment-261919419
146146
fn issue_902_comment() {}
147147

148148
#[cfg_attr(feature = "a", doc = " ```")]
@@ -153,3 +153,9 @@ fn issue_902_comment() {}
153153
/// }
154154
/// ```
155155
fn issue_1469() {}
156+
157+
/**
158+
* This is a doc comment that should not be a list
159+
*This would also be an error under a strict common mark interpretation
160+
*/
161+
fn issue_1920() {}

0 commit comments

Comments
 (0)