Commit Graph

48471 Commits

Author SHA1 Message Date
bors
014bd8290f Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwU
Implement unstable trait impl

This PR allows marking impls of stable trait with stable type as unstable.

## Approach

In std/core, an impl can be marked as unstable by annotating it with ``#[unstable_feature_bound(feat_name)]``. This will add a ``ClauseKind::Unstable_Feature(feat_name)`` to the list of predicates in ``predicates_of`` .

When an unstable impl's function is called, we will first iterate through all the goals in ``param_env`` to check if there is any ``ClauseKind::UnstableFeature(feat_name)`` in ``param_env``.

The existence of ``ClauseKind::Unstable_Feature(feat_name)`` in ``param_env`` means an``#[unstable_feature_bound(feat_name)]`` is present at the call site of the function, so we allow the check to succeed in this case.

If ``ClauseKind::UnstableFeature(feat_name)`` does not exist in ``param_env``, we will still allow the check to succeed for either of the cases below:
1. The feature is enabled through ``#[feature(feat_name)]`` outside of std / core.
2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not.

For the rest of the case, it will fail with ambiguity.

## Limitation

In this PR, we do not support:
1. using items that need ``#[unstable_feature_bound]`` within stable APIs
2. annotate main function with ``#[unstable_feature_bound]``
3. annotate ``#[unstable_feature_bound]`` on items other than free function and impl

## Acknowledgement
The design and mentoring are done by `@BoxyUwU`
2025-07-17 01:57:55 +00:00
Vadim Petrochenkov
6849f816b1 resolve: Change &mut Resolver to &Resolver when possible 2025-07-17 02:09:01 +03:00
Vadim Petrochenkov
8b8889df25 resolve: Split module_map into two maps for local and extern modules 2025-07-17 02:09:01 +03:00
Vadim Petrochenkov
8d7193973f resolve: Use module_map and get_module less 2025-07-17 02:09:00 +03:00
Vadim Petrochenkov
5d611e5548 resolve: Move self_binding to ModuleData 2025-07-17 02:09:00 +03:00
Nicholas Nethercote
6414352bff Use join_path_syms in one more place.
This one is a bit marginal, because the segments are a mix of symbols
and strings.
2025-07-17 08:37:20 +10:00
Nicholas Nethercote
fb7aa9e4fd Improve path segment joining.
There are many places that join path segments with `::` to produce a
string. A lot of these use `join("::")`. Many in rustdoc use
`join_with_double_colon`, and a few use `.joined("..")`. One in Clippy
uses `itertools::join`. A couple of them look for `kw::PathRoot` in the
first segment, which can be important.

This commit introduces `rustc_ast::join_path_{syms,ident}` to do the
joining for everyone. `rustc_ast` is as good a location for these as
any, being the earliest-running of the several crates with a `Path`
type. Two functions are needed because `Ident` printing is more complex
than simple `Symbol` printing.

The commit also removes `join_with_double_colon`, and
`estimate_item_path_byte_length` with it.

There are still a handful of places that join strings with "::" that are
unchanged. They are not that important: some of them are in tests, and
some of them first split a path around "::" and then rejoin with "::".

This fixes one test case where `{{root}}` shows up in an error message.
2025-07-17 08:37:19 +10:00
Folkert de Vries
9c8ab89187 use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
Folkert de Vries
ec0ff720d1 add codegen_instance_attrs query
and use it for naked functions
2025-07-16 21:38:58 +02:00
Folkert de Vries
f100767dce fix -Zsanitizer=kcfi on #[naked] functions
And more broadly only codegen `InstanceKind::Item` using the naked
function codegen code. Other instance kinds should follow the normal
path.
2025-07-16 21:38:48 +02:00
xizheyin
af39c0c57c Emit warning when there is no space between -o and confusing arg
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-16 23:40:49 +08:00
Samuel Tardieu
2a8f97910a Rollup merge of #143968 - Stypox:tracing-FnAbiOf, r=RalfJung
Add tracing to `InterpCx::fn_abi_of_instance/fn_abi_of_fn_ptr`

This PR adds tracing to the `InterpCx::fn_abi_of_instance`/`::fn_abi_of_fn_ptr` functions by shadowing `FnAbiOf`'s trait methods with inherent methods on `InterpCx`, like done in rust-lang/rust#142721. The reason why I am targeting these two functions is because they are used for Miri interpretation, and they make a `layout_of` query down the line without passing through the `layout_of` that was traced in rust-lang/rust#142721.

There are other places where `layout_of` is called without being traced (see the analysis below), but that's because the `Machine` used there is not `MiriMachine` but rather `CompileTimeMachine` which does not implement `enter_trace_span()`. But after discussing with ```````@RalfJung``````` we agreed that the const-eval part should not be traced together with Miri, that's why I am ignoring the other places where `layout_of` is called.

r? ```````@RalfJung```````

<details><summary>Analysis of the places where <code>layout_of</code> is called</summary>

I did some analysis for https://github.com/rust-lang/rust/pull/142721#discussion_r2171494841, and these are all the places where the query `tcx.layout_of` is called (directly or indirectly) outside of a traced `InterpCx::layout_of` while a program is being interpreted by Miri:

```
adjust_for_rust_scalar  at ./compiler/rustc_ty_utils/src/abi.rs:302:35
{closure#2}             at ./compiler/rustc_ty_utils/src/abi.rs:522:25
eval_body_using_ecx<>   at ./compiler/rustc_const_eval/src/const_eval/eval_queries.rs:49:22
{closure#1}<>           at ./compiler/rustc_const_eval/src/interpret/operand.rs:851:76
{closure#0}<>           at ./compiler/rustc_const_eval/src/interpret/stack.rs:612:18
size_and_align          at ./compiler/rustc_middle/src/mir/interpret/mod.rs:387:38
```

I got these by:
- patching rustc with this patch that adds a span to the `layout_of` query which prints the backtrace:
[layout_of_other_places.diff.txt](https://github.com/user-attachments/files/21235523/layout_of_other_places.diff.txt)
- adding this to my bootstrap.toml to have debug symbols inside the Miri binary: `rust.debuginfo-level = "line-tables-only"` and also `build.tool.miri.features = ["tracing"]`
- obtaining a trace file with `MIRI_TRACING=1 ./x.py run miri --stage 1 --warnings warn --args src/tools/miri/tests/pass/hello.rs` (note: maybe using a file different than "src/tools/miri/tests/pass/hello.rs" would lead to more places where layout_of is called?)
-  running this query in Perfetto to select all `layout_of` spans that have as a direct parent a span named "frame" (as opposed to the parent being `InterpCx::layout_of`) and extract their backtrace: `select args.string_value from slice left join args on slice.arg_set_id = args.id where slice.name = "tcx.layout_of" and slice.parent_id in (select slice2.id from slice as slice2 where slice2.name = "frame") group by args.string_value`
- exporting the data as `.tsv` and processing that file through this Python script. It finds the first path in the backtraces where "layout" isn't mentioned, which imo is a good heuristic to not consider `layout_of` wrappers/friends as call places, but rather go down the backtrace until an actual call place is reached. [layout_of_other_places.py.txt](https://github.com/user-attachments/files/21235529/layout_of_other_places.py.txt)

</details>
2025-07-16 17:06:43 +02:00
Samuel Tardieu
b564ecf04b Rollup merge of #143920 - oli-obk:cg-llvm-safety, r=jieyouxu
Make more of codegen_llvm safe

Best reviewed commit-by-commit.
2025-07-16 17:06:40 +02:00
Samuel Tardieu
7b5e08f8ef Rollup merge of #143692 - RalfJung:miri-oob, r=oli-obk
miri: fix out-of-bounds error for ptrs with negative offsets

r? ```````@oli-obk```````
2025-07-16 17:06:39 +02:00
Sasha Pourcelot
4e054fc4c4 Port #[coverage] to the new attribute system 2025-07-16 15:51:18 +02:00
Ralf Jung
0bf0860a0e simplfy memory kind handling during interning 2025-07-16 15:29:52 +02:00
Ralf Jung
8f854d9cb2 const heap: fix ICE on forgotten make_global 2025-07-16 15:29:52 +02:00
David Wood
8d64937dc2 trait_sel: MetaSized always holds temporarily
As a temporary measure while a proper fix for
`tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs`
is implemented, make `MetaSized` obligations always hold. In effect,
temporarily reverting the `sized_hierarchy` feature. This is a small
change that can be backported.
2025-07-16 12:35:44 +00:00
Stypox
07a34c374b Make frame spans appear on a separate trace line
This was done by making the tracing_chrome tracing layer check if "tracing_separate_line" was in the arguments of a span, and act accordingly.
2025-07-16 09:25:35 +02:00
Ralf Jung
42ec028027 type_id_eq: check that the hash fully matches the type 2025-07-16 08:02:47 +02:00
Vadim Petrochenkov
7f398fd5f6 resolve: Optimize fn traits_in_module 2025-07-16 08:30:48 +03:00
Vadim Petrochenkov
1a9a226058 resolve: Import ty::Visibility everywhere 2025-07-16 08:30:48 +03:00
Vadim Petrochenkov
01b546a19b resolve: Remove trait ToNameBinding 2025-07-16 08:30:44 +03:00
Vadim Petrochenkov
babe2c0d0f resolve: Merge NameBindingKind::Module into NameBindingKind::Res 2025-07-16 08:28:17 +03:00
Jacob Greenfield
c6e1b21777 Use hygenic macros for stable-mir 2025-07-15 20:47:09 -04:00
Jonathan Brouwer
8e400f97e5 Fix ice for feature-gated cfg attributes applied to the crate
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-15 23:28:15 +02:00
Deadbeef
fd48b7b8dd Comment more code and make tests clearer
Co-Authored-By: Ralf Jung <post@ralfj.de>
2025-07-16 00:50:20 +08:00
Deadbeef
44b38ca45e format pointer later instead of eagerly converting to string 2025-07-16 00:32:12 +08:00
Deadbeef
3f2dc2bd1a add const_make_global; err for const_allocate ptrs if didn't call
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-16 00:32:12 +08:00
Michael Goulet
3634f46fdb Add alias for ArgOutlivesPredicate 2025-07-15 16:02:26 +00:00
Michael Goulet
512cf3ae88 Gate things properly 2025-07-15 16:02:26 +00:00
Michael Goulet
e3f643c706 Consider outlives assumptions when proving auto traits for coroutine interiors 2025-07-15 16:02:26 +00:00
Michael Goulet
3e7dfaa510 Deduce outlives obligations from WF of coroutine interior types 2025-07-15 16:02:26 +00:00
Michael Goulet
7976ca2442 Add outlives to CoroutineWitnessTypes 2025-07-15 15:58:08 +00:00
tiif
e331de149f Fix CI 2025-07-15 13:48:30 +00:00
tiif
7356ff7517 Implement other logics 2025-07-15 13:48:30 +00:00
tiif
dd067a689a Lint against having both #[unstable_feature_bound] and #[stable] on the same item 2025-07-15 13:48:30 +00:00
tiif
ab29256b96 Make stability attribute not to error when unstable feature bound is in effect 2025-07-15 13:48:30 +00:00
tiif
1e5c7b2877 Add the core logic in old and new solvers 2025-07-15 13:48:30 +00:00
tiif
2586185831 Lower the UnstableFeatureBound predicate to UnstableFeature predicate 2025-07-15 13:48:29 +00:00
tiif
fecd99881d Setup unstable feature bound attribute 2025-07-15 13:48:29 +00:00
David Mládek
8b868fa534 Implement resolver warnings about reexporting private dependencies 2025-07-15 15:44:25 +02:00
David Mládek
4a77a62e56 rustc_resolve: rename check_hidden_glob_reexports to lint_reexports 2025-07-15 15:29:08 +02:00
Stypox
14f47009cc Add InterpCx::fn_abi_of_instance/_fn_ptr with tracing, shadowing FnAbiOf 2025-07-15 15:04:53 +02:00
bors
e27f16a499 Auto merge of #143958 - samueltardieu:rollup-lh1s143, r=samueltardieu
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#142301 (tests: Fix duplicated-path-in-error fail with musl)
 - rust-lang/rust#143630 (Drop `./x suggest`)
 - rust-lang/rust#143736 (Give all bytes of TypeId provenance)
 - rust-lang/rust#143752 (Don't panic if WASI_SDK_PATH not set when detecting compiler)
 - rust-lang/rust#143837 (Adjust `run_make_support::symbols` helpers)
 - rust-lang/rust#143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143905 (Recover and suggest to use `;` to construct array type)
 - rust-lang/rust#143907 (core: make `str::split_at_unchecked()` inline)
 - rust-lang/rust#143910 (Add experimental `backtrace-trace-only` std feature)
 - rust-lang/rust#143927 (Preserve constness in trait objects up to hir ty lowering)
 - rust-lang/rust#143935 (rustc_type_ir/walk: move docstring to `TypeWalker` itself)
 - rust-lang/rust#143938 (Update books)
 - rust-lang/rust#143941 (update `cfg_select!` documentation)

Failed merges:

 - rust-lang/rust#143926 (Remove deprecated fields in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-15 11:42:55 +00:00
Samuel Tardieu
010e3ef113 Rollup merge of #143941 - folkertdev:cfg-select-docs, r=traviscross
update `cfg_select!` documentation

tracking issue: https://github.com/rust-lang/rust/issues/115585

After rust-lang/rust#143461, and with an eye on a soon(ish) stabilization, I think the docs need some work.

The existing text read more like a motivation for the feature existing to me, so I've tried to now be a bit more descriptive. Still, suggestions are very welcome.

I also added a test for an empty `select! {}` because it's just the sort of thing that might break.

r? ``@traviscross``
2025-07-15 12:52:44 +02:00
Samuel Tardieu
790ce4bf39 Rollup merge of #143935 - ada4a:walk-docstring, r=compiler-errors
rustc_type_ir/walk: move docstring to `TypeWalker` itself

having it on the impl block is a bit weird imo
2025-07-15 12:52:43 +02:00
Samuel Tardieu
cc26852148 Rollup merge of #143927 - oli-obk:const-dyn-trait-hir-ty, r=fmease
Preserve constness in trait objects up to hir ty lowering

r? ``@compiler-errors``

While we don't support `dyn const Trait`, we can at least also inform the user that `const Trait` is only legal for `#[const_trait] trait Trait {}`
2025-07-15 12:52:43 +02:00
Samuel Tardieu
281990eb16 Rollup merge of #143905 - xizheyin:143828, r=compiler-errors
Recover and suggest to use `;` to construct array type

Fixes rust-lang/rust#143828

r? compiler
2025-07-15 12:52:40 +02:00
Samuel Tardieu
743e18364b Rollup merge of #143878 - JonathanBrouwer:pointee_parser, r=jdonszelmann
Port `#[pointee]` to the new attribute parsing infrastructure

Ports `#[pointee]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? ``@jdonszelmann``
2025-07-15 12:52:40 +02:00