Skip to content

Commit 4cfb1c3

Browse files
Rollup merge of #128667 - its-the-shrimp:rustdoc_json_types_rename, r=aDotInTheVoid
rustdoc: normalise type/field names Updates #100961 - `Import` -> `Use`, to better reflect the terminology of Rust & its syntax - `TypeBinding` -> `AssocItemConstraint`, to sync up with `clean` - `FnDecl` -> `FunctionSignature`, because that's what it is - `Header` -> `FunctionHeader`, because `Header` is a very word that's very heavily loaded with different meanings - `ItemEnum::AssocType`: `default` -> `type`, because those items appear in `impl` blocks as well, where they're _not_ the "default" - `ItemEnum::AssocConst`: `default` -> `value`, see the previous point - `ForeignType` -> `ExternType`, because "foreign" is not the right word there - boolean fields' names made to consistently be a phrase that can be a yes/no answer, e.g. `async` -> `is_async` The docs of `ItemEnum::AssocType::type_` & of `ItemEnum::AssocConst::value` are also updated to be up to date with the clarification of the name of the fields
2 parents 2cce01e + f2696ab commit 4cfb1c3

74 files changed

Lines changed: 382 additions & 375 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/librustdoc/json/conversions.rs‎

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
156156
match args {
157157
AngleBracketed{ args, constraints } => GenericArgs::AngleBracketed{
158158
args: args.into_vec().into_tcx(tcx),
159-
bindings: constraints.into_tcx(tcx),
159+
constraints: constraints.into_tcx(tcx),
160160
},
161161
Parenthesized{ inputs, output } => GenericArgs::Parenthesized{
162162
inputs: inputs.into_vec().into_tcx(tcx),
@@ -198,22 +198,22 @@ impl FromWithTcx<clean::ConstantKind> for Constant {
198198
}
199199
}
200200

201-
implFromWithTcx<clean::AssocItemConstraint>forTypeBinding{
201+
implFromWithTcx<clean::AssocItemConstraint>forAssocItemConstraint{
202202
fnfrom_tcx(constraint: clean::AssocItemConstraint,tcx:TyCtxt<'_>) -> Self{
203-
TypeBinding{
203+
AssocItemConstraint{
204204
name: constraint.assoc.name.to_string(),
205205
args: constraint.assoc.args.into_tcx(tcx),
206206
binding: constraint.kind.into_tcx(tcx),
207207
}
208208
}
209209
}
210210

211-
implFromWithTcx<clean::AssocItemConstraintKind>forTypeBindingKind{
211+
implFromWithTcx<clean::AssocItemConstraintKind>forAssocItemConstraintKind{
212212
fnfrom_tcx(kind: clean::AssocItemConstraintKind,tcx:TyCtxt<'_>) -> Self{
213213
use clean::AssocItemConstraintKind::*;
214214
match kind {
215-
Equality{ term } => TypeBindingKind::Equality(term.into_tcx(tcx)),
216-
Bound{ bounds } => TypeBindingKind::Constraint(bounds.into_tcx(tcx)),
215+
Equality{ term } => AssocItemConstraintKind::Equality(term.into_tcx(tcx)),
216+
Bound{ bounds } => AssocItemConstraintKind::Constraint(bounds.into_tcx(tcx)),
217217
}
218218
}
219219
}
@@ -314,7 +314,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
314314
ModuleItem(m) => {
315315
ItemEnum::Module(Module{ is_crate,items:ids(m.items, tcx),is_stripped:false})
316316
}
317-
ImportItem(i) => ItemEnum::Import(i.into_tcx(tcx)),
317+
ImportItem(i) => ItemEnum::Use(i.into_tcx(tcx)),
318318
StructItem(s) => ItemEnum::Struct(s.into_tcx(tcx)),
319319
UnionItem(u) => ItemEnum::Union(u.into_tcx(tcx)),
320320
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
@@ -331,7 +331,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
331331
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
332332
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
333333
ForeignStaticItem(s, _) => ItemEnum::Static(s.into_tcx(tcx)),
334-
ForeignTypeItem => ItemEnum::ForeignType,
334+
ForeignTypeItem => ItemEnum::ExternType,
335335
TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_tcx(tcx)),
336336
// FIXME(generic_const_items): Add support for generic free consts
337337
ConstantItem(ci) => {
@@ -347,21 +347,19 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
347347
}
348348
// FIXME(generic_const_items): Add support for generic associated consts.
349349
TyAssocConstItem(_generics, ty) => {
350-
ItemEnum::AssocConst{type_:(*ty).into_tcx(tcx),default:None}
350+
ItemEnum::AssocConst{type_:(*ty).into_tcx(tcx),value:None}
351351
}
352352
// FIXME(generic_const_items): Add support for generic associated consts.
353353
AssocConstItem(ci) => {
354-
ItemEnum::AssocConst{type_: ci.type_.into_tcx(tcx),default:Some(ci.kind.expr(tcx))}
354+
ItemEnum::AssocConst{type_: ci.type_.into_tcx(tcx),value:Some(ci.kind.expr(tcx))}
355+
}
356+
TyAssocTypeItem(g, b) => {
357+
ItemEnum::AssocType{generics: g.into_tcx(tcx),bounds: b.into_tcx(tcx),type_:None}
355358
}
356-
TyAssocTypeItem(g, b) => ItemEnum::AssocType{
357-
generics: g.into_tcx(tcx),
358-
bounds: b.into_tcx(tcx),
359-
default:None,
360-
},
361359
AssocTypeItem(t, b) => ItemEnum::AssocType{
362360
generics: t.generics.into_tcx(tcx),
363361
bounds: b.into_tcx(tcx),
364-
default:Some(t.item_type.unwrap_or(t.type_).into_tcx(tcx)),
362+
type_:Some(t.item_type.unwrap_or(t.type_).into_tcx(tcx)),
365363
},
366364
// `convert_item` early returns `None` for stripped items and keywords.
367365
KeywordItem => unreachable!(),
@@ -385,7 +383,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
385383

386384
implFromWithTcx<clean::Struct>forStruct{
387385
fnfrom_tcx(struct_: clean::Struct,tcx:TyCtxt<'_>) -> Self{
388-
letfields_stripped = struct_.has_stripped_entries();
386+
lethas_stripped_fields = struct_.has_stripped_entries();
389387
let clean::Struct{ ctor_kind, generics, fields } = struct_;
390388

391389
let kind = match ctor_kind {
@@ -394,7 +392,7 @@ impl FromWithTcx<clean::Struct> for Struct {
394392
assert!(fields.is_empty());
395393
StructKind::Unit
396394
}
397-
None => StructKind::Plain{fields:ids(fields, tcx),fields_stripped},
395+
None => StructKind::Plain{fields:ids(fields, tcx),has_stripped_fields},
398396
};
399397

400398
Struct{
@@ -407,22 +405,22 @@ impl FromWithTcx<clean::Struct> for Struct {
407405

408406
implFromWithTcx<clean::Union>forUnion{
409407
fnfrom_tcx(union_: clean::Union,tcx:TyCtxt<'_>) -> Self{
410-
letfields_stripped = union_.has_stripped_entries();
408+
lethas_stripped_fields = union_.has_stripped_entries();
411409
let clean::Union{ generics, fields } = union_;
412410
Union{
413411
generics: generics.into_tcx(tcx),
414-
fields_stripped,
412+
has_stripped_fields,
415413
fields:ids(fields, tcx),
416414
impls:Vec::new(),// Added in JsonRenderer::item
417415
}
418416
}
419417
}
420418

421-
pub(crate)fnfrom_fn_header(header:&rustc_hir::FnHeader) -> Header{
422-
Header{
423-
async_: header.is_async(),
424-
const_: header.is_const(),
425-
unsafe_: header.is_unsafe(),
419+
pub(crate)fnfrom_fn_header(header:&rustc_hir::FnHeader) -> FunctionHeader{
420+
FunctionHeader{
421+
is_async: header.is_async(),
422+
is_const: header.is_const(),
423+
is_unsafe: header.is_unsafe(),
426424
abi:convert_abi(header.abi),
427425
}
428426
}
@@ -474,7 +472,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
474472
Type{ bounds, default, synthetic } => GenericParamDefKind::Type{
475473
bounds: bounds.into_tcx(tcx),
476474
default: default.map(|x| (*x).into_tcx(tcx)),
477-
synthetic,
475+
is_synthetic:synthetic,
478476
},
479477
Const{ ty, default,synthetic: _ } => GenericParamDefKind::Const{
480478
type_:(*ty).into_tcx(tcx),
@@ -508,7 +506,7 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
508506
.map(|bound| bound.into_tcx(tcx))
509507
.collect(),
510508
default: default.map(|ty| (*ty).into_tcx(tcx)),
511-
synthetic,
509+
is_synthetic:synthetic,
512510
}
513511
}
514512
clean::GenericParamDefKind::Const{ ty, default,synthetic: _ } => {
@@ -602,12 +600,12 @@ impl FromWithTcx<clean::Type> for Type {
602600
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
603601
Infer => Type::Infer,
604602
RawPointer(mutability, type_) => Type::RawPointer{
605-
mutable: mutability == ast::Mutability::Mut,
603+
is_mutable: mutability == ast::Mutability::Mut,
606604
type_:Box::new((*type_).into_tcx(tcx)),
607605
},
608606
BorrowedRef{ lifetime, mutability, type_ } => Type::BorrowedRef{
609607
lifetime: lifetime.map(convert_lifetime),
610-
mutable: mutability == ast::Mutability::Mut,
608+
is_mutable: mutability == ast::Mutability::Mut,
611609
type_:Box::new((*type_).into_tcx(tcx)),
612610
},
613611
QPath(box clean::QPathData{ assoc, self_type, trait_, .. }) => Type::QualifiedPath{
@@ -643,29 +641,29 @@ impl FromWithTcx<clean::BareFunctionDecl> for FunctionPointer {
643641
fnfrom_tcx(bare_decl: clean::BareFunctionDecl,tcx:TyCtxt<'_>) -> Self{
644642
let clean::BareFunctionDecl{ safety, generic_params, decl, abi } = bare_decl;
645643
FunctionPointer{
646-
header:Header{
647-
unsafe_:matches!(safety, rustc_hir::Safety::Unsafe),
648-
const_:false,
649-
async_:false,
644+
header:FunctionHeader{
645+
is_unsafe:matches!(safety, rustc_hir::Safety::Unsafe),
646+
is_const:false,
647+
is_async:false,
650648
abi:convert_abi(abi),
651649
},
652650
generic_params: generic_params.into_tcx(tcx),
653-
decl: decl.into_tcx(tcx),
651+
sig: decl.into_tcx(tcx),
654652
}
655653
}
656654
}
657655

658-
implFromWithTcx<clean::FnDecl>forFnDecl{
656+
implFromWithTcx<clean::FnDecl>forFunctionSignature{
659657
fnfrom_tcx(decl: clean::FnDecl,tcx:TyCtxt<'_>) -> Self{
660658
let clean::FnDecl{ inputs, output, c_variadic } = decl;
661-
FnDecl{
659+
FunctionSignature{
662660
inputs: inputs
663661
.values
664662
.into_iter()
665663
.map(|arg| (arg.name.to_string(), arg.type_.into_tcx(tcx)))
666664
.collect(),
667665
output:if output.is_unit(){None}else{Some(output.into_tcx(tcx))},
668-
c_variadic,
666+
is_c_variadic:c_variadic,
669667
}
670668
}
671669
}
@@ -702,12 +700,12 @@ impl FromWithTcx<clean::Impl> for Impl {
702700
let provided_trait_methods = impl_.provided_trait_methods(tcx);
703701
let clean::Impl{ safety, generics, trait_, for_, items, polarity, kind } = impl_;
704702
// FIXME: use something like ImplKind in JSON?
705-
let(synthetic, blanket_impl) = match kind {
703+
let(is_synthetic, blanket_impl) = match kind {
706704
clean::ImplKind::Normal | clean::ImplKind::FakeVariadic => (false,None),
707705
clean::ImplKind::Auto => (true,None),
708706
clean::ImplKind::Blanket(ty) => (false,Some(*ty)),
709707
};
710-
letnegative_polarity = match polarity {
708+
letis_negative = match polarity {
711709
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => false,
712710
ty::ImplPolarity::Negative => true,
713711
};
@@ -721,8 +719,8 @@ impl FromWithTcx<clean::Impl> for Impl {
721719
trait_: trait_.map(|path| path.into_tcx(tcx)),
722720
for_: for_.into_tcx(tcx),
723721
items:ids(items, tcx),
724-
negative: negative_polarity,
725-
synthetic,
722+
is_negative,
723+
is_synthetic,
726724
blanket_impl: blanket_impl.map(|x| x.into_tcx(tcx)),
727725
}
728726
}
@@ -736,7 +734,7 @@ pub(crate) fn from_function(
736734
) -> Function{
737735
let clean::Function{ decl, generics } = *function;
738736
Function{
739-
decl: decl.into_tcx(tcx),
737+
sig: decl.into_tcx(tcx),
740738
generics: generics.into_tcx(tcx),
741739
header:from_fn_header(&header),
742740
has_body,
@@ -745,11 +743,11 @@ pub(crate) fn from_function(
745743

746744
implFromWithTcx<clean::Enum>forEnum{
747745
fnfrom_tcx(enum_: clean::Enum,tcx:TyCtxt<'_>) -> Self{
748-
letvariants_stripped = enum_.has_stripped_entries();
746+
lethas_stripped_variants = enum_.has_stripped_entries();
749747
let clean::Enum{ variants, generics } = enum_;
750748
Enum{
751749
generics: generics.into_tcx(tcx),
752-
variants_stripped,
750+
has_stripped_variants,
753751
variants:ids(variants, tcx),
754752
impls:Vec::new(),// Added in JsonRenderer::item
755753
}
@@ -766,7 +764,7 @@ impl FromWithTcx<clean::Variant> for Variant {
766764
CLike => VariantKind::Plain,
767765
Tuple(fields) => VariantKind::Tuple(ids_keeping_stripped(fields, tcx)),
768766
Struct(s) => VariantKind::Struct{
769-
fields_stripped: s.has_stripped_entries(),
767+
has_stripped_fields: s.has_stripped_entries(),
770768
fields:ids(s.fields, tcx),
771769
},
772770
};
@@ -787,21 +785,21 @@ impl FromWithTcx<clean::Discriminant> for Discriminant {
787785
}
788786
}
789787

790-
implFromWithTcx<clean::Import>forImport{
788+
implFromWithTcx<clean::Import>forUse{
791789
fnfrom_tcx(import: clean::Import,tcx:TyCtxt<'_>) -> Self{
792790
use clean::ImportKind::*;
793-
let(name,glob) = match import.kind{
791+
let(name,is_glob) = match import.kind{
794792
Simple(s) => (s.to_string(),false),
795793
Glob => (
796794
import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
797795
true,
798796
),
799797
};
800-
Import{
798+
Use{
801799
source: import.source.path.whole_name(),
802800
name,
803801
id: import.source.did.map(ItemId::from).map(|i| id_from_item_default(i, tcx)),
804-
glob,
802+
is_glob,
805803
}
806804
}
807805
}
@@ -835,7 +833,7 @@ impl FromWithTcx<clean::Static> for Static {
835833
fnfrom_tcx(stat: clean::Static,tcx:TyCtxt<'_>) -> Self{
836834
Static{
837835
type_:(*stat.type_).into_tcx(tcx),
838-
mutable: stat.mutability == ast::Mutability::Mut,
836+
is_mutable: stat.mutability == ast::Mutability::Mut,
839837
expr: stat
840838
.expr
841839
.map(|e| rendered_const(tcx, tcx.hir().body(e), tcx.hir().body_owner_def_id(e)))
@@ -856,7 +854,7 @@ impl FromWithTcx<ItemType> for ItemKind {
856854
match kind {
857855
Module => ItemKind::Module,
858856
ExternCrate => ItemKind::ExternCrate,
859-
Import => ItemKind::Import,
857+
Import => ItemKind::Use,
860858
Struct => ItemKind::Struct,
861859
Union => ItemKind::Union,
862860
Enum => ItemKind::Enum,
@@ -872,7 +870,7 @@ impl FromWithTcx<ItemType> for ItemKind {
872870
Primitive => ItemKind::Primitive,
873871
AssocConst => ItemKind::AssocConst,
874872
AssocType => ItemKind::AssocType,
875-
ForeignType => ItemKind::ForeignType,
873+
ForeignType => ItemKind::ExternType,
876874
Keyword => ItemKind::Keyword,
877875
TraitAlias => ItemKind::TraitAlias,
878876
ProcAttribute => ItemKind::ProcAttribute,

‎src/librustdoc/json/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
197197

198198
types::ItemEnum::Function(_)
199199
| types::ItemEnum::Module(_)
200-
| types::ItemEnum::Import(_)
200+
| types::ItemEnum::Use(_)
201201
| types::ItemEnum::AssocConst{ .. }
202202
| types::ItemEnum::AssocType{ .. } => true,
203203
types::ItemEnum::ExternCrate{ .. }
@@ -208,7 +208,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
208208
| types::ItemEnum::TypeAlias(_)
209209
| types::ItemEnum::Constant{ .. }
210210
| types::ItemEnum::Static(_)
211-
| types::ItemEnum::ForeignType
211+
| types::ItemEnum::ExternType
212212
| types::ItemEnum::Macro(_)
213213
| types::ItemEnum::ProcMacro(_) => false,
214214
};

0 commit comments

Comments
 (0)