Skip to content

Rollup of 7 pull requests #135576

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

Closed
wants to merge 21 commits into from

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

DiuDiu777 and others added 21 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.
The change between 0.1.143 and 0.1.144 includes refactoring that was in
compiler-builtins before, but had to be reverted before landing in
rust-lang/rust because the traits were leaking into diagnostics [1].
Recently a fix for this issue was merged [2] so the cleanup is reapplied
here.

This also acts as a regression test for [2].

[1]: rust-lang#128691 (comment)
[2]: rust-lang#135278
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!
    }
}
```
…sociated_functions, r=oli-obk

Implement `use` associated items of traits

This PR implements rust-lang#134691.
…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:`.
Update `compiler-builtins` to 0.1.144

The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here.

This also acts as a regression test for [2].

[1]: rust-lang#128691 (comment)
[2]: rust-lang#135278
@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=7

@bors
Copy link
Collaborator

bors commented Jan 16, 2025

📌 Commit 5d1688d 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
@bors
Copy link
Collaborator

bors commented Jan 16, 2025

⌛ Testing commit 5d1688d with merge 83f6d74...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 16, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

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

r? `@ghost`
`@rustbot` modify labels: rollup
@rust-log-analyzer
Copy link
Collaborator

The job test-various failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
diff of stderr:

8   --> $DIR/assoc-const-eq-missing.rs:16:16
9    |
10 LL | fn foo2<F: Foo<Z = usize>>() {}
-    |                ^ associated type `Z` not found
13 error[E0220]: associated constant `Z` not found for `Foo`
14   --> $DIR/assoc-const-eq-missing.rs:18:16



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args associated-consts/assoc-const-eq-missing.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/associated-consts/assoc-const-eq-missing.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=wasm32-wasip1" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/associated-consts/assoc-const-eq-missing" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/wasm32-wasip1/native/rust-test-helpers"
--- stderr -------------------------------
error[E0220]: associated constant `Z` not found for `Foo`
##[error]  --> /checkout/tests/ui/associated-consts/assoc-const-eq-missing.rs:14:16
   |
   |
LL | fn foo1<F: Foo<Z = 3>>() {}
   |                ^ help: there is an associated constant with a similar name: `N`
error[E0220]: associated type `Z` not found for `Foo`
##[error]  --> /checkout/tests/ui/associated-consts/assoc-const-eq-missing.rs:16:16
   |
   |
LL | fn foo2<F: Foo<Z = usize>>() {}
   |                ^ there is a similarly named associated type `H` in the trait `compiler_builtins::int::traits::DInt`
error[E0220]: associated constant `Z` not found for `Foo`
##[error]  --> /checkout/tests/ui/associated-consts/assoc-const-eq-missing.rs:18:16
   |
   |
LL | fn foo3<F: Foo<Z = 5>>() {}
   |                ^ help: there is an associated constant with a similar name: `N`
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0220`.
------------------------------------------
---
diff of stderr:

2   --> $DIR/E0220.rs:5:22
3    |
4 LL | type Foo = dyn Trait<F=i32>;
-    |                      ^ help: `Trait` has the following associated type: `Bar`
7 error[E0191]: the value of the associated type `Bar` in `Trait` must be specified
8   --> $DIR/E0220.rs:5:16



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args error-codes/E0220.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/error-codes/E0220.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=wasm32-wasip1" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/error-codes/E0220" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/wasm32-wasip1/native/rust-test-helpers"
--- stderr -------------------------------
error[E0220]: associated type `F` not found for `Trait`
##[error]  --> /checkout/tests/ui/error-codes/E0220.rs:5:22
   |
   |
LL | type Foo = dyn Trait<F=i32>; //~ ERROR E0220
   |                      ^ there is a similarly named associated type `H` in the trait `compiler_builtins::int::traits::DInt`
error[E0191]: the value of the associated type `Bar` in `Trait` must be specified
##[error]  --> /checkout/tests/ui/error-codes/E0220.rs:5:16
   |
LL |     type Bar;
LL |     type Bar;
   |     -------- `Bar` defined here
...
LL | type Foo = dyn Trait<F=i32>; //~ ERROR E0220
   |                ^^^^^^^^^^^^ help: specify the associated type: `Trait<F=i32, Bar = Type>`
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0191, E0220.
For more information about an error, try `rustc --explain E0191`.
---
diff of stderr:

54   --> $DIR/issue-95023.rs:8:44
55    |
56 LL |     fn foo<const N: usize>(&self) -> Self::B<{ N }>;
-    |                                            ^ help: `Self` has the following associated type: `Output`
59 error: aborting due to 7 previous errors
60 



The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args lifetimes/issue-95023.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lifetimes/issue-95023.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=wasm32-wasip1" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/lifetimes/issue-95023" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/wasm32-wasip1/native/rust-test-helpers"
--- stderr -------------------------------
error: associated function in `impl` without body
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:8:5
   |
   |
LL |     fn foo<const N: usize>(&self) -> Self::B<{ N }>;
   |                                                    |
   |                                                    |
   |                                                    help: provide a definition for the function: `{ <body> }`
error[E0407]: method `foo` is not a member of trait `Fn`
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:8:5
   |
   |
LL |     fn foo<const N: usize>(&self) -> Self::B<{ N }>;

error[E0183]: manual implementations of `Fn` are experimental
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:3:6
   |
---
   |
LL | impl Fn(&isize) for Error {
   |      ^^^^^^^^^^ associated item constraint not allowed here
   |
help: parenthesized trait syntax expands to `Fn<(&isize,), Output=()>`
   |
LL | impl Fn(&isize) for Error {
   |      ^^^^^^^^^^


error[E0277]: expected a `FnMut(&isize)` closure, found `Error`
   |
LL | impl Fn(&isize) for Error {
LL | impl Fn(&isize) for Error {
   |                     ^^^^^ expected an `FnMut(&isize)` closure, found `Error`
   |
   = help: the trait `FnMut(&isize)` is not implemented for `Error`
  --> /rustc/FAKE_PREFIX/library/core/src/ops/function.rs:76:1

error[E0046]: not all trait items implemented, missing: `call`
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:3:1
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:3:1
   |
LL | impl Fn(&isize) for Error {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation
   |
   = help: implement the missing item: `fn call(&self, _: (&isize,)) -> <Self as FnOnce<(&isize,)>>::Output { todo!() }`
error[E0220]: associated type `B` not found for `Self`
##[error]  --> /checkout/tests/ui/lifetimes/issue-95023.rs:8:44
   |
   |
LL |     fn foo<const N: usize>(&self) -> Self::B<{ N }>;
   |                                            ^ there is a similarly named associated type `H` in the trait `compiler_builtins::int::traits::DInt`
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0046, E0183, E0220, E0229, E0277, E0407.
For more information about an error, try `rustc --explain E0046`.

@bors
Copy link
Collaborator

bors commented Jan 16, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 16, 2025
@matthiaskrgr matthiaskrgr deleted the rollup-e38vft0 branch January 25, 2025 09:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
rollup A PR which is a rollup 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants