Skip to content

Commit c4f8546

Browse files
Rollup merge of #104924 - aDotInTheVoid:jsondocck-trait-alias, r=GuillaumeGomez
jsondoclint: Accept trait alias is places where trait expected. More work to make `jsondoclint` work for `core.json` Closes #104923 r? `@GuillaumeGomez` `@rustbot` modify labels: +A-testsuite
2 parents 4019c8a + b1cdb05 commit c4f8546

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/104923>
2+
// ignore-tidy-linelength
3+
4+
#![feature(trait_alias)]
5+
6+
// @set Orig = "$.index[*][?(@.name == 'Orig')].id"
7+
// @is "$.index[*][?(@.name == 'Orig')].kind" '"trait"'
8+
pub trait Orig<T> {}
9+
10+
// @set Alias = "$.index[*][?(@.name == 'Alias')].id"
11+
// @is "$.index[*][?(@.name == 'Alias')].kind" '"trait_alias"'
12+
// @is "$.index[*][?(@.name == 'Alias')].inner.generics" '{"params": [], "where_predicates": []}'
13+
// @count "$.index[*][?(@.name == 'Alias')].inner.params[*]" 1
14+
// @is "$.index[*][?(@.name == 'Alias')].inner.params[0].trait_bound.trait.id" $Orig
15+
// @is "$.index[*][?(@.name == 'Alias')].inner.params[0].trait_bound.trait.args.angle_bracketed.args[0].type.inner" '"i32"'
16+
pub trait Alias = Orig<i32>;
17+
18+
pub struct Struct;
19+
20+
impl Orig<i32> for Struct {}
21+
22+
// @is "$.index[*][?(@.name=='takes_alias')].inner.decl.inputs[0][1].kind" '"impl_trait"'
23+
// @is "$.index[*][?(@.name=='takes_alias')].inner.decl.inputs[0][1].inner[0].trait_bound.trait.id" $Alias
24+
// @is "$.index[*][?(@.name=='takes_alias')].inner.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" $Alias
25+
pub fn takes_alias(_: impl Alias) {}
26+
// FIXME: Should the trait be mentioned in both the decl and generics?
27+
28+
fn main() {
29+
takes_alias(Struct);
30+
}

src/tools/jsondoclint/src/item_kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl Kind {
111111
pub fn is_variant(self) -> bool {
112112
matches!(self, Kind::Variant)
113113
}
114-
pub fn is_trait(self) -> bool {
115-
matches!(self, Kind::Trait)
114+
pub fn is_trait_or_alias(self) -> bool {
115+
matches!(self, Kind::Trait | Kind::TraitAlias)
116116
}
117117
pub fn is_type(self) -> bool {
118118
matches!(self, Kind::Struct | Kind::Enum | Kind::Union | Kind::Typedef)

src/tools/jsondoclint/src/validator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a> Validator<'a> {
266266

267267
fn check_path(&mut self, x: &'a Path, kind: PathKind) {
268268
match kind {
269-
PathKind::Trait => self.add_trait_id(&x.id),
269+
PathKind::Trait => self.add_trait_or_alias_id(&x.id),
270270
PathKind::Type => self.add_type_id(&x.id),
271271
}
272272
if let Some(args) = &x.args {
@@ -391,8 +391,8 @@ impl<'a> Validator<'a> {
391391
self.add_id_checked(id, Kind::is_variant, "Variant");
392392
}
393393

394-
fn add_trait_id(&mut self, id: &'a Id) {
395-
self.add_id_checked(id, Kind::is_trait, "Trait");
394+
fn add_trait_or_alias_id(&mut self, id: &'a Id) {
395+
self.add_id_checked(id, Kind::is_trait_or_alias, "Trait (or TraitAlias)");
396396
}
397397

398398
fn add_type_id(&mut self, id: &'a Id) {

0 commit comments

Comments
 (0)