Commit Graph

271489 Commits

Author SHA1 Message Date
Nicholas Nethercote
16a39bb7ca Streamline lex_token_trees error handling.
- Use iterators instead of `for` loops.
- Use `if`/`else` instead of `match`.
2024-11-25 16:10:55 +11:00
Nicholas Nethercote
4cd2840f00 Clean up c_or_byte_string.
- Rename a misleading local `mk_kind` as `single_quoted`.
- Use `fn` for all three arguments, for consistency.
2024-11-25 16:10:55 +11:00
Nicholas Nethercote
11c96cfd94 Improve strip_shebang testing.
It's currently a bit ad hoc. This commit makes it more methodical, with
pairs of match/no-match tests for all the relevant cases.
2024-11-25 16:10:55 +11:00
Nicholas Nethercote
ba1a1ddc3f Fix some formatting.
Must be one of those cases where the function is too long and rustfmt
bails out.
2024-11-25 16:10:55 +11:00
Nicholas Nethercote
593cf680aa Split Lexer::bump.
It has two different ways of being called.
2024-11-25 16:10:55 +11:00
Nicholas Nethercote
98777b4c49 Merge TokenTreesReader into StringReader.
There is a not-very-useful layering in the lexer, where
`TokenTreesReader` contains a `StringReader`. This commit combines them
and names the result `Lexer`, which is a more obvious name for it.

The methods of `Lexer` are now split across `mod.rs` and `tokentrees.rs`
which isn't ideal, but it doesn't seem worth moving a bunch of code to
avoid it.
2024-11-25 16:10:55 +11:00
bors
481b5fadd7 Auto merge of #133068 - jieyouxu:download-rustc-default-only-for-tools, r=clubby789
Use `download-rustc=false` global default, `if-unchanged` for tools and library profiles, and make `rust.debug-assertions=true` inhibit downloading CI rustc

- Use `download-rustc = false` as global default.
    - Use `download-rustc = 'if-unchanged'` for tools and library profiles.
- Make `rust.debug-assertions = true` inhibit downloading CI rustc because alt rustc builds do not yet have rustc debug assertions enabled.

Fixes #133132.

cc discussions: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Bootstrap.20breakage
compiler contributors poll: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.60download-rustc.20.3D.20'if-unchanged'.60.20for.20.60compiler.60.20profile.3F/near/481877253
library contributors poll: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/.60download-rustc.20.3D.20.22if-unchanged.22.60.20default.20for.20libs.20profile.3F/near/482607011
cc https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/When.20is.20rustc.20built.20with.20debug.20assertions.3F

cc `@MarcoIeni` since you're working on improving CI job times, sorry, this will definitely regress some CI job times because we're probably lying to ourselves that CI rustc had debug assertions for some time 😅

cc `@onur-ozkan` for FYI, but since you're on vacation (sorry for the ping),

r? `@Kobzol` (I *think* you have a bit more context than other bootstrap reviewers?)
2024-11-24 16:28:55 +00:00
bors
f5d1857685 Auto merge of #133415 - matthiaskrgr:rollup-n1ivyd5, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #133300 (inject_panic_runtime(): Avoid double negation for 'any non rlib')
 - #133301 (Add code example for `wrapping_neg` method for signed integers)
 - #133371 (remove is_trivially_const_drop)
 - #133389 (Stabilize `const_float_methods`)
 - #133398 (rustdoc: do not call to_string, it's already impl Display)
 - #133405 (tidy: Distinguish between two different meanings of "style file")

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-24 10:21:07 +00:00
Matthias Krüger
3ccaceff73
Rollup merge of #133405 - Zalathar:style-file, r=jieyouxu
tidy: Distinguish between two different meanings of "style file"

This file contains code that uses “style file” to mean “CSS file”, and other code that uses “style file” to mean “this file, which implements the style checker”.

That's very confusing, so it's easier to just say *CSS file* or *this file* as appropriate.

No functional change.
2024-11-24 11:08:21 +01:00
Matthias Krüger
e87e205010
Rollup merge of #133398 - klensy:rd-to-string, r=aDotInTheVoid
rustdoc: do not call to_string, it's already impl Display

`anchor` returns impl Display, so no need to call to_string().
2024-11-24 11:08:20 +01:00
Matthias Krüger
220251e181
Rollup merge of #133389 - eduardosm:stabilize-const_float_methods, r=RalfJung
Stabilize `const_float_methods`

Tracking issue: https://github.com/rust-lang/rust/issues/130843
Relnotes: #133383

Stabilized const API:

```rust
// in `core`
impl f32/f64 {
    pub const fn recip(self) -> Self;
    pub const fn to_degrees(self) -> Self;
    pub const fn to_radians(self) -> Self;
    pub const fn max(self, other: Self) -> Self;
    pub const fn min(self, other: Self) -> Self;
    pub const fn clamp(self, min: Self, max: Self) -> Self;
    pub const fn abs(self) -> Self;
    pub const fn signum(self) -> Self;
    pub const fn copysign(self, sign: Self) -> Self;
}
```

Closes https://github.com/rust-lang/rust/issues/130843

r? libs-api

cc `@RalfJung` -- I think the way const-stability attributes work have change a bit since the last time a wrote a const-stabilization PR, please make sure I got them right.
2024-11-24 11:08:20 +01:00
Matthias Krüger
5d1c99275d
Rollup merge of #133371 - RalfJung:is_trivially_const_drop, r=compiler-errors
remove is_trivially_const_drop

I'm not sure this still brings any perf benefits, so let's benchmark this.

r? `@compiler-errors`
2024-11-24 11:08:19 +01:00
Matthias Krüger
3c52c9b483
Rollup merge of #133301 - GuillaumeGomez:add-example-wrapping-neg, r=workingjubilee
Add code example for `wrapping_neg` method for signed integers

With this example, we make it obvious that `wrapping_neg` works both ways (neg to pos and pos to neg).

r? `@workingjubilee`
2024-11-24 11:08:19 +01:00
Matthias Krüger
4ad97f2a9a
Rollup merge of #133300 - Enselic:build-std-instrument-coverage, r=jieyouxu
inject_panic_runtime(): Avoid double negation for 'any non rlib'

<details>

<summary>This PR originally did more things .Click to expand to see.</summary>

By not trying to inject a profiler runtime when only building an rlib. This logic already exists for the panic runtime.

This makes

    RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins

work. Note that you probably also need
`RUST_COMPILER_RT_FOR_PROFILER=$src/llvm-project/compiler-rt` in your environment.

cc #79401

# Demonstration

Before this fix you get these errors:

```console
$ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +nightly build --release -Zbuild-std=std,profiler_builtins
error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]`
error[E0152]: found duplicate lang item `manually_drop`
    = note: first definition in `core` loaded from /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-d453bab70303062c.rlib
    = note: second definition in the local crate (`core`)
```

With the fix the build succeeds:

```console
$ rm -rf target ; RUST_COMPILER_RT_FOR_PROFILER=/home/martin/src/llvm-project/compiler-rt RUSTFLAGS="-Cinstrument-coverage" cargo +stage1 build --release -Zbuild-std=std,profiler_builtins
    Finished `release` profile [optimized] target(s) in 45.57s
```

And we can check code coverage. My example program looks like this:

```rs
fn main() {
    if std::env::args_os().nth(1) == Some("write-file".into()) {
        std::fs::write("hello.txt", "Hello, world!").unwrap();
    } else {
        println!("Hello, world!");
    }
}
```

when the program prints to stdout:

```
$ LLVM_PROFILE_FILE=stdout.profraw ./target/release/hello-world
Hello, world!
```

we can see that `fs::write()` is not being used (note the `0`'s):

```console
$ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse stdout.profraw -o stdout.profdata
$ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile stdout.profdata --color | grep -A 3 'pub fn write(&mut self, write: b
ool) -> &mut Self {'
 1357|      0|    pub fn write(&mut self, write: bool) -> &mut Self {
 1358|      0|        self.0.write(write);
 1359|      0|        self
 1360|      0|    }
```

but when we print to a file:

```console
$ LLVM_PROFILE_FILE=file.profraw ./target/release/hello-world write-file
```

the code coverage shows `fs::write()` as being used (note the `1`'s):

```console
$ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -sparse file.profraw -o file.profdata
$ /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/release/hello-world --sources /home/martin/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/fs.rs --instr-profile file.profdata --color | grep -A 3 'pub fn write(&mut self, write: bool) -> &mut Self {'
 1357|      1|    pub fn write(&mut self, write: bool) -> &mut Self {
 1358|      1|        self.0.write(write);
 1359|      1|        self
 1360|      1|    }
```
</summary>
2024-11-24 11:08:18 +01:00
bors
ab3cf268b5 Auto merge of #132791 - tyilo:big-file-fail-fast, r=compiler-errors
rustc: Fail fast when compiling a source file larger than 4 GiB

Currently if you try to compile a file that is larger than 4 GiB, `rustc` will first read the whole into memory before failing.

If we can read the metadata of the file, we can fail before reading the file.
2024-11-24 07:37:32 +00:00
bors
4e4c20d2ab Auto merge of #132611 - compiler-errors:async-prelude, r=ibraheemdev
Add `AsyncFn*` to the prelude in all editions

The general vibe is that we will most likely stabilize the `feature(async_closure)` *without* the `async Fn()` trait bound modifier.

Without `async Fn()` bound syntax, this necessitates users to spell the bound like `AsyncFn()`. Since `core::ops::AsyncFn` is not in the prelude, users will need to import these any time they actually want to use the trait. This seems annoying, so let's add these traits to the prelude unstably.

We're trying to work on the general vision of `async` trait bound modifier in general in: https://github.com/rust-lang/rfcs/pull/3710, however that RFC still needs more time for consensus to converge, and we've decided that the value that users get from calling the bound `async Fn()` is *not really* worth blocking landing async closures in general.
2024-11-24 04:53:16 +00:00
Zalathar
2134a7e363 tidy: Distinguish between two different meanings of "style file" 2024-11-24 14:45:17 +11:00
bors
124eb966e3 Auto merge of #132597 - lukas-code:btree-plug-leak, r=jhpratt
btree: don't leak value if destructor of key panics

This PR fixes a regression from https://github.com/rust-lang/rust/pull/84904.

The `BTreeMap` already attempts to handle panicking destructors of the key-value pairs by continuing to execute the remaining destructors after one destructor panicked. However, after #84904 the destructor of a value in a key-value pair gets skipped if the destructor of the key panics, only continuing with the next key-value pair. This PR reverts to the behavior before #84904 to also drop the corresponding value if the destructor of a key panics.

This avoids potential memory leaks and can fix the soundness of programs that rely on the destructors being executed (even though this should not be relied upon, because the std collections currently do not guarantee that the remaining elements are dropped after a panic in a destructor).

cc `@Amanieu` because you had opinions on panicking destructors
2024-11-24 02:08:58 +00:00
bors
e48241b5d1 Auto merge of #131859 - chriskrycho:update-trpl, r=onur-ozkan
Update TRPL to add new Chapter 17: Async and Await

- Add support to `rustbook` to pass through the `-L`/`--library-path` flag to `mdbook` so that references to the `trpl` crate
- Build the `trpl` crate as part of the book tests. Make it straightforward to add other such book dependencies in the future if needed by implementing that in a fairly general way.
- Update the submodule for the book to pull in the new chapter on async and await, as well as a number of other fixes. This will happen organically/automatically in a week, too, but this lets me group this change with the next one:
- Update the compiler messages which reference the existing chapters 17–20, which are now chapters 18-21. There are only two, both previously referencing chapter 18.
- Update the UI tests which reference the compiler message outputs.
2024-11-23 23:26:19 +00:00
bors
15b663e684 Auto merge of #133379 - jieyouxu:rollup-00jxo71, r=jieyouxu
Rollup of 4 pull requests

Successful merges:

 - #133217 ([AIX] Add option -X32_64 to the "strip" command)
 - #133237 (Minimally constify `Add`)
 - #133355 (Add language tests for aggregate types)
 - #133374 (show abi_unsupported_vector_types lint in future breakage reports)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-23 20:45:19 +00:00
klensy
da4c050bb0 do not to_string, use display 2024-11-23 23:16:26 +03:00
bors
386a7c7ae2 Auto merge of #133242 - lcnr:questionable-uwu, r=compiler-errors,BoxyUwU
finish `Reveal` removal

After #133212 changed the `TypingMode` to be the only source of truth, this entirely rips out `Reveal`.

cc #132279

r? `@compiler-errors`
2024-11-23 18:01:21 +00:00
Eduardo Sánchez Muñoz
6f7dc38031 Stabilize const_float_methods 2024-11-23 18:42:44 +01:00
Chris Krycho
7630b4975c
Vendor trpl crate so The Book tests work offline
Without this change:

    $ ./x test --set build.vendor=true src/doc/book
    # (lots of output)
    error: failed to select a version for the requirement `futures = "^0.3"` (locked to 0.3.30)
    candidate versions found which didn't match: 0.3.31, 0.3.27
    location searched: directory source `/Users/chris/dev/rust-lang/rust/vendor` (which is replacing registry `crates-io`)
    required by package `trpl v0.2.0 (/Users/chris/dev/rust-lang/rust/src/doc/book/packages/trpl)`
    perhaps a crate was updated and forgotten to be re-vendored?
    Build completed unsuccessfully in 0:01:19

With this change:

    $ ./x test --set build.vendor=true src/doc/book
    # (lots of build output)
    Testing stage1 mdbook src/doc/book (aarch64-apple-darwin)
        finished in 86.949 seconds
    Build completed successfully in 0:04:05

# Conflicts:
#	src/bootstrap/src/core/build_steps/vendor.rs
2024-11-23 09:01:08 -07:00
Jieyou Xu
f7f8ad92a1 ci: don't force CI rustc for x86_64-gnu-tools
CI alt rustc builds do not have rustc debug assertions currently.
2024-11-23 23:58:44 +08:00
Jieyou Xu
dab61db1ac bootstrap: add change tracker entry 2024-11-23 23:58:44 +08:00
Chris Krycho
d4275e08e7
Update tests for new TRPL chapter order 2024-11-23 08:57:25 -07:00
Chris Krycho
559a2d21b7
rustbook: fix two small typos 2024-11-23 08:57:25 -07:00
Chris Krycho
d34d426b8f
Update bootstrap tests to support book dependencies
Since TRPL now depends on a `trpl` crate, the test needs to be able to
build that crate to run mdbook against it, and also to invoke mdbook
with `--library-path` in that case. Use the support for that flag added
to `rustbook` in the previous change to invoke it with the path to the
dependencies it will need to run `rustdoc` tests which reference `trpl`.

Co-authored-by: Onur Özkan <onurozkan.dev@outlook.com>
2024-11-23 08:57:25 -07:00
Chris Krycho
f7409e8afb
Add support for --library-path to rustbook test
This makes it possible to test an mdbook which has dependencies other
than the direct crate for the book itself, e.g. the `trpl` crate used in
_The Rust Programming Language_.
2024-11-23 08:57:24 -07:00
Chris Krycho
5e3607626d
Update messages which reference book chs. 17-20
With the insertion of a new chapter 17 on async and await to _The Rust
Programming Language_, references in compiler output to later chapters
need to be updated to avoid confusing users. Redirects exist so that
users who click old links will end up in the right place anyway, but
this way users will be directed to the right URL in the first place.
2024-11-23 08:57:24 -07:00
Chris Krycho
b64da63c4d
Update TRPL to latest, including new Chapter 17: Async and Await
This also incorporates a number of other changes and fixes which would
normally have been part of the automatic update, but which were blocked
from landing because of the changes required to support shipping a crate
as part of the chapter, along with those changes.
2024-11-23 08:57:22 -07:00
Jieyou Xu
835f5f0f39 bootstrap: make rust.debug-assertions = true inhibit downloading CI rustc
Warn if `rust.download-rustc = true` is used with
`rust.debug-assertions` as alt CI rustc is not currently built with
debug assertions (not to be confused with LLVM assertions).
2024-11-23 23:47:19 +08:00
Jieyou Xu
aafd56b87a bootstrap: revert rust.download-rustc global default to false
And only default library and tools profile to `rust.download-rustc =
"if-unchanged"`.
2024-11-23 23:47:03 +08:00
bors
826b673412 Auto merge of #133377 - jieyouxu:rollup-n536hzq, r=jieyouxu
Rollup of 6 pull requests

Successful merges:

 - #127483 (Allow disabling ASan instrumentation for globals)
 - #131505 (use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin)
 - #132949 (Add specific diagnostic for using macro_rules macro as attribute/derive)
 - #133286 (Re-delay a resolve `bug` related to `Self`-ctor in patterns)
 - #133332 (Mark `<[T; N]>::as_mut_slice` with the `const` specifier.)
 - #133366 (Remove unnecessary bool from `ExpectedFound::new`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-23 15:19:32 +00:00
lcnr
776731dc3f rebase 2024-11-23 13:52:57 +01:00
lcnr
8c7c83d6ef review 2024-11-23 13:52:56 +01:00
lcnr
795ff6576c global old solver cache: use TypingEnv 2024-11-23 13:52:56 +01:00
lcnr
a8c8ab1acd remove remaining references to Reveal 2024-11-23 13:52:56 +01:00
lcnr
319843d8cd no more Reveal :( 2024-11-23 13:52:54 +01:00
lcnr
f4b516b10c thir building: use typing_env directly 2024-11-23 13:51:57 +01:00
许杰友 Jieyou Xu (Joe)
f5cfb90082
Rollup merge of #133374 - RalfJung:abi_unsupported_vector_types, r=jieyouxu
show abi_unsupported_vector_types lint in future breakage reports

The lint is now riding the train to 1.84. Given that crater found no case of this lint triggering at all, IMO it's fine to make it "report in deps" already for 1.85.

Part of https://github.com/rust-lang/rust/issues/116558.
2024-11-23 20:50:16 +08:00
许杰友 Jieyou Xu (Joe)
ae4fdf1445
Rollup merge of #133355 - chorman0773:spec-layout-tests, r=jieyouxu
Add language tests for aggregate types

This adds some tests for struct and union types, ensuring that they satisfy the rules for all structs and unions - namely that fields of structs do not overlap, fields are well-aligned, and the size of the entire.

The reference annotations used are from https://github.com/rust-lang/reference/pull/1654, though the rules tested here were FCPed in <https://github.com/rust-lang/reference/pull/1152>.
2024-11-23 20:50:16 +08:00
许杰友 Jieyou Xu (Joe)
75b8f433e3
Rollup merge of #133237 - fee1-dead-contrib:constadd, r=compiler-errors
Minimally constify `Add`

* This PR removes the requirement for `impl const` to have a const stability attribute. cc ``@RalfJung`` I believe you mentioned that it would make much more sense to require `const_trait`s to have const stability instead. I agree with that sentiment but I don't think that is _required_ for a small scale experimentation like this PR. https://github.com/rust-lang/project-const-traits/issues/16 should definitely be prioritized in the future, but removing the impl check should be good for now as all callers need `const_trait_impl` enabled for any const impl to work.
* This PR is intentionally minimal as constifying other traits can become more complicated (`PartialEq`, for example, would run into requiring implementing it for `str` as that is used in matches, which runs into the implementation for slice equality which uses specialization)

Per the reasons above, anyone who is interested in making traits `const` in the standard library are **strongly encouraged** to reach out to us on the [Zulip channel](https://rust-lang.zulipchat.com/#narrow/channel/419616-t-compiler.2Fproject-const-traits) before proceeding with the work.

cc ``@rust-lang/project-const-traits``

I believe there is prior approval from libs that we can experiment, so

r? project-const-traits
2024-11-23 20:50:15 +08:00
许杰友 Jieyou Xu (Joe)
92f5144c9c
Rollup merge of #133217 - xingxue-ibm:fix-strip, r=compiler-errors
[AIX] Add option -X32_64 to the "strip" command

The AIX `strip` utility requires option `-X` to specify the object mode. This patch adds the `-X32_64` option to the `strip` command so that it can handle both 32-bit and 64-bit objects. The parameter `option` of function `strip_symbols_with_external_utility`, previously a single string, has been changed to `options`, an array of string slices, to accommodate multiple `strip` options.
2024-11-23 20:50:14 +08:00
lcnr
0f8405f702 ElaborateDrops: use typing_env directly 2024-11-23 13:46:07 +01:00
许杰友 Jieyou Xu (Joe)
96e8c7c7ba
Rollup merge of #133366 - compiler-errors:expected-found, r=dtolnay
Remove unnecessary bool from `ExpectedFound::new`

It's true almost everywhere, and the one place it's not can be replaced w/ an if statement.
2024-11-23 20:19:54 +08:00
许杰友 Jieyou Xu (Joe)
8036ff1302
Rollup merge of #133332 - bjoernager:const-array-as-mut-slice, r=jhpratt
Mark `<[T; N]>::as_mut_slice` with the `const` specifier.

Tracking issue: #133333

`<[T; N]>::as_mut_slice` can have the `const` specifier without any changes to the function body.
2024-11-23 20:19:54 +08:00
许杰友 Jieyou Xu (Joe)
4d9cd661c7
Rollup merge of #133286 - jieyouxu:bug-ourselves, r=compiler-errors
Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <https://github.com/rust-lang/rust/issues/133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<https://github.com/rust-lang/rust/pull/121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to #121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps).
Fixes #133272.
2024-11-23 20:19:53 +08:00
许杰友 Jieyou Xu (Joe)
f7e3de36fc
Rollup merge of #132949 - clubby789:macro-rules-attr-derive, r=fmease
Add specific diagnostic for using macro_rules macro as attribute/derive

Fixes #132928
2024-11-23 20:19:53 +08:00