about summary refs log tree commit diff
path: root/src/librustdoc/passes/lint
AgeCommit message (Collapse)AuthorLines
2025-09-22fix ICE in rustdoc::invalid_html_tagsbinarycat-1/+2
2025-09-10Simplify code for `find_raw_urls`Guillaume Gomez-17/+11
2025-09-10Improve suggestion in case a bare URL is surrounded by bracketsGuillaume Gomez-13/+40
2025-08-21rustdoc::invalid_html_tags(unclosed comment): fix off by one in spanbinarycat-1/+1
2025-08-21refactor rustdoc::invalid_html_tags tag parserbinarycat-169/+380
previously, this lint did not distinguish between `<img` and `<img>`, and since the latter should be accepted under html5, the former was also accepted. the parser now also handles multi-line tags and multi-line attributes.
2025-07-19Fix clippy lints in librustdocGuillaume Gomez-8/+8
2025-06-23Improve code and documentationGuillaume Gomez-12/+22
2025-06-23Do not emit `redundant_explicit_links` rustdoc lint if the doc comment comes ↵Guillaume Gomez-17/+42
from expansion
2025-06-19Extract Translator structCameron Steffen-18/+10
2025-05-22rustdoc: improve diagnostics on raw doc fragmentsbinarycat-4/+8
1. rustdoc::bare_urls doesn't output invalid suggestions if source_span_for_markdown_range fails to find a span 2. source_span_for_markdown_range tries harder to return a span by applying an additional diagnostic fixes https://github.com/rust-lang/rust/issues/135851
2025-05-06rustdoc: remove unportable markdown lint and old parserMichael Howell-145/+0
Follow up https://github.com/rust-lang/rust/pull/127127
2025-03-06`librustdoc`: flatten nested ifsYotam Ofek-11/+11
2025-02-12Correctly escape hashtags when running `invalid_rust_codeblocks` lintGuillaume Gomez-1/+6
2025-02-08Rustfmtbjorn3-4/+5
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-5/+7
2024-12-06Store a single copy of the error registry in DiagCtxtbjorn3-1/+2
And pass this to the individual emitters when necessary.
2024-11-28Fix new clippy lintsGuillaume Gomez-98/+90
2024-10-07Convert `Option<&Lrc<T>>` return types to `Option<&T>`.Nicholas Nethercote-2/+2
It's simpler and more concise.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-10/+9
2024-09-04rustdoc: unify the short-circuit on all lintsMichael Howell-196/+157
This is a bit of an experiment to see if it improves perf.
2024-08-30Remove `#[macro_use] extern crate tracing` from rustdoc.Nicholas Nethercote-0/+1
2024-08-20Remove unneeded conversion to `DefId` for `ExtraInfo`Guillaume Gomez-2/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-27/+29
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-04Rollup merge of #127301 - estebank:fix-suggestions, r=UrgauMatthias Krüger-19/+17
Tweak some structured suggestions to be more verbose and accurate Addressing some issues I found while working on #127282. ``` error: this URL is not a hyperlink --> $DIR/auxiliary/include-str-bare-urls.md:1:11 | LL | HEADS UP! https://example.com MUST SHOW UP IN THE STDERR FILE! | ^^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here --> $DIR/include-str-bare-urls.rs:14:9 | LL | #![deny(rustdoc::bare_urls)] | ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead | LL | HEADS UP! <https://example.com> MUST SHOW UP IN THE STDERR FILE! | + + ``` ``` error[E0384]: cannot assign twice to immutable variable `v` --> $DIR/assign-imm-local-twice.rs:7:5 | LL | v = 1; | ----- first assignment to `v` LL | println!("v={}", v); LL | v = 2; | ^^^^^ cannot assign twice to immutable variable | help: consider making this binding mutable | LL | let mut v: isize; | +++ ``` ``` error[E0393]: the type parameter `Rhs` must be explicitly specified --> $DIR/issue-22560.rs:9:23 | LL | trait Sub<Rhs=Self> { | ------------------- type parameter `Rhs` must be specified for this ... LL | type Test = dyn Add + Sub; | ^^^ | = note: because of the default `Self` reference, type parameters must be specified on object types help: set the type parameter to the desired type | LL | type Test = dyn Add + Sub<Rhs>; | +++++ ``` ``` error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/issue-33819.rs:4:34 | LL | Some(ref v) => { let a = &mut v; }, | ^^^^^^ cannot borrow as mutable | help: try removing `&mut` here | LL - Some(ref v) => { let a = &mut v; }, LL + Some(ref v) => { let a = v; }, | ``` ``` help: remove the invocation before committing it to a version control system | LL - dbg!(); | ``` ``` error[E0308]: mismatched types --> $DIR/issue-39974.rs:1:21 | LL | const LENGTH: f64 = 2; | ^ expected `f64`, found integer | help: use a float literal | LL | const LENGTH: f64 = 2.0; | ++ ``` ``` error[E0529]: expected an array or slice, found `Vec<i32>` --> $DIR/match-ergonomics.rs:8:9 | LL | [&v] => {}, | ^^^^ pattern cannot match with input type `Vec<i32>` | help: consider slicing here | LL | match x[..] { | ++++ ``` ``` error[E0609]: no field `0` on type `[u32; 1]` --> $DIR/parenthesized-deref-suggestion.rs:10:21 | LL | (x as [u32; 1]).0; | ^ unknown field | help: instead of using tuple indexing, use array indexing | LL | (x as [u32; 1])[0]; | ~ + ```
2024-07-04Adjust rustdoc automatic link suggestionEsteban Küber-19/+17
Use more accurate spans for multipart suggestion.
2024-07-01rustdoc: add usable lint for pulldown-cmark-0.11 parsing changesMichael Howell-0/+152
2024-06-30rustdoc: update to pulldown-cmark 0.11Michael Howell-11/+15
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+2
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-3/+8
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
2024-06-05Reorder `source_str_to_stream` arguments.Nicholas Nethercote-1/+1
It's the only one of these functions where `psess` isn't the first argument.
2024-06-05Don't use the word "parse" for lexing operations.Nicholas Nethercote-8/+3
Lexing converts source text into a token stream. Parsing converts a token stream into AST fragments. This commit renames several lexing operations that have "parse" in the name. I think these names have been subtly confusing me for years. This is just a `s/parse/lex/` on function names, with one exception: `parse_stream_from_source_str` becomes `source_str_to_stream`, to make it consistent with the existing `source_file_to_stream`. The commit also moves that function's location in the file to be just above `source_file_to_stream`. The commit also cleans up a few comments along the way.
2024-06-01Auto merge of #124577 - ↵bors-3/+1
GuillaumeGomez:stabilize-custom_code_classes_in_docs, r=rustdoc Stabilize `custom_code_classes_in_docs` feature Fixes #79483. This feature has been around for quite some time now, I think it's fine to stabilize it now. ## Summary ## What is the feature about? In short, this PR changes two things, both related to codeblocks in doc comments in Rust documentation: * Allow to disable generation of `language-*` CSS classes with the `custom` attribute. * Add your own CSS classes to a code block so that you can use other tools to highlight them. #### The `custom` attribute Let's start with the new `custom` attribute: it will disable the generation of the `language-*` CSS class on the generated HTML code block. For example: ```rust /// ```custom,c /// int main(void) { /// return 0; /// } /// ``` ``` The generated HTML code block will not have `class="language-c"` because the `custom` attribute has been set. The `custom` attribute becomes especially useful with the other thing added by this feature: adding your own CSS classes. #### Adding your own CSS classes The second part of this feature is to allow users to add CSS classes themselves so that they can then add a JS library which will do it (like `highlight.js` or `prism.js`), allowing to support highlighting for other languages than Rust without increasing burden on rustdoc. To disable the automatic `language-*` CSS class generation, you need to use the `custom` attribute as well. This allow users to write the following: ```rust /// Some code block with `{class=language-c}` as the language string. /// /// ```custom,{class=language-c} /// int main(void) { /// return 0; /// } /// ``` fn main() {} ``` This will notably produce the following HTML: ```html <pre class="language-c"> int main(void) { return 0; }</pre> ``` Instead of: ```html <pre class="rust rust-example-rendered"> <span class="ident">int</span> <span class="ident">main</span>(<span class="ident">void</span>) { <span class="kw">return</span> <span class="number">0</span>; } </pre> ``` To be noted, we could have written `{.language-c}` to achieve the same result. `.` and `class=` have the same effect. One last syntax point: content between parens (`(like this)`) is now considered as comment and is not taken into account at all. In addition to this, I added an `unknown` field into `LangString` (the parsed code block "attribute") because of cases like this: ```rust /// ```custom,class:language-c /// main; /// ``` pub fn foo() {} ``` Without this `unknown` field, it would generate in the DOM: `<pre class="language-class:language-c language-c">`, which is quite bad. So instead, it now stores all unknown tags into the `unknown` field and use the first one as "language". So in this case, since there is no unknown tag, it'll simply generate `<pre class="language-c">`. I added tests to cover this. EDIT(camelid): This description is out-of-date. Using `custom,class:language-c` will generate the output `<pre class="language-class:language-c">` as would be expected; it treats `class:language-c` as just the name of a language (similar to the langstring `c` or `js` or what have you) since it does not use the designed class syntax. Finally, I added a parser for the codeblock attributes to make it much easier to maintain. It'll be pretty easy to extend. As to why this syntax for adding attributes was picked: it's [Pandoc's syntax](https://pandoc.org/MANUAL.html#extension-fenced_code_attributes). Even if it seems clunkier in some cases, it's extensible, and most third-party Markdown renderers are smart enough to ignore Pandoc's brace-delimited attributes (from [this comment](https://github.com/rust-lang/rust/pull/110800#issuecomment-1522044456)). r? `@notriddle`
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-20/+77
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-01Stabilize `custom_code_classes_in_docs` featureGuillaume Gomez-3/+1
2024-04-13rustdoc: check redundant explicit links with correct itemidMichael Howell-11/+8
Fixes a regression caused by 0a50dba50bedd24377bd1066da3b4b7066df4d28
2024-03-28Correctly get complete intra-doc link dataGuillaume Gomez-1/+12
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-2/+2
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2024-02-29Rename `DiagCtxt::with_emitter` as `DiagCtxt::new`.Nicholas Nethercote-1/+1
Because it's now the only constructor.
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-2/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-28Rename `Diagnostic` as `DiagInner`.Nicholas Nethercote-2/+2
I started by changing it to `DiagData`, but that didn't feel right. `DiagInner` felt much better.
2024-02-22Overhaul `Diagnostic` args.Nicholas Nethercote-1/+1
First, introduce a typedef `DiagnosticArgMap`. Second, make the `args` field public, and remove the `args` getter and `replace_args` setter. These were necessary previously because the getter had a `#[allow(rustc::potential_query_instability)]` attribute, but that was removed in #120931 when the args were changed from `FxHashMap` to `FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-07docs: also check the inline stmt during redundant link checkbohan-17/+32
2024-02-05Make `Emitter::emit_diagnostic` consuming.Nicholas Nethercote-1/+1
All the other `emit`/`emit_diagnostic` methods were recently made consuming (e.g. #119606), but this one wasn't. But it makes sense to. Much of this is straightforward, and lots of `clone` calls are avoided. There are a couple of tricky bits. - `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and returns a pair. Instead it takes the two fields from `Diagnostic` that it used (`span` and `suggestions`) as `&mut`, and modifies them. This is necessary to avoid the cloning of `diag.children` in two emitters. - `from_errors_diagnostic` is rearranged so various uses of `diag` occur before the consuming `emit_diagnostic` call.
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-6/+6
2024-01-05rustc_span: Remove `fn fresh_expansion`Vadim Petrochenkov-2/+2
In the past it did create a fresh expansion, but now, after surviving a number of refactorings, it does not. Now it's just a thin wrapper around `apply_mark`.
2024-01-04compiler: fix typosvuittont60-1/+1
librustdoc: fix typos
2023-12-23Improve some names.Nicholas Nethercote-1/+1
Lots of vectors of messages called `message` or `msg`. This commit pluralizes them. Note that `emit_message_default` and `emit_messages_default` both already existed, and both process a vector, so I renamed the former `emit_messages_default_inner` because it's called by the latter.
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-2/+2
2023-12-18Rename `ParseSess::with_span_handler` as `ParseSess::with_dcx`.Nicholas Nethercote-1/+1
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-2/+2