Skip to content

Commit 9efa355

Browse files
bors[bot]Veykril
andauthored
Merge #11011
11011: minor: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents d10a3b3 + 901c7c7 commit 9efa355

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,12 @@ impl SourceAnalyzer {
291291
}
292292
}
293293

294-
if let Some(pat) = parent()
295-
.and_then(ast::RecordPat::cast)
296-
.map(ast::Pat::from)
297-
.or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
298-
{
294+
let record_pat = parent().and_then(ast::RecordPat::cast).map(ast::Pat::from);
295+
let tuple_struct_pat = || parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from);
296+
if let Some(pat) = record_pat.or_else(tuple_struct_pat) {
299297
let pat_id = self.pat_id(&pat)?;
300-
if let Some(VariantId::EnumVariantId(variant)) =
301-
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
302-
{
298+
let variant_res_for_pat = self.infer.as_ref()?.variant_resolution_for_pat(pat_id);
299+
if let Some(VariantId::EnumVariantId(variant)) = variant_res_for_pat {
303300
return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
304301
}
305302
}
@@ -335,6 +332,9 @@ impl SourceAnalyzer {
335332
}
336333
}
337334
} else if is_path_of_attr {
335+
// Case where we are resolving the final path segment of a path in an attribute
336+
// in this case we have to check for inert/builtin attributes and tools and prioritize
337+
// resolution of attributes over other namesapces
338338
let name_ref = path.as_single_name_ref();
339339
let builtin =
340340
name_ref.as_ref().map(ast::NameRef::text).as_deref().and_then(BuiltinAttr::by_name);

crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ fn shorten_paths(node: &SyntaxNode, path: &ast::Path) {
102102
match child {
103103
// Don't modify `use` items, as this can break the `use` item when injecting a new
104104
// import into the use tree.
105-
ast::Use(_it) => continue,
105+
ast::Use(_) => continue,
106106
// Don't descend into submodules, they don't have the same `use` items in scope.
107107
// FIXME: This isn't true due to `super::*` imports?
108-
ast::Module(_it) => continue,
108+
ast::Module(_) => continue,
109109
ast::Path(p) => if maybe_replace_path(p.clone(), path.clone()).is_none() {
110110
shorten_paths(p.syntax(), path);
111111
},

crates/ide_completion/src/context.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a> CompletionContext<'a> {
517517

518518
(ty, name)
519519
},
520-
ast::ArgList(_it) => {
520+
ast::ArgList(_) => {
521521
cov_mark::hit!(expected_type_fn_param);
522522
ActiveParameter::at_token(
523523
&self.sema,
@@ -608,9 +608,9 @@ impl<'a> CompletionContext<'a> {
608608
.map(|c| (Some(c.return_type()), None))
609609
.unwrap_or((None, None))
610610
},
611-
ast::ParamList(__) => (None, None),
612-
ast::Stmt(__) => (None, None),
613-
ast::Item(__) => (None, None),
611+
ast::ParamList(_) => (None, None),
612+
ast::Stmt(_) => (None, None),
613+
ast::Item(_) => (None, None),
614614
_ => {
615615
match node.parent() {
616616
Some(n) => {
@@ -702,10 +702,10 @@ impl<'a> CompletionContext<'a> {
702702

703703
Some(match_ast! {
704704
match parent {
705-
ast::LifetimeParam(_it) => LifetimeContext::LifetimeParam(sema.find_node_at_offset_with_macros(original_file, offset)),
706-
ast::BreakExpr(_it) => LifetimeContext::LabelRef,
707-
ast::ContinueExpr(_it) => LifetimeContext::LabelRef,
708-
ast::Label(_it) => LifetimeContext::LabelDef,
705+
ast::LifetimeParam(_) => LifetimeContext::LifetimeParam(sema.find_node_at_offset_with_macros(original_file, offset)),
706+
ast::BreakExpr(_) => LifetimeContext::LabelRef,
707+
ast::ContinueExpr(_) => LifetimeContext::LabelRef,
708+
ast::Label(_) => LifetimeContext::LabelDef,
709709
_ => LifetimeContext::Lifetime,
710710
}
711711
})
@@ -753,7 +753,7 @@ impl<'a> CompletionContext<'a> {
753753
path_ctx.kind = path.syntax().ancestors().find_map(|it| {
754754
match_ast! {
755755
match it {
756-
ast::PathType(_it) => Some(PathKind::Type),
756+
ast::PathType(_) => Some(PathKind::Type),
757757
ast::PathExpr(it) => {
758758
path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind()));
759759
Some(PathKind::Expr)
@@ -772,9 +772,9 @@ impl<'a> CompletionContext<'a> {
772772
Some(PathKind::Pat)
773773
},
774774
ast::MacroCall(it) => it.excl_token().and(Some(PathKind::Mac)),
775-
ast::Meta(_it) => Some(PathKind::Attr),
775+
ast::Meta(_) => Some(PathKind::Attr),
776776
ast::Visibility(it) => Some(PathKind::Vis { has_in_token: it.in_token().is_some() }),
777-
ast::UseTree(_it) => Some(PathKind::Use),
777+
ast::UseTree(_) => Some(PathKind::Use),
778778
_ => None,
779779
}
780780
}
@@ -851,9 +851,9 @@ fn pattern_context_for(pat: ast::Pat) -> PatternContext {
851851
});
852852
return (PatternRefutability::Irrefutable, param.ty().is_some())
853853
},
854-
ast::MatchArm(__) => PatternRefutability::Refutable,
855-
ast::Condition(__) => PatternRefutability::Refutable,
856-
ast::ForExpr(__) => PatternRefutability::Irrefutable,
854+
ast::MatchArm(_) => PatternRefutability::Refutable,
855+
ast::Condition(_) => PatternRefutability::Refutable,
856+
ast::ForExpr(_) => PatternRefutability::Irrefutable,
857857
_ => PatternRefutability::Irrefutable,
858858
}
859859
};

crates/ide_completion/src/patterns.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
100100
let res = match_ast! {
101101
match prev_sibling {
102102
// vis followed by random ident will always error the parser
103-
ast::Visibility(_it) => ImmediatePrevSibling::Visibility,
103+
ast::Visibility(_) => ImmediatePrevSibling::Visibility,
104104
_ => return None,
105105
}
106106
};
@@ -112,7 +112,7 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
112112
let node = it.expr().filter(|_| it.semicolon_token().is_none())?.syntax().clone();
113113
match_ast! {
114114
match node {
115-
ast::IfExpr(_it) => ImmediatePrevSibling::IfExpr,
115+
ast::IfExpr(_) => ImmediatePrevSibling::IfExpr,
116116
_ => return None,
117117
}
118118
}
@@ -128,7 +128,7 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
128128
} else {
129129
return None
130130
},
131-
ast::Attr(_it) => ImmediatePrevSibling::Attribute,
131+
ast::Attr(_) => ImmediatePrevSibling::Attribute,
132132
_ => return None,
133133
}
134134
};
@@ -200,31 +200,31 @@ pub(crate) fn determine_location(
200200

201201
let res = match_ast! {
202202
match parent {
203-
ast::IdentPat(_it) => ImmediateLocation::IdentPat,
204-
ast::Rename(_it) => ImmediateLocation::Rename,
205-
ast::StmtList(_it) => ImmediateLocation::StmtList,
206-
ast::SourceFile(_it) => ImmediateLocation::ItemList,
207-
ast::ItemList(_it) => ImmediateLocation::ItemList,
208-
ast::RefExpr(_it) => ImmediateLocation::RefExpr,
209-
ast::Variant(_it) => ImmediateLocation::Variant,
203+
ast::IdentPat(_) => ImmediateLocation::IdentPat,
204+
ast::Rename(_) => ImmediateLocation::Rename,
205+
ast::StmtList(_) => ImmediateLocation::StmtList,
206+
ast::SourceFile(_) => ImmediateLocation::ItemList,
207+
ast::ItemList(_) => ImmediateLocation::ItemList,
208+
ast::RefExpr(_) => ImmediateLocation::RefExpr,
209+
ast::Variant(_) => ImmediateLocation::Variant,
210210
ast::RecordField(it) => if it.ty().map_or(false, |it| it.syntax().text_range().contains(offset)) {
211211
return None;
212212
} else {
213213
ImmediateLocation::RecordField
214214
},
215-
ast::RecordExprFieldList(_it) => sema
215+
ast::RecordExprFieldList(_) => sema
216216
.find_node_at_offset_with_macros(original_file, offset)
217217
.map(ImmediateLocation::RecordExprUpdate)?,
218-
ast::TupleField(_it) => ImmediateLocation::TupleField,
219-
ast::TupleFieldList(_it) => ImmediateLocation::TupleField,
220-
ast::TypeBound(_it) => ImmediateLocation::TypeBound,
221-
ast::TypeBoundList(_it) => ImmediateLocation::TypeBound,
218+
ast::TupleField(_) => ImmediateLocation::TupleField,
219+
ast::TupleFieldList(_) => ImmediateLocation::TupleField,
220+
ast::TypeBound(_) => ImmediateLocation::TypeBound,
221+
ast::TypeBoundList(_) => ImmediateLocation::TypeBound,
222222
ast::AssocItemList(it) => match it.syntax().parent().map(|it| it.kind()) {
223223
Some(IMPL) => ImmediateLocation::Impl,
224224
Some(TRAIT) => ImmediateLocation::Trait,
225225
_ => return None,
226226
},
227-
ast::GenericArgList(_it) => sema
227+
ast::GenericArgList(_) => sema
228228
.find_node_at_offset_with_macros(original_file, offset)
229229
.map(ImmediateLocation::GenericArgList)?,
230230
ast::Module(it) => {

crates/ide_db/src/defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl NameRefClass {
447447
}
448448
}
449449

450-
if let Some(path) = name_ref.syntax().ancestors().find_map(ast::Path::cast) {
450+
if let Some(path) = ast::PathSegment::cast(parent.clone()).map(|it| it.parent_path()) {
451451
if path.qualifier().is_none() {
452452
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
453453
// Only use this to resolve single-segment macro calls like `foo!()`. Multi-segment

crates/ide_db/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ impl ReferenceCategory {
657657

658658
let mode = r.syntax().ancestors().find_map(|node| {
659659
match_ast! {
660-
match (node) {
660+
match node {
661661
ast::BinExpr(expr) => {
662662
if matches!(expr.op_kind()?, ast::BinaryOp::Assignment { .. }) {
663663
// If the variable or field ends on the LHS's end then it's a Write (covers fields and locals).

crates/syntax/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ macro_rules! match_ast {
242242
(match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
243243

244244
(match ($node:expr) {
245-
$( ast::$ast:ident($it:ident) => $res:expr, )*
245+
$( ast::$ast:ident($it:pat) => $res:expr, )*
246246
_ => $catch_all:expr $(,)?
247247
}) => {{
248248
$( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*

crates/syntax/src/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
275275
return Some(tree_path);
276276
}
277277
},
278-
ast::UseTreeList(_it) => continue,
278+
ast::UseTreeList(_) => continue,
279279
ast::Path(parent) => path = parent,
280280
_ => return None,
281281
}

0 commit comments

Comments
 (0)