Skip to content

Commit 5d9145c

Browse files
bors[bot]matklad
andauthored
Merge #5629
5629: Finalize Path grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 0392a89 + c1c97b2 commit 5d9145c

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

+789
-727
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,25 @@ impl<'a> SubstituteTypeParams<'a> {
7979
};
8080

8181
// FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
82-
// trait ref, and then go from the types in the substs back to the syntax)
82+
// trait ref, and then go from the types in the substs back to the syntax).
8383
fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::Type>> {
8484
let target_trait = impl_def.target_trait()?;
8585
let path_type = match target_trait {
8686
ast::Type::PathType(path) => path,
8787
_ => return None,
8888
};
89-
let type_arg_list = path_type.path()?.segment()?.type_arg_list()?;
89+
let generic_arg_list = path_type.path()?.segment()?.generic_arg_list()?;
90+
9091
let mut result = Vec::new();
91-
for type_arg in type_arg_list.type_args() {
92-
let type_arg: ast::TypeArg = type_arg;
93-
result.push(type_arg.ty()?);
92+
for generic_arg in generic_arg_list.generic_args() {
93+
match generic_arg {
94+
ast::GenericArg::TypeArg(type_arg) => result.push(type_arg.ty()?),
95+
ast::GenericArg::AssocTypeArg(_)
96+
| ast::GenericArg::LifetimeArg(_)
97+
| ast::GenericArg::ConstArg(_) => (),
98+
}
9499
}
100+
95101
Some(result)
96102
}
97103
}
@@ -157,7 +163,7 @@ impl<'a> QualifyPaths<'a> {
157163

158164
let type_args = p
159165
.segment()
160-
.and_then(|s| s.type_arg_list())
166+
.and_then(|s| s.generic_arg_list())
161167
.map(|arg_list| apply(self, arg_list));
162168
if let Some(type_args) = type_args {
163169
let last_segment = path.segment().unwrap();

crates/ra_hir_def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl ExprCollector<'_> {
337337
};
338338
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
339339
let generic_args =
340-
e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it));
340+
e.generic_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx(), it));
341341
self.alloc_expr(
342342
Expr::MethodCall { receiver, method_name, args, generic_args },
343343
syntax_ptr,

crates/ra_hir_def/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a> PathSegments<'a> {
258258
}
259259

260260
impl GenericArgs {
261-
pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::TypeArgList) -> Option<GenericArgs> {
261+
pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::GenericArgList) -> Option<GenericArgs> {
262262
lower::lower_generic_args(lower_ctx, node)
263263
}
264264

crates/ra_hir_def/src/path/lower.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
4141
match hygiene.name_ref_to_name(name_ref) {
4242
Either::Left(name) => {
4343
let args = segment
44-
.type_arg_list()
44+
.generic_arg_list()
4545
.and_then(|it| lower_generic_args(&ctx, it))
4646
.or_else(|| {
4747
lower_generic_args_from_fn_path(
@@ -148,33 +148,37 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
148148

149149
pub(super) fn lower_generic_args(
150150
lower_ctx: &LowerCtx,
151-
node: ast::TypeArgList,
151+
node: ast::GenericArgList,
152152
) -> Option<GenericArgs> {
153153
let mut args = Vec::new();
154-
for type_arg in node.type_args() {
155-
let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty());
156-
args.push(GenericArg::Type(type_ref));
157-
}
158-
// lifetimes ignored for now
159154
let mut bindings = Vec::new();
160-
for assoc_type_arg in node.assoc_type_args() {
161-
let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg;
162-
if let Some(name_ref) = assoc_type_arg.name_ref() {
163-
let name = name_ref.as_name();
164-
let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it));
165-
let bounds = if let Some(l) = assoc_type_arg.type_bound_list() {
166-
l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect()
167-
} else {
168-
Vec::new()
169-
};
170-
bindings.push(AssociatedTypeBinding { name, type_ref, bounds });
155+
for generic_arg in node.generic_args() {
156+
match generic_arg {
157+
ast::GenericArg::TypeArg(type_arg) => {
158+
let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty());
159+
args.push(GenericArg::Type(type_ref));
160+
}
161+
ast::GenericArg::AssocTypeArg(assoc_type_arg) => {
162+
if let Some(name_ref) = assoc_type_arg.name_ref() {
163+
let name = name_ref.as_name();
164+
let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it));
165+
let bounds = if let Some(l) = assoc_type_arg.type_bound_list() {
166+
l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect()
167+
} else {
168+
Vec::new()
169+
};
170+
bindings.push(AssociatedTypeBinding { name, type_ref, bounds });
171+
}
172+
}
173+
// Lifetimes and constants are ignored for now.
174+
ast::GenericArg::LifetimeArg(_) | ast::GenericArg::ConstArg(_) => (),
171175
}
172176
}
177+
173178
if args.is_empty() && bindings.is_empty() {
174-
None
175-
} else {
176-
Some(GenericArgs { args, has_self_type: false, bindings })
179+
return None;
177180
}
181+
Some(GenericArgs { args, has_self_type: false, bindings })
178182
}
179183

180184
/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a> CompletionContext<'a> {
377377
path.syntax().parent().and_then(ast::TupleStructPat::cast).is_some();
378378

379379
self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
380-
self.has_type_args = segment.type_arg_list().is_some();
380+
self.has_type_args = segment.generic_arg_list().is_some();
381381

382382
#[allow(deprecated)]
383383
if let Some(path) = hir::Path::from_ast(path.clone()) {

crates/ra_ide/src/extend_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn try_extend_selection(
4545
VARIANT_LIST,
4646
USE_TREE_LIST,
4747
GENERIC_PARAM_LIST,
48-
TYPE_ARG_LIST,
48+
GENERIC_ARG_LIST,
4949
TYPE_BOUND_LIST,
5050
PARAM_LIST,
5151
ARG_LIST,

crates/ra_parser/src/grammar/type_args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
2222
}
2323
}
2424
p.expect(T![>]);
25-
m.complete(p, TYPE_ARG_LIST);
25+
m.complete(p, GENERIC_ARG_LIST);
2626
}
2727

2828
// test type_arg
@@ -52,7 +52,7 @@ fn type_arg(p: &mut Parser) {
5252
m.complete(p, CONST_ARG);
5353
}
5454
k if k.is_literal() => {
55-
p.bump(k);
55+
expressions::literal(p);
5656
m.complete(p, CONST_ARG);
5757
}
5858
_ => {

crates/ra_parser/src/syntax_kind/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub enum SyntaxKind {
235235
LIFETIME_PARAM,
236236
TYPE_PARAM,
237237
CONST_PARAM,
238-
TYPE_ARG_LIST,
238+
GENERIC_ARG_LIST,
239239
LIFETIME_ARG,
240240
TYPE_ARG,
241241
ASSOC_TYPE_ARG,

crates/ra_ssr/src/matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
348348
// separately via comparing what the path resolves to below.
349349
self.attempt_match_opt(
350350
phase,
351-
pattern_segment.type_arg_list(),
352-
code_segment.type_arg_list(),
351+
pattern_segment.generic_arg_list(),
352+
code_segment.generic_arg_list(),
353353
)?;
354354
self.attempt_match_opt(
355355
phase,

crates/ra_ssr/src/resolving.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn pick_node_for_resolution(node: SyntaxNode) -> SyntaxNode {
217217
fn path_contains_type_arguments(path: Option<ast::Path>) -> bool {
218218
if let Some(path) = path {
219219
if let Some(segment) = path.segment() {
220-
if segment.type_arg_list().is_some() {
220+
if segment.generic_arg_list().is_some() {
221221
mark::hit!(type_arguments_within_path);
222222
return true;
223223
}

0 commit comments

Comments
 (0)