From 4a57399ab0b41b94afb5ef8815f2863ba2507d65 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Sun, 20 Feb 2022 22:51:05 +0000 Subject: [PATCH 1/5] rustdoc-json: Add test for supertraits --- src/test/rustdoc-json/traits/supertrait.rs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/rustdoc-json/traits/supertrait.rs diff --git a/src/test/rustdoc-json/traits/supertrait.rs b/src/test/rustdoc-json/traits/supertrait.rs new file mode 100644 index 0000000000000..486a8e713f811 --- /dev/null +++ b/src/test/rustdoc-json/traits/supertrait.rs @@ -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 {} From ccef93fb891ac2f3426d9f4a733841db256919a9 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 25 Feb 2022 15:27:11 +0000 Subject: [PATCH 2/5] jsondocck: better error for when @set matches multiple items --- src/tools/jsondocck/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index d0f476955e1f7..c5358e2f53a00 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -277,7 +277,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 ); From 42b548cf9d875d878a90e676894c957167796458 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Thu, 10 Mar 2022 15:53:48 +0000 Subject: [PATCH 3/5] rustdoc-json: Add tests for generic fn args and returns --- src/test/rustdoc-json/fns/generic_args.rs | 47 ++++++++++++++++++++ src/test/rustdoc-json/fns/generic_returns.rs | 21 +++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/test/rustdoc-json/fns/generic_args.rs create mode 100644 src/test/rustdoc-json/fns/generic_returns.rs diff --git a/src/test/rustdoc-json/fns/generic_args.rs b/src/test/rustdoc-json/fns/generic_args.rs new file mode 100644 index 0000000000000..3b03724b040ae --- /dev/null +++ b/src/test/rustdoc-json/fns/generic_args.rs @@ -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: 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) +where + F: Foo, +{ +} diff --git a/src/test/rustdoc-json/fns/generic_returns.rs b/src/test/rustdoc-json/fns/generic_returns.rs new file mode 100644 index 0000000000000..1a0f33fe3d28e --- /dev/null +++ b/src/test/rustdoc-json/fns/generic_returns.rs @@ -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 {} From dc6b5cb9f3a554a2a9016e819cb2760b68bd663e Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Thu, 10 Mar 2022 15:55:38 +0000 Subject: [PATCH 4/5] jsondocck: Better error for invalid @count number --- src/tools/jsondocck/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index c5358e2f53a00..c44624666465e 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -73,7 +73,10 @@ impl CommandKind { if let CommandKind::Count = self { if args[2].parse::().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; } } From 26829c03b0689c53e09e5bdfc329de78e95791f4 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 11 Mar 2022 19:11:23 +0000 Subject: [PATCH 5/5] rustdoc-json: Lifetime tests --- src/test/rustdoc-json/lifetime/longest.rs | 33 ++++++++++++++++++++++ src/test/rustdoc-json/lifetime/outlives.rs | 23 +++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/test/rustdoc-json/lifetime/longest.rs create mode 100644 src/test/rustdoc-json/lifetime/outlives.rs diff --git a/src/test/rustdoc-json/lifetime/longest.rs b/src/test/rustdoc-json/lifetime/longest.rs new file mode 100644 index 0000000000000..95b99599e737d --- /dev/null +++ b/src/test/rustdoc-json/lifetime/longest.rs @@ -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 } +} diff --git a/src/test/rustdoc-json/lifetime/outlives.rs b/src/test/rustdoc-json/lifetime/outlives.rs new file mode 100644 index 0000000000000..096dd7f7a6918 --- /dev/null +++ b/src/test/rustdoc-json/lifetime/outlives.rs @@ -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) {}