Skip to content

Commit a7c58e6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents 30c046e + 52cc5fc commit a7c58e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+951
-246
lines changed

.github/workflows/clippy_bors.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ jobs:
240240
- 'Geal/nom'
241241
- 'rust-lang/stdarch'
242242
- 'serde-rs/serde'
243-
- 'chronotope/chrono'
243+
# FIXME: chrono currently cannot be compiled with `--all-targets`
244+
# - 'chronotope/chrono'
244245
- 'hyperium/hyper'
245246
- 'rust-random/rand'
246247
- 'rust-lang/futures-rs'

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ Released 2018-09-13
13521352
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
13531353
[`bind_instead_of_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
13541354
[`blacklisted_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name
1355+
[`blanket_clippy_restriction_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#blanket_clippy_restriction_lints
13551356
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
13561357
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
13571358
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
@@ -1508,6 +1509,7 @@ Released 2018-09-13
15081509
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
15091510
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
15101511
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
1512+
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
15111513
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
15121514
[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref
15131515
[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool

clippy_lints/src/attrs.rs

+67-28
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::reexport::Name;
44
use crate::utils::{
5-
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
6-
span_lint_and_then, without_block_comments,
5+
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help,
6+
span_lint_and_sugg, span_lint_and_then, without_block_comments,
77
};
88
use if_chain::if_chain;
99
use rustc_ast::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
@@ -17,7 +17,7 @@ use rustc_middle::lint::in_external_macro;
1717
use rustc_middle::ty;
1818
use rustc_session::{declare_lint_pass, declare_tool_lint};
1919
use rustc_span::source_map::Span;
20-
use rustc_span::symbol::Symbol;
20+
use rustc_span::symbol::{Symbol, SymbolStr};
2121
use semver::Version;
2222

2323
static UNIX_SYSTEMS: &[&str] = &[
@@ -182,6 +182,29 @@ declare_clippy_lint! {
182182
"unknown_lints for scoped Clippy lints"
183183
}
184184

185+
declare_clippy_lint! {
186+
/// **What it does:** Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
187+
///
188+
/// **Why is this bad?** Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust.
189+
/// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
190+
///
191+
/// **Known problems:** None.
192+
///
193+
/// **Example:**
194+
/// Bad:
195+
/// ```rust
196+
/// #![deny(clippy::restriction)]
197+
/// ```
198+
///
199+
/// Good:
200+
/// ```rust
201+
/// #![deny(clippy::as_conversions)]
202+
/// ```
203+
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
204+
style,
205+
"enabling the complete restriction group"
206+
}
207+
185208
declare_clippy_lint! {
186209
/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
187210
/// with `#[rustfmt::skip]`.
@@ -249,15 +272,17 @@ declare_lint_pass!(Attributes => [
249272
DEPRECATED_SEMVER,
250273
USELESS_ATTRIBUTE,
251274
UNKNOWN_CLIPPY_LINTS,
275+
BLANKET_CLIPPY_RESTRICTION_LINTS,
252276
]);
253277

254278
impl<'tcx> LateLintPass<'tcx> for Attributes {
255279
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
256280
if let Some(items) = &attr.meta_item_list() {
257281
if let Some(ident) = attr.ident() {
258-
match &*ident.as_str() {
282+
let ident = &*ident.as_str();
283+
match ident {
259284
"allow" | "warn" | "deny" | "forbid" => {
260-
check_clippy_lint_names(cx, items);
285+
check_clippy_lint_names(cx, ident, items);
261286
},
262287
_ => {},
263288
}
@@ -363,38 +388,43 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
363388
}
364389
}
365390

366-
#[allow(clippy::single_match_else)]
367-
fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) {
368-
let lint_store = cx.lints();
369-
for lint in items {
391+
fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMetaItem]) {
392+
fn extract_name(lint: &NestedMetaItem) -> Option<SymbolStr> {
370393
if_chain! {
371394
if let Some(meta_item) = lint.meta_item();
372395
if meta_item.path.segments.len() > 1;
373396
if let tool_name = meta_item.path.segments[0].ident;
374397
if tool_name.as_str() == "clippy";
375-
let name = meta_item.path.segments.last().unwrap().ident.name;
376-
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
377-
&name.as_str(),
378-
Some(tool_name.name),
379-
);
398+
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
380399
then {
400+
return Some(lint_name.as_str());
401+
}
402+
}
403+
None
404+
}
405+
406+
let lint_store = cx.lints();
407+
for lint in items {
408+
if let Some(lint_name) = extract_name(lint) {
409+
if let CheckLintNameResult::Tool(Err((None, _))) =
410+
lint_store.check_lint_name(&lint_name, Some(sym!(clippy)))
411+
{
381412
span_lint_and_then(
382413
cx,
383414
UNKNOWN_CLIPPY_LINTS,
384415
lint.span(),
385-
&format!("unknown clippy lint: clippy::{}", name),
416+
&format!("unknown clippy lint: clippy::{}", lint_name),
386417
|diag| {
387-
let name_lower = name.as_str().to_lowercase();
388-
let symbols = lint_store.get_lints().iter().map(
389-
|l| Symbol::intern(&l.name_lower())
390-
).collect::<Vec<_>>();
391-
let sugg = find_best_match_for_name(
392-
symbols.iter(),
393-
&format!("clippy::{}", name_lower),
394-
None,
395-
);
396-
if name.as_str().chars().any(char::is_uppercase)
397-
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
418+
let name_lower = lint_name.to_lowercase();
419+
let symbols = lint_store
420+
.get_lints()
421+
.iter()
422+
.map(|l| Symbol::intern(&l.name_lower()))
423+
.collect::<Vec<_>>();
424+
let sugg = find_best_match_for_name(symbols.iter(), &format!("clippy::{}", name_lower), None);
425+
if lint_name.chars().any(char::is_uppercase)
426+
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok()
427+
{
398428
diag.span_suggestion(
399429
lint.span(),
400430
"lowercase the lint name",
@@ -409,10 +439,19 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) {
409439
Applicability::MachineApplicable,
410440
);
411441
}
412-
}
442+
},
443+
);
444+
} else if lint_name == "restriction" && ident != "allow" {
445+
span_lint_and_help(
446+
cx,
447+
BLANKET_CLIPPY_RESTRICTION_LINTS,
448+
lint.span(),
449+
"restriction lints are not meant to be all enabled",
450+
None,
451+
"try enabling only the lints you really need",
413452
);
414453
}
415-
};
454+
}
416455
}
417456
}
418457

clippy_lints/src/await_holding_lock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare_clippy_lint! {
1111
/// non-async-aware MutexGuard.
1212
///
1313
/// **Why is this bad?** The Mutex types found in syd::sync and parking_lot
14-
/// are not designed to operator in an async context across await points.
14+
/// are not designed to operate in an async context across await points.
1515
///
1616
/// There are two potential solutions. One is to use an asynx-aware Mutex
1717
/// type. Many asynchronous foundation crates provide such a Mutex type. The

clippy_lints/src/deprecated_lints.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,13 @@ declare_deprecated_lint! {
153153
///
154154
/// **Deprecation reason:** Associated-constants are now preferred.
155155
pub REPLACE_CONSTS,
156-
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants"
156+
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
157+
}
158+
159+
declare_deprecated_lint! {
160+
/// **What it does:** Nothing. This lint has been deprecated.
161+
///
162+
/// **Deprecation reason:** The regex! macro does not exist anymore.
163+
pub REGEX_MACRO,
164+
"the regex! macro has been removed from the regex crate in 2018"
157165
}

clippy_lints/src/dereference.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
7373
fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) {
7474
match method_name {
7575
"deref" => {
76-
if cx.tcx.lang_items().deref_trait().map_or(false, |id| {
76+
let impls_deref_trait = cx.tcx.lang_items().deref_trait().map_or(false, |id| {
7777
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
78-
}) {
78+
});
79+
if impls_deref_trait {
7980
span_lint_and_sugg(
8081
cx,
8182
EXPLICIT_DEREF_METHODS,
@@ -88,9 +89,10 @@ fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var
8889
}
8990
},
9091
"deref_mut" => {
91-
if cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| {
92+
let impls_deref_mut_trait = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| {
9293
implements_trait(cx, cx.tables().expr_ty(&call_expr), id, &[])
93-
}) {
94+
});
95+
if impls_deref_mut_trait {
9496
span_lint_and_sugg(
9597
cx,
9698
EXPLICIT_DEREF_METHODS,

clippy_lints/src/lib.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ mod main_recursion;
229229
mod manual_async_fn;
230230
mod manual_non_exhaustive;
231231
mod map_clone;
232+
mod map_identity;
232233
mod map_unit_fn;
233234
mod match_on_vec_items;
234235
mod matches;
@@ -459,7 +460,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
459460
);
460461
store.register_removed(
461462
"clippy::replace_consts",
462-
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants",
463+
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
464+
);
465+
store.register_removed(
466+
"clippy::regex_macro",
467+
"the regex! macro has been removed from the regex crate in 2018",
463468
);
464469
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
465470

@@ -473,6 +478,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
473478
&assign_ops::ASSIGN_OP_PATTERN,
474479
&assign_ops::MISREFACTORED_ASSIGN_OP,
475480
&atomic_ordering::INVALID_ATOMIC_ORDERING,
481+
&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS,
476482
&attrs::DEPRECATED_CFG_ATTR,
477483
&attrs::DEPRECATED_SEMVER,
478484
&attrs::EMPTY_LINE_AFTER_OUTER_ATTR,
@@ -608,6 +614,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
608614
&manual_async_fn::MANUAL_ASYNC_FN,
609615
&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE,
610616
&map_clone::MAP_CLONE,
617+
&map_identity::MAP_IDENTITY,
611618
&map_unit_fn::OPTION_MAP_UNIT_FN,
612619
&map_unit_fn::RESULT_MAP_UNIT_FN,
613620
&match_on_vec_items::MATCH_ON_VEC_ITEMS,
@@ -752,7 +759,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
752759
&reference::DEREF_ADDROF,
753760
&reference::REF_IN_DEREF,
754761
&regex::INVALID_REGEX,
755-
&regex::REGEX_MACRO,
756762
&regex::TRIVIAL_REGEX,
757763
&returns::NEEDLESS_RETURN,
758764
&returns::UNUSED_UNIT,
@@ -1057,6 +1063,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10571063
});
10581064
store.register_early_pass(|| box unnested_or_patterns::UnnestedOrPatterns);
10591065
store.register_late_pass(|| box macro_use::MacroUseImports::default());
1066+
store.register_late_pass(|| box map_identity::MapIdentity);
10601067

10611068
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
10621069
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1186,6 +1193,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11861193
LintId::of(&assign_ops::ASSIGN_OP_PATTERN),
11871194
LintId::of(&assign_ops::MISREFACTORED_ASSIGN_OP),
11881195
LintId::of(&atomic_ordering::INVALID_ATOMIC_ORDERING),
1196+
LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
11891197
LintId::of(&attrs::DEPRECATED_CFG_ATTR),
11901198
LintId::of(&attrs::DEPRECATED_SEMVER),
11911199
LintId::of(&attrs::MISMATCHED_TARGET_OS),
@@ -1273,6 +1281,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12731281
LintId::of(&manual_async_fn::MANUAL_ASYNC_FN),
12741282
LintId::of(&manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE),
12751283
LintId::of(&map_clone::MAP_CLONE),
1284+
LintId::of(&map_identity::MAP_IDENTITY),
12761285
LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN),
12771286
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
12781287
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
@@ -1374,7 +1383,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13741383
LintId::of(&reference::DEREF_ADDROF),
13751384
LintId::of(&reference::REF_IN_DEREF),
13761385
LintId::of(&regex::INVALID_REGEX),
1377-
LintId::of(&regex::REGEX_MACRO),
13781386
LintId::of(&regex::TRIVIAL_REGEX),
13791387
LintId::of(&returns::NEEDLESS_RETURN),
13801388
LintId::of(&returns::UNUSED_UNIT),
@@ -1437,6 +1445,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14371445
store.register_group(true, "clippy::style", Some("clippy_style"), vec![
14381446
LintId::of(&assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
14391447
LintId::of(&assign_ops::ASSIGN_OP_PATTERN),
1448+
LintId::of(&attrs::BLANKET_CLIPPY_RESTRICTION_LINTS),
14401449
LintId::of(&attrs::UNKNOWN_CLIPPY_LINTS),
14411450
LintId::of(&bit_mask::VERBOSE_BIT_MASK),
14421451
LintId::of(&blacklisted_name::BLACKLISTED_NAME),
@@ -1510,7 +1519,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15101519
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
15111520
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
15121521
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
1513-
LintId::of(&regex::REGEX_MACRO),
15141522
LintId::of(&regex::TRIVIAL_REGEX),
15151523
LintId::of(&returns::NEEDLESS_RETURN),
15161524
LintId::of(&returns::UNUSED_UNIT),
@@ -1550,6 +1558,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15501558
LintId::of(&loops::EXPLICIT_COUNTER_LOOP),
15511559
LintId::of(&loops::MUT_RANGE_BOUND),
15521560
LintId::of(&loops::WHILE_LET_LOOP),
1561+
LintId::of(&map_identity::MAP_IDENTITY),
15531562
LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN),
15541563
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
15551564
LintId::of(&matches::MATCH_AS_REF),

0 commit comments

Comments
 (0)