Skip to content

Commit 760a665

Browse files
committed
lowering of generic args in AssocTyConstraint
1 parent 16af7bf commit 760a665

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,16 +1076,40 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10761076
fn lower_assoc_ty_constraint(
10771077
&mut self,
10781078
constraint: &AssocTyConstraint,
1079-
itctx: ImplTraitContext<'_, 'hir>,
1079+
mut itctx: ImplTraitContext<'_, 'hir>,
10801080
) -> hir::TypeBinding<'hir> {
10811081
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
10821082

1083-
if let Some(ref gen_args) = constraint.gen_args {
1084-
self.sess.span_fatal(
1085-
gen_args.span(),
1086-
"generic associated types in trait paths are currently not implemented",
1087-
);
1088-
}
1083+
// lower generic arguments of identifier in constraint
1084+
let gen_args = if let Some(ref gen_args) = constraint.gen_args {
1085+
let gen_args_ctor = match gen_args {
1086+
GenericArgs::AngleBracketed(ref data) => {
1087+
self.lower_angle_bracketed_parameter_data(
1088+
data,
1089+
ParamMode::Explicit,
1090+
itctx.reborrow(),
1091+
)
1092+
.0
1093+
}
1094+
GenericArgs::Parenthesized(ref data) => {
1095+
let mut err = self.sess.struct_span_err(
1096+
gen_args.span(),
1097+
"parenthesized generic arguments cannot be used in associated type constraints"
1098+
);
1099+
// FIXME: try to write a suggestion here
1100+
err.emit();
1101+
self.lower_angle_bracketed_parameter_data(
1102+
&data.as_angle_bracketed_args(),
1103+
ParamMode::Explicit,
1104+
itctx.reborrow(),
1105+
)
1106+
.0
1107+
}
1108+
};
1109+
self.arena.alloc(gen_args_ctor.into_generic_args(&self.arena))
1110+
} else {
1111+
self.arena.alloc(hir::GenericArgs::none())
1112+
};
10891113

10901114
let kind = match constraint.kind {
10911115
AssocTyConstraintKind::Equality { ref ty } => {
@@ -1182,6 +1206,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11821206
hir::TypeBinding {
11831207
hir_id: self.lower_node_id(constraint.id),
11841208
ident: constraint.ident,
1209+
gen_args,
11851210
kind,
11861211
span: constraint.span,
11871212
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
362362
}
363363
}
364364

365-
fn lower_angle_bracketed_parameter_data(
365+
pub(crate) fn lower_angle_bracketed_parameter_data(
366366
&mut self,
367367
data: &AngleBracketedArgs,
368368
param_mode: ParamMode,
@@ -426,6 +426,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
426426
) -> hir::TypeBinding<'hir> {
427427
let ident = Ident::with_dummy_span(hir::FN_OUTPUT_NAME);
428428
let kind = hir::TypeBindingKind::Equality { ty };
429-
hir::TypeBinding { hir_id: self.next_id(), span, ident, kind }
429+
let args = arena_vec![self;];
430+
let bindings = arena_vec![self;];
431+
let gen_args = self.arena.alloc(hir::GenericArgs { args, bindings, parenthesized: false });
432+
hir::TypeBinding { hir_id: self.next_id(), gen_args, span, ident, kind }
430433
}
431434
}

0 commit comments

Comments
 (0)