Skip to content

Commit 46f97f3

Browse files
authored
Merge pull request #20349 from Veykril/push-orvqsnqtttzv
`cargo clippy --fix`
2 parents 423c7dd + 8ce3026 commit 46f97f3

File tree

186 files changed

+3073
-3331
lines changed

Some content is hidden

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

186 files changed

+3073
-3331
lines changed

crates/cfg/src/cfg_expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ fn next_cfg_expr<S: Copy>(it: &mut tt::iter::TtIter<'_, S>) -> Option<CfgExpr> {
134134
};
135135

136136
// Eat comma separator
137-
if let Some(TtElement::Leaf(tt::Leaf::Punct(punct))) = it.peek() {
138-
if punct.char == ',' {
139-
it.next();
140-
}
137+
if let Some(TtElement::Leaf(tt::Leaf::Punct(punct))) = it.peek()
138+
&& punct.char == ','
139+
{
140+
it.next();
141141
}
142142
Some(ret)
143143
}

crates/hir-def/src/attr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ fn parse_repr_tt(tt: &crate::tt::TopSubtree) -> Option<ReprOptions> {
377377
let mut align = None;
378378
if let Some(TtElement::Subtree(_, mut tt_iter)) = tts.peek() {
379379
tts.next();
380-
if let Some(TtElement::Leaf(tt::Leaf::Literal(lit))) = tt_iter.next() {
381-
if let Ok(a) = lit.symbol.as_str().parse() {
382-
align = Align::from_bytes(a).ok();
383-
}
380+
if let Some(TtElement::Leaf(tt::Leaf::Literal(lit))) = tt_iter.next()
381+
&& let Ok(a) = lit.symbol.as_str().parse()
382+
{
383+
align = Align::from_bytes(a).ok();
384384
}
385385
}
386386
ReprOptions { align, ..Default::default() }

crates/hir-def/src/expr_store/lower.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,13 +1487,13 @@ impl ExprCollector<'_> {
14871487
ast::Expr::UnderscoreExpr(_) => self.alloc_pat_from_expr(Pat::Wild, syntax_ptr),
14881488
ast::Expr::ParenExpr(e) => {
14891489
// We special-case `(..)` for consistency with patterns.
1490-
if let Some(ast::Expr::RangeExpr(range)) = e.expr() {
1491-
if range.is_range_full() {
1492-
return Some(self.alloc_pat_from_expr(
1493-
Pat::Tuple { args: Box::default(), ellipsis: Some(0) },
1494-
syntax_ptr,
1495-
));
1496-
}
1490+
if let Some(ast::Expr::RangeExpr(range)) = e.expr()
1491+
&& range.is_range_full()
1492+
{
1493+
return Some(self.alloc_pat_from_expr(
1494+
Pat::Tuple { args: Box::default(), ellipsis: Some(0) },
1495+
syntax_ptr,
1496+
));
14971497
}
14981498
return e.expr().and_then(|expr| self.maybe_collect_expr_as_pat(&expr));
14991499
}
@@ -2569,19 +2569,18 @@ impl ExprCollector<'_> {
25692569
}
25702570
}
25712571
RibKind::MacroDef(macro_id) => {
2572-
if let Some((parent_ctx, label_macro_id)) = hygiene_info {
2573-
if label_macro_id == **macro_id {
2574-
// A macro is allowed to refer to labels from before its declaration.
2575-
// Therefore, if we got to the rib of its declaration, give up its hygiene
2576-
// and use its parent expansion.
2577-
2578-
hygiene_id =
2579-
HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
2580-
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
2581-
let expansion = self.db.lookup_intern_macro_call(expansion.into());
2582-
(parent_ctx.parent(self.db), expansion.def)
2583-
});
2584-
}
2572+
if let Some((parent_ctx, label_macro_id)) = hygiene_info
2573+
&& label_macro_id == **macro_id
2574+
{
2575+
// A macro is allowed to refer to labels from before its declaration.
2576+
// Therefore, if we got to the rib of its declaration, give up its hygiene
2577+
// and use its parent expansion.
2578+
2579+
hygiene_id = HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
2580+
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
2581+
let expansion = self.db.lookup_intern_macro_call(expansion.into());
2582+
(parent_ctx.parent(self.db), expansion.def)
2583+
});
25852584
}
25862585
}
25872586
_ => {}

crates/hir-def/src/expr_store/lower/asm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ impl ExprCollector<'_> {
259259
}
260260
};
261261

262-
if let Some(operand_idx) = operand_idx {
263-
if let Some(position_span) = to_span(arg.position_span) {
264-
mappings.push((position_span, operand_idx));
265-
}
262+
if let Some(operand_idx) = operand_idx
263+
&& let Some(position_span) = to_span(arg.position_span)
264+
{
265+
mappings.push((position_span, operand_idx));
266266
}
267267
}
268268
}

crates/hir-def/src/expr_store/lower/path.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,17 @@ pub(super) fn lower_path(
211211
// Basically, even in rustc it is quite hacky:
212212
// https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
213213
// We follow what it did anyway :)
214-
if segments.len() == 1 && kind == PathKind::Plain {
215-
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
216-
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
217-
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db) {
218-
if collector.db.lookup_intern_macro_call(macro_call_id.into()).def.local_inner {
219-
kind = match resolve_crate_root(collector.db, syn_ctxt) {
220-
Some(crate_root) => PathKind::DollarCrate(crate_root),
221-
None => PathKind::Crate,
222-
}
223-
}
214+
if segments.len() == 1
215+
&& kind == PathKind::Plain
216+
&& let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast)
217+
{
218+
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
219+
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db)
220+
&& collector.db.lookup_intern_macro_call(macro_call_id.into()).def.local_inner
221+
{
222+
kind = match resolve_crate_root(collector.db, syn_ctxt) {
223+
Some(crate_root) => PathKind::DollarCrate(crate_root),
224+
None => PathKind::Crate,
224225
}
225226
}
226227
}

crates/hir-def/src/expr_store/pretty.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,12 @@ impl Printer<'_> {
900900
let field_name = arg.name.display(self.db, edition).to_string();
901901

902902
let mut same_name = false;
903-
if let Pat::Bind { id, subpat: None } = &self.store[arg.pat] {
904-
if let Binding { name, mode: BindingAnnotation::Unannotated, .. } =
903+
if let Pat::Bind { id, subpat: None } = &self.store[arg.pat]
904+
&& let Binding { name, mode: BindingAnnotation::Unannotated, .. } =
905905
&self.store.assert_expr_only().bindings[*id]
906-
{
907-
if name.as_str() == field_name {
908-
same_name = true;
909-
}
910-
}
906+
&& name.as_str() == field_name
907+
{
908+
same_name = true;
911909
}
912910

913911
w!(p, "{}", field_name);

crates/hir-def/src/find_path.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ struct FindPathCtx<'db> {
107107
/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleId
108108
fn find_path_inner(ctx: &FindPathCtx<'_>, item: ItemInNs, max_len: usize) -> Option<ModPath> {
109109
// - if the item is a module, jump straight to module search
110-
if !ctx.is_std_item {
111-
if let ItemInNs::Types(ModuleDefId::ModuleId(module_id)) = item {
112-
return find_path_for_module(ctx, &mut FxHashSet::default(), module_id, true, max_len)
113-
.map(|choice| choice.path);
114-
}
110+
if !ctx.is_std_item
111+
&& let ItemInNs::Types(ModuleDefId::ModuleId(module_id)) = item
112+
{
113+
return find_path_for_module(ctx, &mut FxHashSet::default(), module_id, true, max_len)
114+
.map(|choice| choice.path);
115115
}
116116

117117
let may_be_in_scope = match ctx.prefix {
@@ -226,15 +226,15 @@ fn find_path_for_module(
226226
}
227227

228228
// - if the module can be referenced as self, super or crate, do that
229-
if let Some(kind) = is_kw_kind_relative_to_from(ctx.from_def_map, module_id, ctx.from) {
230-
if ctx.prefix != PrefixKind::ByCrate || kind == PathKind::Crate {
231-
return Some(Choice {
232-
path: ModPath::from_segments(kind, None),
233-
path_text_len: path_kind_len(kind),
234-
stability: Stable,
235-
prefer_due_to_prelude: false,
236-
});
237-
}
229+
if let Some(kind) = is_kw_kind_relative_to_from(ctx.from_def_map, module_id, ctx.from)
230+
&& (ctx.prefix != PrefixKind::ByCrate || kind == PathKind::Crate)
231+
{
232+
return Some(Choice {
233+
path: ModPath::from_segments(kind, None),
234+
path_text_len: path_kind_len(kind),
235+
stability: Stable,
236+
prefer_due_to_prelude: false,
237+
});
238238
}
239239

240240
// - if the module is in the prelude, return it by that path
@@ -604,29 +604,29 @@ fn find_local_import_locations(
604604
&def_map[module.local_id]
605605
};
606606

607-
if let Some((name, vis, declared)) = data.scope.name_of(item) {
608-
if vis.is_visible_from(db, from) {
609-
let is_pub_or_explicit = match vis {
610-
Visibility::Module(_, VisibilityExplicitness::Explicit) => {
611-
cov_mark::hit!(explicit_private_imports);
612-
true
613-
}
614-
Visibility::Module(_, VisibilityExplicitness::Implicit) => {
615-
cov_mark::hit!(discount_private_imports);
616-
false
617-
}
618-
Visibility::PubCrate(_) => true,
619-
Visibility::Public => true,
620-
};
621-
622-
// Ignore private imports unless they are explicit. these could be used if we are
623-
// in a submodule of this module, but that's usually not
624-
// what the user wants; and if this module can import
625-
// the item and we're a submodule of it, so can we.
626-
// Also this keeps the cached data smaller.
627-
if declared || is_pub_or_explicit {
628-
cb(visited_modules, name, module);
607+
if let Some((name, vis, declared)) = data.scope.name_of(item)
608+
&& vis.is_visible_from(db, from)
609+
{
610+
let is_pub_or_explicit = match vis {
611+
Visibility::Module(_, VisibilityExplicitness::Explicit) => {
612+
cov_mark::hit!(explicit_private_imports);
613+
true
629614
}
615+
Visibility::Module(_, VisibilityExplicitness::Implicit) => {
616+
cov_mark::hit!(discount_private_imports);
617+
false
618+
}
619+
Visibility::PubCrate(_) => true,
620+
Visibility::Public => true,
621+
};
622+
623+
// Ignore private imports unless they are explicit. these could be used if we are
624+
// in a submodule of this module, but that's usually not
625+
// what the user wants; and if this module can import
626+
// the item and we're a submodule of it, so can we.
627+
// Also this keeps the cached data smaller.
628+
if declared || is_pub_or_explicit {
629+
cb(visited_modules, name, module);
630630
}
631631
}
632632

crates/hir-def/src/item_scope.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,11 @@ impl ItemScope {
510510
id: AttrId,
511511
idx: usize,
512512
) {
513-
if let Some(derives) = self.derive_macros.get_mut(&adt) {
514-
if let Some(DeriveMacroInvocation { derive_call_ids, .. }) =
513+
if let Some(derives) = self.derive_macros.get_mut(&adt)
514+
&& let Some(DeriveMacroInvocation { derive_call_ids, .. }) =
515515
derives.iter_mut().find(|&&mut DeriveMacroInvocation { attr_id, .. }| id == attr_id)
516-
{
517-
derive_call_ids[idx] = Some(call);
518-
}
516+
{
517+
derive_call_ids[idx] = Some(call);
519518
}
520519
}
521520

crates/hir-def/src/item_tree/lower.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ impl<'a> Ctx<'a> {
8383
.flat_map(|item| self.lower_mod_item(&item))
8484
.collect();
8585

86-
if let Some(ast::Expr::MacroExpr(tail_macro)) = stmts.expr() {
87-
if let Some(call) = tail_macro.macro_call() {
88-
cov_mark::hit!(macro_stmt_with_trailing_macro_expr);
89-
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
90-
self.top_level.push(mod_item);
91-
}
86+
if let Some(ast::Expr::MacroExpr(tail_macro)) = stmts.expr()
87+
&& let Some(call) = tail_macro.macro_call()
88+
{
89+
cov_mark::hit!(macro_stmt_with_trailing_macro_expr);
90+
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
91+
self.top_level.push(mod_item);
9292
}
9393
}
9494

@@ -112,12 +112,11 @@ impl<'a> Ctx<'a> {
112112
_ => None,
113113
})
114114
.collect();
115-
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() {
116-
if let Some(call) = expr.macro_call() {
117-
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
118-
self.top_level.push(mod_item);
119-
}
120-
}
115+
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr()
116+
&& let Some(call) = expr.macro_call()
117+
&& let Some(mod_item) = self.lower_mod_item(&call.into())
118+
{
119+
self.top_level.push(mod_item);
121120
}
122121
self.tree.vis.arena = self.visibilities.into_iter().collect();
123122
self.tree.top_level = self.top_level.into_boxed_slice();

crates/hir-def/src/lang_item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: Crate) -> Option
218218

219219
for (_, module_data) in crate_def_map.modules() {
220220
for def in module_data.scope.declarations() {
221-
if let ModuleDefId::TraitId(trait_) = def {
222-
if db.attrs(trait_.into()).has_doc_notable_trait() {
223-
traits.push(trait_);
224-
}
221+
if let ModuleDefId::TraitId(trait_) = def
222+
&& db.attrs(trait_.into()).has_doc_notable_trait()
223+
{
224+
traits.push(trait_);
225225
}
226226
}
227227
}

0 commit comments

Comments
 (0)