rust/src/librustdoc
Nicholas Nethercote 6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
..
clean Rollup merge of #110631 - notriddle:notriddle/impl-trait-cycle, r=GuillaumeGomez 2023-04-30 16:25:46 +02:00
doctest pass unused_extern_crates in librustdoc::doctest::make_test 2023-04-25 17:20:58 +03:00
formats fix clippy::toplevel_ref_arg and ::manual_map 2023-04-16 13:28:13 +02:00
html Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
json Unify attributes retrieval for JSON and HTML rendering 2023-04-29 23:36:48 +02:00
passes Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
theme Spelling librustdoc 2023-04-16 21:44:12 -04:00
askama.toml Remove unneeded minus sign in jinja tags 2023-03-06 11:38:15 +01:00
Cargo.toml rustdoc: DocFS: Replace rayon with threadpool and enable it for all targets 2023-03-14 20:28:00 +01:00
config.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
core.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
docfs.rs Update docsfs module documentation 2023-03-15 16:47:14 +01:00
doctest.rs handle cfg(bootstrap) 2023-04-28 08:47:55 -07:00
error.rs Remove crate visibility modifier in libs, tests 2022-05-21 00:32:47 -04:00
externalfiles.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
fold.rs clean: Always store enum disriminant. 2023-01-01 18:11:53 +00:00
lib.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
lint.rs Add rustdoc::unescaped_backtick lint 2023-04-29 13:13:25 +02:00
markdown.rs Turn MarkdownWithToc into a struct with named fields 2023-02-06 16:31:17 +01:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
scrape_examples.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
theme.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
visit.rs clean: Always store enum disriminant. 2023-01-01 18:11:53 +00:00
visit_ast.rs Rollup merge of #110450 - GuillaumeGomez:fix-nested-items-on-private-doc, r=notriddle,jyn514 2023-04-18 06:44:47 +02:00
visit_lib.rs rustdoc: Eliminate remaining uses of resolver 2023-02-13 00:10:15 +04:00

For more information about how librustdoc works, see the rustc dev guide.