Skip to content

Commit defc245

Browse files
authored
Rollup merge of rust-lang#129123 - aDotInTheVoid:rustdoc-json-self, r=fmease
rustdoc-json: Add test for `Self` type Inspired by rust-lang#128471, the rustdoc-json suite had no tests in place for the `Self` type. This PR adds one. I've also manually checked locally that this test passes on 29e9248, confirming that adding `clean::Type::SelfTy` didn't change the JSON output. (potentially adding a self type to json (insead of (ab)using generic) is tracked in rust-lang#128522) Updates rust-lang#81359 r? ````````@fmease````````
2 parents 1f0292b + 6ed283b commit defc245

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/rustdoc-json/traits/self.rs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ignore-tidy-linelength
2+
3+
pub struct Foo;
4+
5+
// Check that Self is represented uniformly between inherent impls, trait impls,
6+
// and trait definitions, even though it uses both SelfTyParam and SelfTyAlias
7+
// internally.
8+
//
9+
// Each assertion matches 3 times, and should be the same each time.
10+
11+
impl Foo {
12+
//@ ismany '$.index[*][?(@.name=="by_ref")].inner.function.decl.inputs[0][0]' '"self"' '"self"' '"self"'
13+
//@ ismany '$.index[*][?(@.name=="by_ref")].inner.function.decl.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"'
14+
//@ ismany '$.index[*][?(@.name=="by_ref")].inner.function.decl.inputs[0][1].borrowed_ref.lifetime' null null null
15+
//@ ismany '$.index[*][?(@.name=="by_ref")].inner.function.decl.inputs[0][1].borrowed_ref.mutable' false false false
16+
pub fn by_ref(&self) {}
17+
18+
//@ ismany '$.index[*][?(@.name=="by_exclusive_ref")].inner.function.decl.inputs[0][0]' '"self"' '"self"' '"self"'
19+
//@ ismany '$.index[*][?(@.name=="by_exclusive_ref")].inner.function.decl.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"'
20+
//@ ismany '$.index[*][?(@.name=="by_exclusive_ref")].inner.function.decl.inputs[0][1].borrowed_ref.lifetime' null null null
21+
//@ ismany '$.index[*][?(@.name=="by_exclusive_ref")].inner.function.decl.inputs[0][1].borrowed_ref.mutable' true true true
22+
pub fn by_exclusive_ref(&mut self) {}
23+
24+
//@ ismany '$.index[*][?(@.name=="by_value")].inner.function.decl.inputs[0][0]' '"self"' '"self"' '"self"'
25+
//@ ismany '$.index[*][?(@.name=="by_value")].inner.function.decl.inputs[0][1].generic' '"Self"' '"Self"' '"Self"'
26+
pub fn by_value(self) {}
27+
28+
//@ ismany '$.index[*][?(@.name=="with_lifetime")].inner.function.decl.inputs[0][0]' '"self"' '"self"' '"self"'
29+
//@ ismany '$.index[*][?(@.name=="with_lifetime")].inner.function.decl.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"'
30+
//@ ismany '$.index[*][?(@.name=="with_lifetime")].inner.function.decl.inputs[0][1].borrowed_ref.lifetime' \"\'a\" \"\'a\" \"\'a\"
31+
//@ ismany '$.index[*][?(@.name=="with_lifetime")].inner.function.decl.inputs[0][1].borrowed_ref.mutable' false false false
32+
pub fn with_lifetime<'a>(&'a self) {}
33+
34+
//@ ismany '$.index[*][?(@.name=="build")].inner.function.decl.output.generic' '"Self"' '"Self"' '"Self"'
35+
pub fn build() -> Self {
36+
Self
37+
}
38+
}
39+
40+
pub struct Bar;
41+
42+
pub trait SelfParams {
43+
fn by_ref(&self);
44+
fn by_exclusive_ref(&mut self);
45+
fn by_value(self);
46+
fn with_lifetime<'a>(&'a self);
47+
fn build() -> Self;
48+
}
49+
50+
impl SelfParams for Bar {
51+
fn by_ref(&self) {}
52+
fn by_exclusive_ref(&mut self) {}
53+
fn by_value(self) {}
54+
fn with_lifetime<'a>(&'a self) {}
55+
fn build() -> Self {
56+
Self
57+
}
58+
}

0 commit comments

Comments
 (0)