Commit Graph

233963 Commits

Author SHA1 Message Date
bors
d7229c479c Auto merge of #113753 - dvdsk:master, r=dtolnay
Add implementation for thread::sleep_until

- Feature gate is `thread::sleep_until`
- Tracking issue is: #113752
- APC: https://github.com/rust-lang/libs-team/issues/237
2023-09-17 00:02:45 +00:00
bors
7d9bce3273 Auto merge of #115900 - matthiaskrgr:rollup-3ba15da, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115247 (Document std limitations before/after main)
 - #115329 (fix std::primitive doc: homogenous -> homogeneous)
 - #115487 (Improve documentation on when signes are printed by default)
 - #115560 (Update doc for `alloc::format!` and `core::concat!`)
 - #115836 (update rust_analyzer_settings.json)
 - #115884 (make ty::Const debug printing less verbose)
 - #115890 (Migrate GUI colors test to original CSS color format)
 - #115895 (Improve Vec(Deque)::truncate documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-16 22:09:02 +00:00
Matthias Krüger
e2ea347517
Rollup merge of #115895 - 52:patch-docs-vec-truncate, r=dtolnay
Improve Vec(Deque)::truncate documentation

Fixes #115784
2023-09-16 23:20:43 +02:00
Matthias Krüger
5a8179bf5a
Rollup merge of #115890 - GuillaumeGomez:migrate-gui-test-color-41, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-09-16 23:20:42 +02:00
Matthias Krüger
abae2b66e8
Rollup merge of #115884 - RalfJung:const-debug-print, r=oli-obk
make ty::Const debug printing less verbose

Similar in spirit to https://github.com/rust-lang/rust/pull/115873
2023-09-16 23:20:42 +02:00
Matthias Krüger
edea0d5179
Rollup merge of #115836 - RalfJung:rust_analyzer_settings.json, r=compiler-errors
update rust_analyzer_settings.json

This works around https://github.com/rust-lang/rust-analyzer/issues/15595, and avoids relying on the unspecified working directory of this command.
2023-09-16 23:20:41 +02:00
Matthias Krüger
633f143921
Rollup merge of #115560 - ShE3py:format-results, r=dtolnay
Update doc for `alloc::format!` and `core::concat!`

Closes #115551.

Used comments instead of `assert!`s as [`std::fmt`](https://doc.rust-lang.org/std/fmt/index.html#usage) uses comments.

Should all the str-related macros (`format!`, `format_args!`, `concat!`, `stringify!`, `println!`, `writeln!`, etc.) references each others? For instance, [`concat!`](https://doc.rust-lang.org/core/macro.concat.html) mentions that integers are stringified, but don't link to `stringify!`.

`@rustbot` label +A-docs +A-fmt
2023-09-16 23:20:41 +02:00
Matthias Krüger
b8c4b78a79
Rollup merge of #115487 - ModProg:patch-1, r=dtolnay
Improve documentation on when signes are printed by default

I found the original formulation a bit irritating, but not sure if I really improved it.
2023-09-16 23:20:40 +02:00
Matthias Krüger
edfe8b4434
Rollup merge of #115329 - xzmeng:fix-std-doc, r=dtolnay
fix std::primitive doc: homogenous -> homogeneous

replace "homogenous" with the more commonly used "homogeneous".
2023-09-16 23:20:39 +02:00
Matthias Krüger
cf9ce96a5b
Rollup merge of #115247 - the8472:life-before-main, r=dtolnay
Document std limitations before/after main

Solves #110708
2023-09-16 23:20:39 +02:00
bors
341ef15eee Auto merge of #115733 - Zoxc:group-dep-node-kinds, r=cjgillot
Store a index per dep node kind

This stores an index map per dep node kind instead of using a single index map. This avoids storing `DepKind` in the key for greater cache efficiency.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th><td align="right">Memory</td><td align="right">Memory</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:unchanged</td><td align="right">0.4376s</td><td align="right">0.4334s</td><td align="right"> -0.95%</td><td align="right">92.53 MiB</td><td align="right">92.39 MiB</td><td align="right"> -0.15%</td></tr><tr><td>🟣 <b>hyper</b>:check:unchanged</td><td align="right">0.1442s</td><td align="right">0.1446s</td><td align="right"> 0.29%</td><td align="right">47.48 MiB</td><td align="right">47.63 MiB</td><td align="right"> 0.31%</td></tr><tr><td>🟣 <b>regex</b>:check:unchanged</td><td align="right">0.3296s</td><td align="right">0.3261s</td><td align="right">💚  -1.06%</td><td align="right">72.37 MiB</td><td align="right">71.20 MiB</td><td align="right">💚  -1.62%</td></tr><tr><td>🟣 <b>syn</b>:check:unchanged</td><td align="right">0.6149s</td><td align="right">0.6014s</td><td align="right">💚  -2.19%</td><td align="right">105.74 MiB</td><td align="right">101.69 MiB</td><td align="right">💚  -3.83%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check:unchanged</td><td align="right">1.4882s</td><td align="right">1.4560s</td><td align="right">💚  -2.16%</td><td align="right">209.75 MiB</td><td align="right">201.46 MiB</td><td align="right">💚  -3.95%</td></tr><tr><td>Total</td><td align="right">3.0144s</td><td align="right">2.9616s</td><td align="right">💚  -1.75%</td><td align="right">527.87 MiB</td><td align="right">514.37 MiB</td><td align="right">💚  -2.56%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9879s</td><td align="right">💚  -1.21%</td><td align="right">1 byte</td><td align="right">0.98 bytes</td><td align="right">💚  -1.85%</td></tr></table>
2023-09-16 18:32:11 +00:00
bors
4514fb98d5 Auto merge of #112229 - clarfonthey:range-iter-count, r=dtolnay
Specialize count for range iterators

Since `size_hint` is already specialized, it feels apt to specialize `count` as well. Without any specialized version of `ExactSizeIterator::len` or `Step::steps_between`, this feels like a more reliable way of accessing this without having to rely on knowing that `size_hint` is correct.

In my case, this is particularly useful to access the `steps_between` implementation for `char` from the standard library without having to compute it manually.

I didn't think it was worth modifying the `Step` trait to add a version of `steps_between` that used native overflow checks since this is just doing one subtraction in most cases anyway, and so I decided to make the inclusive version use `checked_add` so it didn't have this lopsided overflow-checks-but-only-sometimes logic.
2023-09-16 16:43:31 +00:00
bors
409e7f6f21 Auto merge of #115894 - matthiaskrgr:rollup-pe5efh4, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #115860 (Enable varargs support for AAPCS calling convention)
 - #115867 (coverage: Simplify internal representation of debug types)
 - #115885 (don't globally ignore rustc-ice files)

Failed merges:

 - #115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - #115884 (make ty::Const debug printing less verbose)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-16 14:55:47 +00:00
Ralf Jung
5a3410ad1a make ty::Const debug printing less verbose 2023-09-16 16:31:09 +02:00
mxnkarou
1c7a77a638
edit std::collections::VecDeque docs 2023-09-16 15:52:34 +02:00
mxnkarou
d1ff5e174b
edit std::vec::Vec::truncate docs 2023-09-16 15:46:31 +02:00
Matthias Krüger
04edb2bab8
Rollup merge of #115885 - RalfJung:dont-ignore-ice, r=oli-obk
don't globally ignore rustc-ice files

Reverts a change that happened in https://github.com/rust-lang/rust/pull/114586 but is unrelated to that PR and wasn't discussed.

ICE files appearing is somewhat of a nuisance, but I'd rather clean them up than have them accumulate in my source folder. `@oli-obk` if you want to ignore them you can add them to your local `.git/info/exclude`.
2023-09-16 15:18:24 +02:00
Matthias Krüger
77e0102d19
Rollup merge of #115867 - Zalathar:debug, r=oli-obk
coverage: Simplify internal representation of debug types

Most of these debug helper types store each of their fields as `Option<T>`, and then set them to `Some` when the relevant debug checks are enabled. This makes the struct fields awkward to read and results in some contortions when accessing the field values.

This PR addresses those problems by changing each of the helper types to have a single `state: Option<FooState>` field. Each individual method can then obtain the state up-front (or return early if it is absent), allowing the rest of the code to just access the state's contents directly.

---

There are some more improvements I'd like to make to the debug code, but for this PR I'm focusing on a straightforward mechanical change that should be fairly easy to review.

(I did thrown in a few trivial changes to imports and docs, along with one switch from `FxHashMap` to `FxHashSet`.)

---

Most of the changed lines are just indentation churn, so ignoring whitespace is recommended.
2023-09-16 15:18:23 +02:00
Matthias Krüger
ab90d708da
Rollup merge of #115860 - Soveu:varargs2, r=WaffleLapkin
Enable varargs support for AAPCS calling convention

Welp, I was looking for a reason why this shouldn't be stabilized after so long... and here it is.
2023-09-16 15:18:23 +02:00
bors
41bafc4ff3 Auto merge of #110800 - GuillaumeGomez:custom_code_classes_in_docs, r=t-rustdoc
Accept additional user-defined syntax classes in fenced code blocks

Part of #79483.

This is a re-opening of https://github.com/rust-lang/rust/pull/79454 after a big update/cleanup. I also converted the syntax to pandoc as suggested by `@notriddle:` the idea is to be as compatible as possible with the existing instead of having our own syntax.

## Motivation

From the original issue: https://github.com/rust-lang/rust/issues/78917

> The technique used by `inline-c-rs` can be ported to other languages. It's just super fun to see C code inside Rust documentation that is also tested by `cargo doc`. I'm sure this technique can be used by other languages in the future.

Having custom CSS classes for syntax highlighting will allow tools like `highlight.js` to be used in order to provide highlighting for languages other than Rust while not increasing technical burden on rustdoc.

## 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.

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)).

## Raised concerns

#### It's not obvious when the `language-*` attribute generation will be added or not.

It is added by default. If you want to disable it, you will need to use the `custom` attribute.

#### Why not using HTML in markdown directly then?

Code examples in most languages are likely to contain `<`, `>`, `&` and `"` characters. These characters [require escaping](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre) when written inside the `<pre>` element. Using the \`\`\` code blocks allows rustdoc to take care of escaping, which means doc authors can paste code samples directly without manually converting them to HTML.

cc `@poliorcetics`
r? `@notriddle`
2023-09-16 13:10:11 +00:00
bors
42dead4d23 Auto merge of #115889 - matthiaskrgr:rollup-kfmauvh, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #115607 (clarify that unsafe code must not rely on our safe traits)
 - #115866 (make interpreter and TyAndLayout type Debug impl independent of Ty debug impl)

Failed merges:

 - #115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - #115884 (make ty::Const debug printing less verbose)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-16 10:53:22 +00:00
Guillaume Gomez
e691752210 Migrate GUI colors test to original CSS color format 2023-09-16 11:54:25 +02:00
Matthias Krüger
53cd9783c5
Rollup merge of #115866 - RalfJung:interpret-debug, r=compiler-errors
make interpreter and TyAndLayout type Debug impl independent of Ty debug impl

This fixes some (but not all) of the fallout from https://github.com/rust-lang/rust/pull/115661.

Second commit is taken from https://github.com/rust-lang/rust/pull/107084 (and slightly adjusted); I preserved the original git author information.
2023-09-16 11:48:18 +02:00
Matthias Krüger
c2f228f654
Rollup merge of #115607 - RalfJung:safe-traits-unsafe-code, r=dtolnay
clarify that unsafe code must not rely on our safe traits

This adds a disclaimer to PartialEq, Eq, PartialOrd, Ord, Hash, Deref, DerefMut.

We already have a similar disclaimer in ExactSizeIterator (worded a bit differently):
```
/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.
```
If there are any other traits that should carry such a disclaimer, please let me know.

Fixes https://github.com/rust-lang/rust/issues/73682
2023-09-16 11:48:18 +02:00
Guillaume Gomez
e39c39346b Fix invalid markdown codeblock label 2023-09-16 11:37:41 +02:00
bors
fd70f7eea2 Auto merge of #115740 - tmiasko:cache-reachable-set, r=cjgillot
Cache reachable_set on disk
2023-09-16 09:07:38 +00:00
Ralf Jung
ec1d04967d don't globally ignore rustc-ice files 2023-09-16 09:44:44 +02:00
ltdk
08aa6c9b65 Specialize count for range iterators 2023-09-16 01:33:56 -04:00
bors
790309b102 Auto merge of #115315 - RalfJung:field-capture-packed-alignment, r=oli-obk
closure field capturing: don't depend on alignment of packed fields

This fixes the closure field capture part of https://github.com/rust-lang/rust/issues/115305: field capturing always stops at projections into packed structs, no matter the alignment of the field. This means changing a private field type from `u8` to `u64` can never change how closures capture fields, which is probably what we want.

Here's an example where, before this PR, changing the type of a private field in a repr(Rust) struct can change the output of a program:

```rust
#![allow(dead_code)]

mod m {
    // before patch
    #[derive(Default)]
    pub struct S1(u8);
    // after patch
    #[derive(Default)]
    pub struct S2(u64);
}

struct NoisyDrop;
impl Drop for NoisyDrop {
    fn drop(&mut self) {
        eprintln!("dropped!");
    }
}

#[repr(packed)]
struct MyType {
    field: m::S1, // output changes when this becomes S2
    other_field: NoisyDrop,
    third_field: Vec<()>,
}

fn test(r: MyType) {
    let c = || {
        let _val = std::ptr::addr_of!(r.field);
        let _val = r.third_field;
    };
    drop(c);
    eprintln!("before dropping");
}

fn main() {
    test(MyType {
        field: Default::default(),
        other_field: NoisyDrop,
        third_field: Vec::new(),
    });
}
```

Of course this is a breaking change for the same reason that doing field capturing in the first place was a breaking change. Packed fields are relatively rare and depending on drop order is relatively rare, so I don't expect this to have much impact, but it's hard to be sure and even a crater run will only tell us so much.

Also see the [nomination comment](https://github.com/rust-lang/rust/pull/115315#issuecomment-1702807825).

Cc `@rust-lang/wg-rfc-2229` `@ehuss`
2023-09-16 05:29:23 +00:00
bors
635c4a5e61 Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726
Make useless_ptr_null_checks smarter about some std functions

This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc.

This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`).

Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null.

Follow-up of PR #113657

Fixes #114442
2023-09-16 03:40:20 +00:00
Zalathar
91e0b46f76 coverage: Replace an unnecessary map with a set
This hashmap's values were never used.
2023-09-16 12:07:35 +10:00
Zalathar
3b5b1aa2a5 coverage: Simplify internal representation of debug types 2023-09-16 12:07:35 +10:00
Zalathar
d0d1187ebb coverage: Update log module names in debug docs 2023-09-16 12:07:35 +10:00
Zalathar
d79cd17199 coverage: Arrange imports in rustc_mir_transform::coverage::debug 2023-09-16 12:07:35 +10:00
bors
e81f85fe9e Auto merge of #115520 - Finomnis:const_transmute_copy, r=dtolnay
Stabilize const_transmute_copy

Closes #83165
2023-09-16 01:51:55 +00:00
bors
c48e6ffce5 Auto merge of #115829 - notriddle:notriddle/rustdoc-theme-css-merge, r=GuillaumeGomez
rustdoc: merge theme css into rustdoc.css

Based on https://github.com/rust-lang/rust/pull/115812#issuecomment-1717960119

Having them in separate files used to make more sense, before the migration to CSS variables made the theme files as small as they are nowadays. This is already how docs.rs and mdBook do it.

WebPageTest comparison page:

https://www.webpagetest.org/video/compare.php?tests=230913_AiDc3F_B9E,230913_AiDc7G_B9B

Filmstrip comparison:

![image](https://github.com/rust-lang/rust/assets/1593513/7ccad27b-7497-47ee-94c0-1a701b69c0c2)

Old waterfall:

![image](https://github.com/rust-lang/rust/assets/1593513/7a6e4375-226d-4205-8871-a4d775a70748)

New waterfall:

![image](https://github.com/rust-lang/rust/assets/1593513/e29112e3-84f7-417d-a250-cd6c10fa50f5)
2023-09-16 00:02:41 +00:00
Boxy
71cab64079 special case TyAndLayout debug impl 2023-09-15 22:57:07 +02:00
bors
20999de3a2 Auto merge of #115878 - weihanglo:update-cargo, r=weihanglo
Update cargo

11 commits in 2fc85d15a542bfb610aff7682073412cf635352f..d5336f813df39d476e61fc46daabb1446350660a
2023-09-09 01:49:46 +0000 to 2023-09-14 19:55:49 +0000
- fix: emit a warning for `credential-alias` shadowing (rust-lang/cargo#12671)
- refactor: fix lint errors in preparation of `[lints]` table integration (rust-lang/cargo#12669)
- Limit cargo add feature print (rust-lang/cargo#12662)
- Clippy (rust-lang/cargo#12667)
- Prerelease candidates error message (rust-lang/cargo#12659)
- Fix typos: `informations` -&gt; `information` (rust-lang/cargo#12666)
- chore: update globset to 0.4.13 (rust-lang/cargo#12665)
- refactor: Consolidate clap/shell styles (rust-lang/cargo#12655)
- libgit2 fixed upstream (rust-lang/cargo#12657)
- Index summary enum (rust-lang/cargo#12643)
- feat(help): Add styling to help output (rust-lang/cargo#12578)

r? ghost
2023-09-15 20:54:56 +00:00
Guillaume Gomez
7c72edf19f Update documentation for custom_code_classes_in_docs feature 2023-09-15 21:32:29 +02:00
Guillaume Gomez
f038f180fd Add custom tag for markdown codeblocks 2023-09-15 21:32:29 +02:00
Guillaume Gomez
113220b970 Update to new emit_error API 2023-09-15 21:32:29 +02:00
Guillaume Gomez
87d2aa5fd3 Improve error emitting code 2023-09-15 21:32:29 +02:00
Guillaume Gomez
bbaa930b35 Fix compilation error "the trait bound SubdiagnosticMessage: From<&std::string::String> is not satisfied" 2023-09-15 21:32:29 +02:00
Guillaume Gomez
6e21e4823d Fix incorrect codeblock attributes in docs 2023-09-15 21:32:29 +02:00
Guillaume Gomez
5f3002ebeb Add eBNF and documentation on TagIterator 2023-09-15 21:32:29 +02:00
Guillaume Gomez
7681f63cab Implement new eBNF for codeblock attributes 2023-09-15 21:32:28 +02:00
Guillaume Gomez
4ce17fa30e Add support for double quotes in markdown codeblock attributes 2023-09-15 21:32:28 +02:00
Guillaume Gomez
d829fee6b5 Add documentation for custom_code_classes_in_docs feature 2023-09-15 21:32:28 +02:00
Guillaume Gomez
f5561842e3 Add tests for custom_code_classes_in_docs feature 2023-09-15 21:32:28 +02:00
Guillaume Gomez
5515fc88dc Implement custom classes for rustdoc code blocks with custom_code_classes_in_docs feature 2023-09-15 21:32:27 +02:00