Skip to content

Commit 129a57a

Browse files
authored
Rollup merge of #112081 - obeis:doc-test-literal, r=compiler-errors
Avoid ICE on `#![doc(test(...)]` with literal parameter Close #109066 r? `@compiler-errors`
2 parents 408bbd0 + 70bbcce commit 129a57a

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

compiler/rustc_passes/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ passes_doc_keyword_not_mod =
211211
passes_doc_keyword_only_impl =
212212
`#[doc(keyword = "...")]` should be used on impl blocks
213213
214+
passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
215+
214216
passes_doc_test_takes_list =
215217
`#[doc(test(...)]` takes a list of attributes
216218

compiler/rustc_passes/src/check_attr.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -944,21 +944,28 @@ impl CheckAttrVisitor<'_> {
944944
let mut is_valid = true;
945945
if let Some(metas) = meta.meta_item_list() {
946946
for i_meta in metas {
947-
match i_meta.name_or_empty() {
948-
sym::attr | sym::no_crate_inject => {}
949-
_ => {
947+
match (i_meta.name_or_empty(), i_meta.meta_item()) {
948+
(sym::attr | sym::no_crate_inject, _) => {}
949+
(_, Some(m)) => {
950950
self.tcx.emit_spanned_lint(
951951
INVALID_DOC_ATTRIBUTES,
952952
hir_id,
953953
i_meta.span(),
954954
errors::DocTestUnknown {
955-
path: rustc_ast_pretty::pprust::path_to_string(
956-
&i_meta.meta_item().unwrap().path,
957-
),
955+
path: rustc_ast_pretty::pprust::path_to_string(&m.path),
958956
},
959957
);
960958
is_valid = false;
961959
}
960+
(_, None) => {
961+
self.tcx.emit_spanned_lint(
962+
INVALID_DOC_ATTRIBUTES,
963+
hir_id,
964+
i_meta.span(),
965+
errors::DocTestLiteral,
966+
);
967+
is_valid = false;
968+
}
962969
}
963970
}
964971
} else {

compiler/rustc_passes/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ pub struct DocTestUnknown {
281281
pub path: String,
282282
}
283283

284+
#[derive(LintDiagnostic)]
285+
#[diag(passes_doc_test_literal)]
286+
pub struct DocTestLiteral;
287+
284288
#[derive(LintDiagnostic)]
285289
#[diag(passes_doc_test_takes_list)]
286290
pub struct DocTestTakesList;
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![deny(warnings)]
2+
3+
#![doc(test(""))]
4+
//~^ ERROR `#![doc(test(...)]` does not take a literal
5+
//~^^ WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: `#![doc(test(...)]` does not take a literal
2+
--> $DIR/doc-test-literal.rs:3:13
3+
|
4+
LL | #![doc(test(""))]
5+
| ^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
9+
note: the lint level is defined here
10+
--> $DIR/doc-test-literal.rs:1:9
11+
|
12+
LL | #![deny(warnings)]
13+
| ^^^^^^^^
14+
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
15+
16+
error: aborting due to previous error
17+

0 commit comments

Comments
 (0)