Commit Graph

6237 Commits

Author SHA1 Message Date
Matthias Krüger
5b66e008e0
Rollup merge of #121888 - cppcoffee:style, r=Nilstrieb
style library/core/src/error.rs

Add an extra blank line for clarity in distinguishing implementations.
2024-03-02 16:53:16 +01:00
Matthias Krüger
3e59b7834a
Rollup merge of #121759 - RalfJung:addr_of, r=the8472
attempt to further clarify addr_of docs
2024-03-02 16:53:15 +01:00
Ralf Jung
ec5e2dc241 attempt to further clarify addr_of docs 2024-03-02 10:12:02 +01:00
Xiaobo Liu
624f9d3c78
style library/core/src/error.rs 2024-03-02 16:03:23 +08:00
Matthias Krüger
441217d9b5
Rollup merge of #121634 - RavuAlHemio:slice-prefix-suffix-docs, r=cuviper
Clarify behavior of slice prefix/suffix operations in case of equality

Operations such as starts_with, ends_with, strip_prefix and strip_suffix can be either strict (do not consider a slice to be a prefix/suffix of itself) or not. In Rust's case, they are not strict. Add a few phrases to the documentation to clarify this.
2024-03-01 22:38:47 +01:00
Markus Reiter
f6d2607163
Make ZeroablePrimitive trait unsafe. 2024-03-01 13:49:37 +01:00
Matthias Krüger
2fdcdd9025
Rollup merge of #121753 - mu001999:core/add_cfg, r=cuviper
Add proper cfg to keep only one AlignmentEnum definition for different target_pointer_widths

Detected by #121752

Only one AlignmentEnum would be used with a specified target_pointer_width
2024-02-29 20:50:03 +01:00
Matthias Krüger
419f7aeed6
Rollup merge of #121681 - jswrenn:nix-visibility-analysis, r=compiler-errors
Safe Transmute: Revise safety analysis

This PR migrates `BikeshedIntrinsicFrom` to a simplified safety analysis (described [here](https://github.com/rust-lang/project-safe-transmute/issues/15)) that does not rely on analyzing the visibility of types and fields.

The revised analysis treats primitive types as safe, and user-defined types as potentially carrying safety invariants. If Rust gains explicit (un)safe fields, this PR is structured so that it will be fairly easy to thread support for those annotations into the analysis.

Notably, this PR removes the `Context` type parameter from `BikeshedIntrinsicFrom`. Most of the files changed by this PR are just UI tests tweaked to accommodate the removed parameter.

r? `@compiler-errors`
2024-02-29 20:50:03 +01:00
r0cky
61fcdf6655 Add proper cfg 2024-02-29 09:25:28 +08:00
Jack Wrenn
23ab1bda92 safe transmute: revise safety analysis
Migrate to a simplified safety analysis that does not use visibility.

Closes https://github.com/rust-lang/project-safe-transmute/issues/15
2024-02-27 16:22:32 +00:00
Ralf Jung
f5c80dcd5a intrinsics.rs: add some notes on unwinding 2024-02-27 12:28:25 +01:00
bors
71ffdf7ff7 Auto merge of #121655 - matthiaskrgr:rollup-qpx3kks, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #121598 (rename 'try' intrinsic to 'catch_unwind')
 - #121639 (Update books)
 - #121648 (Update Vec and String `{from,into}_raw_parts`-family docs)
 - #121651 (Properly emit `expected ;` on `#[attr] expr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-27 00:55:14 +00:00
Matthias Krüger
d95c321062
Rollup merge of #121598 - RalfJung:catch_unwind, r=oli-obk
rename 'try' intrinsic to 'catch_unwind'

The intrinsic has nothing to do with `try` blocks, and corresponds to the stable `catch_unwind` function, so this makes a lot more sense IMO.

Also rename Miri's special function while we are at it, to reflect the level of abstraction it works on: it's an unwinding mechanism, on which Rust implements panics.
2024-02-27 00:40:00 +01:00
bors
5c786a7fe3 Auto merge of #121516 - RalfJung:platform-intrinsics-begone, r=oli-obk
remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics

`@Amanieu` `@workingjubilee` I don't think there is any reason these need to be "special"? The [original RFC](https://rust-lang.github.io/rfcs/1199-simd-infrastructure.html) indicated eventually making them stable, but I think that is no longer the plan, so seems to me like we can clean this up a bit.

Blocked on https://github.com/rust-lang/stdarch/pull/1538, https://github.com/rust-lang/rust/pull/121542.
2024-02-26 22:24:16 +00:00
Ondřej Hošek
c9a4a4a192 Clarify behavior of slice prefix/suffix operations in case of equality
Operations such as starts_with, ends_with, strip_prefix and strip_suffix
can be either strict (do not consider a slice to be a prefix/suffix of
itself) or not. In Rust's case, they are not strict. Add a few phrases to
the documentation to clarify this.
2024-02-26 15:35:30 +01:00
Ralf Jung
b4ca582b89 rename 'try' intrinsic to 'catch_unwind' 2024-02-26 11:10:18 +01:00
bors
b0d3e04ca9 Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
Implement RFC 3373: Avoid non-local definitions in functions

This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25 19:11:06 +00:00
Ralf Jung
cc3df0af7b remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics 2024-02-25 08:14:52 +01:00
bors
e9f9594913 Auto merge of #121114 - Nilstrieb:no-inline!, r=saethlin
Add `#[rustc_no_mir_inline]` for standard library UB checks

should help with #121110 and also with #120848

Because the MIR inliner cannot know whether the checks are enabled or not, so inlining is an unnecessary compile time pessimization when debug assertions are disabled. LLVM knows whether they are enabled or not, so it can optimize accordingly without wasting time.

r? `@saethlin`
2024-02-25 03:47:31 +00:00
Matthias Krüger
4c401531f5
Rollup merge of #121556 - GrigorenkoPV:addr_of, r=Nilstrieb
Use `addr_of!`

As per https://github.com/rust-lang/rust/pull/121303#discussion_r1500954662
2024-02-24 22:39:01 +01:00
Matthias Krüger
9975e848ff
Rollup merge of #121551 - nbdd0121:ffi_unwind, r=RalfJung
Forbid use of `extern "C-unwind"` inside standard library

Those libraries are build with `-C panic=unwind` and is expected to be linkable to `-C panic=abort` library. To ensure unsoundness compiler needs to prevent a `C-unwind` call to exist, as doing so may leak foreign exceptions into `-C panic=abort`.

r? ``@RalfJung``
2024-02-24 22:39:00 +01:00
Matthias Krüger
ed75229a97
Rollup merge of #121343 - Takashiidobe:takashi/examples-for-slice, r=Mark-Simulacrum
Add examples for some methods on slices

Adds some examples to some methods on slice.

`is_empty` didn't have an example for an empty slice, even though `str` and the collections all have one, so I added that in.

`first_mut` and `last_mut` didn't have an example for what happens when the slice is empty, whereas `first` and `last` do, so I added that too.
2024-02-24 22:38:58 +01:00
Nilstrieb
81d7069e34 Add #[rustc_no_mir_inline] for standard library UB checks
Co-authored-by: Ben Kimock <kimockb@gmail.com>
2024-02-24 21:19:41 +01:00
Gary Guo
f08e2d4137 Forbid use of extern "C-unwind" inside standard library
Those libraries are build with `-C panic=unwind` and is expected to
be linkable to `-C panic=abort` library. To ensure unsoundness
compiler needs to prevent a `C-unwind` call to exist, as doing so may leak
foreign exceptions into `-C panic=abort`.
2024-02-24 14:53:04 +00:00
Pavel Grigorenko
ff187a92d8
library: use addr_of! 2024-02-24 16:02:17 +03:00
bors
b6a23b8537 Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnay
Use generic `NonZero` everywhere in `library`.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

Use generic `NonZero` everywhere (except stable examples).

r? `@dtolnay`
2024-02-23 14:27:33 +00:00
bors
a28d221a4b Auto merge of #120730 - estebank:confusable-api, r=oli-obk
Provide suggestions through `rustc_confusables` annotations

Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

Fix #59450 (we can open subsequent tickets for specific cases).

Fix #108437:

```
error[E0599]: `Option<{integer}>` is not an iterator
   --> f101.rs:3:9
    |
3   |     opt.flat_map(|val| Some(val));
    |         ^^^^^^^^ `Option<{integer}>` is not an iterator
    |
   ::: /home/gh-estebank/rust/library/core/src/option.rs:571:1
    |
571 | pub enum Option<T> {
    | ------------------ doesn't satisfy `Option<{integer}>: Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `Option<{integer}>: Iterator`
            which is required by `&mut Option<{integer}>: Iterator`
help: you might have meant to use `and_then`
    |
3   |     opt.and_then(|val| Some(val));
    |         ~~~~~~~~
```

On type error of method call arguments, look at confusables for suggestion. Fix #87212:

```
error[E0308]: mismatched types
    --> f101.rs:8:18
     |
8    |     stuff.append(Thing);
     |           ------ ^^^^^ expected `&mut Vec<Thing>`, found `Thing`
     |           |
     |           arguments to this method are incorrect
     |
     = note: expected mutable reference `&mut Vec<Thing>`
                           found struct `Thing`
note: method defined here
    --> /home/gh-estebank/rust/library/alloc/src/vec/mod.rs:2025:12
     |
2025 |     pub fn append(&mut self, other: &mut Self) {
     |            ^^^^^^
help: you might have meant to use `push`
     |
8    |     stuff.push(Thing);
     |           ~~~~
```
2024-02-23 00:42:56 +00:00
Esteban Küber
f566867ace Add flatmap/flat_map -> and_then suggestions 2024-02-22 18:05:28 +00:00
Esteban Küber
e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
Help with common API confusion, like asking for `push` when the data structure really has `append`.

```
error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope
  --> $DIR/rustc_confusables_std_cases.rs:17:7
   |
LL |     x.size();
   |       ^^^^
   |
help: you might have meant to use `len`
   |
LL |     x.len();
   |       ~~~
help: there is a method with a similar name
   |
LL |     x.resize();
   |       ~~~~~~
```

#59450
2024-02-22 18:04:55 +00:00
Matthias Krüger
e064bf639b
Rollup merge of #121439 - jrudolph:patch-1, r=bjorn3
Fix typo in metadata.rs doc comment
2024-02-22 18:09:55 +01:00
Markus Reiter
b74d8db9d2
Fix example. 2024-02-22 17:16:29 +01:00
Markus Reiter
14ed426eec
Use generic NonZero everywhere in core. 2024-02-22 15:17:33 +01:00
bors
1bb3a9f67a Auto merge of #121309 - Nilstrieb:inline-all-the-fallbacks, r=oli-obk
Make intrinsic fallback bodies cross-crate inlineable

This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`.

Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those.

See the comments for more information.

r? oli-obk
2024-02-22 12:07:08 +00:00
Johannes Rudolph
c276af2373
Fix typo in metadata.rs doc comment 2024-02-22 09:30:03 +01:00
bors
c1b478efd3 Auto merge of #121223 - RalfJung:simd-intrinsics, r=Amanieu
intrinsics::simd: add missing functions, avoid UB-triggering fast-math

Turns out stdarch declares a bunch more SIMD intrinsics that are still missing from libcore.
I hope I got the docs and in particular the safety requirements right for these "unordered" and "nanless" intrinsics.

Many of these are unused even in stdarch, but they are implemented in the codegen backend, so we may as well list them here.

r? `@Amanieu`
Cc `@calebzulawski` `@workingjubilee`
2024-02-22 04:02:31 +00:00
Ralf Jung
07b6240947 remove simd_reduce_{min,max}_nanless 2024-02-21 20:50:47 +01:00
Ralf Jung
b58f647d54 rename ptr::invalid -> ptr::without_provenance
also introduce ptr::dangling matching NonNull::dangling
2024-02-21 20:15:52 +01:00
Ralf Jung
3dc631a61a make simd_reduce_{mul,add}_unordered use only the 'reassoc' flag, not all fast-math flags 2024-02-21 16:28:20 +01:00
Ralf Jung
25fe3cc69d intrinsics::simd: add missing functions 2024-02-21 16:26:32 +01:00
bors
1d447a9946 Auto merge of #121383 - Dylan-DPC:rollup-735p4u4, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #121208 (Convert `delayed_bug`s to `bug`s.)
 - #121288 (make rustc_expand translatable)
 - #121304 (Add docs for extension proc-macro)
 - #121328 (Make --verbose imply -Z write-long-types-to-disk=no)
 - #121338 (Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect)
 - #121361 (diagnostic items for legacy numeric modules)
 - #121375 (Print proper relative path for descriptive name check)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-21 12:09:22 +00:00
bors
bb8b11e67d Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercote
Add "algebraic" fast-math intrinsics, based on fast-math ops that cannot return poison

Setting all of LLVM's fast-math flags makes our fast-math intrinsics very dangerous, because some inputs are UB. This set of flags permits common algebraic transformations, but according to the [LangRef](https://llvm.org/docs/LangRef.html#fastmath), only the flags `nnan` (no nans) and `ninf` (no infs) can produce poison.

And this uses the algebraic float ops to fix https://github.com/rust-lang/rust/issues/120720

cc `@orlp`
2024-02-21 09:43:33 +00:00
Dylan DPC
860ad7c10b
Rollup merge of #121361 - pitaj:diag_items-legacy_numeric_constants, r=Nilstrieb
diagnostic items for legacy numeric modules

For https://github.com/rust-lang/rust-clippy/pull/12312

Missed these in #121272

r? `@Nilstrieb`
2024-02-21 08:55:58 +00:00
Peter Jaszkowiak
0195f21f72 diagnostic items for legacy numeric modules 2024-02-20 13:34:18 -07:00
Matthias Krüger
c03f61ba69
Rollup merge of #121352 - malobre:patch-1, r=Nilstrieb
docs: add missing "the" to `str::strip_prefix` doc

Fix #121348
2024-02-20 19:35:42 +01:00
Matthias Krüger
3099a7931a
Rollup merge of #121277 - reitermarkus:generic-nonzero-convert-num, r=dtolnay
Refactor trait implementations in `core::convert::num`.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

Implement conversion traits using generic `NonZero` type, and refactor all macros to use a consistent format/order of parameters.

r? `@dtolnay`
2024-02-20 19:35:40 +01:00
Matthias Krüger
fc5f6f88e5
Rollup merge of #119203 - farnoy:simd-masked-intrinsic-docfix, r=RalfJung
Correct the simd_masked_{load,store} intrinsic docs

Explains the uniform pointer being used for these two operations and how elements are offset from it.
2024-02-20 19:35:39 +01:00
Ben Kimock
cc73b71e8e Add "algebraic" versions of the fast-math intrinsics 2024-02-20 12:39:03 -05:00
Malobre
9ac73cbdc6
docs: add missing "the" to str::strip_prefix doc 2024-02-20 18:05:55 +01:00
bors
bb594538fc Auto merge of #121345 - Nilstrieb:rollup-reb0xge, r=Nilstrieb
Rollup of 8 pull requests

Successful merges:

 - #121167 (resolve: Scale back unloading of speculatively loaded crates)
 - #121196 (Always inline check in `assert_unsafe_precondition` with cfg(debug_assertions))
 - #121241 (Implement `NonZero` traits generically.)
 - #121278 (Remove the "codegen" profile from bootstrap)
 - #121286 (Rename `ConstPropLint` to `KnownPanicsLint`)
 - #121291 (target: Revert default to the medium code model on LoongArch targets)
 - #121302 (Remove `RefMutL` hack in `proc_macro::bridge`)
 - #121318 (Trigger `unsafe_code` lint on invocations of `global_asm`)

Failed merges:

 - #121206 (Top level error handling)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-20 16:22:48 +00:00
Jakub Okoński
14a4551695
Correct the simd_masked_{load,store} intrinsic docs 2024-02-20 17:03:24 +01:00