Commit Graph

46304 Commits

Author SHA1 Message Date
dianne
17bb4bbc86 always peel &mut, to allow matching on &mut str 2025-05-05 04:29:33 -07:00
dianne
fe98130e0f match ergonomics for string and byte string literal patterns 2025-05-05 04:10:49 -07:00
dianne
e5879018ef move logic for telling whether to peel smart pointers into a helper
The new logic for determining whether to peel references will depend on
whether smart pointers need to be peeled before matching.
2025-05-04 20:43:31 -07:00
Trevor Gross
0b8789c201
Rollup merge of #140630 - azhogin:azhogin/async-drop-proxy-source-info-fix, r=oli-obk
Async drop source info fix for proxy-drop-coroutine

Fixes crash at debug info generation: https://github.com/rust-lang/rust/issues/140426 .
Also, the submitted example requires sync Drop implementation too.
Because sync version is required for unwind and when drop is performed in sync context (sync function).

Probably, it is also needed to add such a lint/error about missed `impl Drop`, when there is `impl AsyncDrop`.

Fix description: even minimal, empty coroutine (for proxy-coroutine) has 3 states and the source info array should have 3 elements too.

```
#![feature(async_drop)]

use std::future::AsyncDrop;
use std::pin::Pin;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let _st = St;
}

struct St;

impl AsyncDrop for St {
    async fn drop(self: Pin<&mut Self>) {
        println!("123");
    }
}
```
2025-05-04 18:11:50 -04:00
Trevor Gross
5b3de49822
Rollup merge of #140627 - dtolnay:rustdoctracing, r=GuillaumeGomez
Allow linking rustc and rustdoc against the same single tracing crate

Alternate title: _Ignore "a global default trace dispatcher has already been set" error in Rustdoc_

By consecutively initializing `tracing` and `rustc_log`, Rustdoc assumes that these involve 2 different tracing crates.

I would like to be able to build rustdoc against the same tracing crate that rustc_log is also built against. Previously this arrangement would crash rustdoc:

```console
thread 'main' panicked at rust/compiler/rustc_log/src/lib.rs:142:65:
called `Result::unwrap()` on an `Err` value: SetGlobalDefaultError("a global default trace dispatcher has already been set")
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_log::init_logger
   4: rustc_driver_impl::init_logger
   5: rustdoc::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

query stack during panic:
end of query stack
```
2025-05-04 18:11:49 -04:00
Trevor Gross
df9f9ca99a
Rollup merge of #140619 - jieyouxu:validate_attr_cleanups, r=Urgau
Small adjustments to `check_attribute_safety` to make the logic more obvious

Follow-up to #140617.
2025-05-04 18:11:48 -04:00
bors
ab62d56603 Auto merge of #140580 - jdonszelmann:variables-external-macros, r=m-ou-se
Don't name variables from external macros in borrow errors.

This came up as part of the expansion of format_args. However, it's a more general problem (and now solution).

I noticed that this does change another test, moving out of fields in derives on packed struct. However, I think this is a better error simply because it used to refer to `other.0` which is an implementation detail which doesn't really make sense.

cc `@m-ou-se`
2025-05-04 15:16:06 +00:00
Jieyou Xu
eb3a8e5b81
Make attribute safety validation logic more obvious 2025-05-04 21:44:50 +08:00
bors
622ac04376 Auto merge of #140633 - Zalathar:rollup-iay94wa, r=Zalathar
Rollup of 7 pull requests

Successful merges:

 - #139675 (Add the AVX10 target features)
 - #140286 (Check if format argument is identifier to avoid error err-emit)
 - #140456 (Fix test simd/extract-insert-dyn on s390x)
 - #140551 (Move some tests out of tests/ui)
 - #140588 (Adjust some ui tests re. target-dependent errors)
 - #140617 (Report the `unsafe_attr_outside_unsafe` lint at the closest node)
 - #140626 (allow `#[rustfmt::skip]` in combination with `#[naked]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-04 06:23:38 +00:00
Stuart Cook
1239f499e8
Rollup merge of #140626 - folkertdev:naked-rustfmt-skip, r=Amanieu
allow `#[rustfmt::skip]` in combination with `#[naked]`

fixes https://github.com/rust-lang/rust/issues/140623

We very deliberately use an allowlist to prevent weird interactions with `#[naked]`, hopefully we've now found all of the useful combinations.

cc `@Amanieu`
2025-05-04 13:21:10 +10:00
Stuart Cook
54821b9ed0
Rollup merge of #140617 - Urgau:unsafe_attr-lint-allow, r=jieyouxu
Report the `unsafe_attr_outside_unsafe` lint at the closest node

This PR have `AstValidation` track a linting node id and then uses it when reporting the `unsafe_attr_outside_unsafe` lint, so that instead of being bound at the crate-root, `#[allow]` of the lint works at any node.

Fixes rust-lang/rust#140602
r? `@jieyouxu`
2025-05-04 13:21:09 +10:00
Stuart Cook
9c949b0373
Rollup merge of #140286 - xizheyin:issue-139104, r=lcnr
Check if format argument is identifier to avoid error err-emit

Fixes #139104

When `argument` is not an identifier, it should not be considered a field access. I checked this and if not emit an invalid format string error. I think we could do with a little finer error handling, I'll open an issue to track this down later.

The first commit submits the ui test, the second commits the code and the changes to the test output.

r? compiler
2025-05-04 13:21:07 +10:00
Stuart Cook
ed7590f1a0
Rollup merge of #139675 - sayantn:avx10, r=Amanieu
Add the AVX10 target features

Parent #138843

Adds the `avx10_target_feature` feature gate, and `avx10.1` and `avx10.2` target features.

It is confirmed that Intel is dropping AVX10/256 (see [this comment](https://github.com/rust-lang/rust/issues/111137#issuecomment-2795442288)), so this should be safe to implement now.

The LLVM fix for llvm/llvm-project#135394 was merged, and has been backported to LLVM20, and the patch has also been propagated to rustc in #140502

`@rustbot` label O-x86_64 O-x86_32 A-target-feature A-SIMD
2025-05-04 13:21:07 +10:00
bors
1bea580f36 Auto merge of #140549 - BoxyUwU:proper_const_norm, r=lcnr
Set groundwork for proper const normalization

r? lcnr

Updates a lot of our normalization/alias infrastructure to be setup to handle mgca aliases and normalization once const items are represented more like aliases than bodies. Inherent associated consts are still super busted, I didn't update the assertions that IACs the right arg setup because that winds up being somewhat involved to do *before* proper support for normalizing const aliases is implemented.

I dont *intend* for this to have any effect on stable. We continue normalizing via ctfe on stable and the codepaths in `project` for consts should only be reachable with mgca or ace.
2025-05-04 03:12:41 +00:00
Andrew Zhogin
a82b7a63b7 Async drop source info fix for proxy-drop-coroutine - fixes crash at debug info generation 2025-05-04 03:11:27 +07:00
David Tolnay
00d3fdce7c
Allow linking rustc and rustdoc against the same single tracing crate
By consecutively initializing `tracing` and `rustc_log`, Rustdoc assumes
that these involve 2 different tracing crates.

I would like to be able to build rustdoc against the same tracing crate
that rustc_log is also built against. Previously this arrangement would
crash rustdoc:

    thread 'main' panicked at rust/compiler/rustc_log/src/lib.rs:142:65:
    called `Result::unwrap()` on an `Err` value: SetGlobalDefaultError("a global default trace dispatcher has already been set")
    stack backtrace:
       0: rust_begin_unwind
       1: core::panicking::panic_fmt
       2: core::result::unwrap_failed
       3: rustc_log::init_logger
       4: rustc_driver_impl::init_logger
       5: rustdoc::main
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

    error: the compiler unexpectedly panicked. this is a bug.

    note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

    note: please make sure that you have updated to the latest nightly

    query stack during panic:
    end of query stack
2025-05-03 10:18:50 -07:00
Folkert de Vries
9aee0aa453
allow #[rustfmt::skip] in combination with #[naked] 2025-05-03 19:15:19 +02:00
xizheyin
873ca5fa04
Just suggest positional arg and adjust issue0139104 ui test
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-03 22:39:43 +08:00
Urgau
f4e1ec111c Report the unsafe_attr_outside_unsafe lint at the closest node 2025-05-03 16:10:25 +02:00
bors
097cd98869 Auto merge of #140613 - matthiaskrgr:rollup-yag6z7w, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138712 (resolve: Support imports of associated types and glob imports from traits)
 - #140395 (organize and extend forbidden target feature tests)
 - #140576 (Remove fragile equal-pointers-unequal tests.)
 - #140582 (Update sysinfo to `0.35.0` in bootstrap and `tools/opt-dist`)
 - #140595 (doc(std): fix typo lchown -> lchmod)
 - #140597 (zkvm: remove schmerik as target maintainer)
 - #140604 (yet another small borrowck cleanup )

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-03 13:51:34 +00:00
Urgau
74a17fd049 Have AstValidation track a linting node id 2025-05-03 15:38:01 +02:00
Matthias Krüger
4360fd7f34
Rollup merge of #140604 - lcnr:revealing-use-prep, r=compiler-errors
yet another small borrowck cleanup

The last borrowck changes from #139587 which can be reviewed entirely separately.

r? `@compiler-errors`
2025-05-03 12:44:37 +02:00
Matthias Krüger
a1a23debd6
Rollup merge of #138712 - petrochenkov:impasst, r=fmease
resolve: Support imports of associated types and glob imports from traits

Follow up to https://github.com/rust-lang/rust/pull/134754, part of https://github.com/rust-lang/rust/issues/134691.
This PR also closes https://github.com/rust-lang/rust/issues/138711 now.

Prohibiting `use Trait::AssocType;` at name resolution stage doesn't make sense, the name itself is perfectly resolveable.
It's a type checker's problem that the necessary generic args are not passed when the imported `AssocType` is used, so an error should be reported there.

And since we can import associated trait items now, glob imports from traits can also be allowed.
2025-05-03 12:44:34 +02:00
bors
d7df5bdf29 Auto merge of #140464 - oli-obk:successors-mut-perf, r=petrochenkov
Use a closure instead of three chained iterators

Fixes the perf regression from #123948

That PR had chained a third option to the iterator which apparently didn't optimize well
2025-05-03 10:43:38 +00:00
Matthias Krüger
185f9e0870
Rollup merge of #140606 - nnethercote:hir-pp, r=dtolnay
Improve hir pretty printing

It's currently pretty bad, so a few small improvements can make a big difference.

r? `@dtolnay`
2025-05-03 08:45:05 +02:00
Matthias Krüger
6cf4fd32bb
Rollup merge of #140548 - BoxyUwU:gci_patterns_user_ty_annotation, r=compiler-errors
Emit user type annotations for free consts in pattern position

This previously wasnt done because free consts couldn't have any generic parameters that need to be preserved for borrowck. This is no longer the case with `feature(generic_const_items)`

r? fmease
2025-05-03 08:45:03 +02:00
Matthias Krüger
9ff7455551
Rollup merge of #140534 - erickt:llvm-21, r=cuviper
PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…

…7e8877fc1908

In LLVM 21 PR https://github.com/llvm/llvm-project/pull/130940 `TargetRegistry::createTargetMachine` was changed to take a `const Triple&` and has deprecated the old `StringRef` method.

``@rustbot`` label llvm-main
2025-05-03 08:45:02 +02:00
Matthias Krüger
ca67f4da76
Rollup merge of #140505 - petrochenkov:expquote, r=bjorn3
linker: Quote symbol names in .def files

To support weird symbol names, including dots in particular.

cc [#134767](https://github.com/rust-lang/rust/pull/134767#issuecomment-2839397610)
2025-05-03 08:45:02 +02:00
lcnr
0be1ec1ccd CreateResult wrap more fields in Frozen 2025-05-03 02:52:37 +00:00
lcnr
27f83a5e05 TypeChecker take fields by ref 2025-05-03 02:49:15 +00:00
lcnr
ad3c35bea5 add ReverseSccGraph::compute 2025-05-03 02:47:14 +00:00
Nicholas Nethercote
9af08429f1 Avoid an indent for labelled loops. 2025-05-03 12:46:51 +10:00
Nicholas Nethercote
809e5b5ed1 Fix some hir pretty-printing over-indenting. 2025-05-03 12:46:51 +10:00
Nicholas Nethercote
e1a177bbba Improve hir pretty-printing of attributes. 2025-05-03 12:46:48 +10:00
bors
2ad5f8607d Auto merge of #140442 - osiewicz:collector-walk-less-fine-grained-locking, r=wesleywiser
mono collector: Reduce # of locking while walking the graph

While profiling Zed's dev build I've noticed that while most of the time `upstream_monomorphizations` takes a lot of time in monomorpization_collector, in some cases (e.g. build of `editor` itself) the rest of monomorphization_collector_graph_walk dominates it. Most of the time is spent in collect_items_rec.

This PR aims to reduce the number of locks taking place; instead of locking output MonoItems once per children of current node, we do so once per *current node*. We also get to reuse locks for mentioned and used items. While this commit does not reduce Wall time of Zed's build, it does shave off CPU time (measured with `cargo build -j1`) from 48s to 47s. I've also tested it with parallel frontend against Zed and ripgrep and found no regressions.
2025-05-03 00:24:14 +00:00
Nicholas Nethercote
aa7bb1c2f5 Enable BoxMarker drop checking.
All the box open/close issues have been fixed.
2025-05-03 09:14:27 +10:00
Nicholas Nethercote
760cf8d3af Fix hir pretty-printing of global_asm!.
One of the boxes isn't closed, and this causes everything after it to be
over-indented.
2025-05-03 09:14:27 +10:00
Nicholas Nethercote
3896ad0acd Remove opaque type printing.
As far as I can tell, this code is not actually reachable.
2025-05-03 09:14:00 +10:00
Nicholas Nethercote
882c74dfcf Remove fake BoxMarkers.
They don't appear to do anything -- no test output is affected -- and no
other pretty-printing code looks like this.
2025-05-03 09:13:28 +10:00
bors
2d5ffc513f Auto merge of #140596 - matthiaskrgr:rollup-s7tzr34, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #140485 (Optimize the codegen for `Span::from_expansion`)
 - #140509 (transmutability: merge contiguous runs with a common destination)
 - #140519 (Use select in projection lookup in `report_projection_error`)
 - #140521 (interpret: better error message for out-of-bounds pointer arithmetic and accesses)
 - #140536 (Rename `*Guard::try_map` to `filter_map`.)
 - #140550 (Stabilize `select_unpredictable`)
 - #140563 (extend the list of registered dylibs on `test::prepare_cargo_test`)
 - #140572 (Add useful comments on `ExprKind::If` variants.)
 - #140574 (Add regression test for 133065)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-02 20:59:24 +00:00
Matthias Krüger
bcf2490c64
Rollup merge of #140572 - nnethercote:comment-ExprKind-If, r=compiler-errors
Add useful comments on `ExprKind::If` variants.

Things that aren't obvious and took me a while to work out.

r? `@BoxyUwU`
2025-05-02 19:38:00 +02:00
Matthias Krüger
c796ef00f8
Rollup merge of #140521 - RalfJung:oob-error, r=saethlin
interpret: better error message for out-of-bounds pointer arithmetic and accesses

Fixes https://github.com/rust-lang/rust/issues/93881
r? `@saethlin`
2025-05-02 19:37:58 +02:00
Matthias Krüger
296733d5ac
Rollup merge of #140519 - compiler-errors:name-based-comparison, r=oli-obk
Use select in projection lookup in `report_projection_error`

Using `for_each_relevant_impl` doesn't actually select the correct impl; we can use `select` here to actually get the correct impl with certainty. Follow-up to https://github.com/rust-lang/rust/pull/140278.

r? oli-obk
2025-05-02 19:37:57 +02:00
Matthias Krüger
429341b445
Rollup merge of #140509 - tmiasko:merge-contiguous-ranges, r=jswrenn
transmutability: merge contiguous runs with a common destination

Based on #140380.

r? `@jswrenn` `@joshlf`
2025-05-02 19:37:56 +02:00
Matthias Krüger
a2ae171b97
Rollup merge of #140485 - Jarcho:from_expansion_opt, r=petrochenkov
Optimize the codegen for `Span::from_expansion`

See https://godbolt.org/z/bq65Y6bc4 for the difference. the new version is less than half the number of instructions.

Also tried fully writing the function by hand:
```rust
sp.ctxt_or_parent_or_marker != 0
        && (
            sp.len_with_tag_or_marker == BASE_LEN_INTERNED_MARKER
            || sp.len_with_tag_or_marker & PARENT_TAG == 0
        )
```

But that was no better than this PR's current use of `match_span_kind`.
2025-05-02 19:37:56 +02:00
bors
4824c2bb74 Auto merge of #140406 - Urgau:autorefs-perf, r=nnethercote
perf: delay checking of `#[rustc_no_implicit_autorefs]` in autoref lint

Try to address the regression seen in https://github.com/rust-lang/rust/pull/123239#issuecomment-2835418470 by delaying the checking of `#[rustc_no_implicit_autorefs]` on method call.
2025-05-02 17:35:50 +00:00
Jana Dönszelmann
5424e4f1db
remove an unused codepath 2025-05-02 18:09:31 +02:00
Jana Dönszelmann
867b4c9e48
Test that names of variables in external macros are not shown on a borrow error 2025-05-02 18:09:25 +02:00
Vadim Petrochenkov
842858f765 linker: Quote symbol names in .def files
To support weird symbol names, including dots in particular.
2025-05-02 16:25:00 +03:00
Vadim Petrochenkov
3eee3dad5c resolve: Support imports of associated types and glob imports from traits 2025-05-02 15:59:38 +03:00