Skip to content

Commit fc6fb3f

Browse files
Allow #[doc(alias)] on impl const items
1 parent 3b6e4a8 commit fc6fb3f

7 files changed

+24
-26
lines changed

src/librustc_passes/check_attr.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,11 @@ impl CheckAttrVisitor<'tcx> {
241241
if let Some(err) = match target {
242242
Target::Impl => Some("implementation block"),
243243
Target::ForeignMod => Some("extern block"),
244-
Target::AssocConst | Target::AssocTy => {
244+
Target::AssocTy => {
245245
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
246246
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
247247
if Target::from_item(containing_item) == Target::Impl {
248-
Some(if target == Target::AssocConst {
249-
"const in implementation block"
250-
} else {
251-
"type alias in implementation block"
252-
})
248+
Some("type alias in implementation block")
253249
} else {
254250
None
255251
}

src/test/rustdoc-js/doc-alias.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const QUERY = [
55
'StructFieldItem',
66
'StructMethodItem',
77
'ImplTraitItem',
8-
'ImplAssociatedConstItem',
8+
'StructImplConstItem',
99
'ImplTraitFunction',
1010
'EnumItem',
1111
'VariantItem',
@@ -64,8 +64,16 @@ const EXPECTED = [
6464
'others': [],
6565
},
6666
{
67-
// ImplAssociatedConstItem
68-
'others': [],
67+
// StructImplConstItem
68+
'others': [
69+
{
70+
'path': 'doc_alias::Struct',
71+
'name': 'ImplConstItem',
72+
'alias': 'StructImplConstItem',
73+
'href': '../doc_alias/struct.Struct.html#associatedconstant.ImplConstItem',
74+
'is_alias': true
75+
},
76+
],
6977
},
7078
{
7179
'others': [
@@ -197,6 +205,10 @@ const EXPECTED = [
197205
'href': '../doc_alias/constant.Const.html',
198206
'is_alias': true
199207
},
208+
{
209+
'path': 'doc_alias::Struct',
210+
'name': 'ImplConstItem',
211+
},
200212
],
201213
},
202214
{

src/test/rustdoc-js/doc-alias.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub struct Struct {
77
}
88

99
impl Struct {
10+
#[doc(alias = "StructImplConstItem")]
11+
pub const ImplConstItem: i32 = 0;
1012
#[doc(alias = "StructMethodItem")]
1113
pub fn method(&self) {}
1214
}

src/test/rustdoc-ui/check-doc-alias-attr-location.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ extern {}
1111

1212
#[doc(alias = "bar")] //~ ERROR
1313
impl Bar {
14-
#[doc(alias = "const")] //~ ERROR
15-
const A: u32 = 0;
14+
#[doc(alias = "const")]
15+
pub const A: u32 = 0;
1616
}
1717

1818
#[doc(alias = "foobar")] //~ ERROR

src/test/rustdoc-ui/check-doc-alias-attr-location.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@ error: `#[doc(alias = "...")]` isn't allowed on implementation block
1616
LL | #[doc(alias = "foobar")]
1717
| ^^^^^^^^^^^^^^^^
1818

19-
error: `#[doc(alias = "...")]` isn't allowed on const in implementation block
20-
--> $DIR/check-doc-alias-attr-location.rs:14:11
21-
|
22-
LL | #[doc(alias = "const")]
23-
| ^^^^^^^^^^^^^^^
24-
2519
error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation block
2620
--> $DIR/check-doc-alias-attr-location.rs:20:11
2721
|
2822
LL | #[doc(alias = "assoc")]
2923
| ^^^^^^^^^^^^^^^
3024

31-
error: aborting due to 5 previous errors
25+
error: aborting due to 4 previous errors
3226

src/test/ui/check-doc-alias-attr-location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern {}
1212

1313
#[doc(alias = "bar")] //~ ERROR
1414
impl Bar {
15-
#[doc(alias = "const")] //~ ERROR
15+
#[doc(alias = "const")]
1616
const A: u32 = 0;
1717
}
1818

src/test/ui/check-doc-alias-attr-location.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@ error: `#[doc(alias = "...")]` isn't allowed on implementation block
1616
LL | #[doc(alias = "foobar")]
1717
| ^^^^^^^^^^^^^^^^
1818

19-
error: `#[doc(alias = "...")]` isn't allowed on const in implementation block
20-
--> $DIR/check-doc-alias-attr-location.rs:15:11
21-
|
22-
LL | #[doc(alias = "const")]
23-
| ^^^^^^^^^^^^^^^
24-
2519
error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation block
2620
--> $DIR/check-doc-alias-attr-location.rs:21:11
2721
|
2822
LL | #[doc(alias = "assoc")]
2923
| ^^^^^^^^^^^^^^^
3024

31-
error: aborting due to 5 previous errors
25+
error: aborting due to 4 previous errors
3226

0 commit comments

Comments
 (0)