Auto merge of #94861 - aDotInTheVoid:rdj-trait-tests, r=CraftSpider
rustdoc-json: More tests, and better jsondocck errors Helps with #81359 r? `@CraftSpider` `@rustbot` modify labels: +A-rustdoc-json +T-rustdoc +A-testsuite
This commit is contained in:
commit
af446e1d70
47
src/test/rustdoc-json/fns/generic_args.rs
Normal file
47
src/test/rustdoc-json/fns/generic_args.rs
Normal file
@ -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
src/test/rustdoc-json/fns/generic_returns.rs
Normal file
21
src/test/rustdoc-json/fns/generic_returns.rs
Normal file
@ -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
src/test/rustdoc-json/lifetime/longest.rs
Normal file
33
src/test/rustdoc-json/lifetime/longest.rs
Normal file
@ -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
src/test/rustdoc-json/lifetime/outlives.rs
Normal file
23
src/test/rustdoc-json/lifetime/outlives.rs
Normal file
@ -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
src/test/rustdoc-json/traits/supertrait.rs
Normal file
26
src/test/rustdoc-json/traits/supertrait.rs
Normal file
@ -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 {}
|
@ -73,7 +73,10 @@ fn validate(&self, args: &[String], command_num: usize, lineno: usize) -> bool {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user