Skip to content

Commit

Permalink
Allow #[doc(alias)] on impl const items
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 12, 2020
1 parent 3b6e4a8 commit fc6fb3f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
8 changes: 2 additions & 6 deletions src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,11 @@ impl CheckAttrVisitor<'tcx> {
if let Some(err) = match target {
Target::Impl => Some("implementation block"),
Target::ForeignMod => Some("extern block"),
Target::AssocConst | Target::AssocTy => {
Target::AssocTy => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
if Target::from_item(containing_item) == Target::Impl {
Some(if target == Target::AssocConst {
"const in implementation block"
} else {
"type alias in implementation block"
})
Some("type alias in implementation block")
} else {
None
}
Expand Down
18 changes: 15 additions & 3 deletions src/test/rustdoc-js/doc-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const QUERY = [
'StructFieldItem',
'StructMethodItem',
'ImplTraitItem',
'ImplAssociatedConstItem',
'StructImplConstItem',
'ImplTraitFunction',
'EnumItem',
'VariantItem',
Expand Down Expand Up @@ -64,8 +64,16 @@ const EXPECTED = [
'others': [],
},
{
// ImplAssociatedConstItem
'others': [],
// StructImplConstItem
'others': [
{
'path': 'doc_alias::Struct',
'name': 'ImplConstItem',
'alias': 'StructImplConstItem',
'href': '../doc_alias/struct.Struct.html#associatedconstant.ImplConstItem',
'is_alias': true
},
],
},
{
'others': [
Expand Down Expand Up @@ -197,6 +205,10 @@ const EXPECTED = [
'href': '../doc_alias/constant.Const.html',
'is_alias': true
},
{
'path': 'doc_alias::Struct',
'name': 'ImplConstItem',
},
],
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc-js/doc-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct Struct {
}

impl Struct {
#[doc(alias = "StructImplConstItem")]
pub const ImplConstItem: i32 = 0;
#[doc(alias = "StructMethodItem")]
pub fn method(&self) {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/check-doc-alias-attr-location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extern {}

#[doc(alias = "bar")] //~ ERROR
impl Bar {
#[doc(alias = "const")] //~ ERROR
const A: u32 = 0;
#[doc(alias = "const")]
pub const A: u32 = 0;
}

#[doc(alias = "foobar")] //~ ERROR
Expand Down
8 changes: 1 addition & 7 deletions src/test/rustdoc-ui/check-doc-alias-attr-location.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ error: `#[doc(alias = "...")]` isn't allowed on implementation block
LL | #[doc(alias = "foobar")]
| ^^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` isn't allowed on const in implementation block
--> $DIR/check-doc-alias-attr-location.rs:14:11
|
LL | #[doc(alias = "const")]
| ^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation block
--> $DIR/check-doc-alias-attr-location.rs:20:11
|
LL | #[doc(alias = "assoc")]
| ^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/check-doc-alias-attr-location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern {}

#[doc(alias = "bar")] //~ ERROR
impl Bar {
#[doc(alias = "const")] //~ ERROR
#[doc(alias = "const")]
const A: u32 = 0;
}

Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/check-doc-alias-attr-location.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ error: `#[doc(alias = "...")]` isn't allowed on implementation block
LL | #[doc(alias = "foobar")]
| ^^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` isn't allowed on const in implementation block
--> $DIR/check-doc-alias-attr-location.rs:15:11
|
LL | #[doc(alias = "const")]
| ^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` isn't allowed on type alias in implementation block
--> $DIR/check-doc-alias-attr-location.rs:21:11
|
LL | #[doc(alias = "assoc")]
| ^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

0 comments on commit fc6fb3f

Please sign in to comment.