Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 853ae19

Browse files
committed
Slim down GenericArgs by one usize
1 parent 4c2aef6 commit 853ae19

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,16 @@ fn desugar_future_path(orig: TypeRef) -> Path {
659659
let path = path![core::future::Future];
660660
let mut generic_args: Vec<_> =
661661
std::iter::repeat(None).take(path.segments().len() - 1).collect();
662-
let mut last = GenericArgs::empty();
663662
let binding = AssociatedTypeBinding {
664663
name: name![Output],
665664
args: None,
666665
type_ref: Some(orig),
667666
bounds: Box::default(),
668667
};
669-
last.bindings.push(binding);
670-
generic_args.push(Some(Interned::new(last)));
668+
generic_args.push(Some(Interned::new(GenericArgs {
669+
bindings: Box::new([binding]),
670+
..GenericArgs::empty()
671+
})));
671672

672673
Path::from_known_path(path, generic_args)
673674
}

crates/hir-def/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct GenericArgs {
5757
/// is left out.
5858
pub has_self_type: bool,
5959
/// Associated type bindings like in `Iterator<Item = T>`.
60-
pub bindings: Vec<AssociatedTypeBinding>,
60+
pub bindings: Box<[AssociatedTypeBinding]>,
6161
/// Whether these generic args were desugared from `Trait(Arg) -> Output`
6262
/// parenthesis notation typically used for the `Fn` traits.
6363
pub desugared_from_fn: bool,
@@ -214,7 +214,7 @@ impl GenericArgs {
214214
GenericArgs {
215215
args: Vec::new(),
216216
has_self_type: false,
217-
bindings: Vec::new(),
217+
bindings: Box::default(),
218218
desugared_from_fn: false,
219219
}
220220
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ pub(super) fn lower_generic_args(
208208
if args.is_empty() && bindings.is_empty() {
209209
return None;
210210
}
211-
Some(GenericArgs { args, has_self_type: false, bindings, desugared_from_fn: false })
211+
Some(GenericArgs {
212+
args,
213+
has_self_type: false,
214+
bindings: bindings.into_boxed_slice(),
215+
desugared_from_fn: false,
216+
})
212217
}
213218

214219
/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
@@ -219,7 +224,6 @@ fn lower_generic_args_from_fn_path(
219224
ret_type: Option<ast::RetType>,
220225
) -> Option<GenericArgs> {
221226
let mut args = Vec::new();
222-
let mut bindings = Vec::new();
223227
let params = params?;
224228
let mut param_types = Vec::new();
225229
for param in params.params() {
@@ -228,23 +232,23 @@ fn lower_generic_args_from_fn_path(
228232
}
229233
let arg = GenericArg::Type(TypeRef::Tuple(param_types));
230234
args.push(arg);
231-
if let Some(ret_type) = ret_type {
235+
let bindings = if let Some(ret_type) = ret_type {
232236
let type_ref = TypeRef::from_ast_opt(ctx, ret_type.ty());
233-
bindings.push(AssociatedTypeBinding {
237+
Box::new([AssociatedTypeBinding {
234238
name: name![Output],
235239
args: None,
236240
type_ref: Some(type_ref),
237241
bounds: Box::default(),
238-
});
242+
}])
239243
} else {
240244
// -> ()
241245
let type_ref = TypeRef::Tuple(Vec::new());
242-
bindings.push(AssociatedTypeBinding {
246+
Box::new([AssociatedTypeBinding {
243247
name: name![Output],
244248
args: None,
245249
type_ref: Some(type_ref),
246250
bounds: Box::default(),
247-
});
248-
}
251+
}])
252+
};
249253
Some(GenericArgs { args, has_self_type: false, bindings, desugared_from_fn: true })
250254
}

crates/hir-def/src/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn print_generic_args(generics: &GenericArgs, buf: &mut dyn Write) ->
7171
first = false;
7272
print_generic_arg(arg, buf)?;
7373
}
74-
for binding in &generics.bindings {
74+
for binding in generics.bindings.iter() {
7575
if !first {
7676
write!(buf, ", ")?;
7777
}

crates/hir-def/src/type_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl TypeRef {
301301
| crate::path::GenericArg::Lifetime(_) => {}
302302
}
303303
}
304-
for binding in &args_and_bindings.bindings {
304+
for binding in args_and_bindings.bindings.iter() {
305305
if let Some(type_ref) = &binding.type_ref {
306306
go(type_ref, f);
307307
}

crates/hir-ty/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ impl HirDisplay for Path {
14311431
}
14321432
arg.hir_fmt(f)?;
14331433
}
1434-
for binding in &generic_args.bindings {
1434+
for binding in generic_args.bindings.iter() {
14351435
if first {
14361436
first = false;
14371437
} else {

crates/hir-ty/src/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl<'a> TyLoweringContext<'a> {
10251025
last_segment
10261026
.into_iter()
10271027
.filter_map(|segment| segment.args_and_bindings)
1028-
.flat_map(|args_and_bindings| &args_and_bindings.bindings)
1028+
.flat_map(|args_and_bindings| args_and_bindings.bindings.iter())
10291029
.flat_map(move |binding| {
10301030
let found = associated_type_by_name_including_super_traits(
10311031
self.db,

0 commit comments

Comments
 (0)