Commit Graph

259668 Commits

Author SHA1 Message Date
Nicholas Nethercote
dad95578b0 Add unit tests for Parser::look_ahead.
It's currently buggy, so some of the test results are surprising, as
described in the `FIXME` comments. The bugs will be fixed in subsequent
commits.
2024-07-12 13:30:00 +10:00
bors
0ca92de473 Auto merge of #127454 - matthiaskrgr:rollup-k3vfen2, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #127179 (Print `TypeId` as hex for debugging)
 - #127189 (LinkedList's Cursor: method to get a ref to the cursor's list)
 - #127236 (doc: update config file path in platform-support/wasm32-wasip1-threads.md)
 - #127297 (Improve std::Path's Hash quality by avoiding prefix collisions)
 - #127308 (Attribute cleanups)
 - #127354 (Describe Sized requirements for mem::offset_of)
 - #127409 (Emit a wrap expr span_bug only if context is not tainted)
 - #127447 (once_lock: make test not take as long in Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-07 16:29:52 +00:00
bors
959a2eb275 Auto merge of #127455 - Nilstrieb:blazing-tidy, r=jieyouxu
Make tidy problematic const checking fast again

fixes pathological tidy performance described in #127453 by reverting #127428

i think anyone can approve this ASAP, it makes working on this repo significantly worse.
2024-07-07 14:15:33 +00:00
Nilstrieb
1cfc89ad69 Add note about performance of tidy problematic consts 2024-07-07 14:23:36 +02:00
Nilstrieb
76ba11994e Revert "remove regexes"
This reverts commit 8d8504300f.

The regexes are important for performance.
2024-07-07 14:22:06 +02:00
Matthias Krüger
b564c510c1
Rollup merge of #127447 - RalfJung:once_lock_miri, r=joboet
once_lock: make test not take as long in Miri

Allocating 1000 list elements takes a while (`@zachs18` reported >5min), so let's reduce the iteration count when running in Miri. Unfortunately due to this clever `while let i @ 0..LEN =` thing, the count needs to be a constants, and constants cannot be shadowed, so we need to use another trick to hide the `cfg!(miri)` from the docs. (I think this loop condition may be a bit too clever, it took me a bit to decipher. Ideally this would be `while let i = ... && i < LEN`, but that is not stable yet.)
2024-07-07 14:22:03 +02:00
Matthias Krüger
1ee6345b7b
Rollup merge of #127409 - gurry:127332-ice-with-expr-not-struct, r=oli-obk
Emit a wrap expr span_bug only if context is not tainted

Fixes #127332

The ICE occurs because of this `span_bug`: 51917e2e69/compiler/rustc_hir_typeck/src/expr_use_visitor.rs (L732-L738)
which is triggered by the fact that we're trying to use an `enum` in a `with` expression instead of a `struct`.

The issue originates in commit 814bfe9335   from PR #127202. As per the title of that commit the ICEing code should not be reachable any more, but looks like it still is.

This PR changes the code so that the `span_bug` will be emitted only if the context is not tainted by a previous error.
2024-07-07 14:22:02 +02:00
Matthias Krüger
c40530d0de
Rollup merge of #127354 - nicholasbishop:bishop-sized-doc, r=Nilstrieb
Describe Sized requirements for mem::offset_of

The container doesn't have to be sized, but the field must be sized (at least until https://github.com/rust-lang/rust/issues/126151 is stable).
2024-07-07 14:22:02 +02:00
Matthias Krüger
510020ad4c
Rollup merge of #127308 - nnethercote:Attribute-cleanups, r=petrochenkov
Attribute cleanups

More refactoring done while trying to fix the final remaining test failure for #124141.

r? `@petrochenkov`
2024-07-07 14:22:01 +02:00
Matthias Krüger
56557c4555
Rollup merge of #127297 - the8472:path-new-hash, r=Nilstrieb
Improve std::Path's Hash quality by avoiding prefix collisions

This adds a bit rotation to the already existing state so that the same sequence of characters chunked at different offsets into separate path components results in different hashes.

The tests are from #127255

Closes #127254
2024-07-07 14:22:00 +02:00
Matthias Krüger
d84d2214cd
Rollup merge of #127236 - iawia002:wasip1-threads-doc, r=Nilstrieb
doc: update config file path in platform-support/wasm32-wasip1-threads.md

The config content described in the `Building the target` section should be the configuration used for building Rust itself:

7d97c59438/config.example.toml (L845-L848)

I believe this is different from Cargo's configuration. There seems to be some misunderstanding in the discussion here: https://github.com/rust-lang/rust/pull/112922#discussion_r1272263810.
2024-07-07 14:22:00 +02:00
Matthias Krüger
94d07befe7
Rollup merge of #127189 - GrigorenkoPV:linkedlist-cursor-list, r=Nilstrieb
LinkedList's Cursor: method to get a ref to the cursor's list

We're already providing `.back()` & `.front()`, for which we hold onto a reference to the parent list, so why not share it? Useful for when you got `LinkedList` -> `CursorMut` -> `Cursor` and cannot take another ref to the list, even though you should be able to. This seems to be completely safe & sound.

The name is, of course, bikesheddable.
2024-07-07 14:21:59 +02:00
Matthias Krüger
35a1ca043e
Rollup merge of #127179 - tgross35:typeid-debug-hex, r=Nilstrieb
Print `TypeId` as hex for debugging

In <https://github.com/rust-lang/rust/pull/127134>, the `Debug` impl for `TypeId` was changed to print a single integer rather than a tuple. Change this again to print as hex for more concise and consistent formatting, as was suggested.

Result:

    TypeId(0x1378bb1c0a0202683eb65e7c11f2e4d7)
2024-07-07 14:21:59 +02:00
bors
382148d9a2 Auto merge of #123253 - ChayimFriedman2:extend-trusted, r=the8472
Specialize `TrustedLen` for `Iterator::unzip()`

Don't check the capacity every time (and also for `Extend` for tuples, as this is how `unzip()` is implemented).

I did this with an unsafe method on `Extend` that doesn't check for growth (`extend_one_unchecked()`). I've marked it as perma-unstable currently, although we may want to expose it in the future so collections outside of std can benefit from it. Then specialize `Extend for (A, B)` for `TrustedLen` to call it.

An alternative way of implementing this is to have a semi-public trait (`#[doc(hidden)]` public, so collections outside of core can implement it) for `extend()` inside tuples, and specialize it from collections. However:

 1. This looks more complex to me.
 2. This prohibits the option of exposing this somewhen to collections outside of std, as we never expose specializations.

A concern that may arise with the current approach is that implementing `extend_one_unchecked()` correctly must also incur implementing `extend_reserve()`, otherwise you can have UB. This is a somewhat non-local safety invariant. However, I believe this is fine, since to have actual UB you must have unsafe code inside your `extend_one_unchecked()` that makes incorrect assumption, *and* not implement `extend_reserve()`. I've also documented this requirement.

**Benchmark:**

Code:
```rust
#[bench]
fn unzip(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10_000 {
            let v: (Vec<_>, VecDeque<_>) =
                (black_box(0u32)..black_box(1_000)).map(|i| (i, i * 2)).unzip();
            black_box(v);
        }
    });
}
```

Before:
```
unzip::unzip 14.17ms/iter  +/- 374.85µs
```
After:
```
unzip::unzip 5.33ms/iter  +/- 164.54µs
```
2024-07-07 11:32:19 +00:00
Gurinder Singh
9da3638c6a Move a span_bug under a condition that cx is tainted
Fixes an ICE caused when a with expression is not a struct
2024-07-07 15:44:55 +05:30
bors
98dcbae5c9 Auto merge of #127428 - donno2048:master, r=albertlarsan68
Don't use regexes in tidy checks

No need for them, and it makes the tests and the checking simpler

r? `@albertlarsan68`
2024-07-07 08:09:23 +00:00
Ralf Jung
bee9120458 once_lock: make test not take as long in Miri 2024-07-07 09:19:32 +02:00
Nicholas Nethercote
9e0aab71a4 Use filter_map instead of flat_map in configure_tokens.
All the branches produce either zero or one elements.
2024-07-07 16:34:29 +10:00
Nicholas Nethercote
9f16f1f6f6 Add an size assertion.
`Option<LazyAttrTokenStream>` is the type that's actually used in all
the aST nodes.
2024-07-07 16:25:22 +10:00
Nicholas Nethercote
022582ca46 Remove Clone derive from LazyAttrTokenStreamImpl. 2024-07-07 16:24:51 +10:00
Nicholas Nethercote
3a5c4b6e4e Rename some attribute types for consistency.
- `AttributesData` -> `AttrsTarget`
- `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget`
- `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
2024-07-07 16:14:30 +10:00
Nicholas Nethercote
9d33a8fe51 Simplify ReplaceRange.
Currently the second element is a `Vec<(FlatToken, Spacing)>`. But the
vector always has zero or one elements, and the `FlatToken` is always
`FlatToken::AttrTarget` (which contains an `AttributesData`), and the
spacing is always `Alone`. So we can simplify it to
`Option<AttributesData>`.

An assertion in `to_attr_token_stream` can can also be removed, because
`new_tokens.len()` was always 0 or 1, which means than `range.len()`
is always greater than or equal to it, because `range.is_empty()` is
always false (as per the earlier assertion).
2024-07-07 15:58:36 +10:00
Nicholas Nethercote
b261501b71 Remove HasSpan trait.
The only place it is meaningfully used is in a panic message in
`TokenStream::from_ast`. But `node.span()` doesn't need to be printed
because `node` is also printed and it must contain the span.
2024-07-07 15:58:34 +10:00
Nicholas Nethercote
88373e9f0c Remove an unnecessary local variable. 2024-07-07 15:58:12 +10:00
Nicholas Nethercote
14b859fa3b Rename Attribute::tokens (the inherent method).
To distinguish it from the `HasTokens` method.
2024-07-07 15:58:10 +10:00
bors
35e6e4c5e9 Auto merge of #127321 - Kobzol:bootstrap-cmd-refactor-4, r=onur-ozkan
Bootstrap command refactoring: quality-of-life improvements (step 4)

Continuation of https://github.com/rust-lang/rust/pull/127120.

This PR simply introduce two new functions (`BootstrapCommand:run` and `command`) that make it a bit easier to use commands in bootstrap. It also adds several `#[must_use]` annotations. This shouldn't (hopefully) have any effect on behavior.

Especially the first commit IMO makes any code that runs commands more readable, and allows using the API in a fluent way, without needing to jump back and forth between the command and the `Build(er)`.

Tracking issue: https://github.com/rust-lang/rust/issues/126819

r? `@onur-ozkan`
2024-07-07 05:53:57 +00:00
Chayim Refael Friedman
54556f49d3 Specialize TrustedLen for Iterator::unzip()
Don't check the capacity every time (and also for `Extend` for tuples, as this is how `unzip()` is implemented).

I did this with an unsafe method on `Extend` that doesn't check for growth (`extend_one_unchecked()`). I've marked it as perma-unstable currently, although we may want to expose it in the future so collections outside of std can benefit from it. Then specialize `Extend for (A, B)` for `TrustedLen` to call it.

It may seem that an alternative way of implementing this is to have a semi-public trait (`#[doc(hidden)]` public, so collections outside of core can implement it) for `extend()` inside tuples, and specialize it from collections. However, it is impossible due to limitations of `min_specialization`.

A concern that may arise with the current approach is that implementing `extend_one_unchecked()` correctly must also incur implementing `extend_reserve()`, otherwise you can have UB. This is a somewhat non-local safety invariant. However, I believe this is fine, since to have actual UB you must have unsafe code inside your `extend_one_unchecked()` that makes incorrect assumption, *and* not implement `extend_reserve()`. I've also documented this requirement.
2024-07-07 06:58:52 +03:00
bors
9e27377bec Auto merge of #127404 - compiler-errors:rpitit-entailment-false-positive, r=oli-obk
Don't try to label `ObligationCauseCode::CompareImplItem` for an RPITIT, since it has no name

The old (current) trait solver has a limitation that when a where clause in param-env must be normalized using the same where clause, then we get spurious errors in `normalize_param_env_or_error`. I don't think there's an issue tracking it, but it's the root cause for many of the "fixed-by-next-solver" labeled issues.

Specifically, these errors may occur when checking predicate entailment of the GAT that comes out of desugaring RPITITs. Since we use `ObligationCauseCode::CompareImplItem` for these predicates, we try calling `item_name` on an RPITIT which fails, since the RPITIT has no name.

We simply suppress this logic when we're reporting a predicate entailment error for an RPITIT. RPITITs should never have predicate entailment errors, *by construction*, but they may due to this bug in the old solver.

Addresses the ICE in #127331, though doesn't fix the underlying issue (which is fundamental to the old solver).

r? types
2024-07-07 03:22:12 +00:00
bors
289deb9ed7 Auto merge of #127335 - Oneirical:put-on-a-petestal, r=jieyouxu
Migrate `emit-shared-files` and `emit-path-unhashed` `run-make` tests to rmake

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

try-job: x86_64-msvc
try-job: aarch64-apple
try-job: armhf-gnu
try-job: test-various
2024-07-07 01:05:25 +00:00
bors
6ba80a9f8d Auto merge of #126987 - petrochenkov:atvisord2, r=pnkfelix
out_of_scope_macro_calls: Detect calls inside attributes more precisely

Fixes https://github.com/rust-lang/rust/issues/126984.
2024-07-06 22:53:07 +00:00
bors
ed7e35f349 Auto merge of #127430 - compiler-errors:rollup-76ni16s, r=compiler-errors
Rollup of 4 pull requests

Successful merges:

 - #127386 (Uplift outlives components to `rustc_type_ir`)
 - #127405 (uplift `PredicateEmittingRelation`)
 - #127410 (Correct description of E0502)
 - #127417 (Show fnsig's unit output  explicitly when there is output diff in diagnostics)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-06 20:26:50 +00:00
Elisha Hollander
8d8504300f remove regexes 2024-07-06 20:11:42 +00:00
Michael Goulet
d6276b37ea Don't try to label ObligationCauseCode::CompareImplItem for an RPITIT, since it has no name 2024-07-06 15:20:37 -04:00
Michael Goulet
413345c61d
Rollup merge of #127417 - chenyukang:yukang-method-output-diff, r=oli-obk
Show fnsig's unit output  explicitly when there is output diff in diagnostics

Fixes #127263
2024-07-06 14:55:25 -04:00
Michael Goulet
9352026d26
Rollup merge of #127410 - trevyn:patch-1, r=compiler-errors
Correct description of E0502

Closes #126495
2024-07-06 14:55:24 -04:00
Michael Goulet
f664171cb5
Rollup merge of #127405 - compiler-errors:uplift-predicate-emitting-relation, r=lcnr
uplift `PredicateEmittingRelation`

Small follow-up to #127333

r? lcnr
2024-07-06 14:55:24 -04:00
Michael Goulet
dfc02d28c7
Rollup merge of #127386 - compiler-errors:uplift-outlives-components, r=lcnr
Uplift outlives components to `rustc_type_ir`

We need this to uplift `push_outlives_components`, since the elaborator uses `push_outlives_components` to elaborate type outlives obligations and I want to uplift elaboration.

This ends up reworking and inlining a fair portion of the `GenericArg::walk_shallow` function, whose only callsite was this one. I believe I got the logic correct, but may be worthwhile to look at it closely just in case. Unfortunately github was too dumb to understand that this is a rename + change -- I could also rework the git history to split the "copy the file over" part from the actual logical changes if that makes this easier to review.

r? lcnr
2024-07-06 14:55:23 -04:00
Jakub Beránek
061edfe1fa Add #[must_use] attribute to several command-related methods
This should make it harder to accidentally forget to use results of methods on `BootstrapCommand` and `CommandStatus`.
2024-07-06 20:47:54 +02:00
bors
8a8ad3433e Auto merge of #127388 - compiler-errors:elaboration-tweaks, r=lcnr
Elaboration tweaks

Removes `Filter::OnlySelfThatDefines` and reimplements `transitive_bounds_that_define_assoc_item` as a separate function, since I don't want to have to uplift that mode since it's both an implementation detail (only exists to avoid cycles in astconv) and requires exposing `Ident` as an associated type on `Interner`.

r? lcnr
2024-07-06 15:56:16 +00:00
yukang
81c86ddf8e show fnsig's output when there is difference 2024-07-06 23:29:58 +08:00
Michael Goulet
c2a88ea6ca Remove walk_shallow 2024-07-06 10:47:46 -04:00
Michael Goulet
cc6c5de39d Import via rustc_type_ir::outlives
We could use rustc_middle::ty::outlives I guess?
2024-07-06 10:47:46 -04:00
Michael Goulet
23c6f23b21 Uplift push_outlives_components 2024-07-06 10:47:46 -04:00
Michael Goulet
e5d6a416e8 Uplift PredicateEmittingRelation first 2024-07-06 10:05:49 -04:00
yukang
f46c4129e0 show unit output when there is only output diff in diagnostics 2024-07-06 21:00:30 +08:00
Vadim Petrochenkov
83cf471361 out_of_scope_macro_calls: Detect calls inside attributes more precisely 2024-07-06 15:36:30 +03:00
bors
3bec61736a Auto merge of #127420 - matthiaskrgr:rollup-vpitwow, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #127275 (offset_from, offset: clearly separate safety requirements the user needs to prove from corollaries that automatically follow)
 - #127379 (rustdoc-search: stop constructing pointless arrays in decode)
 - #127391 (Use verbose suggestion for `ptr::null_mut()`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-06 12:07:55 +00:00
Matthias Krüger
1e0028197f
Rollup merge of #127391 - estebank:null_mut, r=cjgillot
Use verbose suggestion for `ptr::null_mut()`
2024-07-06 13:26:26 +02:00
Matthias Krüger
04056524a0
Rollup merge of #127379 - notriddle:notriddle/decode, r=GuillaumeGomez
rustdoc-search: stop constructing pointless arrays in decode

I'm not sure why I ever thought that would be okay. This is clearly hot code, and should avoid Array.prototype.map when it's not needed. In any case, it shows up in the profiler.

rustdoc-js-profiler:
https://notriddle.com/rustdoc-html-demo-11/decode-opt-1/index.html

Firefox profiler:
[Before](https://share.firefox.dev/3RRH2fR)
[After](https://share.firefox.dev/3Wblcq8)
2024-07-06 13:26:26 +02:00
Matthias Krüger
2137d19ef6
Rollup merge of #127275 - RalfJung:offset-from-isize-min, r=Amanieu
offset_from, offset: clearly separate safety requirements the user needs to prove from corollaries that automatically follow

By landing https://github.com/rust-lang/rust/pull/116675 we decided that objects larger than `isize::MAX` cannot exist in the address space of a Rust program, which lets us simplify these rules.

For `offset_from`, we can even state that the *absolute* distance fits into an `isize`, and therefore exclude `isize::MIN`. This PR also changes Miri to treat an `isize::MIN` difference like the other isize-overflowing cases.
2024-07-06 13:26:25 +02:00