1
Fork 0

Allow #[doc(alias)] on impl const items

This commit is contained in:
Guillaume Gomez 2020-08-12 00:12:49 +02:00
parent 3b6e4a84f9
commit fc6fb3fb8f
7 changed files with 24 additions and 26 deletions

View file

@ -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
}

View file

@ -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',
},
],
},
{

View file

@ -7,6 +7,8 @@ pub struct Struct {
}
impl Struct {
#[doc(alias = "StructImplConstItem")]
pub const ImplConstItem: i32 = 0;
#[doc(alias = "StructMethodItem")]
pub fn method(&self) {}
}

View file

@ -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

View file

@ -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

View file

@ -12,7 +12,7 @@ extern {}
#[doc(alias = "bar")] //~ ERROR
impl Bar {
#[doc(alias = "const")] //~ ERROR
#[doc(alias = "const")]
const A: u32 = 0;
}

View file

@ -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