Commit graph

2216 commits

Author SHA1 Message Date
Mara Bos
5f4d676e70 Remove #[rustc_macro_edition_2021].
It was only temporarily used by pin!(), which no longer needs it.
2025-04-20 11:15:46 +02:00
Matthias Krüger
9842698be5
Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco
hygiene: Rename semi-transparent to semi-opaque

"Semi-transparent" is just too damn long for a name, especially when used multiple times on a single line, it bothered me when working on #139083.

An optimist sees a macro as semi-opaque, a pessimist sees it as semi-transparent.
Or is it the other way round?
2025-04-17 00:14:24 +02:00
Matthias Krüger
2144c940ce
Rollup merge of #139848 - nnethercote:kw-Empty-5, r=compiler-errors
Reduce kw::Empty usage, part 5

Another step towards https://github.com/rust-lang/rust/issues/137978.

r? `@davidtwco`
2025-04-15 21:16:05 +02:00
bors
f433fa46b0 Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests

Successful merges:

 - #138374 (Enable contracts for const functions)
 - #138380 (ci: add runners for vanilla LLVM 20)
 - #138393 (Allow const patterns of matches to contain pattern types)
 - #139517 (std: sys: process: uefi: Use NULL stdin by default)
 - #139554 (std: add Output::exit_ok)
 - #139660 (compiletest: Add an experimental new executor to replace libtest)
 - #139669 (Overhaul `AssocItem`)
 - #139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file})
 - #139750 (std/thread: Use default stack size from menuconfig for NuttX)
 - #139772 (Remove `hir::Map`)
 - #139785 (Let CStrings be either 1 or 2 byte aligned.)
 - #139789 (do not unnecessarily leak auto traits in item bounds)
 - #139791 (drop global where-bounds before merging candidates)
 - #139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates)
 - #139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix)
 - #139833 (Fix some HIR pretty-printing problems)
 - #139836 (Basic tests of MPMC receiver cloning)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-15 08:02:23 +00:00
Nicholas Nethercote
c12b4aade0 Use a dummy ident for a lint_if_path_starts_with_module call.
This is pretty weird code. As the `HACK` comment indicates, we push the
empty ident here only to make the path longer, so certain checks to
occur within `lint_if_path_starts_with_module`. `dummy` is a better
choice because it explicitly communicates that the actual value doesn't
matter.
2025-04-15 16:05:13 +10:00
Stuart Cook
13cd5256ac
Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk
Overhaul `AssocItem`

`AssocItem` has multiple fields that only make sense some of the time. E.g. the `name` can be empty if it's an RPITIT associated type. It's clearer and less error prone if these fields are moved to the relevant `kind` variants.

r? ``@fee1-dead``
2025-04-15 15:47:27 +10:00
Nicholas Nethercote
78599d83e7 Move name field from AssocItem to AssocKind variants.
To accurately reflect that RPITIT assoc items don't have a name. This
avoids the use of `kw::Empty` to mean "no name", which is error prone.

Helps with #137978.
2025-04-15 08:07:15 +10:00
Matthias Krüger
04d10520f0
Rollup merge of #139811 - yotamofek:pr/newtype_cleanups, r=oli-obk
Use `newtype_index!`-generated types more idiomatically

Continuation of sorts of #139674
Shouldn't affect anything, just makes some code simpler
2025-04-14 21:55:40 +02:00
Yotam Ofek
4b63362f3d Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
Matthias Krüger
a4adc005a1
Rollup merge of #139127 - compiler-errors:prim-ty-hack, r=oli-obk
Fix up partial res of segment in primitive resolution hack

There is a hack in the resolver:

```
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
// don't report an error right away, but try to fallback to a primitive type.
```

This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics.

We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it.

cc https://github.com/rust-lang/rust/issues/139095#issuecomment-2764371934
2025-04-14 18:15:30 +02:00
Nicholas Nethercote
ce2aa97cd6 Move has_self field to hir::AssocKind::Fn.
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field,
which is misplaced, because it's only relevant for associated fns, not
for associated consts or types. This commit moves it (and renames it) to
the `AssocKind::Fn` variant, where it belongs.

This requires introducing a new C-style enum, `AssocTag`, which is like
`AssocKind` but without the fields. This is because `AssocKind` values
are passed to various functions like `find_by_ident_and_kind` to
indicate what kind of associated item should be searched for, and having
to specify `has_self` isn't relevant there.

New methods:
- Predicates `AssocItem::is_fn` and `AssocItem::is_method`.
- `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`.

Removed `find_by_name_and_kinds`, which is unused.

`AssocItem::descr` can now distinguish between methods and associated
functions, which slightly improves some error messages.
2025-04-14 16:13:04 +10:00
Jacob Pratt
2b54f9bfb1
Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errors
Tweak `DefPathData`

Some improvements in and around `DefPathData`, following on from #137977.

r? `@spastorino`
2025-04-11 21:21:01 +02:00
Oli Scherer
98d51fb44f Only compute the DefId when a diagnostic is definitely emitted 2025-04-11 10:04:27 +00:00
Oli Scherer
d35e830aad Avoid a node_id_to_def_id call by just storing DefIds instead of NodeIds 2025-04-11 10:04:27 +00:00
Oli Scherer
33a6820c2f Avoid storing the LocalDefId twice 2025-04-11 10:04:27 +00:00
Oli Scherer
f5c60f616f Avoid another node_id_to_def_id call 2025-04-11 09:49:35 +00:00
Oli Scherer
24efefafcb Avoid a reverse map that is only used in diagnostics paths 2025-04-11 09:33:38 +00:00
Nicholas Nethercote
fad2535e4b Adjust an assertion.
No need to convert the `DefKind` to `DefPathData`, they're very similar
types.
2025-04-11 16:03:48 +10:00
Matthias Krüger
79f357e63d
Rollup merge of #139510 - nnethercote:name-to-ident, r=fee1-dead
Rename some `name` variables as `ident`.

It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`.

This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.

r? `@fee1-dead`
2025-04-10 17:27:14 +02:00
Nicholas Nethercote
1b3fc585cb Rename some name variables as ident.
It bugs me when variables of type `Ident` are called `name`. It leads to
silly things like `name.name`. `Ident` variables should be called
`ident`, and `name` should be used for variables of type `Symbol`.

This commit improves things by by doing `s/name/ident/` on a bunch of
`Ident` variables. Not all of them, but a decent chunk.
2025-04-10 09:30:55 +10:00
Nicholas Nethercote
7ae5c7f32d Avoid an empty trait name in impl blocks.
`resolve_ident_in_lexical_scope` checks for an empty name. Why is this
necessary? Because `parse_item_impl` can produce an `impl` block with an
empty trait name in some cases. This is pretty gross and very
non-obvious.

This commit avoids the use of the empty trait name. In one case the
trait name is instead pulled from `TyKind::ImplTrait`, which prevents
the output for `tests/ui/impl-trait/extra-impl-in-trait-impl.rs` from
changing. In the other case we just fail the parse and don't try to
recover. I think losing error recovery in this obscure case is worth
the code cleanup.

This change affects `tests/ui/parser/impl-parsing.rs`, which is split in
two, and the obsolete `..` syntax cases are removed (they are tested
elsewhere).
2025-04-09 15:01:14 +10:00
Stuart Cook
82df6229b6
Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obk
Add new `PatKind::Missing` variants

To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits.

r? ``@oli-obk``
2025-04-07 22:29:17 +10:00
Takayuki Maeda
eb23a597c8
Rollup merge of #139184 - Urgau:crate-root-lint-levels, r=jieyouxu
Add unstable `--print=crate-root-lint-levels`

This PR implements `--print=crate-root-lint-levels` from MCP 833 https://github.com/rust-lang/compiler-team/issues/833.

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

Best reviewed commit by commit.
2025-04-02 22:52:45 +09:00
Matthias Krüger
068594e365
Rollup merge of #138790 - xizheyin:issue-138626, r=compiler-errors
Note potential but private items in show_candidates

Closes #138626 .
We should add potential private items to give ample hints.
And for the other seemingly false positive ` pub use crate:1️⃣:Foo;` should be kept because we don't know if the user wants to import other module's items or not, and therefore should be given the full option to do so.
r? compiler
2025-04-01 20:25:21 +02:00
bors
ed201574c5 Auto merge of #138740 - nnethercote:ast-ItemKind-idents, r=fmease
Move `ast::Item::ident` into `ast::ItemKind`

The follow-up to #138384, which did the same thing for `hir::ItemKind`.

r? `@fmease`
2025-04-01 07:21:28 +00:00
Nicholas Nethercote
ec10833609 Address review comments. 2025-04-01 16:07:23 +11:00
Nicholas Nethercote
df247968f2 Move ast::Item::ident into ast::ItemKind.
`ast::Item` has an `ident` field.

- It's always non-empty for these item kinds: `ExternCrate`, `Static`,
  `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`,
  `Trait`, `TraitAlias`, `MacroDef`, `Delegation`.

- It's always empty for these item kinds: `Use`, `ForeignMod`,
  `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`.

There is a similar story for `AssocItemKind` and `ForeignItemKind`.

Some sites that handle items check for an empty ident, some don't. This
is a very C-like way of doing things, but this is Rust, we have sum
types, we can do this properly and never forget to check for the
exceptional case and never YOLO possibly empty identifiers (or possibly
dummy spans) around and hope that things will work out.

The commit is large but it's mostly obvious plumbing work. Some notable
things.

- `ast::Item` got 8 bytes bigger. This could be avoided by boxing the
  fields within some of the `ast::ItemKind` variants (specifically:
  `Struct`, `Union`, `Enum`). I might do that in a follow-up; this
  commit is big enough already.

- For the visitors: `FnKind` no longer needs an `ident` field because
  the `Fn` within how has one.

- In the parser, the `ItemInfo` typedef is no longer needed. It was used
  in various places to return an `Ident` alongside an `ItemKind`, but
  now the `Ident` (if present) is within the `ItemKind`.

- In a few places I renamed identifier variables called `name` (or
  `foo_name`) as `ident` (or `foo_ident`), to better match the type, and
  because `name` is normally used for `Symbol`s. It's confusing to see
  something like `foo_name.name`.
2025-04-01 14:08:57 +11:00
Nicholas Nethercote
a6a6d01bbc Use sym::dummy in one more place.
It makes it clearer that the symbol is unused and doesn't matter.
2025-04-01 07:34:23 +11:00
Urgau
69cb0a9e15 Expose registered_tools directly without TyCtxt-query 2025-03-31 18:03:12 +02:00
Vadim Petrochenkov
54bb849aff hygiene: Rename semi-transparent to semi-opaque
The former is just too long, see the examples in `hygiene.rs`
2025-03-31 15:41:48 +03:00
Michael Goulet
18c787f48f Fix up partial res of segment in primitive resolution hack 2025-03-30 04:22:14 +00:00
Matthias Krüger
3e968c7e9f
Rollup merge of #139075 - oli-obk:resolver-item-lifetime, r=compiler-errors
Do not treat lifetimes from parent items as influencing child items

```rust
struct A;
impl Bar<'static> for A {
    const STATIC: &str = "";
    //            ^ no future incompat warning
}
```

has no future incompat warning, because there is no ambiguity. But

```rust
struct C;
impl Bar<'_> for C {
//       ^^ this lifeimte
    const STATIC: &'static str = {
        struct B;
        impl Bar<'static> for B {
            const STATIC: &str = "";
            // causes     ^ to emit a future incompat warning
        }
        ""
    };
}
```

had one before this PR, because the impl for `B` (which is just a copy of `A`) thought it was influenced by a lifetime on the impl for `C`.

I double checked all other `lifetime_ribs` iterations and all of them do check for `Item` boundaries. This feels very fragile tho, and ~~I think we should do not even be able to see ribs from parent items, but that's a different refactoring that I'd rather not do at the same time as a bugfix~~. EDIT: ah nevermind, this is needed for improving diagnostics like "use of undeclared lifetime" being "can't use generic parameters from outer item" instead.

r? `@compiler-errors`
2025-03-28 21:18:32 +01:00
Oli Scherer
dabee5d563 Do not treat lifetimes from parent items as influencing child items 2025-03-28 17:06:00 +00:00
Matthias Krüger
bdc5adfe78
Rollup merge of #138678 - durin42:rmeta-stability, r=fmease
rustc_resolve: fix instability in lib.rmeta contents

rust-lang/rust@23032f31c9 accidentally introduced some nondeterminism in the ordering of lib.rmeta files, which we caught in our bazel-based builds only recently due to being further behind than normal. In my testing, this fixes the issue.
2025-03-28 12:59:55 +01:00
Nicholas Nethercote
909f449247 Remove kw::Extra checks that are no longer necessary.
Thanks to the introduction of `PatKind::Missing`.
2025-03-28 09:20:40 +11:00
Jacob Pratt
d517a4f0ae
Rollup merge of #139014 - xizheyin:issue-138931, r=oli-obk
Improve suggest construct with literal syntax instead of calling

Closing #138931

When constructing a structure through a format similar to calling a constructor, we can use verbose suggestions to hint at using literal syntax for clearer advice. The case of multiple fields is also considered here, provided that the field has the same number of arguments as CallExpr.

r? compiler
2025-03-27 13:11:20 -04:00
Augie Fackler
1437dec799 rustc_resolve: prevent iteration of refids for completeness
This came up in review, and it should help some future author
not introduce non-deterministic output here.
2025-03-27 12:39:48 -04:00
xizheyin
4648650d89
Improve suggest construct with literal syntax instead of calling
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-27 20:09:37 +08:00
Stuart Cook
3db0999100
Rollup merge of #138985 - oli-obk:push-mvlqmtmyozro, r=compiler-errors
Use the correct binder scope for elided lifetimes in assoc consts

Beyond diagnostics this has no real effect, and it's also just about a future incompat lint. But it causes ICEs in some refactorings that I'm doing, so trying to get it out of the way
2025-03-27 15:57:25 +11:00
Stuart Cook
d26047dcaa
Rollup merge of #138977 - oli-obk:invoc-parent-keep-aggregated, r=compiler-errors
Don't deaggregate InvocationParent just to reaggregate it again

Also makes it easier to add more things to it in the future (which I am doing in some local experiments, so not really a reason to do this just now, but I think this PR stands on its own).
2025-03-27 15:57:24 +11:00
Oli Scherer
a830c59f24 Use the correct binder scope for elided lifetimes in assoc consts 2025-03-26 12:44:33 +00:00
Oli Scherer
781785d2b6 Don't deaggregate InvocationParent just to reaggregate it again 2025-03-26 09:40:27 +00:00
Stuart Cook
30344f7fa3
Rollup merge of #138898 - fmease:decrustify-parser-post-ty-ascr, r=compiler-errors
Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax

**Disclaimer**: This PR is intended to mostly clean up code as opposed to bringing about behavioral changes. Therefore it doesn't aim to address any of the 'FIXME: remove after a month [dated: 2023-05-02]: "type ascription syntax has been removed, see issue [#]101728"'.

---

By commit:

1. Removes truly dead code:
   * Since 1.71 (#109128) `let _ = { f: x };` is a syntax error as opposed to a semantic error which allows the parse-time diagnostic (suggestion) "*struct literal body without path // you might have forgotten […]*" to kick in.
   * The analysis-time diagnostic (suggestion) from <=1.70 "*cannot find value \`f\` in this scope // you might have forgotten […]*" is therefore no longer reachable.
2. Updates `is_certainly_not_a_block` to be in line with the current grammar:
   * The seq. `{ ident:` is definitely not the start of a block. Before the removal of ty ascr, `{ ident: ty_start` would begin a block expr.
   * This shouldn't make more code compile IINM, it should *ultimately* only affect diagnostics.
   * For example, `if T { f: () } {}` will now be interpreted as an `if` with struct lit `T { f: () }` as its *condition* (which is banned in the parser anyway) as opposed to just `T` (with the *consequent* being `f : ()` which is also invalid (since 1.71)). The diagnostics are almost the same because we have two separate parse recovery procedures + diagnostics: `StructLiteralNeedingParens` (*invalid struct lit*) before and `StructLiteralNotAllowedHere` (*struct lits aren't allowed here*) now, as you can see from the diff.
   * (As an aside, even before this PR, fn `maybe_suggest_struct_literal` should've just used the much older & clearer `StructLiteralNotAllowedHere`)
   * NB: This does sadly regress the compiler output for `tests/ui/parser/type-ascription-in-pattern.rs` but that can be fixed in follow-up PRs. It's not super important IMO and a natural consequence.
3. Removes code that's become dead due to the prior commit.
   * Basically reverts #106620 + #112475 (without regressing rustc's output!).
   * Now the older & more robust parse recovery procedure (cc `StructLiteralNotAllowedHere`) takes care of the cases the removed code used to handle.
   * This automatically fixes the suggestions for \[[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e2030163b11ee96d17adc3325b01780)\]:
     * `if Ty::<i32> { f: K }.m() {}`: `if Ty::<i32> { SomeStruct { f: K } }.m() {}` (broken) → ` if (Ty::<i32> { f: K }).m() {}`
     * `if <T as Trait>::Out { f: K::<> }.m() {}`: `if <T as Trait>(::Out { f: K::<> }).m() {}` (broken) → `if (<T as Trait>::Out { f: K::<> }).m() {}`
4. Merge and simplify UI tests pertaining to this issue, so it's easier to add more regression tests like for the two cases mentioned above.
5. Merge UI tests and add the two regression tests.

Best reviewed commit by commit (on request I'll partially squash after approval).
2025-03-26 19:40:28 +11:00
Jacob Pratt
5bd69d940e
Rollup merge of #138911 - compiler-errors:define-opaque, r=oli-obk
Allow defining opaques in statics and consts

r? oli-obk

Fixes https://github.com/rust-lang/rust/issues/138902
2025-03-25 20:34:49 -04:00
Matthias Krüger
1107fc7ad2
Rollup merge of #138929 - oli-obk:assoc-ctxt-of-trait, r=compiler-errors
Visitors track whether an assoc item is in a trait impl or an inherent impl

`AssocCtxt::Impl` now contains an `of_trait` field. This allows ast lowering and nameres to not have to track whether we're in a trait impl or an inherent impl.
2025-03-25 18:09:07 +01:00
Matthias Krüger
ffc571797b
Rollup merge of #138924 - nnethercote:less-kw-Empty-3, r=compiler-errors
Reduce `kw::Empty` usage, part 3

Remove some more `kw::Empty` uses, in support of #137978.

r? `@davidtwco`
2025-03-25 18:09:07 +01:00
Matthias Krüger
946192b25a
Rollup merge of #138886 - samueltardieu:push-xxkzmupznoky, r=jieyouxu
Fix autofix for `self` and `self as …` in `unused_imports` lint

This fixes two problems with the autofixes for the `unused_imports` lint:

- `use std::collections::{HashMap, self as coll};` would suggest, when `HashMap` is unused, the incorrect `use std::collections::self as coll;` which does not compile.
- `use std::borrow::{self, Cow};` would suggest, when `self` is unused, `use std::borrow::{Cow};`, which contains unnecessary brackets.

The first problem was reported in rust-lang/rust-clippy#14450, the second found while fixing the first one.

Fix #133750
(thanks to `@richardsamuels` for spotting the duplicate)
2025-03-25 18:09:06 +01:00
Michael Goulet
f8df298d74 Allow defining opaques in statics and consts 2025-03-25 16:44:59 +00:00
Oli Scherer
7cdc456727 Track whether an assoc item is in a trait impl or an inherent impl 2025-03-25 10:12:07 +00:00
Takayuki Maeda
117b3fdbb8
Rollup merge of #138837 - petrochenkov:resinstab2, r=jieyouxu
resolve: Avoid remaining unstable iteration

Continuation of #138580.
This should be the performance sensitive part.
2025-03-25 15:36:35 +09:00