Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"compiler/persist_if_changed",
"px_workspace_hack",
]
# Note: pavex_rustdoc_ext is included via "compiler/pavex*" glob
resolver = "3"

[workspace.package]
Expand Down Expand Up @@ -36,6 +37,7 @@ pavexc = { path = "compiler/pavexc", version = "0.2.10" }
pavexc_attr_parser = { path = "compiler/pavexc_attr_parser", version = "0.2.10" }
pavexc_cli_client = { path = "compiler/pavexc_cli_client", version = "0.2.10" }
pavexc_rustdoc_cache = { path = "compiler/pavexc_rustdoc_cache", version = "0.2.10" }
pavexc_annotations = { path = "compiler/pavexc_annotations", version = "0.2.10" }
persist_if_changed = { path = "compiler/persist_if_changed", version = "0.2.10" }
# Our own fork of `rustdoc-types` to minimise (de)ser overhead.
rustdoc-types = { path = "compiler/pavex_rustdoc_types", version = "0.2.10", features = ["rustc-hash"], package = "pavex_rustdoc_types" }
Expand Down
14 changes: 14 additions & 0 deletions compiler/pavex_rustdoc_ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "pavex_rustdoc_ext"
description = "Extension traits for pavex_rustdoc_types"
edition.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
version.workspace = true
keywords = ["pavex"]

[dependencies]
rustdoc-types = { workspace = true }

px_workspace_hack = { version = "0.1", path = "../../px_workspace_hack" }
124 changes: 124 additions & 0 deletions compiler/pavex_rustdoc_ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! Extension traits for types in `pavex_rustdoc_types`.
//!
//! This crate provides utility traits that augment the types from our fork of `rustdoc-types`.
//! We keep these extensions separate to maintain `pavex_rustdoc_types` as close to upstream
//! as possible.

use rustdoc_types::{ItemEnum, ItemKind, MacroKind};

/// Extension trait for `ItemEnum` to get the corresponding `ItemKind`.
pub trait ItemEnumExt {
/// Returns the `ItemKind` corresponding to this `ItemEnum` variant.
fn item_kind(&self) -> ItemKind;
}

impl ItemEnumExt for ItemEnum {
fn item_kind(&self) -> ItemKind {
match self {
ItemEnum::Module(_) => ItemKind::Module,
ItemEnum::ExternCrate { .. } => ItemKind::ExternCrate,
ItemEnum::Use(_) => ItemKind::Use,
ItemEnum::Union(_) => ItemKind::Union,
ItemEnum::Struct(_) => ItemKind::Struct,
ItemEnum::StructField(_) => ItemKind::StructField,
ItemEnum::Enum(_) => ItemKind::Enum,
ItemEnum::Variant(_) => ItemKind::Variant,
ItemEnum::Function(_) => ItemKind::Function,
ItemEnum::Trait(_) => ItemKind::Trait,
ItemEnum::TraitAlias(_) => ItemKind::TraitAlias,
ItemEnum::Impl(_) => ItemKind::Impl,
ItemEnum::TypeAlias(_) => ItemKind::TypeAlias,
ItemEnum::Constant { .. } => ItemKind::Constant,
ItemEnum::Static(_) => ItemKind::Static,
ItemEnum::ExternType => ItemKind::ExternType,
ItemEnum::Macro(_) => ItemKind::Macro,
ItemEnum::ProcMacro(pm) => match pm.kind {
MacroKind::Bang => ItemKind::Macro,
MacroKind::Attr => ItemKind::ProcAttribute,
MacroKind::Derive => ItemKind::ProcDerive,
},
ItemEnum::Primitive(_) => ItemKind::Primitive,
ItemEnum::AssocConst { .. } => ItemKind::AssocConst,
ItemEnum::AssocType { .. } => ItemKind::AssocType,
}
}
}

/// Extension trait for `ItemEnum` to get a human-readable description of the item kind.
pub trait RustdocKindExt {
/// Return a human-readable string description of this item's kind (e.g. "a function").
fn kind(&self) -> &'static str;
}

impl RustdocKindExt for ItemEnum {
fn kind(&self) -> &'static str {
match self {
ItemEnum::Module(_) => "a module",
ItemEnum::ExternCrate { .. } => "an external crate",
ItemEnum::Use(_) => "an import",
ItemEnum::Union(_) => "a union",
ItemEnum::Struct(_) => "a struct",
ItemEnum::StructField(_) => "a struct field",
ItemEnum::Enum(_) => "an enum",
ItemEnum::Variant(_) => "an enum variant",
ItemEnum::Function(func) => {
if let Some((param, _)) = func.sig.inputs.first()
&& param == "self"
{
"a method"
} else {
"a function"
}
}
ItemEnum::Trait(_) => "a trait",
ItemEnum::TraitAlias(_) => "a trait alias",
ItemEnum::Impl(_) => "an impl block",
ItemEnum::TypeAlias(_) => "a type alias",
ItemEnum::Constant { .. } => "a constant",
ItemEnum::Static(_) => "a static",
ItemEnum::ExternType => "a foreign type",
ItemEnum::Macro(_) => "a macro",
ItemEnum::ProcMacro(_) => "a procedural macro",
ItemEnum::Primitive(_) => "a primitive type",
ItemEnum::AssocConst { .. } => "an associated constant",
ItemEnum::AssocType { .. } => "an associated type",
}
}
}

/// Extension trait for `ItemKind` to get human-readable descriptions.
pub trait ItemKindExt {
/// Return the plural form of this item kind (e.g. "functions", "structs").
fn plural(&self) -> &'static str;
}

impl ItemKindExt for ItemKind {
fn plural(&self) -> &'static str {
match self {
ItemKind::Module => "modules",
ItemKind::ExternCrate => "extern crate declarations",
ItemKind::Use => "use declarations",
ItemKind::Struct => "structs",
ItemKind::StructField => "struct fields",
ItemKind::Union => "unions",
ItemKind::Enum => "enums",
ItemKind::Variant => "enum variants",
ItemKind::Function => "functions",
ItemKind::TypeAlias => "type aliases",
ItemKind::Constant => "constants",
ItemKind::Trait => "traits",
ItemKind::TraitAlias => "trait aliases",
ItemKind::Impl => "impl blocks",
ItemKind::Static => "statics",
ItemKind::ExternType => "extern types",
ItemKind::Macro => "macros",
ItemKind::ProcAttribute => "proc macro attributes",
ItemKind::ProcDerive => "derive macros",
ItemKind::AssocConst => "associated constants",
ItemKind::AssocType => "associated types",
ItemKind::Primitive => "primitive types",
ItemKind::Keyword => "keywords",
ItemKind::Attribute => "attributes",
}
}
}
2 changes: 2 additions & 0 deletions compiler/pavexc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ debug_assertions = []

[dependencies]
pavex = { workspace = true }
pavex_rustdoc_ext = { path = "../pavex_rustdoc_ext", version = "=0.2.10" }
pavexc_annotations = { path = "../pavexc_annotations", version = "=0.2.10" }
pavexc_attr_parser = { path = "../pavexc_attr_parser", version = "=0.2.10" }
pavexc_rustdoc_cache = { path = "../pavexc_rustdoc_cache", version = "=0.2.10" }
pavex_bp_schema = { path = "../pavex_bp_schema", version = "=0.2.10" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ use crate::{
ResolvedType,
},
rustdoc::{
AnnotationCoordinates, Crate, CrateCollection, ExternalReExportsExt, GlobalItemId,
ImplInfo, RustdocKindExt,
AnnotationCoordinates, Crate, CrateCollection, ExternalReExportsExt, GlobalItemId, ImplInfo,
},
};
use pavex_rustdoc_ext::RustdocKindExt;
use pavex_bp_schema::{CloningPolicy, Lifecycle, Lint, LintSetting};
use pavexc_attr_parser::{AnnotationKind, AnnotationProperties};
use rustdoc_types::{GenericArgs, Item, ItemEnum};
Expand Down
4 changes: 2 additions & 2 deletions compiler/pavexc/src/compiler/resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::language::{
GenericArgument, GenericLifetimeParameter, InvocationStyle, PathType, ResolvedPathLifetime,
ResolvedType, Slice, Tuple, TypeReference, UnknownPath, UnknownPrimitive,
};
use crate::rustdoc::{CannotGetCrateData, RustdocKindExt};
use crate::rustdoc::{CrateCollection, ResolvedItem};
use crate::rustdoc::{CannotGetCrateData, CrateCollection, ResolvedItem};
use pavex_rustdoc_ext::RustdocKindExt;

#[derive(Default)]
pub(crate) struct GenericBindings {
Expand Down
5 changes: 2 additions & 3 deletions compiler/pavexc/src/language/fq_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use crate::language::callable_path::{CallPathGenericArgument, CallPathLifetime,
use crate::language::krate_name::dependency_name2package_id;
use crate::language::resolved_type::{GenericArgument, Lifetime, ScalarPrimitive, Slice};
use crate::language::{CallPath, InvalidCallPath, ResolvedType, Tuple, TypeReference};
use crate::rustdoc::{
CannotGetCrateData, CrateCollection, GlobalItemId, ResolvedItem, RustdocKindExt,
};
use crate::rustdoc::{CannotGetCrateData, CrateCollection, GlobalItemId, ResolvedItem};
use pavex_rustdoc_ext::RustdocKindExt;

use super::krate_name::CrateNameResolutionError;
use super::krate2package_id;
Expand Down
Loading
Loading