about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-04-02Fix problem causing `rusqlite` compilation to OOM.Nicholas Nethercote-1/+3
This makes the expression re-parsing more like how it's originally done in `parse_nonterminal`.
2025-04-02Fix a problem with metavars and inner attributes.Nicholas Nethercote-22/+39
2025-04-02Remove `Token::uninterpolated_span`.Nicholas Nethercote-44/+48
In favour of the similar method on `Parser`, which works on things other than identifiers and lifetimes.
2025-04-02Remove `NtExpr` and `NtLiteral`.Nicholas Nethercote-163/+277
Notes about tests: - tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs: some messages are now duplicated due to repeated parsing. - tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs: ditto. - `tests/ui/proc-macro/macro-rules-derive-cfg.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar. - `tests/ui/attributes/nonterminal-expansion.rs`: a slight span degradation, somehow related to the recent massive attr parsing rewrite (#135726). I couldn't work out exactly what is going wrong, but I don't think it's worth holding things up for a single slightly suboptimal error message.
2025-04-01replace extra_filename with strict version hash in metrics file namesJane Losare-Lusby-8/+10
2025-04-01Rollup merge of #139202 - bjorn3:improve_comment, r=jieyouxuMatthias Krüger-1/+1
Improve docs of ValTreeKind
2025-04-01Rollup merge of #139193 - compiler-errors:inline-synthetic, r=eholkMatthias Krüger-0/+2
Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs See the comments in the test. I'm surprised that nobody found this[^1] (edit: nvm haha), but you have to go out of your way to construct the by-move body and then inline it w/ a poll call, so I guess the inliner just never really gets into this situation before. Fixes #134335 r? oli-obk [^1]: Well, ````@eholk```` found this when working on the `iter! {}` macro, since it more dramatically affects those.
2025-04-01Rollup merge of #139188 - durin42:llvm-21-LintPass, r=dianqkMatthias Krüger-4/+9
PassWrapper: adapt for llvm/llvm-project@94122d58fc77079a291a3d008914… …006cb509d9db We also have to remove the LLVM argument in cast-target-abi.rs for LLVM 21. I'm not really sure what the best approach here is since that test already uses revisions. We could also fork the test into a copy for LLVM 19-20 and another for LLVM 21, but what I did for now was drop the lint-abort-on-error flag to LLVM figuring that some coverage was better than none, but I'm happy to change this if that was a bad direction. r? dianqk ````@rustbot```` label llvm-main
2025-04-01Rollup merge of #139022 - lcnr:incr-obligation-depth, r=oli-obkMatthias Krüger-38/+38
increment depth of nested obligations properly fixes the root cause of #109268. While we didn't get hangs here before, I ended up encountering its root cause again with #138785. r? types
2025-04-01Rollup merge of #138790 - xizheyin:issue-138626, r=compiler-errorsMatthias Krüger-12/+12
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::one::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-01Add unstable `--print=crate-root-lint-levels`Urgau-0/+31
2025-04-01Allow formatting example/gen_block_iterate.rsbjorn3-8/+12
2025-04-01check_struct_for_power_alignment: simplify codeRalf Jung-15/+6
2025-04-01Auto merge of #138492 - lcnr:rm-inline_const_pat, r=oli-obkbors-29/+14
remove `feature(inline_const_pat)` Summarizing https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/remove.20feature.28inline_const_pat.29.20and.20shared.20borrowck. With https://github.com/rust-lang/types-team/issues/129 we will start to borrowck items together with their typeck parent. This is necessary to correctly support opaque types, blocking the new solver and TAIT/ATPIT stabilization with the old one. This means that we cannot really support `inline_const_pat` as they are implemented right now: - we want to typeck inline consts together with their parent body to allow inference to flow both ways and to allow the const to refer to local regions of its parent.This means we also need to borrowck the inline const together with its parent as that's necessary to properly support opaque types - we want the inline const pattern to participate in exhaustiveness checking - to participate in exhaustiveness checking we need to evaluate it, which requires borrowck, which now relies on borrowck of the typeck root, which ends up checking exhaustiveness again. **This is a query cycle**. There are 4 possible ways to handle this: - stop typechecking inline const patterns together with their parent - causes inline const patterns to be different than inline const exprs - prevents bidirectional inference, we need to either fail to compile `if let const { 1 } = 1u32` or `if let const { 1u32 } = 1` - region inference for inline consts will be harder, it feels non-trivial to support inline consts referencing local regions from the parent fn - inline consts no longer participate in exhaustiveness checking. Treat them like `pat if pat == const { .. }` instead. We then only evaluate them after borrowck - difference between `const { 1 }` and `const FOO: usize = 1; match x { FOO => () }`. This is confusing - do they carry their weight if they are now just equivalent to using an if-guard - delay exhaustiveness checking until after borrowck - should be possible in theory, but is a quite involved change and may have some unexpected challenges - remove this feature for now I believe we should either delay exhaustiveness checking or remove the feature entirely. As moving exhaustiveness checking to after borrow checking is quite complex I think the right course of action is to fully remove the feature for now and to add it again once/if we've got that implementation figured out. `const { .. }`-expressions remain stable. These seem to have been the main motivation for https://github.com/rust-lang/rfcs/issues/2920. r? types cc `@rust-lang/types` `@rust-lang/lang` #76001
2025-04-01interpret: add a version of run_for_validation for &selfRalf Jung-12/+33
2025-04-01Auto merge of #137535 - Kobzol:split-metadata, r=petrochenkovbors-58/+156
Introduce `-Zembed-metadata` to allow omitting full metadata from rlibs and dylibs This is a continuation of https://github.com/rust-lang/rust/pull/120855 (I was mentored by `@bjorn3` to move it forward). Most of the original code was written by bjorn3, I tried to clean it up a bit and add some documentation and tests. This PR introduces a new unstable compiler flag called `-Zembed-metadata=[no|yes]`, with the default being `yes` (see https://github.com/rust-lang/rust/issues/57076 for context). When set to `no`, rustc will only store a small metadata stub inside rlibs/dylibs instead of the full metadata, to keep their size smaller. It should be used in combination with `--emit=metadata`, so that the users of such a compiled library can still read the metadata from the corresponding `.rmeta` file. [This comment](https://github.com/rust-lang/rust/pull/120855#issuecomment-1937018169) shows an example of binary/artifact size wins that can be achieved using this approach. Contrary to https://github.com/rust-lang/rust/pull/120855, this PR only introduces the new flag, along with a couple of run-make tests and documentation, but does not yet use it in bootstrap to actually compile rustc. I plan to do that as a follow-up step (along with integration in Cargo, which should ideally just always pass this flag to reduce the size of target directories). Fixes https://github.com/rust-lang/rust/issues/23366 Closes https://github.com/rust-lang/rust/issues/29511 Fixes https://github.com/rust-lang/rust/issues/57076 Another attempt of https://github.com/rust-lang/rust/pull/93945 and https://github.com/rust-lang/rust/pull/120855. r? `@petrochenkov`
2025-04-01Ensure `calculcate_dtor` is only ever called on local typesOli Scherer-4/+4
2025-04-01Store adt_async_destructor in metadataOli Scherer-4/+7
2025-04-01Store adt_destructor in metadataOli Scherer-4/+7
2025-04-01Make missing optimized MIR error more informativeOli Scherer-1/+3
2025-04-01Remove an unnecessary dtor computation and use the cached query result insteadOli Scherer-1/+1
2025-04-01Decouple trait impls of different traits wrt incrementalOli Scherer-2/+12
2025-04-01Implement `associated_items` api.makai410-7/+185
2025-04-01Improve docs of ValTreeKindbjorn3-1/+1
2025-04-01Auto merge of #138740 - nnethercote:ast-ItemKind-idents, r=fmeasebors-793/+931
Move `ast::Item::ident` into `ast::ItemKind` The follow-up to #138384, which did the same thing for `hir::ItemKind`. r? `@fmease`
2025-04-01Skip suggest impl or dyn when poly trait is not a real traitxizheyin-0/+1
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-01Bump metadata versionJakub Beránek-1/+1
2025-04-01Address review comments.Nicholas Nethercote-81/+78
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-704/+857
`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-01Ignore `#[test_case]` on anything other than `fn`/`const`/`static`.Nicholas Nethercote-20/+26
`expand_test_case` looks for any item with a `#[test_case]` attribute and adds a `test_path_symbol` attribute to it while also fiddling with the item's ident's span. This is pretty weird, because `#[test_case]` is only valid on `fn`/`const`/`static` items, as far as I can tell. But you don't currently get an error or warning if you use it on other kinds of items. This commit changes things so that a `#[test_case]` item is modified only if it is `fn`/`const`/`static`. This is relevant for moving idents from `Item` to `ItemKind`, because some item kinds don't have an ident, e.g. `impl` blocks. The commit also does the following. - Renames a local variable `test_id` as `test_ident`. - Changes a `const` to `static` in `tests/ui/custom_test_frameworks/full.rs` to give the `static` case some test coverage. - Adds a `struct` and `impl` to the same test to give some test coverage to the non-affected item kinds. These have a `FIXME` comment identifying the weirdness here. Hopefully this will be useful breadcrumbs for somebody else in the future.
2025-04-01Factor out some shared code.Nicholas Nethercote-32/+14
`global_allocator_spans` and `alloc_error_handler_span` are identical except for `name`.
2025-04-01coverage: Don't split bang-macro spans, just truncate themZalathar-32/+15
2025-04-01coverage: Instead of splitting, just discard any span that overlaps a holeZalathar-46/+17
2025-04-01coverage: Shrink call spans to just the function nameZalathar-11/+7
This is a way to shrink call spans that doesn't involve mixing different spans, and avoids overlap with argument spans. This patch also removes some low-value comments that were causing rustfmt to ignore the match arms.
2025-03-31increment depth of nested obligationslcnr-38/+38
2025-03-31Feed HIR for by-move coroutine body def, since the inliner tries to read its ↵Michael Goulet-0/+2
attrs
2025-03-31Rollup merge of #139181 - tiif:doc, r=NoratriebMatthias Krüger-2/+2
Fix invalid link in docs
2025-03-31Rollup merge of #139039 - nnethercote:less-kw-Empty-4, r=petrochenkovMatthias Krüger-10/+15
Reduce kw::Empty usage, part 4 Another step towards #137978. r? `@petrochenkov`
2025-03-31Rollup merge of #138426 - madsmtm:vita-llvm-target, r=jieyouxuMatthias Krüger-1/+1
Fix `armv7-sony-vita-newlibeabihf` LLVM target triple It was previously normalized by LLVM to `thumbv7a-vita-unknown-eabihf` (can be seen with `clang -target thumbv7a-vita-eabihf -v`), which seems wrong, as Vita is the OS name. Motivation: To make it easier to verify that [`cc-rs`' conversion from `rustc` to Clang/LLVM triples](https://github.com/rust-lang/cc-rs/issues/1431) is correct. CC target maintainers ``@nikarh,`` ``@pheki`` and ``@ZetaNumbers.`` r? jieyouxu
2025-04-01Improve `is_doc_keyword`.Nicholas Nethercote-3/+7
This is part of the implementation of `#[doc(keyword = "match")]` attributes used by `std` to provide documentation for keywords. `is_doc_keyword` currently does a crude keyword range test that's intended to catch all keywords but misses `kw::Yeet`. This commit changes it to use `Symbol` methods, including the new `is_weak` method (required for `union`). `Symbol` methods are much less prone to falling out of date if new keywords are added.
2025-04-01Tweak `check_doc_keyword`.Nicholas Nethercote-5/+5
To use one `kw::Empty` instead of two. It's a little more direct this way, and avoids `kw::Empty` being used for both "no string" and "empty string".
2025-04-01Use `sym::dummy` in one more place.Nicholas Nethercote-2/+3
It makes it clearer that the symbol is unused and doesn't matter.
2025-03-31PassWrapper: adapt for ↵Augie Fackler-4/+9
llvm/llvm-project@94122d58fc77079a291a3d008914006cb509d9db We also have to remove the LLVM argument in cast-target-abi.rs for LLVM 21. I'm not really sure what the best approach here is since that test already uses revisions. We could also fork the test into a copy for LLVM 19-20 and another for LLVM 21, but what I did for now was drop the lint-abort-on-error flag to LLVM figuring that some coverage was better than none, but I'm happy to change this if that was a bad direction. The above also applies for ffi-out-of-bounds-loads.rs. r? dianqk @rustbot label llvm-main
2025-03-31Fix invalid linktiif-2/+2
2025-03-31Expose `registered_tools` directly without `TyCtxt`-queryUrgau-4/+13
2025-03-31Expose `LintLevelsBuilder` with crate root builderUrgau-0/+14
2025-03-31Auto merge of #139169 - matthiaskrgr:rollup-nfy4aew, r=matthiaskrgrbors-40/+166
Rollup of 6 pull requests Successful merges: - #138176 (Prefer built-in sized impls (and only sized impls) for rigid types always) - #138749 (Fix closure recovery for missing block when return type is specified) - #138842 (Emit `unused_attributes` for `#[inline]` on exported functions) - #139153 (Encode synthetic by-move coroutine body with a different `DefPathData`) - #139157 (Remove mention of `exhaustive_patterns` from `never` docs) - #139167 (Remove Amanieu from the libs review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-31hygiene: Rename semi-transparent to semi-opaqueVadim Petrochenkov-30/+30
The former is just too long, see the examples in `hygiene.rs`
2025-03-31Rollup merge of #139153 - compiler-errors:incr-comp-closure, r=oli-obkMatthias Krüger-12/+32
Encode synthetic by-move coroutine body with a different `DefPathData` See the included test. In the first revision rpass1, we have an async closure `{closure#0}` which has a coroutine as a child `{closure#0}::{closure#0}`. We synthesize a by-move coroutine body, which is `{closure#0}::{closure#1}` which depends on the mir_built query, which depends on the typeck query. In the second revision rpass2, we've replaced the coroutine-closure by a closure with two children closure. Notably, the def path of the second child closure is the same as the synthetic def id from the last revision: `{closure#0}::{closure#1}`. When type-checking this closure, we end up trying to compute its def_span, which tries to fetch it from the incremental cache; this will try to force the dependencies from the last run, which ends up forcing the mir_built query, which ends up forcing the typeck query, which ends up with a query cycle. The problem here is that we really should never have used the same `DefPathData` for the synthetic by-move coroutine body, since it's not a closure. Changing the `DefPathData` will mean that we can see that the def ids are distinct, which means we won't try to look up the closure's def span from the incremental cache, which will properly skip replaying the node's dependencies and avoid a query cycle. Fixes #139142
2025-03-31Rollup merge of #138842 - Noratrieb:inline-exported, r=me,saethlinMatthias Krüger-0/+29
Emit `unused_attributes` for `#[inline]` on exported functions I saw someone post a code sample that contained these two attributes, which immediately made me suspicious. My suspicions were confirmed when I did a small test and checked the compiler source code to confirm that in these cases, `#[inline]` is indeed ignored (because you can't exactly `LocalCopy`an unmangled symbol since that would lead to duplicate symbols, and doing a mix of an unmangled `GloballyShared` and mangled `LocalCopy` instantiation is too complicated for our current instatiation mode logic, which I don't want to change right now). So instead, emit the usual unused attribute lint with a message saying that the attribute is ignored in this position. I think this is not 100% true, since I expect LLVM `inlinehint` to still be applied to such a function, but that's not why people use this attribute, they use it for the `LocalCopy` instantiation mode, where it doesn't work. r? saethlin as the instantiation guy Procedurally, I think this should be fine to merge without any lang involvement, as this only does a very minor extension to an existing lint.