Skip to content

Commit ba39290

Browse files
chore: Formatting
1 parent d78e40a commit ba39290

File tree

5 files changed

+107
-54
lines changed

5 files changed

+107
-54
lines changed

compiler/pavexc/src/compiler/analyses/user_components/annotations/coordinates.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,21 @@ pub(crate) fn resolve_annotation_coordinates(
211211
}
212212

213213
let outcome = match annotation.impl_ {
214-
Some(ImplInfo { attached_to, impl_ }) => {
215-
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
216-
}
217-
None => resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
218-
.map(rustdoc_ir::Callable::FreeFunction),
214+
Some(ImplInfo { attached_to, impl_ }) => rustdoc_method2callable(
215+
attached_to,
216+
impl_,
217+
&item,
218+
krate,
219+
krate_collection,
220+
TypeAliasResolution::ResolveThrough,
221+
),
222+
None => resolve_free_function(
223+
&item,
224+
krate,
225+
krate_collection,
226+
TypeAliasResolution::ResolveThrough,
227+
)
228+
.map(rustdoc_ir::Callable::FreeFunction),
219229
};
220230
let callable = match outcome {
221231
Ok(callable) => callable,

compiler/pavexc/src/compiler/analyses/user_components/annotations/mod.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use pavex_bp_schema::{CloningPolicy, Lifecycle, Lint, LintSetting};
3333
use pavexc_attr_parser::{AnnotationKind, AnnotationProperties};
3434
use rustdoc_ext::RustdocKindExt;
3535
use rustdoc_resolver::{
36-
TypeAliasResolution, resolve_free_function, rustdoc_method2callable,
37-
rustdoc_new_type_def2type, rustdoc_type_alias2type,
36+
TypeAliasResolution, resolve_free_function, rustdoc_method2callable, rustdoc_new_type_def2type,
37+
rustdoc_type_alias2type,
3838
};
3939
use rustdoc_types::{Item, ItemEnum};
4040

@@ -178,11 +178,21 @@ pub(super) fn register_imported_components(
178178
}
179179

180180
let outcome = match annotation.impl_ {
181-
Some(ImplInfo { attached_to, impl_ }) => {
182-
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
183-
}
184-
None => resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
185-
.map(rustdoc_ir::Callable::FreeFunction),
181+
Some(ImplInfo { attached_to, impl_ }) => rustdoc_method2callable(
182+
attached_to,
183+
impl_,
184+
&item,
185+
krate,
186+
krate_collection,
187+
TypeAliasResolution::ResolveThrough,
188+
),
189+
None => resolve_free_function(
190+
&item,
191+
krate,
192+
krate_collection,
193+
TypeAliasResolution::ResolveThrough,
194+
)
195+
.map(rustdoc_ir::Callable::FreeFunction),
186196
};
187197
let callable = match outcome {
188198
Ok(callable) => callable,
@@ -521,7 +531,12 @@ fn rustdoc_item_def2type(
521531
Err(())
522532
}
523533
},
524-
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(item, krate, krate_collection, TypeAliasResolution::ResolveThrough) {
534+
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(
535+
item,
536+
krate,
537+
krate_collection,
538+
TypeAliasResolution::ResolveThrough,
539+
) {
525540
Ok(t) => Ok(t),
526541
Err(e) => {
527542
type_resolution_error(e, item, diagnostics);

compiler/pavexc/src/compiler/framework_rustdoc.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,13 @@ pub(crate) fn resolve_framework_free_function(
199199
.unwrap_or_else(|e| panic!("Unknown free function path {}: {e:?}", segments.join("::")));
200200

201201
let item = krate.get_item_by_local_type_id(&global_id.rustdoc_item_id);
202-
let free_fn = rustdoc_resolver::resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
203-
.expect("Failed to resolve free function");
202+
let free_fn = rustdoc_resolver::resolve_free_function(
203+
&item,
204+
krate,
205+
krate_collection,
206+
TypeAliasResolution::ResolveThrough,
207+
)
208+
.expect("Failed to resolve free function");
204209
Callable::FreeFunction(free_fn)
205210
}
206211

rustdoc/rustdoc_ir/src/type_.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ impl Type {
7979
base_type: t.base_type.clone(),
8080
generic_arguments: bound_generics,
8181
};
82-
if is_alias { Type::TypeAlias(path) } else { Type::Path(path) }
82+
if is_alias {
83+
Type::TypeAlias(path)
84+
} else {
85+
Type::Path(path)
86+
}
8387
}
8488
Type::Reference(r) => Type::Reference(TypeReference {
8589
is_mutable: r.is_mutable,
@@ -133,14 +137,16 @@ impl Type {
133137
/// Check if a type can be used as a "template"—i.e. if it has any unassigned generic parameters.
134138
pub fn is_a_template(&self) -> bool {
135139
match self {
136-
Type::Path(path) | Type::TypeAlias(path) => path.generic_arguments.iter().any(|arg| match arg {
137-
GenericArgument::TypeParameter(g) => g.is_a_template(),
138-
GenericArgument::Lifetime(
139-
GenericLifetimeParameter::Static
140-
| GenericLifetimeParameter::Named(_)
141-
| GenericLifetimeParameter::Inferred,
142-
) => false,
143-
}),
140+
Type::Path(path) | Type::TypeAlias(path) => {
141+
path.generic_arguments.iter().any(|arg| match arg {
142+
GenericArgument::TypeParameter(g) => g.is_a_template(),
143+
GenericArgument::Lifetime(
144+
GenericLifetimeParameter::Static
145+
| GenericLifetimeParameter::Named(_)
146+
| GenericLifetimeParameter::Inferred,
147+
) => false,
148+
})
149+
}
144150
Type::Reference(r) => r.inner.is_a_template(),
145151
Type::Tuple(t) => t.elements.iter().any(|t| t.is_a_template()),
146152
Type::ScalarPrimitive(_) => false,
@@ -334,8 +340,7 @@ impl Type {
334340
) -> bool {
335341
use Type::*;
336342
match (self, other) {
337-
(Path(self_path), Path(other_path))
338-
| (TypeAlias(self_path), TypeAlias(other_path)) => {
343+
(Path(self_path), Path(other_path)) | (TypeAlias(self_path), TypeAlias(other_path)) => {
339344
self_path._is_equivalent_to(other_path, self_id_gen, other_id_gen)
340345
}
341346
(Slice(self_slice), Slice(other_slice)) => self_slice.element_type._is_equivalent_to(
@@ -408,13 +413,15 @@ impl Type {
408413
/// E.g. `&'_ str` and `&str` would both return `true`. `&'static str` or `&'a str` wouldn't.
409414
pub fn has_implicit_lifetime_parameters(&self) -> bool {
410415
match self {
411-
Type::Path(path) | Type::TypeAlias(path) => path.generic_arguments.iter().any(|arg| match arg {
412-
GenericArgument::TypeParameter(g) => g.has_implicit_lifetime_parameters(),
413-
GenericArgument::Lifetime(GenericLifetimeParameter::Inferred) => true,
414-
GenericArgument::Lifetime(
415-
GenericLifetimeParameter::Named(_) | GenericLifetimeParameter::Static,
416-
) => false,
417-
}),
416+
Type::Path(path) | Type::TypeAlias(path) => {
417+
path.generic_arguments.iter().any(|arg| match arg {
418+
GenericArgument::TypeParameter(g) => g.has_implicit_lifetime_parameters(),
419+
GenericArgument::Lifetime(GenericLifetimeParameter::Inferred) => true,
420+
GenericArgument::Lifetime(
421+
GenericLifetimeParameter::Named(_) | GenericLifetimeParameter::Static,
422+
) => false,
423+
})
424+
}
418425
Type::Reference(r) => {
419426
match &r.lifetime {
420427
Lifetime::Inferred => {
@@ -754,7 +761,11 @@ impl Type {
754761
base_type: t.base_type.clone(),
755762
generic_arguments,
756763
};
757-
if is_alias { Type::TypeAlias(path) } else { Type::Path(path) }
764+
if is_alias {
765+
Type::TypeAlias(path)
766+
} else {
767+
Type::Path(path)
768+
}
758769
}
759770
Type::Reference(r) => Type::Reference(TypeReference {
760771
is_mutable: r.is_mutable,

rustdoc/rustdoc_resolver/src/resolve_type.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub enum TypeAliasResolution {
2525
Preserve,
2626
}
2727

28-
2928
/// Convert a `rustdoc_types::Type` into a `rustdoc_ir::Type`, recursively resolving
3029
/// through type aliases and substituting generic bindings.
3130
pub fn resolve_type<I: CrateIndexer>(
@@ -183,7 +182,8 @@ fn _resolve_type<I: CrateIndexer>(
183182
alias_generic_bindings
184183
.types
185184
.insert(generic_param_def.name.to_string(), generic_type.clone());
186-
resolved_alias_generics.push(GenericArgument::TypeParameter(generic_type));
185+
resolved_alias_generics
186+
.push(GenericArgument::TypeParameter(generic_type));
187187
}
188188
GenericParamDefKind::Lifetime { .. } => {
189189
let provided_arg = generic_args.and_then(|v| v.get(i));
@@ -517,15 +517,21 @@ fn _resolve_type<I: CrateIndexer>(
517517
.iter()
518518
.enumerate()
519519
.map(|(i, (_, ty))| {
520-
resolve_type(ty, used_by_package_id, krate_collection, generic_bindings, alias_resolution)
521-
.map_err(|source| {
522-
TypeResolutionErrorDetails::TypePartResolutionError(Box::new(
523-
TypePartResolutionError {
524-
role: format!("function pointer input {}", i),
525-
source,
526-
},
527-
))
528-
})
520+
resolve_type(
521+
ty,
522+
used_by_package_id,
523+
krate_collection,
524+
generic_bindings,
525+
alias_resolution,
526+
)
527+
.map_err(|source| {
528+
TypeResolutionErrorDetails::TypePartResolutionError(Box::new(
529+
TypePartResolutionError {
530+
role: format!("function pointer input {}", i),
531+
source,
532+
},
533+
))
534+
})
529535
})
530536
.collect::<Result<Vec<_>, _>>()?;
531537

@@ -534,15 +540,21 @@ fn _resolve_type<I: CrateIndexer>(
534540
.output
535541
.as_ref()
536542
.map(|ty| {
537-
resolve_type(ty, used_by_package_id, krate_collection, generic_bindings, alias_resolution)
538-
.map_err(|source| {
539-
TypeResolutionErrorDetails::TypePartResolutionError(Box::new(
540-
TypePartResolutionError {
541-
role: "function pointer output".into(),
542-
source,
543-
},
544-
))
545-
})
543+
resolve_type(
544+
ty,
545+
used_by_package_id,
546+
krate_collection,
547+
generic_bindings,
548+
alias_resolution,
549+
)
550+
.map_err(|source| {
551+
TypeResolutionErrorDetails::TypePartResolutionError(Box::new(
552+
TypePartResolutionError {
553+
role: "function pointer output".into(),
554+
source,
555+
},
556+
))
557+
})
546558
})
547559
.transpose()?;
548560

0 commit comments

Comments
 (0)