Skip to content

Commit fc00bb8

Browse files
Fix ui tests
1 parent 81530be commit fc00bb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+727
-305
lines changed

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::lints::AttributeLintKind;
1010
use rustc_span::{Span, Symbol, edition, sym};
1111
use thin_vec::ThinVec;
1212

13-
use super::prelude::{Allow, AllowedTargets, MethodKind, Target};
13+
use super::prelude::{Allow, AllowedTargets, Error, MethodKind, Target};
1414
use super::{AcceptMapping, AttributeParser};
1515
use crate::context::{AcceptContext, FinalizeContext, Stage};
1616
use crate::fluent_generated as fluent;
@@ -459,7 +459,9 @@ impl DocParser {
459459
) {
460460
match args {
461461
ArgParser::NoArgs => {
462-
todo!()
462+
let suggestions = cx.suggestions();
463+
let span = cx.attr_span;
464+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
463465
}
464466
ArgParser::List(items) => {
465467
for i in items.mixed() {
@@ -493,12 +495,41 @@ impl DocParser {
493495
impl<S: Stage> AttributeParser<S> for DocParser {
494496
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
495497
&[sym::doc],
496-
template!(List: &["hidden", "inline", "test"], NameValueStr: "string"),
498+
template!(
499+
List: &[
500+
"alias",
501+
"attribute",
502+
"hidden",
503+
"html_favicon_url",
504+
"html_logo_url",
505+
"html_no_source",
506+
"html_playground_url",
507+
"html_root_url",
508+
"issue_tracker_base_url",
509+
"inline",
510+
"no_inline",
511+
"masked",
512+
"cfg",
513+
"notable_trait",
514+
"keyword",
515+
"fake_variadic",
516+
"search_unbox",
517+
"rust_logo",
518+
"auto_cfg",
519+
"test",
520+
"spotlight",
521+
"include",
522+
"no_default_passes",
523+
"passes",
524+
"plugins",
525+
],
526+
NameValueStr: "string"
527+
),
497528
|this, cx, args| {
498529
this.accept_single_doc_attr(cx, args);
499530
},
500531
)];
501-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
532+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
502533
Allow(Target::ExternCrate),
503534
Allow(Target::Use),
504535
Allow(Target::Static),
@@ -527,6 +558,7 @@ impl<S: Stage> AttributeParser<S> for DocParser {
527558
Allow(Target::ForeignTy),
528559
Allow(Target::MacroDef),
529560
Allow(Target::Crate),
561+
Error(Target::WherePredicate),
530562
]);
531563

532564
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
346346
continue;
347347
}
348348

349-
let path = parser.path();
350349
for accept in accepts {
351350
let mut cx: AcceptContext<'_, 'sess, S> = AcceptContext {
352351
shared: SharedContext {

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<L::Id>, lint_emi
3333
}
3434
AttributeLintKind::DuplicateDocAlias { first_definition } => {
3535
lint_emitter.emit_node_span_lint(
36-
rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT,
36+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
3737
*id,
3838
*span,
3939
session_diagnostics::DocAliasDuplicated { first_defn: *first_definition },

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21772177
continue;
21782178
}
21792179

2180-
if attr.is_doc_comment() {
2180+
if attr.doc_str_and_fragment_kind().is_some() {
21812181
self.cx.sess.psess.buffer_lint(
21822182
UNUSED_DOC_COMMENTS,
21832183
current_span,

compiler/rustc_lint/src/builtin.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,19 +813,23 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
813813
let mut sugared_span: Option<Span> = None;
814814

815815
while let Some(attr) = attrs.next() {
816-
let is_doc_comment = attr.is_doc_comment();
816+
let (is_doc_comment, is_doc_attribute) = match &attr.kind {
817+
AttrKind::DocComment(..) => (true, false),
818+
AttrKind::Normal(normal) if normal.item.path == sym::doc => (true, true),
819+
_ => (false, false),
820+
};
817821
if is_doc_comment {
818822
sugared_span =
819823
Some(sugared_span.map_or(attr.span, |span| span.with_hi(attr.span.hi())));
820824
}
821825

822-
if attrs.peek().is_some_and(|next_attr| next_attr.is_doc_comment()) {
826+
if !is_doc_attribute && attrs.peek().is_some_and(|next_attr| next_attr.is_doc_comment()) {
823827
continue;
824828
}
825829

826830
let span = sugared_span.take().unwrap_or(attr.span);
827831

828-
if is_doc_comment {
832+
if is_doc_comment || is_doc_attribute {
829833
let sub = match attr.kind {
830834
AttrKind::DocComment(CommentKind::Line, _) | AttrKind::Normal(..) => {
831835
BuiltinUnusedDocCommentSub::PlainHelp

compiler/rustc_passes/src/check_attr.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,25 +1029,27 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10291029
}
10301030
}
10311031

1032-
if let Some((_, span)) = keyword {
1033-
self.check_attr_not_crate_level(*span, hir_id, "keyword");
1032+
if let Some((_, span)) = keyword
1033+
&& self.check_attr_not_crate_level(*span, hir_id, "keyword")
1034+
{
10341035
self.check_doc_keyword_and_attribute(*span, hir_id, "keyword");
10351036
}
1036-
if let Some((_, span)) = attribute {
1037-
self.check_attr_not_crate_level(*span, hir_id, "attribute");
1037+
if let Some((_, span)) = attribute
1038+
&& self.check_attr_not_crate_level(*span, hir_id, "attribute")
1039+
{
10381040
self.check_doc_keyword_and_attribute(*span, hir_id, "attribute");
10391041
}
10401042

1041-
if let Some(span) = fake_variadic {
1042-
if self.check_attr_not_crate_level(*span, hir_id, "fake_variadic") {
1043-
self.check_doc_fake_variadic(*span, hir_id);
1044-
}
1043+
if let Some(span) = fake_variadic
1044+
&& self.check_attr_not_crate_level(*span, hir_id, "fake_variadic")
1045+
{
1046+
self.check_doc_fake_variadic(*span, hir_id);
10451047
}
10461048

1047-
if let Some(span) = search_unbox {
1048-
if self.check_attr_not_crate_level(*span, hir_id, "search_unbox") {
1049-
self.check_doc_search_unbox(*span, hir_id);
1050-
}
1049+
if let Some(span) = search_unbox
1050+
&& self.check_attr_not_crate_level(*span, hir_id, "search_unbox")
1051+
{
1052+
self.check_doc_search_unbox(*span, hir_id);
10511053
}
10521054

10531055
for i in [
@@ -1070,18 +1072,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10701072

10711073
self.check_doc_inline(hir_id, target, inline);
10721074

1073-
if let Some(span) = rust_logo {
1074-
if self.check_attr_crate_level(*span, hir_id)
1075-
&& !self.tcx.features().rustdoc_internals()
1076-
{
1077-
feature_err(
1078-
&self.tcx.sess,
1079-
sym::rustdoc_internals,
1080-
*span,
1081-
fluent::passes_doc_rust_logo,
1082-
)
1083-
.emit();
1084-
}
1075+
if let Some(span) = rust_logo
1076+
&& self.check_attr_crate_level(*span, hir_id)
1077+
&& !self.tcx.features().rustdoc_internals()
1078+
{
1079+
feature_err(
1080+
&self.tcx.sess,
1081+
sym::rustdoc_internals,
1082+
*span,
1083+
fluent::passes_doc_rust_logo,
1084+
)
1085+
.emit();
10851086
}
10861087

10871088
if let Some(span) = masked {
@@ -1984,7 +1985,14 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
19841985
.hir_attrs(where_predicate.hir_id)
19851986
.iter()
19861987
.filter(|attr| !ATTRS_ALLOWED.iter().any(|&sym| attr.has_name(sym)))
1987-
.filter(|attr| !attr.is_parsed_attr())
1988+
// FIXME: We shouldn't need to special-case `doc`!
1989+
.filter(|attr| {
1990+
matches!(
1991+
attr,
1992+
Attribute::Parsed(AttributeKind::DocComment { .. } | AttributeKind::Doc(_))
1993+
| Attribute::Unparsed(_)
1994+
)
1995+
})
19881996
.map(|attr| attr.span())
19891997
.collect::<Vec<_>>();
19901998
if !spans.is_empty() {

tests/rustdoc-ui/bad-render-options.stderr

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ LL - #![doc(html_favicon_url)]
1212
LL + #![doc = "string"]
1313
|
1414
LL - #![doc(html_favicon_url)]
15-
LL + #![doc(hidden)]
15+
LL + #![doc(alias)]
1616
|
1717
LL - #![doc(html_favicon_url)]
18-
LL + #![doc(inline)]
18+
LL + #![doc(attribute)]
1919
|
2020
LL - #![doc(html_favicon_url)]
21-
LL + #![doc(test)]
21+
LL + #![doc(auto_cfg)]
2222
|
23+
= and 21 other candidates
2324

2425
error[E0539]: malformed `doc` attribute input
2526
--> $DIR/bad-render-options.rs:6:1
@@ -35,14 +36,15 @@ LL - #![doc(html_logo_url)]
3536
LL + #![doc = "string"]
3637
|
3738
LL - #![doc(html_logo_url)]
38-
LL + #![doc(hidden)]
39+
LL + #![doc(alias)]
3940
|
4041
LL - #![doc(html_logo_url)]
41-
LL + #![doc(inline)]
42+
LL + #![doc(attribute)]
4243
|
4344
LL - #![doc(html_logo_url)]
44-
LL + #![doc(test)]
45+
LL + #![doc(auto_cfg)]
4546
|
47+
= and 21 other candidates
4648

4749
error[E0539]: malformed `doc` attribute input
4850
--> $DIR/bad-render-options.rs:9:1
@@ -58,14 +60,15 @@ LL - #![doc(html_playground_url)]
5860
LL + #![doc = "string"]
5961
|
6062
LL - #![doc(html_playground_url)]
61-
LL + #![doc(hidden)]
63+
LL + #![doc(alias)]
6264
|
6365
LL - #![doc(html_playground_url)]
64-
LL + #![doc(inline)]
66+
LL + #![doc(attribute)]
6567
|
6668
LL - #![doc(html_playground_url)]
67-
LL + #![doc(test)]
69+
LL + #![doc(auto_cfg)]
6870
|
71+
= and 21 other candidates
6972

7073
error[E0539]: malformed `doc` attribute input
7174
--> $DIR/bad-render-options.rs:12:1
@@ -81,14 +84,15 @@ LL - #![doc(issue_tracker_base_url)]
8184
LL + #![doc = "string"]
8285
|
8386
LL - #![doc(issue_tracker_base_url)]
84-
LL + #![doc(hidden)]
87+
LL + #![doc(alias)]
8588
|
8689
LL - #![doc(issue_tracker_base_url)]
87-
LL + #![doc(inline)]
90+
LL + #![doc(attribute)]
8891
|
8992
LL - #![doc(issue_tracker_base_url)]
90-
LL + #![doc(test)]
93+
LL + #![doc(auto_cfg)]
9194
|
95+
= and 21 other candidates
9296

9397
error[E0539]: malformed `doc` attribute input
9498
--> $DIR/bad-render-options.rs:15:1
@@ -104,14 +108,15 @@ LL - #![doc(html_favicon_url = 1)]
104108
LL + #![doc = "string"]
105109
|
106110
LL - #![doc(html_favicon_url = 1)]
107-
LL + #![doc(hidden)]
111+
LL + #![doc(alias)]
108112
|
109113
LL - #![doc(html_favicon_url = 1)]
110-
LL + #![doc(inline)]
114+
LL + #![doc(attribute)]
111115
|
112116
LL - #![doc(html_favicon_url = 1)]
113-
LL + #![doc(test)]
117+
LL + #![doc(auto_cfg)]
114118
|
119+
= and 22 other candidates
115120

116121
error[E0539]: malformed `doc` attribute input
117122
--> $DIR/bad-render-options.rs:18:1
@@ -127,14 +132,15 @@ LL - #![doc(html_logo_url = 2)]
127132
LL + #![doc = "string"]
128133
|
129134
LL - #![doc(html_logo_url = 2)]
130-
LL + #![doc(hidden)]
135+
LL + #![doc(alias)]
131136
|
132137
LL - #![doc(html_logo_url = 2)]
133-
LL + #![doc(inline)]
138+
LL + #![doc(attribute)]
134139
|
135140
LL - #![doc(html_logo_url = 2)]
136-
LL + #![doc(test)]
141+
LL + #![doc(auto_cfg)]
137142
|
143+
= and 22 other candidates
138144

139145
error[E0539]: malformed `doc` attribute input
140146
--> $DIR/bad-render-options.rs:21:1
@@ -150,14 +156,15 @@ LL - #![doc(html_playground_url = 3)]
150156
LL + #![doc = "string"]
151157
|
152158
LL - #![doc(html_playground_url = 3)]
153-
LL + #![doc(hidden)]
159+
LL + #![doc(alias)]
154160
|
155161
LL - #![doc(html_playground_url = 3)]
156-
LL + #![doc(inline)]
162+
LL + #![doc(attribute)]
157163
|
158164
LL - #![doc(html_playground_url = 3)]
159-
LL + #![doc(test)]
165+
LL + #![doc(auto_cfg)]
160166
|
167+
= and 22 other candidates
161168

162169
error[E0539]: malformed `doc` attribute input
163170
--> $DIR/bad-render-options.rs:24:1
@@ -173,14 +180,15 @@ LL - #![doc(issue_tracker_base_url = 4)]
173180
LL + #![doc = "string"]
174181
|
175182
LL - #![doc(issue_tracker_base_url = 4)]
176-
LL + #![doc(hidden)]
183+
LL + #![doc(alias)]
177184
|
178185
LL - #![doc(issue_tracker_base_url = 4)]
179-
LL + #![doc(inline)]
186+
LL + #![doc(attribute)]
180187
|
181188
LL - #![doc(issue_tracker_base_url = 4)]
182-
LL + #![doc(test)]
189+
LL + #![doc(auto_cfg)]
183190
|
191+
= and 22 other candidates
184192

185193
error[E0565]: malformed `doc` attribute input
186194
--> $DIR/bad-render-options.rs:27:1
@@ -196,14 +204,15 @@ LL - #![doc(html_no_source = "asdf")]
196204
LL + #![doc = "string"]
197205
|
198206
LL - #![doc(html_no_source = "asdf")]
199-
LL + #![doc(hidden)]
207+
LL + #![doc(alias)]
200208
|
201209
LL - #![doc(html_no_source = "asdf")]
202-
LL + #![doc(inline)]
210+
LL + #![doc(attribute)]
203211
|
204212
LL - #![doc(html_no_source = "asdf")]
205-
LL + #![doc(test)]
213+
LL + #![doc(auto_cfg)]
206214
|
215+
= and 22 other candidates
207216

208217
error: aborting due to 9 previous errors
209218

0 commit comments

Comments
 (0)