Commit graph

985 commits

Author SHA1 Message Date
Ralf Jung
4b4d43fe6a bless tests 2020-08-12 10:48:08 +02:00
Ralf Jung
fd3851aadb add test for unused erroneous const in CTFE 2020-08-10 10:58:53 +02:00
Yuki Okushi
cd7204ef39
Forbid non-derefable types explicitly in unsizing casts 2020-08-04 17:46:10 +09:00
liuzhenyu
3b4151c9f3 fix typos 2020-08-02 23:20:00 +08:00
Valentin Lazureanu
40e6dccfb4 Rename HAIR to THIR (Typed HIR). 2020-07-31 22:15:12 +00:00
bors
3a92b9987a Auto merge of #74956 - ecstatic-morse:const-option-unwrap, r=oli-obk
Make `Option::unwrap` unstably const

This is lumped into the `const_option` feature gate (#67441), which enables a potpourri of `Option` methods.

cc @rust-lang/wg-const-eval

r? @oli-obk
2020-07-31 08:26:33 +00:00
Dylan MacKenzie
96c84ac3cb Test Option::unwrap in a const context 2020-07-30 13:09:45 -07:00
Manish Goregaokar
b0d426165f
Rollup merge of #74934 - nbdd0121:issue-73976, r=ecstatic-morse
Improve diagnostics when constant pattern is too generic

This PR is a follow-up to PR #74538 and issue #73976

When constants queries Layout, TypeId or type_name of a generic parameter, instead of emitting `could not evaluate constant pattern`, we will instead emit a more detailed message `constant pattern depends on a generic parameter`.
2020-07-30 13:04:42 -07:00
Gary Guo
4e963d58c7 Fix ui tests 2020-07-30 06:34:16 +01:00
Dylan MacKenzie
88fd4943a6 Test {align,size}_of_val in a const context 2020-07-29 19:41:35 -07:00
Ashley Mannix
9d4818c6f9 update stderr for polymorphic ui test 2020-07-28 14:37:31 +10:00
Ashley Mannix
a99d2cbfe7 remove unstable const_type_id feature 2020-07-28 13:33:08 +10:00
Ashley Mannix
cac16c9793 stabilize const_type_id feature 2020-07-28 13:30:29 +10:00
mark
2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00
Manish Goregaokar
7864c3f5fa
Rollup merge of #73858 - tspiteri:const-methods, r=oli-obk
Make more primitive integer methods const

Now that #72437 has been merged and `const_if_match` is stable, these methods can be stabilized const. The methods are grouped in commits according to feature names:

* `const_nonzero_int_methods`
    - `NonZero*::new`
* some `const_checked_int_methods`
    - `{i*,u*}::checked_add`
    - `{i*,u*}::checked_sub`
    - `{i*,u*}::checked_mul`
    - `{i*,u*}::checked_neg`
    - `{i*,u*}::checked_shl`
    - `{i*,u*}::checked_shr`
    - `i*::checked_abs`
* `const_saturating_int_methods`
    - `{i*,u*}::saturating_add`
    - `{i*,u*}::saturating_sub`
    - `{i*,u*}::saturating_mul`
    - `i*::saturating_neg`
    - `i*::saturating_abs`
* `const_int_sign`
    - `i*::signum`
* `const_ascii_ctype_on_intrinsics`
    - `{char,u8}::is_ascii_alphabetic`
    - `{char,u8}::is_ascii_uppercase`
    - `{char,u8}::is_ascii_lowercase`
    - `{char,u8}::is_ascii_alphanumeric`
    - `{char,u8}::is_ascii_digit`
    - `{char,u8}::is_ascii_hexdigit`
    - `{char,u8}::is_ascii_punctuation`
    - `{char,u8}::is_ascii_graphic`
    - `{char,u8}::is_ascii_whitespace`
    - `{char,u8}::is_ascii_control`
2020-07-27 09:20:15 -07:00
bors
4a90e36c85 Auto merge of #74775 - RalfJung:miri-alloc-ids, r=oli-obk
Miri: replace canonical_alloc_id mechanism by extern_static_alloc_id

We only have to call `extern_static_alloc_id` when a `Pointer` is "imported" from the `tcx` to the machine, not on each access. Also drop the old hook for TLS handling, it is not needed any more.

The Miri side of this is at https://github.com/rust-lang/miri/pull/1489.

Fixes https://github.com/rust-lang/rust/issues/71194
r? @oli-obk
2020-07-27 13:07:46 +00:00
Ralf Jung
debe597a9a check that even referencing a TLS static during CTFE fails 2020-07-26 11:12:22 +02:00
bors
461707c5a1 Auto merge of #74060 - kpp:remove_length_at_most_32, r=dtolnay
Remove trait LengthAtMost32

This is a continuation of https://github.com/rust-lang/rust/pull/74026 preserving the original burrbull's commit.

I talked to @burrbull, he suggested me to finish his PR.
2020-07-26 05:50:51 +00:00
Manish Goregaokar
e59effed30
Rollup merge of #74491 - xldenis:constant-binop-opt, r=oli-obk
Optimize away BitAnd and BitOr when possible

This PR lets `const_prop` optimize away `a | true == true` , `a & false == false` and `a * 0 = 0`. While I was writing this I've realized that constant propagation misses a lot of opportunities. For example:  https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2a4b45e772f214210a36749b27223bb0

Constant propagation doesn't seem to... propagate constants, additionally the way constant propagation is currently setup makes it tricky to add cases like `a | false == a`.

I tried to organize `eval_rvalue_with_identities` to make the pattern of the optimizations easier to see but it still obscurs what should be a simple peephole optmization.

cc @oli-obk
2020-07-24 10:01:32 -07:00
Xavier Denis
711a6807a7 Optimize away BitAnd and BitOr when possible 2020-07-22 11:32:36 +02:00
Gary Guo
b3340b5cea Expand test to cover type_name and monomorphic use 2020-07-21 02:28:51 +01:00
Gary Guo
4fb260bb32 Guard against non-monomorphized type_id intrinsic call 2020-07-19 23:33:12 +01:00
Manish Goregaokar
2fad396368
Rollup merge of #74459 - canova:const-unreachable-unchecked, r=oli-obk
Make unreachable_unchecked a const fn

This PR makes `std::hint::unreachable_unchecked` a const fn so we can use it inside a const function.
r? @RalfJung
Fixes #53188.
2020-07-18 16:50:59 -07:00
Nazım Can Altınova
6cd164f49e Update UB test to fail during build with contant errors 2020-07-18 02:27:47 +02:00
Manish Goregaokar
f6cd31c3b7
Rollup merge of #73930 - a1phyr:feature_const_option, r=dtolnay
Make some Option methods const

Tracking issue: #67441

Constantify the following methods of `Option`:
- `as_ref`
- `is_some`
- `is_none`
- `iter` (not sure about this one, but it is possible, and will be useful when const traits are a thing)

cc @rust-lang/wg-const-eval @rust-lang/libs
2020-07-17 14:09:02 -07:00
Nazım Can Altınova
c45e9c86ca Add a test for const unsafe_unreachable that triggers UB 2020-07-17 22:03:33 +02:00
Nazım Can Altınova
2f28d5945d Add a passing test for const unsafe_unreachable 2020-07-17 22:00:06 +02:00
marmeladema
4a96800aef Constify most non-trait Duration methods as described in #72440 2020-07-15 21:37:16 +01:00
Esteban Küber
b7db6bb5af Remove Sized on_unimplemented note 2020-07-14 10:50:24 -07:00
Manish Goregaokar
90f1d724c8
Rollup merge of #72920 - oli-obk:const_transmute, r=RalfJung
Stabilize `transmute` in constants and statics but not const fn

cc #53605 (leaving issue open so we can add `transmute` to `const fn` later)

Previous attempt: #64011

r? @RalfJung

cc @rust-lang/wg-const-eval
2020-07-11 08:53:06 -07:00
Oliver Scherer
dd872be5da Stabilize transmute in constants and statics but not const fn 2020-07-11 09:22:17 +02:00
Manish Goregaokar
ef3dc09fa7
Rollup merge of #73989 - RalfJung:ub-enum-test, r=oli-obk
adjust ub-enum test to be endianess-independent

@cuviper noted that our test fails on "other" endianess systems (I never know which is which^^), so let's fix that.
2020-07-10 23:26:30 -07:00
Manish Goregaokar
efda2b58b0
Rollup merge of #73887 - DutchGhost:master, r=oli-obk
stabilize const mem::forget

Stabilizes const `mem::forget` as implemented in https://github.com/rust-lang/rust/pull/69617 and tracked in https://github.com/rust-lang/rust/issues/69616.

Closes https://github.com/rust-lang/rust/issues/69616
2020-07-10 23:26:28 -07:00
Manish Goregaokar
f4f969027c
Rollup merge of #73862 - oli-obk:const_array_to_slice, r=RalfJung
Stabilize casts and coercions to `&[T]` in const fn

Part of #64992

There was never a reason to not stabilize this, we just accidentally prevented them when we implemented the `min_const_fn` feature that gave us `const fn` on stable. This PR stabilizes these casts (which are already stable in `const` outside `const fn`), while keeping all other unsizing casts (so `T` -> `dyn Trait`) unstable within const fn.
These casts have no forward compatibility concerns with any future features for const eval and users were able to use them under the `const_fn` feature gate already since at least the miri merger, possibly longer.

r? @rust-lang/lang
2020-07-10 23:26:26 -07:00
Roman Proskuryakov
eff62069ad Remove the usage of the LengthAtMost32 trait 2020-07-05 15:47:08 +03:00
Ralf Jung
751b594cc8 const validation: add test for uninit bool 2020-07-05 13:48:06 +02:00
Ralf Jung
c3fc4f0420 catch errors more locally around read_discriminant 2020-07-05 13:40:27 +02:00
Ralf Jung
fb9fa5ba3e adjust ub-enum test to be endianess-independent 2020-07-03 13:22:54 +02:00
Benoît du Garreau
e7d9944e20 Add feature const_option 2020-07-01 18:14:03 +02:00
LeSeulArtichaut
6a7a6528f6 Bless failing tests 2020-06-30 21:03:34 +02:00
Dodo
a065096ff4 stabilize const mem::forget 2020-06-30 11:34:27 +02:00
Oliver Scherer
7e682d3f6f Stabilize casts and coercions to &[T] in const fn 2020-06-30 11:15:28 +02:00
Trevor Spiteri
2a84e313df stabilize const_ascii_ctype_on_intrinsics 2020-06-29 10:36:55 +02:00
Trevor Spiteri
056d925167 stabilize const_int_sign 2020-06-29 10:36:41 +02:00
Trevor Spiteri
c1c674c2db stabilize const_saturating_int_methods 2020-06-29 10:36:18 +02:00
Trevor Spiteri
6dfe144bdd stabilize const_nonzero_int_methods 2020-06-29 10:28:39 +02:00
Dylan MacKenzie
d84f0c8d32 Update tests 2020-06-28 10:08:12 -07:00
Dylan MacKenzie
d6139f76c0 Update tests 2020-06-28 10:08:10 -07:00
Oliver Scherer
819cde5dab Show the values and computation that would overflow a const evaluation or propagation 2020-06-26 10:08:52 +02:00
Nathan Corbyn
c2dfc25c0e Fix tests 2020-06-24 15:10:10 +01:00