Skip to content

Rollup of 5 pull requests #135587

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 17 commits into from
Jan 16, 2025
Merged

Rollup of 5 pull requests #135587

merged 17 commits into from
Jan 16, 2025

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

DiuDiu777 and others added 17 commits December 19, 2024 22:20
Apply eta-reduction on map to simplify code and make the style more
consistent
Changes the behavior of the `overflowing_literals` suggestion so that it
always suggest the smallest type regardless of the original type size.
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
…joshtriplett

[cfg_match] Adjust syntax

A year has passed since the creation of rust-lang#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 rust-lang#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.
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 [rust-lang#134242](rust-lang#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!
    }
}
```
…als-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 rust-lang#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 rust-lang#131849)

Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
Only treat plain literal patterns as short

See rust-lang#134228 (comment) and rust-lang#134228 (comment) 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
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:`.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Jan 16, 2025
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=5

@bors
Copy link
Collaborator

bors commented Jan 16, 2025

📌 Commit dbbbed0 has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2025
@fmease

This comment was marked as off-topic.

@bors
Copy link
Collaborator

bors commented Jan 16, 2025

⌛ Testing commit dbbbed0 with merge 8a6878a...

@bors
Copy link
Collaborator

bors commented Jan 16, 2025

☀️ Test successful - checks-actions
Approved by: matthiaskrgr
Pushing 8a6878a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 16, 2025
@bors bors merged commit 8a6878a into rust-lang:master Jan 16, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 16, 2025
@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#133720 [cfg_match] Adjust syntax 856ee09de00bfc373852c9499b6c0384145220b6 (link)
#134496 Update documentation for Arc::from_raw, Arc::increment_stro… 641a374131ca4f9f7b0c862de338732f9d6d9845 (link)
#135249 Fix overflows in the implementation of `overflowing_literal… 1e87a339508e2a130a4c6313b551e88c43cfe863 (link)
#135251 Only treat plain literal patterns as short 3796e0a2875e49aaa00599571143433b429660b1 (link)
#135556 Clarify note in std::sync::LazyLock example d252be36b6ac422ab5b45305f8fc2ae3ac556865 (link)

previous master: d8a64098c9

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8a6878a): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -1.2%, secondary -0.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.0% [1.0%, 1.0%] 2
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) -1.2% [-1.2%, -1.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 762.749s -> 763.031s (0.04%)
Artifact size: 326.07 MiB -> 326.06 MiB (-0.01%)

@matthiaskrgr matthiaskrgr deleted the rollup-851qgnh branch January 25, 2025 09:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. rollup A PR which is a rollup S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants