Commit Graph

278856 Commits

Author SHA1 Message Date
bors
76a030a6c2 Auto merge of #135592 - matthiaskrgr:rollup-4t69l7i, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #134754 (Implement `use` associated items of traits)
 - #135481 (coverage: Completely overhaul counter assignment, using node-flow graphs)
 - #135504 (Allow coercing safe-to-call target_feature functions to safe fn pointers)
 - #135561 (Update docs for `-Clink-dead-code` to discourage its use)
 - #135574 (ci: mirror ubuntu:22.04 to ghcr.io)
 - #135585 (resolve symlinks of LLVM tool binaries before copying them)
 - #135588 (Add license-metadata.json to rustc-src tarball.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-16 21:31:19 +00:00
Samuel Tardieu
8d59545daa Fix suggestion to convert dereference of raw pointer to ref 2025-01-16 21:23:55 +01:00
bors
99db2737c9 Auto merge of #134504 - oli-obk:push-rltsvnyttwll, r=compiler-errors
Use trait definition cycle detection for trait alias definitions, too

fixes #133901

In general doing this for `All` is not right, but this code path is specifically for traits and trait aliases, and there we only ever use `All` for trait aliases.
2025-01-16 18:46:28 +00:00
binarycat
08c1256dc2 fix error for when results in a rustdoc-js test are in the wrong order
see COMPILETEST_FORCE_STAGE0=1
2025-01-16 12:10:38 -06:00
binarycat
9397d133f6 Treat other items as functions for the purpose of type-based search
constants and statics are nullary functions, and struct fields are unary functions.

functions (along with methods and trait methods) are prioritized over other
items, like fields and constants.
2025-01-16 11:52:00 -06:00
Matthias Krüger
f4bbe30974
Rollup merge of #135588 - ferrocene:add-license-json-to-source-tarball, r=Kobzol
Add license-metadata.json to rustc-src tarball.

Adds a license-metadata.json to the source tarball.

This file was reported as missing as a comment on #133461, and it prevents you building the compiler from the source tarball (unless you re-generate it yourself, which is non-obvious and requires `reuse` to be installed).

r? Kobzol
2025-01-16 18:46:12 +01:00
Matthias Krüger
6997ea2cf5
Rollup merge of #135585 - onur-ozkan:135554, r=Kobzol
resolve symlinks of LLVM tool binaries before copying them

There is a chance that these tools are being installed from an external LLVM and we have no control over them. If any of these tools use symlinks, they will fail during tarball distribution. This change makes copying process to resolve symlinks just before placing them into the destination path.

Fixes https://github.com/rust-lang/rust/issues/135554
2025-01-16 18:46:11 +01:00
Matthias Krüger
701f1922ef
Rollup merge of #135574 - marcoieni:docker-ghcr-mirror, r=Kobzol
ci: mirror ubuntu:22.04 to ghcr.io
2025-01-16 18:46:11 +01:00
Matthias Krüger
f7e1ae40f5
Rollup merge of #135561 - Zalathar:link-dead-code, r=saethlin
Update docs for `-Clink-dead-code` to discourage its use

The `-Clink-dead-code` flag was originally added way back in #31368, apparently to help improve the output of some older forms of code coverage measurement, and also to address some use-cases for wanting to suppress linker flags like `-dead_strip` and `--gc-section`.

In the past it might have also been useful in conjunction with `-Cinstrument-coverage`, but subsequent improvements to coverage instrumentation have made it unnecessary there.

[It is also currently used by cargo-fuzz by default](https://github.com/rust-fuzz/cargo-fuzz/issues/391), for reasons that are possibly no longer relevant.

---

The flag currently does more than its name suggests, affecting not just linker flags, but also monomorphization decisions. It has also contributed to ICEs (e.g. #135515) that would not have occurred without link-dead-code.

---

For now, this PR just updates the documentation to be more realistic about what the flag does, and when it should be used (approximately never). In the future, it might be worth looking into properly deprecating this flag, and perhaps making it a no-op if feasible.
2025-01-16 18:46:10 +01:00
Matthias Krüger
bbc6d16ad6
Rollup merge of #135504 - veluca93:target-feature-cast-to-fn-ptr, r=oli-obk
Allow coercing safe-to-call target_feature functions to safe fn pointers

r? oli-obk

`@oli-obk:` this is based on your PR #134353 :-)

See https://github.com/rust-lang/rust/pull/134090#issuecomment-2539422624 for the motivation behind this change.
2025-01-16 18:46:09 +01:00
Matthias Krüger
4aae8d15d6
Rollup merge of #135481 - Zalathar:node-flow, r=oli-obk
coverage: Completely overhaul counter assignment, using node-flow graphs

The existing code for choosing where to put physical counter-increments gets the job done, but is very ad-hoc and hard to modify without introducing tricky regressions.

This PR replaces all of that with a more principled approach, based on the algorithm described in "Optimal measurement points for program frequency counts" (Knuth & Stevenson, 1973).

---

We start by ensuring that our graph has “balanced flow”, i.e. each node's flow (execution count) is equal to the sum of all its in-edge flows, and equal to the sum of all its out-edge flows. That isn't naturally true of control-flow graphs, so we introduce a wrapper type `BalancedFlowGraph` to fix that by introducing synthetic nodes and edges as needed.

Once our graph has balanced flow, the next step is to create another view of that graph in which each node's successors have all been merged into one “supernode”. Consequently, each node's out-edges can be coalesced into a single out-edge to one of those supernodes. Because of the balanced-flow property, the flow of that coalesced edge is equal to the flow of the original node.

Having expressed all of our node flows as edge flows, we can then analyze node flows using techniques for analyzing edge flows. We incrementally build a spanning tree over the merged supernodes, such that each new edge in the spanning tree represents a node whose flow can be computed from that of other nodes.

When this is done, we end up with a list of “counter terms” for each node, describing which nodes need physical counters, and how the remaining nodes can have their flow calculated by adding and subtracting those physical counters.

---

The re-blessed coverage tests show that this results in modest or major improvements for our test programs. Some tests need fewer physical counters, some tests need fewer expression nodes for the same number of physical counters, and some tests show striking reductions in both.
2025-01-16 18:46:09 +01:00
Matthias Krüger
62d0f457d4
Rollup merge of #134754 - frank-king:feature/import_trait_associated_functions, r=oli-obk
Implement `use` associated items of traits

This PR implements #134691.
2025-01-16 18:46:08 +01:00
Jonathan Pallant
1fcbb4dea7
Add license-metadata.json to rustc-src tarball. 2025-01-16 16:04:02 +00:00
bors
8a6878a117 Auto merge of #135587 - matthiaskrgr:rollup-851qgnh, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #133720 ([cfg_match] Adjust syntax)
 - #134496 (Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement)
 - #135249 (Fix overflows in the implementation of `overflowing_literals` lint's help)
 - #135251 (Only treat plain literal patterns as short)
 - #135556 (Clarify note in `std::sync::LazyLock` example)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-16 16:02:34 +00:00
Matthias Krüger
dbbbed0579
Rollup merge of #135556 - AeonSolstice:patch-1, r=tgross35
Clarify note in `std::sync::LazyLock` example

I doubt most people know what it means, as I did not until a week ago. In the current form, it seems like a `TODO:`.
2025-01-16 17:00:47 +01:00
Matthias Krüger
10d22fc949
Rollup merge of #135251 - oli-obk:push-lmpyvvyrtplk, r=ytmimi
Only treat plain literal patterns as short

See https://github.com/rust-lang/rust/pull/134228#discussion_r1905848384 and https://github.com/rust-lang/rust/pull/134228#discussion_r1905916702 for context. We never wanted to treat const blocks and paths as short, only plain literals.

I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
2025-01-16 17:00:47 +01:00
Matthias Krüger
8f9ccc5d1b
Rollup merge of #135249 - s-cerevisiae:fix-overflowing-literals-help, r=chenyukang
Fix overflows in the implementation of `overflowing_literals` lint's help

This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases.

1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes #135248)
2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes #131849)

Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
2025-01-16 17:00:46 +01:00
Matthias Krüger
87b3671ce9
Rollup merge of #134496 - DiuDiu777:fix-doc, r=ibraheemdev
Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement

### Related Issue:
This update addresses parts of the issue raised in [#134242](https://github.com/rust-lang/rust/issues/134242), where Arc's documentation lacks `Global Allocator` safety descriptions for three APIs. And this was confirmed by ```@workingjubilee``` :
> Wait, nevermind. I apparently forgot the `increment_strong_count` is implicitly A = Global. Ugh. Another reason these things are hard to track, unfortunately.

### PR Description
This PR updates the document for the following APIs:
- `Arc::from_raw`
- `Arc::increment_strong_count`
- `Arc::decrement_strong_count`

These APIs currently lack an important piece of documentation: **the raw pointer must point to a block of memory allocated by the global allocator**. This crucial detail is specified in the source code but is not reflected in the documentation, which could lead to confusion or incorrect usage by users.

### Problem:
The following example demonstrates the potential confusion caused by the lack of documentation:

```rust
#![feature(allocator_api)]
use std::alloc::{Allocator,AllocError, Layout};
use std::ptr::NonNull;
use std::sync::Arc;

struct LocalAllocator {
    memory: NonNull<u8>,
    size: usize,
}

impl LocalAllocator {
    fn new(size: usize) -> Self {
        Self {
            memory: unsafe { NonNull::new_unchecked(&mut 0u8 as *mut u8) },
            size,
        }
    }
}

unsafe impl Allocator for LocalAllocator {
    fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        Ok(NonNull::slice_from_raw_parts(self.memory, self.size))
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
    }
}

fn main() {
    let allocator = LocalAllocator::new(64);
    let arc = Arc::new_in(5, &allocator); // Here, allocator could be any non-global allocator
    let ptr = Arc::into_raw(arc);

    unsafe {
        Arc::increment_strong_count(ptr);
        let arc = Arc::from_raw(ptr);
        assert_eq!(2, Arc::strong_count(&arc)); // Failed here!
    }
}
```
2025-01-16 17:00:45 +01:00
Matthias Krüger
fca148185e
Rollup merge of #133720 - c410-f3r:cfg-match-foo-bar-baz, r=joshtriplett
[cfg_match] Adjust syntax

A year has passed since the creation of #115585 and the feature, as expected, is not moving forward. Let's change that.

This PR proposes changing the arm's syntax from  `cfg(SOME_CONDITION) => { ... }` to `SOME_CODITION => {}`.

```rust
match_cfg! {
   unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}
```

Why? Because after several manual migrations in https://github.com/rust-lang/rust/pull/116342 it became clear,  at least for me, that `cfg` prefixes are unnecessary, verbose and redundant.

Again, everything is just a proposal to move things forward. If the shown syntax isn't ideal, feel free to close this PR or suggest other alternatives.
2025-01-16 17:00:44 +01:00
jnyfah
474c73bd94 CRLF to LF 2025-01-16 16:46:06 +01:00
jnyfah
05712c6c85 added tests 2025-01-16 16:19:47 +01:00
onur-ozkan
cde58dd5f7 resolve symlinks of LLVM tool binaries before copying them
There is a chance that these tools are being installed from an external LLVM
and we have no control over them. If any of these tools use symlinks, they will
fail during tarball distribution. This change makes copying process to resolve
symlinks just before placing them into the destination path.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-01-16 17:42:14 +03:00
Jiahao XU
efe888871c
Move std::pipe::* into std::io
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-17 01:30:05 +11:00
Lukas Wirth
99c7013070
Merge pull request #18952 from lh123/add-raw-keyword-complete
feat: complete raw, const keyword
2025-01-16 14:24:53 +00:00
Folkert de Vries
702134a930
use indirect return for i128 and f128 on wasm32 2025-01-16 13:25:40 +01:00
jnyfah
715e457500 revert blocklike changes 2025-01-16 12:54:26 +01:00
lh123
1f32c2a9ec don't complete raw in &mut $0 2025-01-16 19:40:42 +08:00
Laurențiu Nicola
8d784becae
Merge pull request #18953 from VinTarZ/master
Fix `debug_assertions` broken in 1c5a125
2025-01-16 11:36:04 +00:00
VinTarZ
824bad7f65
Fix debug_assertions broken in 1c5a125beb35725ccc2ade005db9870db734bf23 2025-01-16 14:19:16 +03:00
jnyfah
39a1bb9e98 update blocklike 2025-01-16 12:11:55 +01:00
Zalathar
6eabf03526 coverage: Make yank_to_spantree_root iterative instead of recursive
This avoids having to worry about stack space when traversing very long
spantree paths, e.g. when instrumenting a long sequence of if/else statements.
2025-01-16 22:07:18 +11:00
Zalathar
f1300c860e coverage: Completely overhaul counter assignment, using node-flow graphs 2025-01-16 22:07:18 +11:00
bors
d8a64098c9 Auto merge of #135344 - scottmcm:safe-dangling, r=joboet
Less unsafe in `dangling`/`without_provenance`

This PR was inspired by the new `NonNull::without_provenance` (cc https://github.com/rust-lang/rust/issues/135243#issuecomment-2583913562) since it made me realize that we could write `NonNull::dangling` in completely-safe code using other existing things.

Then doing that led me to a few more places that could be simplified, like now that GVN will optimize Transmute-then-PtrToPtr, we can just implement `ptr::without_provenance` by calling `ptr::without_provenance_mut` since the shipped rlib of `core` ends up with the same single statement as the implementation (thanks to GVN merging the steps) and thus there's no need to duplicate the `transmute` -- and more importantly, no need to repeat a long safety comment.

There did end up being a couple of other changes needed to avoid exploding certain bits of MIR, though -- like `<Box<[i32]>>::default()`'s MIR originally got way worse as certain things didn't inline, or had a bunch of extraneous UbChecks -- so there's a couple of other changes to solve that.
2025-01-16 10:52:11 +00:00
lh123
341a6d5bba feat: complete raw, const keyword 2025-01-16 18:27:59 +08:00
MarcoIeni
f5fe0a0293
ci: mirror ubuntu:22.04 to ghcr.io 2025-01-16 11:21:41 +01:00
Lukas Wirth
fa71da9ff0
Merge pull request #18951 from Veykril/push-zpvunsvlpuxt
Add missing `#[rust_analyzer::rust_fixture]` annotations
2025-01-16 10:21:22 +00:00
Lukas Wirth
56059f8c7a
Merge pull request #18950 from Veykril/push-okmsynnltxts
Generalize some type walking in hover type actions
2025-01-16 10:19:37 +00:00
Lukas Wirth
4d5632b720 Generalize some type walking in hover type actions 2025-01-16 11:06:11 +01:00
Lukas Wirth
664cdd2936 Minor docs improvement 2025-01-16 11:05:20 +01:00
Lukas Wirth
548d70f8aa Add edit test for await skipping completions 2025-01-16 10:56:57 +01:00
Luca Versari
8fee6a7739 Coerce safe-to-call target_feature functions to fn pointers. 2025-01-16 10:54:33 +01:00
Lukas Wirth
5a9763750e Add missing #[rust_analyzer::rust_fixture] annotations 2025-01-16 10:51:57 +01:00
bjorn3
cda9145b00 Fix rustc test suite 2025-01-16 09:42:35 +00:00
bjorn3
8a46f85c7e Rustup to rustc 1.86.0-nightly (419b3e2d3 2025-01-15) 2025-01-16 09:33:11 +00:00
bjorn3
aebad29932 Sync from rust 419b3e2d3e 2025-01-16 09:24:37 +00:00
Lukas Wirth
419bdb20e2
Merge pull request #18949 from Veykril/push-yzklntsnnuts
Partially back out "fix: Fix sourceroot construction for virtual manifests"
2025-01-16 09:18:48 +00:00
Lukas Wirth
c00dfedc34 Partially back out "fix: Fix sourceroot construction for virtual manifests" 2025-01-16 10:02:26 +01:00
Lukas Wirth
8ec90940f2
Merge pull request #18946 from lh123/goto-to-type-def-func-param-and-trait-bound
feat: show go-to-type-def actions for func param and trait bound when hovering
2025-01-16 08:48:02 +00:00
Lukas Wirth
d6477b952b
Merge pull request #18927 from ChayimFriedman2/skip-iter-await
feat: Add smart completions that skip `await` or `iter()` and `into_iter()`
2025-01-16 08:47:26 +00:00
Frank King
5079acc060 Implement use associated items of traits 2025-01-16 16:34:05 +08:00