Skip to content

Conversation

flip1995
Copy link
Member

r? @ghost

changelog: none

Ryan van Polen and others added 21 commits May 16, 2025 13:28
Keep the `P` constructor function for now, to minimize immediate churn.

All the `into_inner` calls are removed, which is nice.
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match
the textual order in the source code.

The interesting part of the change is in
`compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical
refactoring.
…jhpratt

Stabilize feature `result_flattening`

Stabilizes the `Result::flatten` method

## Implementations

- [x] Implementation `Result::flatten`: rust-lang/rust#70140
- [x] Implementation `const` `Result::flatten`: rust-lang/rust#130692
- [x] Update stabilization attribute macros (this PR)

## Stabilization process

- [x] Created this PR [suggested](rust-lang/rust#70142 (comment)) by ``@RalfJung``
- [x] FCP (haven't found any, is it applicable here?)
- [ ] Close issue rust-lang/rust#70142
I find it much easier to think about in the positive sense.
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res`
results, one per namespace (type, value, or macro). `lower_import_res`
takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the
`SmallVec`. This is pretty weird. The input `PerNS` makes it clear which
`Res` belongs to which namespace, but the `SmallVec` throws that
information away.

And code that operates on the `SmallVec` tends to use iteration (or even
just grabbing the first entry!) without knowing which namespace the
`Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible
type to use here, because it can contain any number of elements (even
though it's optimized for 3 in this case).

This commit changes `UsePath` so it also contains a
`PerNS<Option<Res<HirId>>>`. This type preserves more information and is
more self-documenting. The commit also changes a lot of the use sites to
access the result for a particular namespace. E.g. if you're looking up
a trait, it will be in the `Res` for the type namespace if it's present;
it's silly to look in the `Res` for the value namespace or macro
namespace. Overall I find the new code much easier to understand.

However, some use sites still iterate. These now use `present_items`
because that filters out the `None` results.

Also, `redundant_pub_crate.rs` gets a bigger change. A
`UseKind:ListStem` item gets no `Res` results, which means the old `all`
call in `is_not_macro_export` would succeed (because `all` succeeds on
an empty iterator) and the `ListStem` would be ignored. This is what we
want, but was more by luck than design. The new code detects `ListStem`
explicitly. The commit generalizes the name of that function
accordingly.

Finally, the commit also removes the `use_path` arena, because
`PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be
allocated in the arena shared by all `Copy` types.
Overhaul `UsePath`

It currently uses `SmallVec<[Res; 3]>` which is really weird. Details in the individual commits.

r? `@petrochenkov`
Use the informative error as the main const eval error message

r? `@RalfJung`

I only did the minimal changes necessary to the const eval error machinery. I'd prefer not to mix test changes with refactorings 😆
…ngjubilee

Fix incorrect eq_unspanned in TokenStream

Fixes rust-lang/rust#141522

r? ``@workingjubilee``

should we remove this function?
since it's used in several places, i'd prefer to keep it.
… r=traviscross,jieyouxu

Add a new `mismatched-lifetime-syntaxes` lint

The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](rust-lang/rust#120808 (comment)) their decision. The summary-of-the-summary is:

- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](rust-lang/rust#48686)! Some examples:

    ```rust
    // Lint will warn about these
    fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
    fn(&'static u8) -> &u8;
    ```

- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:

    ```rust
    // Lint will not warn about these
    fn(&u8) -> &'_ u8;
    fn(&'_ u8) -> &u8;
    fn(&u8) -> ContainsLifetime<'_>;
    ```

- Having a lint for consistent syntax of elided lifetimes will make the [future goal](rust-lang/rust#91639) of warning-by-default for paths participating in elision much simpler.

---

This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None

Turns out many locations actually have a span available that we could use, so I used it
Reduce `ast::ptr::P` to a typedef of `Box`

As per the MCP at rust-lang/compiler-team#878.

r? `@fee1-dead`
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 13, 2025
@flip1995 flip1995 enabled auto-merge June 13, 2025 08:21
@flip1995 flip1995 added this pull request to the merge queue Jun 13, 2025
Merged via the queue into rust-lang:master with commit 4ef7529 Jun 13, 2025
11 checks passed
@flip1995 flip1995 deleted the rustup branch June 13, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants