about summary refs log tree commit diff
path: root/src/librustdoc/html/sources.rs
AgeCommit message (Collapse)AuthorLines
2023-11-15Re-format code with new rustfmtMark Rousskov-2/+6
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-2/+1
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-17[RFC 3127 - Trim Paths]: Fix building tools (rustdoc, clippy, ...)Urgau-1/+2
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+3
2023-09-03Use relative positions inside a SourceFile.Camille GILLOT-1/+1
2023-08-16Use more named format argsGuillaume Gomez-2/+2
2023-08-16Improve code readability by moving fmt args directly into the stringGuillaume Gomez-2/+1
2023-07-14rustdoc: use `src` consistently over `source` in codeMichael Howell-1/+1
The CSS uses an inconsistent mix of both. This commit switches it to always use `src`.
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
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-04-03rustdoc: migrate document functions to return a DisplayMichael Howell-3/+3
2023-03-23Rollup merge of #109187 - clubby789:askama-source, r=GuillaumeGomezDylan DPC-31/+27
Render source page layout with Askama ~~I was looking at making `code_html` render into the buffer instead of in advance, but it turned out to need a pretty big refactor, so starting with rearranging the high-level layout.~~ Found another approach which required much less changes cc #108868
2023-03-16clean up few allocklensy-1/+1
2023-03-16Render source page layout with Askamaclubby789-31/+27
Co-authored-by: Michael Howell <michael@notriddle.com>
2023-01-30rustdoc: remove meta keywords from HTMLMichael Howell-2/+1
Discussed in <https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.60.3Cmeta.20name.3D.22keywords.22.3E.60>
2023-01-06Correctly render sidebar for relative module pathsclubby789-16/+44
2022-12-10Clean up lifetimes in rustdoc syntax highlightingNilstrieb-1/+1
Removes a few lifetimes and renames some.
2022-11-19rustdoc: use real buttons for scrape examples controlsMichael Howell-2/+5
2022-11-12rustdoc: avoid excessive HTML generated in example sourcesMichael Howell-5/+5
2022-10-31rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a`Michael Howell-10/+11
This allows people to treat them like real links, such as right-click to copy URL, and makes the line numbers in a scraped example work at all, when before this commit was added, they had the clickable pointer cursor but did not actually do anything when clicked.
2022-10-29Fix z-indexes of code example feature and cleanup its CSSGuillaume Gomez-2/+7
2022-09-26rustdoc: give `.line-number` / `.line-numbers` meaningful namesMichael Howell-1/+1
2022-09-15rustdoc: use more precise URLs for jump-to-definition linksMichael Howell-1/+4
As an example, this cuts down <https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/mod.rs.html> by about 11%. $ du -h new_mod.rs.html old_mod.rs.html 296K new_mod.rs.html 332K old_mod.rs.html
2022-08-13make clean::Item::span return option instead of dummy spanMichael Goulet-0/+2
2022-08-09rustdoc: simplify highlight.rsJacob Hoffman-Andrews-12/+5
Split render_with_highlighting, which took many optional parameters, into three functions for specific purposes, which each take a smaller number of mostly required parameters. Remove some plumbing to pass through an "edition" parameter, which was used solely to avoid highlighting some 2021 Edition keywords in non-2021 code.
2022-06-24Rollup merge of #91264 - GuillaumeGomez:macro-jump-to-def, r=jshaYuki Okushi-1/+1
Add macro support in jump to definition feature Fixes #91174. To do so, I check if the span comes from an expansion, and if so, I infer the original macro `DefId` or `Span` depending if it's a defined in the current crate or not. There is one limitation due to macro expansion though: ```rust macro_rules! yolo { () => {}} fn foo() { yolo!(); } ``` In `foo`, `yolo!` won't be linked because after expansion, it is replaced by nothing (which seems logical). So I can't get an item from the `Visitor` from which I could tell if its `Span` comes from an expansion. I added a test for this specific limitation alongside others. Demo: https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html As for the empty macro issue that cannot create a jump to definition, you can see it [here](https://rustdoc.crud.net/imperio/macro-jump-to-def/src/foo/check-source-code-urls-to-def-std.rs.html#35). r? ```@jyn514```
2022-06-20Improve loading of crates.js and sidebar-items.jsJacob Hoffman-Andrews-2/+0
Now that the "All Crates" dropdown is only rendered on the search results page, there is no need to load crates.js on most pages. Load it only on crate pages. Also, add the `defer` attribute so it does not block page rendering. For sidebar-items.js, move the script tag to `<head>`. Since it already has the defer attribute it won't block loading. The defer attribute does preserve ordering between scripts, so instead of the callback on load, it can set a global variable on load, which is slightly simpler. Also, since it is required to finish rendering the page, beginning its load earlier is better. Remove generation and handling of sidebar-vars. Everything there can be computed with information available in JS via other means. Remove the "other" wrapper in the sidebar. It was unnecessary. Remove excess script fields
2022-06-20Rename ContextInfo into HrefContextGuillaume Gomez-1/+1
2022-05-27Pass Context as a &mut to allow to remove RefCell fieldsGuillaume Gomez-11/+16
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-5/+5
2022-03-07Remove unneeded whitespace generation and use CSS instead instead to align ↵Guillaume Gomez-8/+2
line numbers to the right
2022-01-10Migrate rustdoc from Tera to AskamaDirkjan Ochtman-1/+0
See #84419.
2021-12-28remove in_band_lifetimes from librustdocMichael Goulet-1/+1
2021-12-21Move pattern matching outside of the loopGuillaume Gomez-6/+8
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-1/+1
2021-10-31rustdoc: Small micro-optimizations and cleanupsNoah Lev-7/+8
* Flip conjuncts of `&&` in rustdoc The `CrateNum` comparison should be very cheap, while `span.filename()` fetches and clones a `FileName`. * Use `into_local_path()` instead of `local_path().clone()`
2021-10-31Fix FIXMEs in `rustdoc::html::sources`Noah Lev-5/+6
One of the FIXMEs is irrelevant since that code is only run if `include_sources` is set. I fixed the other FIXME.
2021-10-31Clean up now that visitors only need `&clean::Crate`Noah Lev-7/+7
2021-10-31rustdoc: Use `DocVisitor` for sources collectionNoah Lev-12/+14
2021-10-30rustdoc: Remove `Crate.name` and instead compute it on-demandNoah Lev-1/+1
It is not as large as `Crate.src` was, but it's still 8 bytes, and `clean::Crate` is moved by-value a lot.
2021-10-25Fix clippy lints in librustdocGuillaume Gomez-3/+3
2021-10-07Move some expansion logic into generation-time, fix section header links, ↵Will Crichton-4/+15
remove ID from line numbers, fix horizontal scrolling on non-expanded elements
2021-10-06Move highlighting logic from JS to RustWill Crichton-0/+3
Continue migrating JS functionality Cleanup Fix compile error Clean up the diff Set toggle font to sans-serif
2021-10-06Generate example source files with corresponding linksWill Crichton-2/+12
Add display name Fix remaining merge conflicts Only embed code for items containing examples
2021-10-06Add updated support for example-analyzerWill Crichton-1/+1
Move rendering of examples into Finalize design Cleanup, rename found -> scraped Softer yellow Clean up dead code Document scrape_examples More simplification and documentation Remove extra css Test
2021-09-16Auto merge of #88219 - jyn514:parallel-io, r=GuillaumeGomezbors-1/+1
rustdoc: reduce number of copies when using parallel IO This is Windows-only for now; I was getting really bad slowdowns from this on linux for some reason. Helps with https://github.com/rust-lang/rust/issues/82741. Follow-up to https://github.com/rust-lang/rust/pull/60971.
2021-08-31some low hanging clippy::perf fixesMatthias Krüger-4/+3
2021-08-26Remove unnecessary copies when using parallel IOJoshua Nelson-1/+1
Previously, rustdoc was making lots of copies of temporary owned values. Now, it uses the owned value wherever possible.
2021-08-05Remove LightSpan and use Span directlyGuillaume Gomez-13/+11
2021-08-05Move extra arguments for highlight URL generation into a new ContextInfo ↵Guillaume Gomez-3/+1
struct for better readability
2021-08-05Add links on source types to go to definitionGuillaume Gomez-45/+131