Skip to content

Commit

Permalink
Auto merge of rust-lang#94861 - aDotInTheVoid:rdj-trait-tests, r=Craf…
Browse files Browse the repository at this point in the history
…tSpider

rustdoc-json: More tests, and better jsondocck errors

Helps with rust-lang#81359

r? `@CraftSpider`

`@rustbot` modify labels: +A-rustdoc-json +T-rustdoc +A-testsuite
  • Loading branch information
bors committed Mar 16, 2022
2 parents f21488a + 26829c0 commit af446e1
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/test/rustdoc-json/fns/generic_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ignore-tidy-linelength

#![feature(no_core)]
#![no_core]

// @set foo = generic_args.json "$.index[*][?(@.name=='Foo')].id"
pub trait Foo {}

// @is - "$.index[*][?(@.name=='generics')].inner.generics.where_predicates" "[]"
// @count - "$.index[*][?(@.name=='generics')].inner.generics.params[*]" 1
// @is - "$.index[*][?(@.name=='generics')].inner.generics.params[0].name" '"F"'
// @is - "$.index[*][?(@.name=='generics')].inner.generics.params[0].kind.type.default" 'null'
// @count - "$.index[*][?(@.name=='generics')].inner.generics.params[0].kind.type.bounds[*]" 1
// @is - "$.index[*][?(@.name=='generics')].inner.generics.params[0].kind.type.bounds[0].trait_bound.trait.inner.id" '$foo'
// @count - "$.index[*][?(@.name=='generics')].inner.decl.inputs[*]" 1
// @is - "$.index[*][?(@.name=='generics')].inner.decl.inputs[0][0]" '"f"'
// @is - "$.index[*][?(@.name=='generics')].inner.decl.inputs[0][1].kind" '"generic"'
// @is - "$.index[*][?(@.name=='generics')].inner.decl.inputs[0][1].inner" '"F"'
pub fn generics<F: Foo>(f: F) {}

// @is - "$.index[*][?(@.name=='impl_trait')].inner.generics.where_predicates" "[]"
// @count - "$.index[*][?(@.name=='impl_trait')].inner.generics.params[*]" 1
// @is - "$.index[*][?(@.name=='impl_trait')].inner.generics.params[0].name" '"impl Foo"'
// @is - "$.index[*][?(@.name=='impl_trait')].inner.generics.params[0].kind.type.bounds[0].trait_bound.trait.inner.id" $foo
// @count - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[*]" 1
// @is - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[0][0]" '"f"'
// @is - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[0][1].kind" '"impl_trait"'
// @count - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[0][1].inner[*]" 1
// @is - "$.index[*][?(@.name=='impl_trait')].inner.decl.inputs[0][1].inner[0].trait_bound.trait.inner.id" $foo
pub fn impl_trait(f: impl Foo) {}

// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.params[*]" 1
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.params[0].name" '"F"'
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.params[0].kind" '{"type": {"bounds": [], "default": null, "synthetic": false}}'
// @count - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[*]" 1
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][0]" '"f"'
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][1].kind" '"generic"'
// @is - "$.index[*][?(@.name=='where_clase')].inner.decl.inputs[0][1].inner" '"F"'
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[*]" 1
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.type" '{"inner": "F", "kind": "generic"}'
// @count - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.bounds[*]" 1
// @is - "$.index[*][?(@.name=='where_clase')].inner.generics.where_predicates[0].bound_predicate.bounds[0].trait_bound.trait.inner.id" $foo
pub fn where_clase<F>(f: F)
where
F: Foo,
{
}
21 changes: 21 additions & 0 deletions src/test/rustdoc-json/fns/generic_returns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ignore-tidy-linelength

#![feature(no_core)]
#![no_core]

// @count generic_returns.json "$.index[*][?(@.name=='generic_returns')].inner.items[*]" 2

// @set foo = - "$.index[*][?(@.name=='Foo')].id"
pub trait Foo {}

// @is - "$.index[*][?(@.name=='get_foo')].inner.decl.inputs" []
// @is - "$.index[*][?(@.name=='get_foo')].inner.decl.output.kind" '"impl_trait"'
// @count - "$.index[*][?(@.name=='get_foo')].inner.decl.output.inner[*]" 1
// @is - "$.index[*][?(@.name=='get_foo')].inner.decl.output.inner[0].trait_bound.trait.inner.id" $foo
pub fn get_foo() -> impl Foo {
Fooer {}
}

struct Fooer {}

impl Foo for Fooer {}
33 changes: 33 additions & 0 deletions src/test/rustdoc-json/lifetime/longest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ignore-tidy-linelength

#![feature(no_core)]
#![no_core]

// @is longest.json "$.index[*][?(@.name=='longest')].inner.generics.params[0].name" \"\'a\"
// @is - "$.index[*][?(@.name=='longest')].inner.generics.params[0].kind" '{"lifetime": {"outlives": []}}'
// @is - "$.index[*][?(@.name=='longest')].inner.generics.params[0].kind" '{"lifetime": {"outlives": []}}'
// @count - "$.index[*][?(@.name=='longest')].inner.generics.params[*]" 1
// @is - "$.index[*][?(@.name=='longest')].inner.generics.where_predicates" []

// @count - "$.index[*][?(@.name=='longest')].inner.decl.inputs[*]" 2
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[0][0]" '"l"'
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[1][0]" '"r"'

// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[0][1].kind" '"borrowed_ref"'
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[0][1].inner.lifetime" \"\'a\"
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[0][1].inner.mutable" false
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[0][1].inner.type" '{"inner": "str", "kind": "primitive"}'

// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[1][1].kind" '"borrowed_ref"'
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[1][1].inner.lifetime" \"\'a\"
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[1][1].inner.mutable" false
// @is - "$.index[*][?(@.name=='longest')].inner.decl.inputs[1][1].inner.type" '{"inner": "str", "kind": "primitive"}'

// @is - "$.index[*][?(@.name=='longest')].inner.decl.output.kind" '"borrowed_ref"'
// @is - "$.index[*][?(@.name=='longest')].inner.decl.output.inner.lifetime" \"\'a\"
// @is - "$.index[*][?(@.name=='longest')].inner.decl.output.inner.mutable" false
// @is - "$.index[*][?(@.name=='longest')].inner.decl.output.inner.type" '{"inner": "str", "kind": "primitive"}'

pub fn longest<'a>(l: &'a str, r: &'a str) -> &'a str {
if l.len() > r.len() { l } else { r }
}
23 changes: 23 additions & 0 deletions src/test/rustdoc-json/lifetime/outlives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ignore-tidy-linelength

#![feature(no_core)]
#![no_core]

// @count outlives.json "$.index[*][?(@.name=='foo')].inner.generics.params[*]" 3
// @is - "$.index[*][?(@.name=='foo')].inner.generics.where_predicates" []
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[0].name" \"\'a\"
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[1].name" \"\'b\"
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[2].name" '"T"'
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[0].kind.lifetime.outlives" []
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[1].kind.lifetime.outlives" [\"\'a\"]
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[2].kind.type.default" null
// @count - "$.index[*][?(@.name=='foo')].inner.generics.params[2].kind.type.bounds[*]" 1
// @is - "$.index[*][?(@.name=='foo')].inner.generics.params[2].kind.type.bounds[0].outlives" \"\'b\"
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].kind" '"borrowed_ref"'
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.lifetime" \"\'a\"
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.mutable" false
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.type.kind" '"borrowed_ref"'
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.type.inner.lifetime" \"\'b\"
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.type.inner.mutable" false
// @is - "$.index[*][?(@.name=='foo')].inner.decl.inputs[0][1].inner.type.inner.type" '{"inner": "T", "kind": "generic"}'
pub fn foo<'a, 'b: 'a, T: 'b>(_: &'a &'b T) {}
26 changes: 26 additions & 0 deletions src/test/rustdoc-json/traits/supertrait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ignore-tidy-linelength

#![feature(no_core)]
#![feature(lang_items)]
#![no_core]

// @set loud_id = supertrait.json "$.index[*][?(@.name=='Loud')].id"
pub trait Loud {}

// @set very_loud_id = - "$.index[*][?(@.name=='VeryLoud')].id"
// @count - "$.index[*][?(@.name=='VeryLoud')].inner.bounds[*]" 1
// @is - "$.index[*][?(@.name=='VeryLoud')].inner.bounds[0].trait_bound.trait.inner.id" $loud_id
pub trait VeryLoud: Loud {}

// @set sounds_good_id = - "$.index[*][?(@.name=='SoundsGood')].id"
pub trait SoundsGood {}

// @count - "$.index[*][?(@.name=='MetalBand')].inner.bounds[*]" 2
// @is - "$.index[*][?(@.name=='MetalBand')].inner.bounds[0].trait_bound.trait.inner.id" $very_loud_id
// @is - "$.index[*][?(@.name=='MetalBand')].inner.bounds[1].trait_bound.trait.inner.id" $sounds_good_id
pub trait MetalBand: VeryLoud + SoundsGood {}

// @count - "$.index[*][?(@.name=='DnabLatem')].inner.bounds[*]" 2
// @is - "$.index[*][?(@.name=='DnabLatem')].inner.bounds[1].trait_bound.trait.inner.id" $very_loud_id
// @is - "$.index[*][?(@.name=='DnabLatem')].inner.bounds[0].trait_bound.trait.inner.id" $sounds_good_id
pub trait DnabLatem: SoundsGood + VeryLoud {}
7 changes: 5 additions & 2 deletions src/tools/jsondocck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ impl CommandKind {

if let CommandKind::Count = self {
if args[2].parse::<usize>().is_err() {
print_err(&format!("Third argument to @count must be a valid usize"), lineno);
print_err(
&format!("Third argument to @count must be a valid usize (got `{}`)", args[2]),
lineno,
);
return false;
}
}
Expand Down Expand Up @@ -277,7 +280,7 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
assert_eq!(
results.len(),
1,
"Didn't get 1 result for `{}`: got {:?}",
"Expected 1 match for `{}` (because of @set): matched to {:?}",
command.args[3],
results
);
Expand Down

0 comments on commit af446e1

Please sign in to comment.