about summary refs log tree commit diff
path: root/library
AgeCommit message (Collapse)AuthorLines
2023-08-18resolve conflictsKyle Lin-2/+4
2023-08-18tidy doc linkKyle Lin-1/+1
2023-08-18lint linksKyle Lin-1/+1
2023-08-18Inline strlen_rt in CStr::from_ptrKonrad Borowski-1/+3
This enables LLVM to optimize this function as if it was strlen without having to enable std-aware LTO.
2023-08-17Rollup merge of #114897 - joshtriplett:partial-revert-ok-0, r=m-ou-seJosh Stone-3/+3
Partially revert #107200 `Ok(0)` is indeed something the caller may interpret as an error, but that's the *correct* thing to return if the writer can't accept any more bytes.
2023-08-17Auto merge of #114799 - RalfJung:less-transmute, r=m-ou-sebors-2/+2
avoid transmuting Box when we can just cast raw pointers instead Always better to avoid a transmute, in particular when the layout assumptions it is making are not clearly documented. :)
2023-08-17Rollup merge of #114881 - RalfJung:cstr, r=cuviperMatthias Krüger-4/+4
clarify CStr lack of layout guarnatees Follow-up to https://github.com/rust-lang/rust/pull/114800 r? `@cuviper`
2023-08-17Rollup merge of #114749 - gurry:issue-114722, r=thomccMatthias Krüger-3/+2
Update `mpsc::Sender` doc to reflect that it implements `Sync` Fixes #114722
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Auto merge of #114905 - matthiaskrgr:rollup-uxhhr7p, r=matthiaskrgrbors-0/+2
Rollup of 5 pull requests Successful merges: - #113115 (we are migrating to askama) - #114784 (Improve `invalid_reference_casting` lint) - #114822 (Improve code readability by moving fmt args directly into the string) - #114878 (rustc book: make more pleasant to search) - #114899 (Add missing Clone/Debug impls to SMIR Trait related tys) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Rollup merge of #114784 - Urgau:many-improve-invalid_reference_casting-lint, ↵Matthias Krüger-0/+2
r=est31 Improve `invalid_reference_casting` lint This PR improves the `invalid_reference_casting` lint: - by considering an unlimited number of casts instead only const to mut ptr - by also considering ptr-to-integer and integer-to-ptr casts - by also taking into account [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast), [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1) and [`ptr::cast_const`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const) Most of this improvements comes from skimming Github Code Search result for [`&mut \*.*as \*const`](https://github.com/search?q=lang%3Arust+%2F%26mut+%5C*.*as+%5C*const%2F&type=code) r? ``@est31`` (maybe)
2023-08-16Auto merge of #114617 - petrochenkov:docspacing, r=Mark-Simulacrumbors-13/+25
proc_macro: Update docs for `Spacing` Brings the docs more in line with reality
2023-08-16Partially revert #107200Josh Triplett-3/+3
`Ok(0)` is indeed something the caller may interpret as an error, but that's the *correct* thing to return if the writer can't accept any more bytes.
2023-08-16proc_macro: Update docs for `Spacing`Vadim Petrochenkov-13/+25
Brings the docs more in line with reality
2023-08-16address commentsGeorgii Rylov-11/+7
2023-08-16Fix a pthread_t handle leak #114610Georgii Rylov-0/+12
2023-08-16clarify CStr lack of layout guarnateesRalf Jung-4/+4
2023-08-16use mem::swap instead of ptr::swap_nonoverlappingRalf Jung-1/+1
2023-08-16Rollup merge of #114871 - schvv31n:fix-link-in-docs, r=scottmcmMatthias Krüger-1/+1
Update the link in the docs of `std::intrinsics` The previous link in that place, https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs, no longer points to an existing file.
2023-08-16Rollup merge of #114867 - ttsugriy:ttsugriy-patch-1, r=scottmcmMatthias Krüger-1/+1
[nit] Fix a comment typo.
2023-08-16Rollup merge of #114861 - RalfJung:no-effect, r=wesleywiserMatthias Krüger-3/+3
fix typo: affect -> effect I just realized I made a silly typo when writing that comment...
2023-08-16Rollup merge of #114721 - danflapjax:bool-ord-optimization, r=cuviperMatthias Krüger-0/+16
Optimizing the rest of bool's Ord implementation After coming across issue #66780, I realized that the other functions provided by Ord (`min`, `max`, and `clamp`) were similarly inefficient for bool. This change provides implementations for them in terms of boolean operators, resulting in much simpler assembly and faster code. Fixes issue #114653 [Comparison on Godbolt](https://rust.godbolt.org/z/5nb5P8e8j) `max` assembly before: ```assembly example::max: mov eax, edi mov ecx, eax neg cl mov edx, esi not dl cmp dl, cl cmove eax, esi ret ``` `max` assembly after: ```assembly example::max: mov eax, edi or eax, esi ret ``` `clamp` assembly before: ```assembly example::clamp: mov eax, esi sub al, dl inc al cmp al, 2 jae .LBB1_1 mov eax, edi sub al, sil movzx ecx, dil sub dil, dl cmp dil, 1 movzx edx, dl cmovne edx, ecx cmp al, -1 movzx eax, sil cmovne eax, edx ret .LBB1_1: ; identical assert! code ``` `clamp` assembly after: ```assembly example::clamp: test edx, edx jne .LBB1_2 test sil, sil jne .LBB1_3 .LBB1_2: or dil, sil and dil, dl mov eax, edi ret .LBB1_3: ; identical assert! code ```
2023-08-16Auto merge of #114689 - m-ou-se:stabilize-thread-local-cell-methods, r=thomccbors-19/+9
Stabilize thread local cell methods. Closes #92122.
2023-08-15Auto merge of #111071 - nyurik:simpler-issue-94005, r=m-ou-sebors-8/+6
Cleaner assert_eq! & assert_ne! panic messages This PR finishes refactoring of the assert messages per #94005. The panic message format change #112849 used to be part of this PR, but has been factored out and just merged. It might be better to keep both changes in the same release once FCP vote completes. Modify panic message for `assert_eq!`, `assert_ne!`, the currently unstable `assert_matches!`, as well as the corresponding `debug_assert_*` macros. ```rust assert_eq!(1 + 1, 3); assert_eq!(1 + 1, 3, "my custom message value={}!", 42); ``` #### Old messages ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3` ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3`: my custom message value=42! ``` #### New messages ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed left: 2 right: 3 ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed: my custom message value=42! left: 2 right: 3 ``` History of fixing #94005 * #94016 was a lengthy PR that was abandoned * #111030 was similar, but it stringified left and right arguments, and thus caused compile time performance issues, thus closed * #112849 factored out the two-line formatting of all panic messages Fixes #94005 r? `@m-ou-se`
2023-08-15other elementsManish Goregaokar-3/+3
2023-08-15Update the link in the docs of `std::intrinsics`Tim Kurdov-1/+1
The previous link in that place, https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs, no longer points to an existing file.
2023-08-15Cleaner assert_eq! & assert_ne! panic messagesYuri Astrakhan-8/+6
Modify panic message for `assert_eq!`, `assert_ne!`, the currently unstable `assert_matches!`, as well as the corresponding `debug_assert_*` macros. ```rust assert_eq!(1 + 1, 3); assert_eq!(1 + 1, 3, "my custom message value={}!", 42); ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3` ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3`: my custom message value=42! ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed left: 2 right: 3 ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed: my custom message value=42! left: 2 right: 3 ``` This PR is a simpler subset of the #111030, but it does NOT stringify the original left and right source code assert expressions, thus should be faster to compile.
2023-08-15[nit] Fix a comment typo.Taras Tsugrii-1/+1
2023-08-15Rollup merge of #114837 - RalfJung:error_in_core, r=cuviperMatthias Krüger-0/+10
add missing feature(error_in_core) Needed to fix feature gate errors in https://github.com/rust-lang/miri-test-libstd/actions/runs/5862810459/job/15895203359. I don't know how doctests are passing in-tree without this feature gate...
2023-08-15Rollup merge of #114619 - g0djan:godjan/fix_#114608, r=m-ou-seMatthias Krüger-3/+3
Fix pthread_attr_union layout on Wasi Fixes https://github.com/rust-lang/rust/issues/114608 Ran the tests as described in https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md?plain=1#L125
2023-08-15Rollup merge of #114588 - ijackson:exit-status-default-2, r=m-ou-seMatthias Krüger-1/+10
Improve docs for impl Default for ExitStatus This addresses a review comment in #106425 (which is on the way to being merged I think). Some of the other followup work is more complicated so I'm going to do individual MRs. ~~Note this branch is on top of #106425~~
2023-08-15fix typo: affect -> effectRalf Jung-3/+3
2023-08-15Auto merge of #114852 - GuillaumeGomez:rollup-vjagxjr, r=GuillaumeGomezbors-18/+26
Rollup of 10 pull requests Successful merges: - #114711 (Infer `Lld::No` linker hint when the linker stem is a generic compiler driver) - #114772 (Add `{Local}ModDefId` to more strongly type DefIds`) - #114800 (std: add some missing repr(transparent)) - #114820 (Add test for unknown_lints from another file.) - #114825 (Upgrade std to gimli 0.28.0) - #114827 (Only consider object candidates for object-safe dyn types in new solver) - #114828 (Probe when assembling upcast candidates so they don't step on eachother's toes in new solver) - #114829 (Separate `consider_unsize_to_dyn_candidate` from other unsize candidates) - #114830 (Clean up some bad UI testing annotations) - #114831 (Check projection args before substitution in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Document Default for ExitStatusIan Jackson-1/+10
This lets us put a version on the impl, too.
2023-08-15Auto merge of #112387 - clarfonthey:non-panicking-ceil-char-boundary, r=m-ou-sebors-9/+5
Don't panic in ceil_char_boundary Implementing the alternative mentioned in this comment: https://github.com/rust-lang/rust/issues/93743#issuecomment-1579935853 Since `floor_char_boundary` will always work (rounding down to the length of the string is possible), it feels best for `ceil_char_boundary` to not panic either. However, the semantics of "rounding up" past the length of the string aren't very great, which is why the method originally panicked in these cases. Taking into account how people are using this method, it feels best to simply return the end of the string in these cases, so that the result is still a valid char boundary.
2023-08-15Fix typo.Mara Bos-1/+1
Co-authored-by: Josh Stone <cuviper@gmail.com>
2023-08-15Rollup merge of #114800 - RalfJung:transparent, r=cuviperGuillaume Gomez-18/+26
std: add some missing repr(transparent) For some types we don't want to stably guarantee this, so hide the `repr` from rustdoc. This nice approach was suggested by `@thomcc.`
2023-08-15clarify that these assumtpions are for us, not all Rust codeRalf Jung-0/+4
2023-08-15Add alignment to the NPO guaranteeScott McMurray-1/+33
As far as I know, this is always true already, but it's not in the text of the Option module docs, so I figured I'd bring this up to FCP it.
2023-08-15Add diagnostic items for `<*const _>::cast` and `<*mut _>::cast_const`Urgau-0/+2
2023-08-15add missing feature(error_in_core)Ralf Jung-0/+10
2023-08-14Auto merge of #113658 - Dirreke:csky-unknown-linux-gunabiv2, r=bjorn3bors-3/+14
add a csky-unknown-linux-gnuabiv2 target This is the rustc side changes to support csky based Linux target(`csky-unknown-linux-gnuabiv2`). Tier 3 policy: > A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.) I pledge to do my best maintaining it. > Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target. This `csky` section is the arch name and the `unknown-linux` section is the same as other linux target, and `gnuabiv2` is from the cross-compile toolchain of `gcc` > Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it. I think the explanation in platform support doc is enough to make this aspect clear. > Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users. It's using open source tools only. > The target must not introduce license incompatibilities. No new license > Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0). Understood. > The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements. There are no new dependencies/features required. > Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3. As previously said it's using open source tools only. > "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users. There are no such terms present/ > Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions. I'm not the reviewer here. > This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements. I'm not the reviewer here. > Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions. It supports for std > The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary. I have added the documentation, and I think it's clear. > Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages. Understood. > Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications. Understood. > Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target. I believe I didn't break any other target. > In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target. I think there are no such problems in this PR.
2023-08-14actually this doesn't even affect doctests. nice.Ralf Jung-24/+12
2023-08-14Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieubors-739/+736
core/any: remove Provider trait, rename Demand to Request This touches on two WIP features: * `error_generic_member_access` * tracking issue: https://github.com/rust-lang/rust/issues/99301 * RFC (WIP): https://github.com/rust-lang/rfcs/pull/2895 * `provide_any` * tracking issue: https://github.com/rust-lang/rust/issues/96024 * RFC: https://github.com/rust-lang/rfcs/pull/3192 The changes in this PR are intended to address libs meeting feedback summarized by `@Amanieu` in https://github.com/rust-lang/rust/issues/96024#issuecomment-1554773172 The specific items this PR addresses so far are: > We feel that the names "demand" and "request" are somewhat synonymous and would like only one of those to be used for better consistency. I went with `Request` here since it sounds nicer, but I'm mildly concerned that at first glance it could be confused with the use of the word in networking context. > The Provider trait should be deleted and its functionality should be merged into Error. We are happy to only provide an API that is only usable with Error. If there is demand for other uses then this can be provided through an external crate. The net impact this PR has is that examples which previously looked like ``` core::any::request_ref::<String>(&err).unwramp() ``` now look like ``` (&err as &dyn core::error::Error).request_value::<String>().unwrap() ``` These are methods that based on the type hint when called return an `Option<T>` of that type. I'll admit I don't fully understand how that's done, but it involves `core::any::tags::Type` and `core::any::TaggedOption`, neither of which are exposed in the public API, to construct a `Request` which is then passed to the `Error.provide` method. Something that I'm curious about is whether or not they are essential to the use of `Request` types (prior to this PR referred to as `Demand`) and if so does the fact that they are kept private imply that `Request`s are only meant to be constructed privately within the standard library? That's what it looks like to me. These methods ultimately call into code that looks like: ``` /// Request a specific value by tag from the `Error`. fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified> where I: tags::Type<'a>, { let mut tagged = core::any::TaggedOption::<'a, I>(None); err.provide(tagged.as_request()); tagged.0 } ``` As far as the `Request` API is concerned, one suggestion I would like to make is that the previous example should look more like this: ``` /// Request a specific value by tag from the `Error`. fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified> where I: tags::Type<'a>, { let tagged_request = core::any::Request<I>::new_tagged(); err.provide(tagged_request); tagged.0 } ``` This makes it possible for anyone to construct a `Request` for use in their own projects without exposing an implementation detail like `TaggedOption` in the API surface. Otherwise noteworthy is that I had to add `pub(crate)` on both `core::any::TaggedOption` and `core::any::tags` since `Request`s now need to be constructed in the `core::error` module. I considered moving `TaggedOption` into the `core::error` module but again I figured it's an implementation detail of `Request` and belongs closer to that. At the time I am opening this PR, I have not yet looked into the following bit of feedback: > We took a look at the generated code and found that LLVM is unable to optimize multiple .provide_* calls into a switch table because each call fetches the type id from Erased::type_id separately each time and the compiler doesn't know that these calls all return the same value. This should be fixed. This is what I'll focus on next while waiting for feedback on the progress so far. I suspect that learning more about the type IDs will help me understand the need for `TaggedOption` a little better.
2023-08-14Upgrade Object and related depsdirreke-2/+2
2023-08-14add a csky-unknown-linux-gnuabiv2 targetDirreke-1/+12
2023-08-14reference-counting analogyRalf Jung-20/+23