Emit an error for invalid use of the linkage attribute
This commit is contained in:
parent
730d5d4095
commit
3c8dad152b
5 changed files with 124 additions and 1 deletions
|
@ -243,6 +243,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
[sym::coroutine, ..] => {
|
||||
self.check_coroutine(attr, target);
|
||||
}
|
||||
[sym::linkage, ..] => self.check_linkage(attr, span, target),
|
||||
[
|
||||
// ok
|
||||
sym::allow
|
||||
|
@ -256,7 +257,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| sym::cfi_encoding // FIXME(cfi_encoding)
|
||||
| sym::may_dangle // FIXME(dropck_eyepatch)
|
||||
| sym::pointee // FIXME(derive_smart_pointer)
|
||||
| sym::linkage // FIXME(linkage)
|
||||
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
|
||||
| sym::used // handled elsewhere to restrict to static items
|
||||
| sym::repr // handled elsewhere to restrict to type decls items
|
||||
|
@ -2349,6 +2349,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_linkage(&self, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(..)
|
||||
| Target::Static
|
||||
| Target::ForeignStatic
|
||||
| Target::ForeignFn => {}
|
||||
_ => {
|
||||
self.dcx().emit_err(errors::Linkage { attr_span: attr.span, span });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||
|
|
|
@ -643,6 +643,15 @@ pub struct CoroutineOnNonClosure {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_linkage)]
|
||||
pub struct Linkage {
|
||||
#[primary_span]
|
||||
pub attr_span: Span,
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_empty_confusables)]
|
||||
pub(crate) struct EmptyConfusables {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue