diff options
| author | Obei Sideg <obei.sideg@gmail.com> | 2023-05-29 22:29:50 +0300 |
|---|---|---|
| committer | Obei Sideg <obei.sideg@gmail.com> | 2023-05-29 22:29:50 +0300 |
| commit | 33eef8221db63c6871f5c1957521b40e65eb3c5d (patch) | |
| tree | aff79410e6ca45bb15f2cf3aa0ea1068c5daf191 | |
| parent | 39c03fb65268e3331f381714c664a581a6e86b8c (diff) | |
| download | rust-33eef8221db63c6871f5c1957521b40e65eb3c5d.tar.gz rust-33eef8221db63c6871f5c1957521b40e65eb3c5d.zip | |
Avoid ICE on `#![doc(test(...)]` with literal parameter
| -rw-r--r-- | compiler/rustc_passes/messages.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 4 |
3 files changed, 19 insertions, 6 deletions
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 7f9222dac6c..139df68bb63 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -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}` diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index c3189d1fefe..c35c7da2664 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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 { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 99fc69d1bec..ae624dbc9c9 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -282,6 +282,10 @@ pub struct DocTestUnknown { } #[derive(LintDiagnostic)] +#[diag(passes_doc_test_literal)] +pub struct DocTestLiteral; + +#[derive(LintDiagnostic)] #[diag(passes_doc_test_takes_list)] pub struct DocTestTakesList; |
