Allow #[doc(alias)] on impl const items
This commit is contained in:
parent
3b6e4a84f9
commit
fc6fb3fb8f
7 changed files with 24 additions and 26 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const QUERY = [
|
|||
'StructFieldItem',
|
||||
'StructMethodItem',
|
||||
'ImplTraitItem',
|
||||
'ImplAssociatedConstItem',
|
||||
'StructImplConstItem',
|
||||
'ImplTraitFunction',
|
||||
'EnumItem',
|
||||
'VariantItem',
|
||||
|
@ -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': [
|
||||
|
@ -197,6 +205,10 @@ const EXPECTED = [
|
|||
'href': '../doc_alias/constant.Const.html',
|
||||
'is_alias': true
|
||||
},
|
||||
{
|
||||
'path': 'doc_alias::Struct',
|
||||
'name': 'ImplConstItem',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -7,6 +7,8 @@ pub struct Struct {
|
|||
}
|
||||
|
||||
impl Struct {
|
||||
#[doc(alias = "StructImplConstItem")]
|
||||
pub const ImplConstItem: i32 = 0;
|
||||
#[doc(alias = "StructMethodItem")]
|
||||
pub fn method(&self) {}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ extern {}
|
|||
|
||||
#[doc(alias = "bar")] //~ ERROR
|
||||
impl Bar {
|
||||
#[doc(alias = "const")] //~ ERROR
|
||||
#[doc(alias = "const")]
|
||||
const A: u32 = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue