Commit Graph

1787 Commits

Author SHA1 Message Date
Matthias Krüger 5fb00f2f28 Rollup merge of #149919 - GuillaumeGomez:doc-metadata-encoding, r=lqd
Correctly encode doc attribute metadata

Follow-up of https://github.com/rust-lang/rust/pull/149645.

The change I made was slightly wrong. [Originally](https://github.com/rust-lang/rust/pull/149645/changes#diff-72bf3e63aae0c5f24a5ce78a560db321ac6ead9df5ada3e33462a7f7d6218a55) the check was:

```rust
        if let Some(item_list) = attr.meta_item_list() {
            for item in item_list {
                if !item.has_name(sym::inline) {
```

So we were checking that there was no `doc(inline)` attribute. This PR should fix it.

r? ``@lqd``
2025-12-17 18:46:17 +01:00
Jonathan Brouwer 9308518af9 Rollup merge of #150025 - BoxyUwU:mgca_no_unused_defids, r=oli-obk
dont create unnecessary `DefId`s under mgca

Fixes rust-lang/rust#149977
Fixes rust-lang/rust#148838

Accidentally left this out of rust-lang/rust#149136 even though being able to do this was a large part of the point of the PR :3

First ICE was caused by the fact that we create a defid but never lower the nodeid associated with it to a hirid which later parts of the compiler can't handle.

See test for second ICE

r? oli-obk
2025-12-16 20:21:09 +01:00
Boxy Uwu dbfc8c218e dont create unnecessary DefIds under mgca 2025-12-15 22:59:15 +00:00
Guillaume Gomez 854f619d6a Correctly encode doc attribute metadata 2025-12-15 14:53:20 +01:00
bjorn3 0e1e72a4e7 Remove dependencies field of CrateMetadata
It is always identical to the list of values in cnum_map.
2025-12-15 09:52:58 +00:00
bjorn3 aff1f2a0de Handle CrateOrigin::Injected in CrateOrigin::private_dep 2025-12-15 09:52:58 +00:00
bjorn3 c7a99e2029 Rename variants of CrateDepKind to be more descriptive
Perhaps the old name used to be accurate in the past, but nowadays most
injected dependencies are unconditionally linked too.
2025-12-15 09:52:57 +00:00
bjorn3 a0f8dffeee Use CrateDepKind::Explicit for the profiler runtime
It is unconditionally included.
2025-12-15 09:52:41 +00:00
bjorn3 7d57c6fc8e Rename dep_root field of CrateOrigin to dep_root_for_errors 2025-12-15 09:30:42 +00:00
bors 08de25c4ea Auto merge of #149273 - bjorn3:crate_locator_improvements, r=petrochenkov
Don't leak sysroot crates through dependencies

Previously if a dependency of the current crate depended on a sysroot crate, then `extern crate` would in the current crate would pick the first loaded version of said sysroot crate even in case of an ambiguity. This is surprising and brittle. For `-Ldependency=` we already blocked this since rust-lang/rust#110229, but the fix didn't account for sysroot crates.

Should fix https://github.com/rust-lang/rust/issues/147966
2025-12-14 09:16:11 +00:00
bors 3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
Jana Dönszelmann b732030025 make EII iteration faster 2025-12-12 11:28:58 +01:00
Jana Dönszelmann 1cbdaf246b EII collection queries
EII collection queries
2025-12-12 11:28:58 +01:00
Jana Dönszelmann 2de02ac86e EII ast changes 2025-12-12 11:17:33 +01:00
Urgau 8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
bjorn3 8fec0f495e Only check for already loaded indirect dependencies in existing_match
For direct dependencies it is a lot harder to not accidentally resolve
an ambiguity through an indirect dependency edge and as it turns out
this check was actually more expensive than the work it skipped. For
indirect dependencies existing_match is still necessary due to an assert
in load, but at the same time it also can't accidentally resolve an
ambiguity given that we already know exactly which crate to look for
based on the crate hash.
2025-12-11 12:08:20 +01:00
Guillaume Gomez 9c8c67bfdd Fix warning messages 2025-12-10 12:27:34 +01:00
Guillaume Gomez acb32df7b1 Continue migration to new Attribute API for doc attribute 2025-12-10 12:27:33 +01:00
bors c61a3a44d1 Auto merge of #147984 - petrochenkov:expambig, r=yaahc
resolve: Preserve ambiguous glob reexports in crate metadata

So in cross-crate scenarios they can work in the same way as in crate-local scenarios.

Change Description: https://github.com/rust-lang/rust/pull/147984#issuecomment-3455514826

Resurrection of https://github.com/rust-lang/rust/pull/114682.
One of unblocking steps for https://github.com/rust-lang/rust/pull/145108.
Fixes https://github.com/rust-lang/rust/issues/36837.
2025-12-09 16:22:54 +00:00
Vadim Petrochenkov 51780a53f6 resolve: Preserve ambiguous glob reexports in crate metadata
So in cross-crate scenarios they can work in the same way as in crate-local scenarios.
2025-12-09 13:40:02 +03:00
Matthias Krüger ece99775da Rollup merge of #149215 - JonathanBrouwer:cfg_lints2, r=jdonszelmann
Emit `check-cfg` lints during attribute parsing rather than evaluation

The goal of this PR is to make the `eval_config_entry` not have any side effects, by moving the check-cfg lints to the attribute parsing. This also helps ensure we do emit the lint in situations where the attribute happens to be parsed, but never evaluated.

cc ``@jdonszelmann`` ``@Urgau`` for a vibe check if you feel like it
2025-12-09 06:17:22 +01:00
Jana Dönszelmann 8c7889bd18 document various traits 2025-12-08 00:28:43 +01:00
Jana Dönszelmann fa5f075d1c add TyCtxt everywhere replacing nothing or passed sessions 2025-12-08 00:24:28 +01:00
Jana Dönszelmann 395b508ce6 remove unnecessary method 2025-12-08 00:24:28 +01:00
Jana Dönszelmann 40a77eb1a2 make cdata required 2025-12-08 00:24:28 +01:00
Jana Dönszelmann f8bbf2ca06 split out blob decode trait 2025-12-08 00:24:28 +01:00
Jonathan Brouwer 71b093fd2c Emit check-cfg lints during attribute parsing rather than evaluation#149215 2025-12-06 10:22:13 +01:00
Oli Scherer 0ab78c1523 is_const_default_method is completely handled by the constness query 2025-12-03 12:38:24 +00:00
Matthias Krüger 4912d12efc Rollup merge of #149388 - jdonszelmann:rm-sess-blob, r=jieyouxu
remove session+blob decoder construction

turns out, we only did that in one place and we didn't need it.... Working on ways to make this statically known in the future. For now just a smol deletion :3
2025-11-27 20:07:15 +01:00
bjorn3 00ec159c71 Remove PathKind from CrateSource
It is never used anywhere anymore now that existing_matches doesn't use
it anymore. And there is no good reason for any other code to use it in
the future either.
2025-11-27 18:09:05 +00:00
Jana Dönszelmann e399091785 remove session+blob decoder construction 2025-11-27 16:01:56 +01:00
Oli Scherer b93f2d8b26 Add a macro for defaulted enum encoding, use it for hir::Defaultness and deduplicate the logic for other similar enums 2025-11-25 11:19:52 +00:00
bjorn3 6a11d0be89 Don't leak sysroot crates through dependencies
Previously if a dependency of the current crate depended on a sysroot
crate, then extern crate would in the current crate would pick the first
loaded version of said sysroot crate even in case of an ambiguity. This
is surprising and brittle. For -Ldependency= we already blocked this,
but the fix didn't account for sysroot crates.
2025-11-24 14:55:45 +00:00
Oli Scherer c489b92845 Not encoding the default is already handled by set 2025-11-20 12:01:31 +00:00
Oli Scherer a3062aac12 Only encode hir::Safety::Safe in metadata.
While `Unsafe` is much less common, a failure to encode it would make downstream crates default to `Safe` and think a thing marked as unsafe is actually safe
2025-11-20 12:01:31 +00:00
Oli Scherer 697419163a Remove some now-unnecessary impls 2025-11-20 12:01:31 +00:00
bors 07bdbaedc6 Auto merge of #149054 - oli-obk:min-encode, r=fee1-dead
Avoid encoding non-constness or non-asyncness in metadata

r? `@fee1-dead`

Let's see if we can get any benefit (even just metadata size) from not encoding the common case.

Inspired by https://github.com/rust-lang/rust/pull/148434#discussion_r2491732811
2025-11-19 12:06:14 +00:00
bors 6159a44067 Auto merge of #148434 - oli-obk:inherent-const-impl, r=fee1-dead
Inherent const impl

Some constifications are annoying because we need to repeat `T: Trait` bounds from an impl block on the individual constified `const fn`s as `T: [const] Trait`. We've brainstormed solutions before, and one would be to have separate `const impl` blocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along.

Also interacts with the discussion around `impl const Trait for Type` vs `const impl Trait for Type`, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme).

* [ ] rustdoc + tests
* [ ] macro stability /regression tests

r? `@fee1-dead`

cc `@traviscross` `@rust-lang/project-const-traits`
2025-11-19 02:23:56 +00:00
Oli Scherer ababa26251 Collect const_conditions for inherent impls 2025-11-18 16:00:18 +00:00
Matthias Krüger ceb33e9a3a Rollup merge of #149061 - jdonszelmann:fixed-size-encoding-assert, r=oli-obk
debug-assert FixedSizeEncoding invariant

Something like this? It asserts during encoding that for that type, decoding 0 would give the default.
Preferably, I'd either somehow statically/in const assert it once, instead of every time, but I see no easy way to do so. It'd require us to iterate all types that implement the trait or something. Let me know what you think

No types currently violate this invariant.

r? `@oli-obk`
2025-11-18 16:52:13 +01:00
Jana Dönszelmann d1bcf2ec84 debug-assert FixedSizeEncoding invariant 2025-11-18 15:59:04 +01:00
Oli Scherer 357fd66c04 Avoid encoding non-constness or non-asyncness in metadata 2025-11-18 10:12:13 +00:00
Weihang Lo cf57b9b292 fix(span): track unnormalized source len for dep-info
Add `unnormalized_source_len` field to track the byte length
of source files before normalization (the original length).

`unnormalized_source_len` is for writing the correct file length
to dep-info for `-Zchecksum-hash-algorithm`
2025-11-15 09:05:08 -05:00
Weihang Lo 5f385829e2 refactor(span): rename source_len to normalized_source_len
This is a preparation for introducing a unnormalized source length field
2025-11-15 09:05:08 -05:00
Tamir Duberstein fcf6809b05 rustc_target: introduce Os
Improve type safety by using an enum rather than strings.
2025-11-11 18:55:40 -05:00
Tamir Duberstein ddd7596400 rustc_target: introduce Env
Improve type safety by using an enum rather than strings.
2025-11-11 18:34:47 -05:00
Tamir Duberstein 86c74a4d16 rustc_target: introduce Abi
Improve type safety by using an enum rather than strings.
2025-11-11 18:22:38 -05:00
Tamir Duberstein c5f2eb61a1 rustc_target: hide TargetOptions::vendor 2025-11-09 17:43:36 -05:00
Stuart Cook 74e90d8804 Rollup merge of #148688 - JonathanBrouwer:remove_features, r=jdonszelmann
Remove unused argument `features` from `eval_config_entry`
2025-11-09 13:22:35 +11:00
bors 72b21e1a64 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
2025-11-08 22:31:33 +00:00