Commit graph

878 commits

Author SHA1 Message Date
Albin Hedman
4f9fd2a5d4 Undo fn -> const fn for all intrinsics but assert_inhabited 2020-12-02 21:07:40 +01:00
Albin Hedman
f311db100b Added tests for assume_init 2020-12-02 19:14:10 +01:00
Albin Hedman
1ef5dbe716 Resolved some of the comments
* Undo fn -> const fn for some fns.
* Split feature gate.
* Made all three intrinsics const
2020-12-02 16:17:37 +01:00
Albin Hedman
91772c35c8 Even more const 2020-12-02 03:22:47 +01:00
Albin Hedman
8bd80e25f0 Make some of MaybeUninit's methods const 2020-12-02 03:22:47 +01:00
Mara Bos
b565fe241e
Rollup merge of #79038 - CDirkx:move-ui-tests, r=dtolnay
Change ui test that are run-pass and that do not test the compiler to library tests

Part of #76268, these are some of the relevant ui tests I found that can be replaced by library tests.

Note: this PR just moves the tests, I have not checked for any overlap between these tests and existing library tests. The only test I changed is `env_home_dir`, where I added code to restore the old home dir after testing.

All moved tests:

| ui test | library test file | test |
| --- | --- | --- |
| `const\ascii_ctype.rs` | `core\tests\ascii.rs` | `ascii_ctype_const` |
| `const\const-str-ptr.rs` | `alloc\tests\str.rs` | `const_str_ptr` |
| `assert-eq-trailing-comma.rs` | `core\tests\macros.rs` | `assert_eq_trailing_comma` |
| `assert-escape.rs` | `core\tests\macros.rs` | `assert_escape` |
| `assert-ne-trailing-comma.rs` | `core\tests\macros.rs` | `assert_ne_trailing_comma` |
| `atomic-access-bool.rs` | `core\tests\atomic.rs` | `atomic_access_bool` |
| `atomic-alignment.rs` | `core\tests\atomic.rs` | `atomic_alignment` |
| `atomic-compare_exchange.rs` | `core\tests\atomic.rs` | `atomic_compare_exchange` |
| ~~`atomic-print.rs`~~ | ~~`std\tests\process.rs`~~ | ~~`atomic_print`~~ |
| `bool.rs` | `core\tests\bool.rs` | `test_bool` |
| `bool_not.rs` | `core\tests\bool.rs` | `test_bool_not` |
| `char_unicode.rs` | `core\tests\unicode.rs` | `version` |
| `cmp-default.rs` | `core\tests\cmp.rs` | `cmp_default` |
| `deref-mut-on-ref.rs` | `core\tests\ops.rs` | `deref_mut_on_ref` |
| `deref-on-ref.rs` | `core\tests\ops.rs` | `deref_on_ref` |
| `env-home-dir.rs` | `std\tests\env.rs` | `env_home_dir` |
| ~~`env-vars.rs`~~ | ~~`std\tests\env.rs`~~ | ~~`env_vars`~~ |
| `extend-for-unit.rs` | `core\tests\iter.rs` | `extend_for_unit` |
| `offset_from.rs` | `core\tests\ptr.rs` | `offset_from` |
| `option-ext.rs` | `core\tests\option.rs` | `option_ext` |
| `result-opt-conversions.rs` | `core\tests\result.rs` | `result_opt_conversions` |
| `sleep.rs` | `std\tests\thread.rs` | `sleep` |
| ~~`try-wait.rs`~~ | ~~`std\tests\process.rs`~~ | ~~`try_wait`~~ |
| `utf8.rs` | `alloc\tests\str.rs` | `utf8` |
| `utf8_chars.rs` | `alloc\tests\str.rs` | `utf8_chars` |
| `wrapping-int-api.rs` | `core\tests\num\wrapping.rs` | `wrapping_int_api` |
2020-12-01 10:50:02 +00:00
Alexis Bourget
5bdd640913 Fix several broken links in doc that used the wrong qualifier or Self:: 2020-11-30 21:21:15 +01:00
Alexis Bourget
c0560c2755 Back to #method for links on char 2020-11-30 21:18:56 +01:00
Alexis Bourget
af40c04301 ptr links 2020-11-30 21:18:56 +01:00
Alexis Bourget
ac8d1173b5 Use core::primitive module instead of prim@ 2020-11-30 21:18:56 +01:00
Alexis Bourget
a5726eb28d Use Self:: in links 2020-11-30 21:18:56 +01:00
Alexis Bourget
b702060865 Intra doc links for iterator adapters 2020-11-30 21:18:55 +01:00
Alexis Bourget
b3b1e0c224 Intra doc links for f32/f64 2020-11-30 21:18:55 +01:00
Alexis Bourget
4e54b4c3e6 Intra doc links for the pointer primitive 2020-11-30 21:18:55 +01:00
Alexis Bourget
9c27ccff19 Intra doc links for str/mod.rs 2020-11-30 21:18:55 +01:00
Alexis Bourget
0bf4aafc54 Intra doc links for the char primitive 2020-11-30 21:18:55 +01:00
Alexis Bourget
19fb4fec50 Intra doc links for cell.rs 2020-11-30 21:18:55 +01:00
Christiaan Dirkx
be554c4101 Make ui test that are run-pass and do not test the compiler itself library tests 2020-11-30 02:47:32 +01:00
bors
cf9bfdb872 Auto merge of #78122 - fusion-engineering-forks:fmt-write-bounds-check, r=Mark-Simulacrum
Avoid panic_bounds_check in fmt::write.

Writing any fmt::Arguments would trigger the inclusion of usize formatting and padding code in the resulting binary, because indexing used in fmt::write would generate code using panic_bounds_check, which prints the index and length.

These bounds checks are not necessary, as fmt::Arguments never contains any out-of-bounds indexes.

This change replaces them with unsafe get_unchecked, to reduce the amount of generated code, which is especially important for embedded targets.

---

Demonstration of the size of and the symbols in a 'hello world' no_std binary:

<details>
<summary>Source code</summary>

```rust
#![feature(lang_items)]
#![feature(start)]
#![no_std]

use core::fmt;
use core::fmt::Write;

#[link(name = "c")]
extern "C" {
    #[allow(improper_ctypes)]
    fn write(fd: i32, s: &str) -> isize;
    fn exit(code: i32) -> !;
}

struct Stdout;

impl fmt::Write for Stdout {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        unsafe { write(1, s) };
        Ok(())
    }
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
    let _ = writeln!(Stdout, "Hello World");
    0
}

#[lang = "eh_personality"]
fn eh_personality() {}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    unsafe { exit(1) };
}
```
</details>

Before:
```
   text	   data	    bss	    dec	    hex	filename
   6059	    736	      8	   6803	   1a93	before
```
```
0000000000001e00 T <T as core::any::Any>::type_id
0000000000003dd0 D core::fmt::num::DEC_DIGITS_LUT
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for u64>::fmt
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for usize>::fmt
0000000000001370 T core::fmt::write
0000000000001b30 t core::fmt::Formatter::pad_integral::write_prefix
0000000000001660 T core::fmt::Formatter::pad_integral
0000000000001350 T core::ops::function::FnOnce::call_once
0000000000001b80 t core::ptr::drop_in_place
0000000000001120 t core::ptr::drop_in_place
0000000000001c50 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001c90 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001b90 T core::panicking::panic_bounds_check
0000000000001c10 T core::panicking::panic_fmt
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```

After:
```
   text	   data	    bss	    dec	    hex	filename
   3068	    600	      8	   3676	    e5c	after
```
```
0000000000001360 T core::fmt::write
0000000000001340 T core::ops::function::FnOnce::call_once
0000000000001120 t core::ptr::drop_in_place
0000000000001620 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001660 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```
2020-11-29 23:14:40 +00:00
bstrie
90a2e5e3fe Update tests to remove old numeric constants
Part of #68490.

Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros.

For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
2020-11-29 00:55:55 -05:00
Jonas Schievink
248e5ad299
Rollup merge of #79478 - lukaslueg:peek_mut_docs, r=m-ou-se
Expand docs on Peekable::peek_mut

Slightly expand docs on `std::iter::Peekable::peek_mut`, tracked in #78302

r? `@m-ou-se`
2020-11-28 15:58:28 +01:00
Lukas Lueg
08ec201c72 Expand docs on Peekable::peek_mut 2020-11-27 22:50:22 +01:00
Aaron Hill
6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
bors
ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
bors
b387f62d4d Auto merge of #77491 - lukaslueg:peek_mut, r=m-ou-se
Proposal to add Peekable::peek_mut

A "peekable" iterator has a `peek()`-method which provides an immutable reference to the next item. We currently do not have a method to modify that item, which we could easily add via a `peek_mut()`. See the test for a use-case (alike to my original use case), where a "pristine" iterator is passed on after modifying its state via `peek_mut()`.

If there is interest in this, I can expand on the tests and docs.
2020-11-25 05:10:53 +00:00
bors
3f7ccb4cf5 Auto merge of #76688 - yokodake:patch-2, r=kodrAus
Document unsafety in core::slice::memchr

Contributes to #66219

Note sure if that's good enough, especially for the `align_to` call.
The docs only mention transmuting and I don't think that everything related to reference lifetimes and state validity mentioned in the [nomicon](https://doc.rust-lang.org/nomicon/transmutes.html) are relevant here.
2020-11-25 02:49:28 +00:00
Lukas Lueg
3b015622be Add Peekable::peek_mut 2020-11-23 23:52:19 +01:00
Camelid
810324d1f3 Rename optin_builtin_traits to auto_traits
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
bors
f32a0cce2f Auto merge of #78343 - camelid:macros-qualify-panic, r=m-ou-se
Qualify `panic!` as `core::panic!` in non-built-in `core` macros

Fixes #78333.

-----

Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.
2020-11-23 22:05:28 +00:00
Camelid
d8b1d51b95 Clean up core macros documentation
* Switch a couple links over to intra-doc links
* Clean up some formatting/typography
2020-11-23 11:28:25 -08:00
Camelid
d37e1e186e Qualify panic! as core::panic! in non-built-in core macros
Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.
2020-11-23 11:28:25 -08:00
Jonas Schievink
703f176d57
Rollup merge of #76829 - tspiteri:const-int-pow, r=oli-obk
stabilize const_int_pow

This also requires stabilizing constctlz for const ctlz_nonzero.
2020-11-23 15:25:38 +01:00
bors
068320b39e Auto merge of #77893 - petertodd:2020-impl-default-for-phantompinned, r=dtolnay
Impl Default for PhantomPinned

`PhantomPinned` is just a marker type, with an obvious default value (the only value). So I can't think of a reason not to do this. Sure, it's used in exotic situations with unsafe code. But the people writing that code can decide for themselves if they can derive `Default`, and in many situations the derived impl will make sense:

```rust
#[derive(Default)]
struct NeedsPin {
   marker: PhantomPinned,
   buf: [u8; 1024],
   ptr_to_data: Option<*const u8>,
}
```
2020-11-23 07:00:30 +00:00
Trevor Spiteri
a6bcf7a2b6 const_int_pow will be stabilized in 1.50.0, not in 1.49.0
Same for constctlz.
2020-11-23 02:04:37 +01:00
Trevor Spiteri
aca37b65f1 stabilize const_int_pow
Also stabilize constctlz for const ctlz_nonzero.

The public methods stabilized const by this commit are:

  * `{i*,u*}::checked_pow`
  * `{i*,u*}::saturating_pow`
  * `{i*,u*}::wrapping_pow`
  * `{i*,u*}::overflowing_pow`
  * `{i*,u*}::pow`
  * `u*::next_power_of_two`
  * `u*::checked_next_power_of_two`
  * `u*::wrapping_next_power_of_two` (the method itself is still unstable)
2020-11-23 01:58:27 +01:00
bors
32da90b431 Auto merge of #79319 - m-ou-se:rollup-d9n5viq, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #76941 (Add f{32,64}::is_subnormal)
 - #77697 (Split each iterator adapter and source into individual modules)
 - #78305 (Stabilize alloc::Layout const functions)
 - #78608 (Stabilize refcell_take)
 - #78793 (Clean up `StructuralEq` docs)
 - #79267 (BTreeMap: address namespace conflicts)
 - #79293 (Add test for eval order for a+=b)
 - #79295 (BTreeMap: fix minor testing mistakes in #78903)
 - #79297 (BTreeMap: swap the names of NodeRef::new and Root::new_leaf)
 - #79299 (Stabilise `then`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-22 23:59:48 +00:00
Mara Bos
41c033b2f7
Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-se
Stabilise `then`

Stabilises the lazy variant of https://github.com/rust-lang/rust/issues/64260 now that the FCP [has ended](https://github.com/rust-lang/rust/issues/64260#issuecomment-731636203).

I've kept the original feature gate `bool_to_option` for the strict variant (`then_some`), and created a new insta-stable feature gate `lazy_bool_to_option` for `then`.
2020-11-22 23:01:08 +01:00
Mara Bos
8a623e6f98
Rollup merge of #78793 - camelid:fixup-structuraleq, r=jyn514
Clean up `StructuralEq` docs
2020-11-22 23:01:00 +01:00
Mara Bos
b249844c33
Rollup merge of #78608 - ThinkChaos:stabilize_refcell_take, r=m-ou-se
Stabilize refcell_take

Tracking Issue: #71395

``@KodrAus`` nominated this for FCP, so here's a PR!
I've never made a stabilization PR, so please mention if there's anything I can improve, thanks.
2020-11-22 23:00:58 +01:00
Mara Bos
186ec64947
Rollup merge of #78305 - ChrisDenton:const-layout, r=oli-obk
Stabilize alloc::Layout const functions

Stabilizes #67521. In particular the following stable methods are stabilized as `const fn`:

* `size`
* `align`
* `from_size_align`

Stabilizing `size` and `align` should not be controversial as they are simple (usize and NonZeroUsize) fields and I don't think there's any reason to make them not const compatible in the future. That being true, the other methods are trivially `const`. The only other issue being returning a `Result` from a `const fn` but this has been made more usable by recent stabilizations.
2020-11-22 23:00:56 +01:00
Mara Bos
4407049fcb
Rollup merge of #77697 - WaffleLapkin:iter_split_adaptors, r=m-ou-se
Split each iterator adapter and source into individual modules

This PR creates individual modules for each iterator adapter and iterator source.

This is done to enhance the readability of corresponding modules (`adapters/mod.rs` and `sources.rs`) which were hard to navigate and read because of lots of repeated lines (e.g.: `adapters/mod.rs` was 3k lines long). This is also in line with some adapters which already had their own modules (`Flatten`, `FlatMap`, `Chain`, `Zip`, `Fuse`).

This PR also makes `Take`s adapter fields private (I have no idea why they were `pub(super)` before).

r? ``@LukasKalbertodt``
2020-11-22 23:00:55 +01:00
Mara Bos
9b98f1d226
Rollup merge of #76941 - clarfonthey:is_subnormal, r=m-ou-se
Add f{32,64}::is_subnormal

The docs recommend that you use dedicated methods instead of calling `classify` directly, although there isn't actually a way of checking if a number is subnormal without calling classify. There are dedicated methods for all other forms, excluding `is_zero` (which is just `== 0.0` anyway).
2020-11-22 23:00:48 +01:00
Chris Denton
9050d12714
Stabilize alloc::Layout const functions
Stabilizes #67521. In particular the following stable methods are stabilized as const fn:

* size
* align
* from_size_align
2020-11-22 21:43:30 +00:00
bors
a0d664bae6 Auto merge of #79219 - shepmaster:beta-bump, r=Mark-Simulacrum
Bump bootstrap compiler version

r? `@Mark-Simulacrum`

/cc `@pietroalbini`
2020-11-22 21:38:03 +00:00
ltdk
cf26f2f00e Add f{32,64}::is_subnormal 2020-11-22 15:37:46 -05:00
ThinkChaos
5c6689baff Stabilize refcell_take 2020-11-22 20:13:31 +01:00
varkor
cf32afcf48 Stabilise then 2020-11-22 13:45:14 +00:00
bors
828461b4b2 Auto merge of #78816 - SkiFire13:fix-slice-pointer-provenance, r=RalfJung
<[T]>::reverse: Fix pointer provenance rules

Should fix #78749
2020-11-22 13:10:15 +00:00
bors
5d5ff84130 Auto merge of #77872 - Xaeroxe:stabilize-clamp, r=scottmcm
Stabilize clamp

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

Clamp has been merged and unstable for about a year and a half now. How do we feel about stabilizing this?
2020-11-22 10:50:04 +00:00
bors
20328b5323 Auto merge of #79275 - integer32llc:doc-style, r=jonas-schievink
More consistently use spaces after commas in lists in docs

This PR changes instances of lists that didn't use spaces after commas, like `vec![1,2,3]`, to `vec![1, 2, 3]` to be more consistent with idiomatic Rust style (the way these were looks strange to me, especially because there are often lists that *do* use spaces after the commas later in the same code block 😬).

I noticed one of these in an example in the stdlib docs and went looking for more, but as far as I can see, I'm only changing those spots in user-facing documentation or rustc output, and the changes make no semantic difference.
2020-11-22 08:30:23 +00:00