Commit Graph

16873 Commits

Author SHA1 Message Date
Ralf Jung
19e287060d remove const-support for align_offset
Operations like is_aligned would return actively wrong results at compile-time,
i.e. calling it on the same pointer at compiletime and runtime could yield
different results. That's no good.

Instead of having hacks to make align_offset kind-of work in const-eval, just
use const_eval_select in the few places where it makes sense, which also ensures
those places are all aware they need to make sure the fallback behavior is
consistent.
2024-11-03 17:00:44 +01:00
bors
67395551d0 Auto merge of #132458 - RalfJung:rustc-const-unstable, r=Amanieu
get rid of a whole bunch of unnecessary rustc_const_unstable attributes

In general, when a `const fn` is still unstable, it doesn't need a `#[rustc_const_unstable]` attribute. The only exception is functions that internally use things that can't be used in stable const fn yet.

So this gets rid of a whole bunch of `#[rustc_const_unstable]` in libcore.
2024-11-03 02:32:48 +00:00
Matthias Krüger
c4024585a4
Rollup merge of #132495 - Houtamelo:remove_unintended_link, r=jieyouxu
Remove unintended link

Since `#[link_section]` is enclosed in braces, it was being confused with a link during docs compilation.

This caused compilation to fail when running `x dist` since it emitted a warning regarding broken links.
2024-11-02 12:14:15 +01:00
Matthias Krüger
52ff41ccaa
Rollup merge of #132493 - Houtamelo:doc_type-ref_html-tag, r=jieyouxu
Fix type reference in documents which was being confused with html tags.

Running `x dist` was failing due to it invoking commands with `-D warnings`, which emitted a warning about unclosed html tags.
2024-11-02 12:14:13 +01:00
Matthias Krüger
90c5f86298
Rollup merge of #132482 - lukas-code:stab-attrs, r=Noratrieb
library: fix some stability annotations

This PR updates some stability attributes to correctly reflect when some items actually got stabilized. Found while testing https://github.com/rust-lang/rust/pull/132481.

### `core::char` / `std::char`

In https://github.com/rust-lang/rust/pull/26192, the `core::char` module got "stabilized" for 1.2.0, but the `core` crate itself was still unstable until 1.6.0.

In https://github.com/rust-lang/rust/pull/49698, the `std::char` module was changed to a re-export of `core::char`, making `std::char` appear as "stable since 1.2.0", even though it was already stable in 1.0.0.

By marking `core::char` as stable since 1.0.0, the docs will show correct versions for both `core::char` (since 1.6.0) and `std::char` (since 1.0.0). This is also consistent with the stabilities of similar re-exported modules like `core::mem`/`std::mem` for example.

### `{core,std}::array` and `{core,std}::array::TryFromSliceError`

In https://github.com/rust-lang/rust/pull/58302, the `core::array::TryFromSliceError` type got stabilized for 1.34.0, together with `TryFrom`. At that point the `core::array` module was still unstable and a `std::array` re-export didn't exist, but `core::array::TryFromSliceError` could still be named due to https://github.com/rust-lang/rust/pull/95956 to existing yet.

Then, `core::array` got stabilized and `std::array` got added, first targeting 1.36.0 in https://github.com/rust-lang/rust/pull/60657, but then getting backported for 1.35.0 in https://github.com/rust-lang/rust/pull/60838.

This means that `core::array` and `std::array` actually got stabilized in 1.35.0 and `core::array::TryFromSliceError` was accessible through the unstable module in 1.34.0 -- mark them as such so that the docs display the correct versions.
2024-11-02 12:14:13 +01:00
Ralf Jung
66351a6184 get rid of a whole bunch of unnecessary rustc_const_unstable attributes 2024-11-02 09:59:55 +01:00
Matthias Krüger
ec1cebfcb6
Rollup merge of #132398 - krtab:add_doc_link, r=Noratrieb
Add a couple of intra-doc links to str
2024-11-02 08:33:11 +01:00
Houtamelo
102fac7af6
Remove unintended link
Since `#[link_section]` is enclosed in braces, it was being confused with a link during docs compilation.
2024-11-02 04:09:17 -03:00
Houtamelo
1acb1043fe
Fix type reference in documents which was being confused with html tags. 2024-11-02 04:02:32 -03:00
Lukas Markeffsky
2a6a70606d fix some stability annotations 2024-11-02 01:37:45 +01:00
Guillaume Gomez
305ca05cbe
Rollup merge of #132459 - RalfJung:byte_sub_ptr, r=scottmcm
feat(byte_sub_ptr): unstably add ptr::byte_sub_ptr

This is an API that naturally should exist as a combination of byte_offset_from and sub_ptr
both existing (they showed up at similar times so this union was never made). Adding these
is a logical (and perhaps final) precondition of stabilizing ptr_sub_ptr (https://github.com/rust-lang/rust/issues/95892).

Original PR by ``@Gankra`` (https://github.com/rust-lang/rust/pull/121919), I am just reviving it. The 2nd commit (with a small docs tweak) is by me.
2024-11-02 03:08:56 +08:00
Guillaume Gomez
d5366090f9
Rollup merge of #132455 - RalfJung:const_alloc_layout, r=dtolnay
make const_alloc_layout feature gate only about functions that are already stable

The const_alloc_layout feature gate has two kinds of functions: those that are stable, but not yet const-stable, and those that are fully unstable.

I think we should split that up. So this PR makes const_alloc_layout just about functions that are already stable but waiting for const-stability; all the other functions now have their constness guarded by the gate that also guards their regular stability.

Cc https://github.com/rust-lang/rust/issues/67521
2024-11-02 03:08:55 +08:00
Guillaume Gomez
5f8d7e84cc
Rollup merge of #132451 - RalfJung:less-rustc_allow_const_fn_unstable, r=tgross35
remove some unnecessary rustc_allow_const_fn_unstable

These are either unstable functions that don't need the attribute, or the attribute refers to a feature that is already stable.
2024-11-02 03:08:55 +08:00
Guillaume Gomez
8366ecca2e
Rollup merge of #132445 - RalfJung:const-unchecked-shifts, r=tgross35
Cleanup attributes around unchecked shifts and unchecked negation in const

The underlying intrinsic is marked as "safe to expose on stable", so we shouldn't need any `rustc_allow_const_fn_unstable(unchecked_shifts)` anywhere. However, bootstrap rustc doesn't yet have the new const stability checks, so these changes only apply under `cfg(not(bootstrap))`.
2024-11-02 03:08:54 +08:00
Guillaume Gomez
5f0568b7b7
Rollup merge of #132413 - lolbinarycat:offset_of_nested-docs, r=workingjubilee
update offset_of! docs to reflect the stabilization of nesting

this seems to have been missed.
2024-11-02 03:08:51 +08:00
Ralf Jung
c38865502e offset_from / sub_ptr docs: emphasize that pointers must be in the same allocation 2024-11-01 15:30:08 +01:00
Aria Beingessner
aba2088735 feat(byte_sub_ptr): add ptr::byte_sub_ptr
This is an API that naturally should exist as a combination of byte_offset_from and sub_ptr
both existing (they showed up at similar times so this union was never made). Adding these
is a logical (and perhaps final) precondition of stabilizing ptr_sub_ptr (#95892).
2024-11-01 15:27:43 +01:00
Ralf Jung
c9e77e8776 make const_alloc_layout feature gate only about functions that are already stable
the rest has their constness guarded by their usual feature gate
2024-11-01 14:32:59 +01:00
Ralf Jung
901b340c1f unchecked_shifts, unchecked_neg are safe-to-const-expose-on-stable, so we can get rid of a bunch of attributes 2024-11-01 11:48:49 +01:00
Ralf Jung
506812d087 remove some unnecessary rustc_allow_const_fn_unstable 2024-11-01 11:47:31 +01:00
bors
24254efb43 Auto merge of #132206 - tgross35:update-builtins, r=wesleywiser
Update compiler-builtins to 0.1.136

This includes:

* The license change https://github.com/rust-lang/compiler-builtins/pull/717
* The `libm` submodule update, which also has a license change https://github.com/rust-lang/libm/pull/317
* Re-enabling `math` on i686 UEFI https://github.com/rust-lang/compiler-builtins/pull/715

Fixes: https://github.com/rust-lang/rust/issues/128533
2024-10-31 23:31:48 +00:00
lolbinarycat
fc67203d59
use semantic line break
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2024-10-31 17:27:31 -05:00
binarycat
dd651be7bc update offset_of! docs to reflect the stablization of nesting 2024-10-31 14:33:00 -05:00
Arthur Carcano
df445264b3 Add intra-doc link in str::xxx_char_boundary 2024-10-31 11:55:12 +01:00
Michael Goulet
c62f0977a0 Remove do_not_const_check from Iterator methods 2024-10-30 19:24:34 +00:00
Arthur Carcano
df8c20d7a5 Add intra-doc link in str::xxx_prefix 2024-10-30 16:45:54 +01:00
bors
16422dbd89 Auto merge of #132238 - Urgau:midpoint-i64-hackers-impl, r=joboet
Use Hacker's Delight impl in `i64::midpoint` instead of wide `i128` impl

This PR switches `i64::midpoint` and (`isize::midpoint` where `isize == i64`) to using our Hacker's Delight impl instead of wide `i128` implementation.

As LLVM seems to be outperformed by the complexity of signed 128-bits number compared to our Hacker's Delight implementation.[^1]

It doesn't seems like it's an improvement for the other sizes[^2], so we let them with the wide implementation.

[^1]: https://rust.godbolt.org/z/ravE75EYj
[^2]: https://rust.godbolt.org/z/fzr171zKh

r? libs
2024-10-30 02:26:18 +00:00
bors
1e4f10ba64 Auto merge of #132326 - matthiaskrgr:rollup-ngyw18g, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #131984 (Stabilize if_let_rescope)
 - #132151 (Ensure that resume arg outlives region bound for coroutines)
 - #132157 (Remove detail from label/note that is already available in other note)
 - #132274 (Cleanup op lookup in HIR typeck)
 - #132319 (cg_llvm: Clean up FFI calls for setting module flags)
 - #132321 (xous: sync: remove `rustc_const_stable` attribute on Condvar and Mutex new())

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-29 19:25:03 +00:00
Matthias Krüger
07afe8d12f
Rollup merge of #132321 - betrusted-io:xous/fix-rustc_const_stable-attribute, r=joboet
xous: sync: remove `rustc_const_stable` attribute on Condvar and Mutex new()

These functions had `#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]` on them because they were originally taken from `no_threads`. with d066dfd these no longer compile. Since other platforms do not have this attribute, remove it. This fixes the build for Xous.
2024-10-29 18:39:00 +01:00
bors
e473783d90 Auto merge of #132231 - lukas-code:rc-plug-leaks, r=tgross35
Rc/Arc: don't leak the allocation if drop panics

Currently, when the last `Rc<T>` or `Arc<T>` is dropped and the destructor of `T` panics, the allocation will be leaked. This leak is unnecessary since the data cannot be (safely) accessed again and `Box` already deallocates in this case, so let's do the same for `Rc` and `Arc`, too.
2024-10-29 16:26:00 +00:00
Sean Cross
59944c9c9f xous: sync: remove rustc_const_stable attribute
These functions had `#[rustc_const_stable(feature = "const_locks", since
= "1.63.0")]` on them because they were originally taken from
`no_threads`. with d066dfd these no longer compile. Since other
platforms do not have this attribute, remove it. This fixes the build
for Xous.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-10-29 22:43:46 +08:00
Jubilee
29a7ca993d
Rollup merge of #132270 - yakiimoninja:fs-truncate-docs, r=Noratrieb
clarified doc for `std::fs::OpenOptions.truncate()`

Clarified what method does when `std::fs::OpenOptions.truncate()` parameter is set to `true`.
2024-10-29 03:11:43 -07:00
Jubilee
5ee13ae513
Rollup merge of #132233 - WaffleLapkin:box-module-split, r=workingjubilee
Split `boxed.rs` into a few modules

I wanted to add an impl for `Box<_>`, but was quickly discouraged by the 3K file. This splits off a couple bits, making it at least a bit more manageable.

r? ````@workingjubilee```` (I think you are not bothered by refactorings like this?)
2024-10-29 03:11:42 -07:00
Jubilee
b496974c53
Rollup merge of #131520 - zachs18:const-str-split, r=Noratrieb
Mark `str::is_char_boundary` and `str::split_at*` unstably `const`.

Tracking issues: #131516, #131518

First commit implements `const_is_char_boundary`, second commit implements `const_str_split_at` (which depends on `const_is_char_boundary`)

~~I used `const_eval_select` for `is_char_boundary` since there is a comment about optimizations that would theoretically not happen with the simple `const`-compatible version (since `slice::get` is not `const`ifiable) cc #84751. I have not checked if this code difference is still required for the optimization, so it might not be worth the code complication, but 🤷.~~

This changes `str::split_at_checked` to use a new private helper function `split_at_unchecked` (copied from `split_at_mut_unchecked`) that does pointer stuff instead of `get_unchecked`, since that is not currently `const`ifiable due to using the `SliceIndex` trait.
2024-10-29 03:11:39 -07:00
bors
2df8dbb1b3 Auto merge of #132277 - workingjubilee:rollup-5e6q6e4, r=workingjubilee
Rollup of 9 pull requests

Successful merges:

 - #130259 (Lower AST node id only once)
 - #131441 (Add a new trait `proc_macro::ToTokens`)
 - #132247 (stable_mir: Directly use types from rustc_abi)
 - #132249 (compiler: Add rustc_abi dependence to the compiler)
 - #132255 (Add `LayoutData::is_uninhabited` and use it)
 - #132258 ([rustdoc] Unify variant struct fields margins with struct fields)
 - #132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`)
 - #132261 (refactor: cleaner check to return None)
 - #132271 (Updating Fuchsia platform-support documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-29 07:32:45 +00:00
bors
a9d17627d2 Auto merge of #128985 - GrigorenkoPV:instantly-dangling-pointer, r=Urgau
Lint against getting pointers from immediately dropped temporaries

Fixes #123613

## Changes:
1. New lint: `dangling_pointers_from_temporaries`. Is a generalization of `temporary_cstring_as_ptr` for more types and more ways to get a temporary.
2. `temporary_cstring_as_ptr` is removed and marked as renamed to `dangling_pointers_from_temporaries`.
3. `clippy::temporary_cstring_as_ptr` is marked as renamed to `dangling_pointers_from_temporaries`.
4. Fixed a false positive[^fp] for when the pointer is not actually dangling because of lifetime extension for function/method call arguments.
5. `core::cell::Cell` is now `rustc_diagnostic_item = "Cell"`

## Questions:
- [ ]  Instead of manually checking for a list of known methods and diagnostic items, maybe add some sort of annotation to those methods in library and check for the presence of that annotation? https://github.com/rust-lang/rust/pull/128985#issuecomment-2318714312

## Known limitations:

### False negatives[^fn]:

See the comments in `compiler/rustc_lint/src/dangling.rs`

1. Method calls that are not checked for:
   - `temporary_unsafe_cell.get()`
   - `temporary_sync_unsafe_cell.get()`
2. Ways to get a temporary that are not recognized:
   - `owning_temporary.field`
   - `owning_temporary[index]`
3. No checks for ref-to-ptr conversions:
   - `&raw [mut] temporary`
   - `&temporary as *(const|mut) _`
    - `ptr::from_ref(&temporary)` and friends

[^fn]: lint **should** be emitted, but **is not**

[^fp]: lint **should not** be emitted, but **is**
2024-10-29 00:24:07 +00:00
Lukas Markeffsky
02ee6395fd Rc destructor: tweak inlining 2024-10-28 22:59:14 +01:00
Maybe Lapkin
b2f335ea99 Split boxed.rs into a few modules
+ some minor style changes
2024-10-28 12:29:19 -07:00
Jubilee
c9347f1e27
Rollup merge of #131441 - SpriteOvO:proc-macro-to-tokens-trait, r=dtolnay
Add a new trait `proc_macro::ToTokens`

Tracking issue #130977

This PR adds a new trait `ToTokens`, implemented for types that can be interpolated inside a `quote!` invocation.

```rust
impl ToTokens for TokenTree
impl ToTokens for TokenStream
impl ToTokens for Literal
impl ToTokens for Ident
impl ToTokens for Punct
impl ToTokens for Group
impl<T: ToTokens + ?Sized> ToTokens for &T
impl<T: ToTokens + ?Sized> ToTokens for &mut T
impl<T: ToTokens + ?Sized> ToTokens for Box<T>
impl<T: ToTokens + ?Sized> ToTokens for Rc<T>
impl<T: ToTokens + ToOwned + ?Sized> ToTokens for Cow<'_, T>
impl<T: ToTokens> ToTokens for Option<T>
impl ToTokens for u{8,16,32,64,128}
impl ToTokens for i{8,16,32,64,128}
impl ToTokens for f{32,64}
impl ToTokens for {u,i}size
impl ToTokens for bool
impl ToTokens for char
impl ToTokens for str
impl ToTokens for String
impl ToTokens for CStr
impl ToTokens for CString
```

~This PR also implements the migration mentioned in the tracking issue, replacing `Extend<Token{Tree,Stream}>` with `Extend<T: ToTokens>`, and replacing `FromIterator<Token{Tree,Stream}>` with `FromIterator<T: ToTokens>`.~
**UPDATE**: Reverted.

```diff
-impl FromIterator<TokenTree> for TokenStream
-impl FromIterator<TokenStream> for TokenStream
+impl<T: ToTokens> FromIterator<T> for TokenStream

-impl Extend<TokenTree> for TokenStream
-impl Extend<TokenStream> for TokenStream
+impl<T: ToTokens> Extend<T> for TokenStream
```

I'm going to leave some comments in the review where I'm unsure and concerned.

r? ``@dtolnay``
CC ``@tgross35``
2024-10-28 10:18:49 -07:00
yakiimoninja
5910a4f1bc
clarified std::fs truncate doc
Co-authored-by: nora <48135649+Noratrieb@users.noreply.github.com>
2024-10-28 17:14:15 +00:00
bors
3f1be1ec7e Auto merge of #132145 - RalfJung:stdarch, r=Amanieu
bump stdarch

This lets us remove a hack from https://github.com/rust-lang/rust/pull/131349.

r? `@Amanieu`

try-job: test-various
2024-10-28 16:25:56 +00:00
yakiimoninja
a946721408
clarified doc for std::fs::OpenOptions.truncate()
Clarified what method does when `truncate` parameter is set to `true`.
2024-10-28 16:07:20 +00:00
Pavel Grigorenko
c69894eaec New lint: dangling_pointers_from_temporaries 2024-10-28 14:16:05 +03:00
Matthias Krüger
81d885b933
Rollup merge of #131391 - ChaiTRex:isqrt, r=scottmcm,tgross35
Stabilize `isqrt` feature

Stabilizes the `isqrt` feature. FCP is incomplete.

Closes #116226
2024-10-28 12:14:57 +01:00
Ralf Jung
d066dfdb83 we can now enable the 'const stable fn must be stable' check 2024-10-28 11:48:39 +01:00
Ralf Jung
f370f3493d bump stdarch 2024-10-28 09:42:42 +01:00
bors
66701c4226 Auto merge of #132251 - jieyouxu:rollup-mtv9mpd, r=jieyouxu
Rollup of 7 pull requests

Successful merges:

 - #131633 (error on alignments greater than `isize::MAX`)
 - #132086 (Tweak E0277 highlighting and "long type" path printing)
 - #132220 (Add GUI regression test for doc struct fields margins)
 - #132225 (Dynamically link run-make support)
 - #132227 (Pass constness with span into lower_poly_trait_ref)
 - #132242 (Support `char::is_digit` in const contexts.)
 - #132243 (Remove `ObligationCause::span()` method)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-28 07:14:11 +00:00
bors
6929a48275 Auto merge of #132200 - Mark-Simulacrum:strengthen-cross-lang, r=RalfJung
Make clearer that guarantees in ABI compatibility are for Rust only

cc https://github.com/rust-lang/rust/pull/132136#issuecomment-2439737631 -- it looks like we already had a note that I missed in my initial look here, but this goes further to emphasize the guarantees, including uplifting it to the top of the general documentation.

r? `@RalfJung`
2024-10-28 04:47:06 +00:00
ultrabear
66209cd9b5
Support char::is_digit in const contexts 2024-10-27 14:31:58 -07:00
Urgau
ad80da6729 Use Hacker's Delight impl in i64::midpoint instead of wide i128 impl
As LLVM seems to be outperformed by the complexity of signed 128-bits
number compared to our Hacker's Delight implementation.[^1]

It doesn't seems like it's an improvement for the other sizes[^2], so we
let them with the wide implementation.

[^1]: https://rust.godbolt.org/z/ravE75EYj
[^2]: https://rust.godbolt.org/z/fzr171zKh
2024-10-27 20:34:13 +01:00