Skip to content

Commit 0e68e1b

Browse files
Prevent #[doc(alias = "...")] at crate level
1 parent 738d4a7 commit 0e68e1b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler/rustc_hir/src/target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use crate::{Item, ItemKind, TraitItem, TraitItemKind};
99

1010
use std::fmt::{self, Display};
1111

12-
#[derive(Copy, Clone, PartialEq)]
12+
#[derive(Copy, Clone, PartialEq, Debug)]
1313
pub enum MethodKind {
1414
Trait { body: bool },
1515
Inherent,
1616
}
1717

18-
#[derive(Copy, Clone, PartialEq)]
18+
#[derive(Copy, Clone, PartialEq, Debug)]
1919
pub enum Target {
2020
ExternCrate,
2121
Use,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_errors::{pluralize, struct_span_err};
1313
use rustc_hir as hir;
1414
use rustc_hir::def_id::LocalDefId;
1515
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
16-
use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem};
16+
use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID};
1717
use rustc_hir::{MethodKind, Target};
1818
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1919
use rustc_session::parse::feature_err;
@@ -333,6 +333,17 @@ impl CheckAttrVisitor<'tcx> {
333333
.emit();
334334
return false;
335335
}
336+
if CRATE_HIR_ID == hir_id {
337+
self.tcx
338+
.sess
339+
.struct_span_err(
340+
meta.span(),
341+
"`#![doc(alias = \"...\")]` isn't allowed as a crate \
342+
level attribute",
343+
)
344+
.emit();
345+
return false;
346+
}
336347
}
337348
}
338349
}
@@ -811,6 +822,11 @@ fn is_c_like_enum(item: &Item<'_>) -> bool {
811822
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
812823
tcx.hir()
813824
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
825+
if module_def_id.is_top_level_module() {
826+
for attr in tcx.hir().krate_attrs() {
827+
CheckAttrVisitor { tcx }.check_doc_alias(attr, CRATE_HIR_ID, Target::Mod);
828+
}
829+
}
814830
}
815831

816832
pub(crate) fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)