Skip to content

Commit

Permalink
Avoid ICE on #![doc(test(...)] with literal parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
obeis committed May 29, 2023
1 parent 39c03fb commit 33eef82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ passes_doc_keyword_only_impl =
passes_doc_test_takes_list =
`#[doc(test(...)]` takes a list of attributes
passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
passes_doc_test_unknown =
unknown `doc(test)` attribute `{$path}`
Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,21 +944,28 @@ impl CheckAttrVisitor<'_> {
let mut is_valid = true;
if let Some(metas) = meta.meta_item_list() {
for i_meta in metas {
match i_meta.name_or_empty() {
sym::attr | sym::no_crate_inject => {}
_ => {
match (i_meta.name_or_empty(), i_meta.meta_item()) {
(sym::attr | sym::no_crate_inject, _) => {}
(_, Some(m)) => {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span(),
errors::DocTestUnknown {
path: rustc_ast_pretty::pprust::path_to_string(
&i_meta.meta_item().unwrap().path,
),
path: rustc_ast_pretty::pprust::path_to_string(&m.path),
},
);
is_valid = false;
}
(_, None) => {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span(),
errors::DocTestLiteral,
);
is_valid = false;
}
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ pub struct DocTestUnknown {
pub path: String,
}

#[derive(LintDiagnostic)]
#[diag(passes_doc_test_literal)]
pub struct DocTestLiteral;

#[derive(LintDiagnostic)]
#[diag(passes_doc_test_takes_list)]
pub struct DocTestTakesList;
Expand Down

0 comments on commit 33eef82

Please sign in to comment.