Commit Graph

921 Commits

Author SHA1 Message Date
bors 9b2f8dbba3 Auto merge of #71007 - Amanieu:deprecate_asm, r=Mark-Simulacrum
Deprecate the asm! macro in favor of llvm_asm!

Since we will be changing the syntax of `asm!` soon, deprecate it and encourage people to use `llvm_asm!` instead (which preserves the old syntax). This will avoid breakage when `asm!` is changed.

RFC: https://github.com/rust-lang/rfcs/pull/2843
2020-04-20 02:18:00 +00:00
Josh Stone 2edd123a23 Dogfood or_patterns in the standard library 2020-04-16 12:44:57 -07:00
Amanieu d'Antras ce83b49d16 Deprecate the asm! macro 2020-04-15 18:09:00 +01:00
Yoshua Wuyts 004ce25ec0 Remove labels in libstd/lib.rs macro imports
These labels were probably moved around when rustfmt was introduced.
2020-04-05 22:30:25 +02:00
Benjamin Kästner dc8a9854d2 Replace last mention of IRC with Discord
Mozilla's IRC service was shut down in March 2020. The official
instant messaging variant has been Discord for a while, and most of
the links were already replaced by #61524.

This was the last line that came up with `irc.mozilla.org` or any
combination of "irc.*#[a-z]+" in a `git grep`:

    git grep -i -E "irc.*#[a-z]+"

As there is only one other link directly to Rust's discord, I used the
same Markdown link `[rust-discord]` as in `bootstrap/README.md` to
stay consistent. This might come in handy if the chat platform changes
at a later point again.

As an aside: for those interested in the use of IRC, Mozilla's [wiki]
still offers a lot of in-depth knowledge.

 [wiki]: https://wiki.mozilla.org/IRC
2020-03-28 12:38:52 +01:00
Amanieu d'Antras d162d096dd Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-26 15:49:22 +00:00
Niko Matsakis fda3378e3f introduce `negative_impls` feature gate and document
They used to be covered by `optin_builtin_traits` but negative impls
are now applicable to all traits, not just auto traits.

This also adds docs in the unstable book for the current state of auto traits.
2020-03-26 06:52:55 -04:00
Saoirse Shipwreckt a4875a797d Update src/libstd/lib.rs
Co-Authored-By: Ashley Mannix <ashleymannix@live.com.au>
2020-03-23 15:45:30 +01:00
Without Boats d8a835f1a1 Add `wake_trait` feature directive to std 2020-03-23 15:45:30 +01:00
Without Boats 06ede350c2 Add Wake trait for safe construction of Wakers.
Currently, constructing a waker requires calling the unsafe
`Waker::from_raw` API. This API requires the user to manually construct
a vtable for the waker themself - which is both cumbersome and very
error prone. This API would provide an ergonomic, straightforward and
guaranteed memory-safe way of constructing a waker.

It has been our longstanding intention that the `Waker` type essentially
function as an `Arc<dyn Wake>`, with a `Wake` trait as defined here. Two
considerations prevented the original API from being shipped as simply
an `Arc<dyn Wake>`:

- We want to support futures on embedded systems, which may not have an
  allocator, and in optimized executors for which this API may not be
  best-suited. Therefore, we have always explicitly supported the
  maximally-flexible (but also memory-unsafe) `RawWaker` API, and
  `Waker` has always lived in libcore.
- Because `Waker` lives in libcore and `Arc` lives in liballoc, it has
  not been feasible to provide a constructor for `Waker` from `Arc<dyn
  Wake>`.

Therefore, the Wake trait was left out of the initial version of the
task waker API.

However, as Rust 1.41, it is possible under the more flexible orphan
rules to implement `From<Arc<W>> for Waker where W: Wake` in liballoc.
Therefore, we can now define this constructor even though `Waker` lives
in libcore.

This PR adds these APIs:

- A `Wake` trait, which contains two methods
    - A required method `wake`, which is called by `Waker::wake`
    - A provided method `wake_by_ref`, which is called by
      `Waker::wake_by_ref` and which implementors can override if they
      can optimize this use case.
- An implementation of `From<Arc<W>> for Waker where W: Wake + Send +
  Sync + 'static`
- A similar implementation of `From<Arc<W>> for RawWaker`.
2020-03-23 15:44:58 +01:00
Mazdak Farrokhzad 9fc5c2d00d
Rollup merge of #69870 - petrochenkov:cfgacc, r=matthewjasper
expand: Implement something similar to `#[cfg(accessible(path))]`

cc https://github.com/rust-lang/rust/issues/64797

The feature is implemented as a `#[cfg_accessible(path)]` attribute macro rather than as `#[cfg(accessible(path))]` because it needs to wait until `path` becomes resolvable, and `cfg` cannot wait, but macros can wait.

Later we can think about desugaring or not desugaring `#[cfg(accessible(path))]` into `#[cfg_accessible(path)]`.

This implementation is also incomplete in the sense that it never returns "false" from `cfg_accessible(path)`, it requires some tweaks to resolve, which is not quite ready to answer queries like this during early resolution.

However, the most important part of this PR is not `cfg_accessible` itself, but expansion infrastructure for retrying expansions.
Before this PR we could say "we cannot resolve this macro path, let's try it later", with this PR we can say "we cannot expand this macro, let's try it later" as well.

This is a pre-requisite for
- turning `#[derive(...)]` into a regular attribute macro,
- properly supporting eager expansion for macros that cannot yet be resolved like
    ```
    fn main() {
        println!(not_available_yet!());
    }

    macro_rules! make_available {
        () => { #[macro_export] macro_rules! not_available_yet { () => { "Hello world!" } }}
    }

    make_available!();
    ```
2020-03-17 03:05:12 +01:00
Matthew Jasper 4377ac3e2f Use min_specialization in libstd and libproc_macro 2020-03-15 13:23:03 +00:00
Mazdak Farrokhzad 61150353bf
Rollup merge of #69514 - GuillaumeGomez:remove-spotlight, r=kinnison
Remove spotlight

I had a few comments saying that this feature was at best misunderstood or not even used so I decided to organize a poll about on [twitter](https://twitter.com/imperioworld_/status/1232769353503956994). After 87 votes, the result is very clear: it's not useful. Considering the amount of code we have just to run it, I think it's definitely worth it to remove it.

r? @kinnison

cc @ollie27
2020-03-10 06:47:47 +01:00
Vadim Petrochenkov 2e6528961c builtin_macros: Add attribute macro `#[cfg_accessible(path)]` 2020-03-10 01:02:13 +03:00
bors 7a3700c371 Auto merge of #68952 - faern:stabilize-assoc-int-consts, r=dtolnay
Stabilize assoc_int_consts associated int/float constants

The next step in RFC https://github.com/rust-lang/rfcs/pull/2700 (tracking issue #68490). Stabilizing the associated constants that were added in #68325.

* Stabilize all constants under the `assoc_int_consts` feature flag.
* Update documentation on old constants to say they are soft-deprecated and the new ones should be preferred.
* Update documentation examples to use new constants.
* Remove `uint_macro` and use `int_macro` for all integer types since the macros were identical anyway.

r? @LukasKalbertodt
2020-03-04 07:29:32 +00:00
Guillaume Gomez 13c6d5819a Remove spotlight usage 2020-02-27 14:51:22 +01:00
Dylan DPC 0860f5aebd
Rollup merge of #67637 - Mark-Simulacrum:primitive-mod, r=dtolnay
Add primitive module to libcore

This re-exports the primitive types from libcore at `core::primitive` to allow
macro authors to have a reliable location to use them from.

Fixes #44865
2020-02-26 02:07:05 +01:00
David Tolnay 9c3ee1bc35
Bump core::primitive to 1.43 2020-02-23 23:59:39 -08:00
Dylan DPC d28b35812f
Rollup merge of #64069 - danielhenrymantilla:feature/cstring_from_vec_of_nonzerou8, r=KodrAus
Added From<Vec<NonZeroU8>> for CString

Added a `From<Vec<NonZeroU8>>` `impl` for `CString`

# Rationale

  - `CString::from_vec_unchecked` is a subtle function, that makes `unsafe` code harder to audit when the generated `Vec`'s creation is non-trivial. This `impl` allows to write safer `unsafe` code thanks to the very explicit semantics of the `Vec<NonZeroU8>` type.

  - One such situation is when trying to `.read()` a `CString`, see issue #59229.

      - this lead to a PR: #59314, that was closed for being too specific / narrow (it only targetted being able to `.read()` a `CString`, when this pattern could have been generalized).

     - the issue suggested another route, based on `From<Vec<NonZeroU8>>`, which is indeed a less general and more concise code pattern.

  - quoting @shnatsel:

      - >  For me the main thing about making this safe is simplifying auditing - people have spent like an hour looking at just this one unsafe block in libflate because it's not clear what exactly is unchecked, so you have to look it up when auditing anyway. This has distracted us from much more serious memory safety issues the library had.
Having this trivial impl in stdlib would turn this into safe code with compiler more or less guaranteeing that it's fine, and save anyone auditing the code a whole lot of time.
2020-02-15 09:45:38 +01:00
Linus Färnstrand 271ba5a3ea Stabilize assoc_int_consts 2020-02-12 20:20:39 +01:00
Mark Rousskov 178de46116 Add primitive module to libcore/std
This re-exports the primitive types from libcore at `core::primitive` to allow
macro authors to have a reliable location to use them from.
2020-02-06 16:29:01 -05:00
bors eda1a7adfc Auto merge of #68755 - Tyg13:update_stdarch, r=alexcrichton
Update `rust-lang/stdarch` submodule

Update submodule [rust-lang/stdarch](https://github.com/rust-lang/stdarch/)
2020-02-05 10:39:01 +00:00
Daniel Henry-Mantilla 60274a95fe Added From<Vec<NonZeroU8>> for CString
Updated tracking issue number

Added safeguards for transmute_vec potentially being factored out elsewhere

Clarified comment about avoiding mem::forget

Removed unneeded unstable guard

Added back a stability annotation for CI

Minor documentation improvements

Thanks to @Centril's code review

Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>

Improved layout checks, type annotations and removed unaccurate comment

Removed unnecessary check on array layout

Adapt the stability annotation to the new 1.41 milestone

Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>

Simplify the implementation.

Use `Vec::into_raw_parts` instead of a manual implementation of
`Vec::transmute`.

If `Vec::into_raw_parts` uses `NonNull` instead, then the code here
will need to be adjusted to take it into account (issue #65816)

Reduce the whitespace of safety comments
2020-02-04 17:20:33 +01:00
bors 126ad2b813 Auto merge of #68708 - Mark-Simulacrum:stage0-step, r=pietroalbini
Step stage0 to bootstrap from 1.42

This also includes a commit which fixes the rustfmt downloading logic to redownload when the rustfmt channel changes, and bumps rustfmt to a more recent version.
2020-02-04 14:16:18 +00:00
Dylan DPC 1028978e8f
Rollup merge of #68797 - GuillaumeGomez:link-to-types, r=Dylan-DPC
Fix links to types instead of modules

r? @Dylan-DPC
2020-02-03 18:58:35 +01:00
Guillaume Gomez 46f6dad101 Fix links to types instead of modules 2020-02-03 16:12:35 +01:00
Tyler Lanphear 9fa54e594b stdarch: update submodule. 2020-02-01 22:04:18 -05:00
Mark Rousskov 31dcdc9e13 Drop cfg(bootstrap) code 2020-01-31 12:31:09 -05:00
Linus Färnstrand 4d9e90d2a5 Unlock assoc_int_consts in core+std 2020-01-23 20:55:06 +01:00
bors b5a3341f1b Auto merge of #68066 - CAD97:stabilize-manuallydrop-take, r=Amanieu,Mark-Simulacrum
Stabilize ManuallyDrop::take

Tracking issue: closes #55422
FCP merge: https://github.com/rust-lang/rust/issues/55422#issuecomment-572653619

Reclaims the doc improvements from closed #62198.

-----

Stable version is a simple change if necessary.

Proposal: [relnotes] (this changes how to best take advantage of `ManuallyDrop`, esp. wrt. `Drop::drop` and finalize-by-value members)
2020-01-20 20:11:20 +00:00
Mazdak Farrokhzad 3ccb0f9b8f slice_patterns: remove internal uses of gate 2020-01-18 19:33:47 +01:00
CAD97 4e98966757 stabalize ManuallyDrop::take 2020-01-09 13:32:10 -05:00
Dylan DPC cce055daef
Rollup merge of #67137 - anp:tracked-panic-internals, r=eddyb
libstd uses `core::panic::Location` where possible.

cc @eddyb
2020-01-04 23:52:44 +05:30
Adam Perry eaccda009f core and std macros and panic internals use panic::Location::caller. 2020-01-04 10:02:17 -08:00
Wesley Wiser 717702dffd Revert "core: add IntoFuture trait and support for await"
This reverts commit f35517ee86.
2019-12-31 19:18:08 -05:00
Oliver Scherer 335c887721
Rollup merge of #67659 - SimonSapin:matches, r=rkruppe
Stabilize the `matches!` macro

Fixes https://github.com/rust-lang/rust/issues/65721

FCP: https://github.com/rust-lang/rust/issues/65721#issuecomment-569118119
2019-12-28 00:36:17 +01:00
Sean McArthur f35517ee86 core: add IntoFuture trait and support for await 2019-12-27 11:56:11 -08:00
Simon Sapin 1c572a2d6e Stabilize the `matches!` macro
Fixes https://github.com/rust-lang/rust/issues/65721

FCP: https://github.com/rust-lang/rust/issues/65721#issuecomment-569118119
2019-12-27 14:07:16 +01:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Jakub Kądziołka df93bab135
Correct the todo! stabilization version 2019-12-19 19:09:20 +01:00
Mark Rousskov 82184440ec Propagate cfg bootstrap 2019-12-18 12:16:19 -05:00
bors 6f829840f7 Auto merge of #67224 - nikomatsakis:revert-stabilization-of-never-type, r=centril
Revert stabilization of never type

Fixes https://github.com/rust-lang/rust/issues/66757

I decided to keep the separate `never-type-fallback` feature gate, but tried to otherwise revert https://github.com/rust-lang/rust/pull/65355. Seemed pretty clean.

( cc @Centril, author of #65355, you may want to check this over briefly )
2019-12-14 22:02:59 +00:00
Niko Matsakis d286113024 Revert "Stabilize the `never_type`, written `!`."
This reverts commit 15c30ddd69.
2019-12-14 09:01:09 -05:00
Oliver Scherer d75c7530f3 Reuse the `staged_api` feature for `rustc_const_unstable` 2019-12-13 11:27:01 +01:00
Mazdak Farrokhzad 123406cac7
Rollup merge of #66705 - pitdicker:atomic_mut_ptr, r=KodrAus
Atomic as_mut_ptr

I encountered the following pattern a few times: In Rust we use some atomic type like `AtomicI32`, and an FFI interface exposes this as `*mut i32` (or some similar `libc` type).

It was not obvious to me if a just transmuting a pointer to the atomic was acceptable, or if this should use a cast that goes through an `UnsafeCell`. See https://github.com/rust-lang/rust/issues/66136#issuecomment-557802477

Transmuting the pointer directly:
```rust
let atomic = AtomicI32::new(1);
let ptr = &atomic as *const AtomicI32 as *mut i32;
unsafe {
    ffi(ptr);
}
```

A dance with `UnsafeCell`:
```rust
let atomic = AtomicI32::new(1);
unsafe {
    let ptr = (&*(&atomic as *const AtomicI32 as *const UnsafeCell<i32>)).get();
    ffi(ptr);
}
```

Maybe in the end both ways could be valid. But why not expose a direct method to get a pointer from the standard library?

An `as_mut_ptr` method on atomics can be safe, because only the use of the resulting pointer is where things can get unsafe. I documented its use for FFI, and "Doing non-atomic reads and writes on the resulting integer can be a data race."

The standard library could make use this method in a few places in the WASM module.

cc @RalfJung as you answered my original question.
2019-11-30 16:56:47 +01:00
Paul Dicker 23c5e584e0 Use as_mut_ptr instead of casts 2019-11-24 16:49:50 +01:00
Mazdak Farrokhzad 15c30ddd69 Stabilize the `never_type`, written `!`. 2019-11-21 14:55:32 +01:00
Yu Ding f6b327baa6
Remove compiler_builtins_lib feature from libstd 2019-11-18 19:43:24 -08:00
Mark Rousskov 997feacddd Snap cfgs 2019-11-12 16:36:57 -05:00
Mazdak Farrokhzad 1c7595fd0f gate rustc_on_unimplemented under rustc_attrs 2019-11-06 07:34:51 +01:00