Skip to content

Commit c706c27

Browse files
committed
submodules: update clippy from 9897442 to 8c0e038
Changes: ```` Rustup for rust-lang/rust#59042 Update pulldown_cmark to 0.5 Only run AppVeyor on r+, try and the master branch Remove approx_constant known problems Suppress let_and_return if let has attributes Add test for or_fun_call macro suggestion UI test cleanup: Extract needless_range_loop tests Change "if types change" to "if you later change the type" ````
1 parent e750c55 commit c706c27

18 files changed

+319
-318
lines changed

appveyor.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ environment:
88
- TARGET: x86_64-pc-windows-msvc
99

1010
branches:
11-
# Don't build these branches
12-
except:
13-
# Used by bors
14-
- trying.tmp
15-
- staging.tmp
11+
# Only build AppVeyor on r+, try and the master branch
12+
only:
13+
- auto
14+
- try
15+
- master
1616

1717
install:
1818
- curl -sSf -o rustup-init.exe https://win.rustup.rs/

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ serde = "1.0"
2828
serde_derive = "1.0"
2929
toml = "0.4"
3030
unicode-normalization = "0.1"
31-
pulldown-cmark = "0.2"
31+
pulldown-cmark = "0.5.0"
3232
url = "1.7.0"
3333
if_chain = "0.1.3"
3434
smallvec = { version = "0.6.5", features = ["union"] }

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ declare_clippy_lint! {
1919
/// actually more precise, please [file a Rust
2020
/// issue](https://github.com/rust-lang/rust/issues).
2121
///
22-
/// **Known problems:** If you happen to have a value that is within 1/8192 of a
23-
/// known constant, but is not *and should not* be the same, this lint will
24-
/// report your value anyway. We have not yet noticed any false positives in
25-
/// code we tested clippy with (this includes servo), but YMMV.
22+
/// **Known problems:** None.
2623
///
2724
/// **Example:**
2825
/// ```rust

clippy_lints/src/doc.rs

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use pulldown_cmark;
44
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
55
use rustc::{declare_tool_lint, impl_lint_pass};
66
use rustc_data_structures::fx::FxHashSet;
7+
use std::ops::Range;
78
use syntax::ast;
89
use syntax::source_map::{BytePos, Span};
910
use syntax_pos::Pos;
@@ -57,25 +58,6 @@ impl EarlyLintPass for DocMarkdown {
5758
}
5859
}
5960

60-
struct Parser<'a> {
61-
parser: pulldown_cmark::Parser<'a>,
62-
}
63-
64-
impl<'a> Parser<'a> {
65-
fn new(parser: pulldown_cmark::Parser<'a>) -> Self {
66-
Self { parser }
67-
}
68-
}
69-
70-
impl<'a> Iterator for Parser<'a> {
71-
type Item = (usize, pulldown_cmark::Event<'a>);
72-
73-
fn next(&mut self) -> Option<Self::Item> {
74-
let offset = self.parser.get_offset();
75-
self.parser.next().map(|event| (offset, event))
76-
}
77-
}
78-
7961
/// Cleanup documentation decoration (`///` and such).
8062
///
8163
/// We can't use `syntax::attr::AttributeMethods::with_desugared_doc` or
@@ -159,30 +141,31 @@ pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>,
159141
}
160142

161143
if !doc.is_empty() {
162-
let parser = Parser::new(pulldown_cmark::Parser::new(&doc));
163-
let parser = parser.coalesce(|x, y| {
144+
let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter();
145+
// Iterate over all `Events` and combine consecutive events into one
146+
let events = parser.coalesce(|previous, current| {
164147
use pulldown_cmark::Event::*;
165148

166-
let x_offset = x.0;
167-
let y_offset = y.0;
149+
let previous_range = previous.1;
150+
let current_range = current.1;
168151

169-
match (x.1, y.1) {
170-
(Text(x), Text(y)) => {
171-
let mut x = x.into_owned();
172-
x.push_str(&y);
173-
Ok((x_offset, Text(x.into())))
152+
match (previous.0, current.0) {
153+
(Text(previous), Text(current)) => {
154+
let mut previous = previous.to_string();
155+
previous.push_str(&current);
156+
Ok((Text(previous.into()), previous_range))
174157
},
175-
(x, y) => Err(((x_offset, x), (y_offset, y))),
158+
(previous, current) => Err(((previous, previous_range), (current, current_range))),
176159
}
177160
});
178-
check_doc(cx, valid_idents, parser, &spans);
161+
check_doc(cx, valid_idents, events, &spans);
179162
}
180163
}
181164

182-
fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
165+
fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize>)>>(
183166
cx: &EarlyContext<'_>,
184167
valid_idents: &FxHashSet<String>,
185-
docs: Events,
168+
events: Events,
186169
spans: &[(usize, Span)],
187170
) {
188171
use pulldown_cmark::Event::*;
@@ -191,15 +174,15 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
191174
let mut in_code = false;
192175
let mut in_link = None;
193176

194-
for (offset, event) in docs {
177+
for (event, range) in events {
195178
match event {
196-
Start(CodeBlock(_)) | Start(Code) => in_code = true,
197-
End(CodeBlock(_)) | End(Code) => in_code = false,
198-
Start(Link(link, _)) => in_link = Some(link),
199-
End(Link(_, _)) => in_link = None,
179+
Start(CodeBlock(_)) => in_code = true,
180+
End(CodeBlock(_)) => in_code = false,
181+
Start(Link(_, url, _)) => in_link = Some(url),
182+
End(Link(..)) => in_link = None,
200183
Start(_tag) | End(_tag) => (), // We don't care about other tags
201184
Html(_html) | InlineHtml(_html) => (), // HTML is weird, just ignore it
202-
SoftBreak | HardBreak => (),
185+
SoftBreak | HardBreak | TaskListMarker(_) | Code(_) => (),
203186
FootnoteReference(text) | Text(text) => {
204187
if Some(&text) == in_link.as_ref() {
205188
// Probably a link of the form `<http://example.com>`
@@ -209,15 +192,15 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
209192
}
210193

211194
if !in_code {
212-
let index = match spans.binary_search_by(|c| c.0.cmp(&offset)) {
195+
let index = match spans.binary_search_by(|c| c.0.cmp(&range.start)) {
213196
Ok(o) => o,
214197
Err(e) => e - 1,
215198
};
216199

217200
let (begin, span) = spans[index];
218201

219202
// Adjust for the beginning of the current `Event`
220-
let span = span.with_lo(span.lo() + BytePos::from_usize(offset - begin));
203+
let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin));
221204

222205
check_text(cx, valid_idents, &text, span);
223206
}

clippy_lints/src/loops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,12 +1459,12 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
14591459
// For each candidate, check the parent block to see if
14601460
// it's initialized to zero at the start of the loop.
14611461
let map = &cx.tcx.hir();
1462-
let expr_node_id = map.hir_to_node_id(expr.hir_id);
1462+
let expr_node_id = expr.hir_id;
14631463
let parent_scope = map
14641464
.get_enclosing_scope(expr_node_id)
14651465
.and_then(|id| map.get_enclosing_scope(id));
14661466
if let Some(parent_id) = parent_scope {
1467-
if let Node::Block(block) = map.get(parent_id) {
1467+
if let Node::Block(block) = map.get_by_hir_id(parent_id) {
14681468
for (id, _) in visitor.states.iter().filter(|&(_, v)| *v == VarState::IncrOnce) {
14691469
let mut visitor2 = InitializeVisitor {
14701470
cx,

clippy_lints/src/returns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Return {
157157
if let ast::StmtKind::Local(ref local) = stmt.node;
158158
// don't lint in the presence of type inference
159159
if local.ty.is_none();
160-
if !local.attrs.iter().any(attr_is_cfg);
160+
if local.attrs.is_empty();
161161
if let Some(ref initexpr) = local.init;
162162
if let ast::PatKind::Ident(_, ident, _) = local.pat.node;
163163
if let ast::ExprKind::Path(_, ref path) = retexpr.node;

clippy_lints/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_fro
949949
CAST_LOSSLESS,
950950
expr.span,
951951
&format!(
952-
"casting {} to {} may become silently lossy if types change",
952+
"casting {} to {} may become silently lossy if you later change the type",
953953
cast_from, cast_to
954954
),
955955
"try",

clippy_lints/src/utils/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,11 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c
591591
})
592592
}
593593

594-
pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, node: HirId) -> Option<&'tcx Block> {
594+
pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, hir_id: HirId) -> Option<&'tcx Block> {
595595
let map = &cx.tcx.hir();
596-
let node_id = map.hir_to_node_id(node);
597596
let enclosing_node = map
598-
.get_enclosing_scope(node_id)
599-
.and_then(|enclosing_id| map.find(enclosing_id));
597+
.get_enclosing_scope(hir_id)
598+
.and_then(|enclosing_id| map.find_by_hir_id(enclosing_id));
600599
if let Some(node) = enclosing_node {
601600
match node {
602601
Node::Block(block) => Some(block),

tests/ui/cast_lossless_float.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
error: casting i8 to f32 may become silently lossy if types change
1+
error: casting i8 to f32 may become silently lossy if you later change the type
22
--> $DIR/cast_lossless_float.rs:9:5
33
|
44
LL | x0 as f32;
55
| ^^^^^^^^^ help: try: `f32::from(x0)`
66
|
77
= note: `-D clippy::cast-lossless` implied by `-D warnings`
88

9-
error: casting i8 to f64 may become silently lossy if types change
9+
error: casting i8 to f64 may become silently lossy if you later change the type
1010
--> $DIR/cast_lossless_float.rs:10:5
1111
|
1212
LL | x0 as f64;
1313
| ^^^^^^^^^ help: try: `f64::from(x0)`
1414

15-
error: casting u8 to f32 may become silently lossy if types change
15+
error: casting u8 to f32 may become silently lossy if you later change the type
1616
--> $DIR/cast_lossless_float.rs:12:5
1717
|
1818
LL | x1 as f32;
1919
| ^^^^^^^^^ help: try: `f32::from(x1)`
2020

21-
error: casting u8 to f64 may become silently lossy if types change
21+
error: casting u8 to f64 may become silently lossy if you later change the type
2222
--> $DIR/cast_lossless_float.rs:13:5
2323
|
2424
LL | x1 as f64;
2525
| ^^^^^^^^^ help: try: `f64::from(x1)`
2626

27-
error: casting i16 to f32 may become silently lossy if types change
27+
error: casting i16 to f32 may become silently lossy if you later change the type
2828
--> $DIR/cast_lossless_float.rs:15:5
2929
|
3030
LL | x2 as f32;
3131
| ^^^^^^^^^ help: try: `f32::from(x2)`
3232

33-
error: casting i16 to f64 may become silently lossy if types change
33+
error: casting i16 to f64 may become silently lossy if you later change the type
3434
--> $DIR/cast_lossless_float.rs:16:5
3535
|
3636
LL | x2 as f64;
3737
| ^^^^^^^^^ help: try: `f64::from(x2)`
3838

39-
error: casting u16 to f32 may become silently lossy if types change
39+
error: casting u16 to f32 may become silently lossy if you later change the type
4040
--> $DIR/cast_lossless_float.rs:18:5
4141
|
4242
LL | x3 as f32;
4343
| ^^^^^^^^^ help: try: `f32::from(x3)`
4444

45-
error: casting u16 to f64 may become silently lossy if types change
45+
error: casting u16 to f64 may become silently lossy if you later change the type
4646
--> $DIR/cast_lossless_float.rs:19:5
4747
|
4848
LL | x3 as f64;
4949
| ^^^^^^^^^ help: try: `f64::from(x3)`
5050

51-
error: casting i32 to f64 may become silently lossy if types change
51+
error: casting i32 to f64 may become silently lossy if you later change the type
5252
--> $DIR/cast_lossless_float.rs:21:5
5353
|
5454
LL | x4 as f64;
5555
| ^^^^^^^^^ help: try: `f64::from(x4)`
5656

57-
error: casting u32 to f64 may become silently lossy if types change
57+
error: casting u32 to f64 may become silently lossy if you later change the type
5858
--> $DIR/cast_lossless_float.rs:23:5
5959
|
6060
LL | x5 as f64;
6161
| ^^^^^^^^^ help: try: `f64::from(x5)`
6262

63-
error: casting f32 to f64 may become silently lossy if types change
63+
error: casting f32 to f64 may become silently lossy if you later change the type
6464
--> $DIR/cast_lossless_float.rs:26:5
6565
|
6666
LL | 1.0f32 as f64;

0 commit comments

Comments
 (0)