Commit Graph

101431 Commits

Author SHA1 Message Date
Simon Sapin
e76a184615 Document guard expressions in matches! 2019-10-23 15:46:42 +02:00
Simon Sapin
f7ebe19338 Add tracking issue for the matches! macro
https://github.com/rust-lang/rust/issues/65721
2019-10-23 15:35:36 +02:00
Simon Sapin
7472cd46aa Move the matches! macro to the prelude 2019-10-23 15:35:36 +02:00
Simon Sapin
f69293ae80 Add core::macros::matches!( $expr, $pat ) -> bool
# Motivation

This macro is:

* General-purpose (not domain-specific)
* Simple (the implementation is short)
* Very popular [on crates.io](https://crates.io/crates/matches)
  (currently 37th in all-time downloads)
* The two previous points combined make it number one in
  [left-pad index](https://twitter.com/bascule/status/1184523027888988160)
  score

As such, I feel it is a good candidate for inclusion in the standard library.

In fact I already felt that way five years ago:
https://github.com/rust-lang/rust/pull/14685
(Although the proof of popularity was not as strong at the time.)

Back then, the main concern was that this macro may not be quite
universally-enough useful to belong in the prelude.

# API

Therefore, this PR adds the macro such that using it requires one of:

```
use core::macros::matches;
use std::macros::matches;
```

Like arms of a `match` expression,
the macro supports multiple patterns separated by `|`
and optionally followed by `if` and a guard expression:

```
let foo = 'f';
assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));

let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
```

# Implementation constraints

A combination of reasons make it tricky
for a standard library macro not to be in the prelude.

Currently, all public `macro_rules` macros in the standard library macros
end up “in the prelude” of every crate not through `use std::prelude::v1::*;`
like for other kinds of items,
but through `#[macro_use]` on `extern crate std;`.
(Both are injected by `src/libsyntax_ext/standard_library_imports.rs`.)

`#[macro_use]` seems to import every macro that is available
at the top-level of a crate, even if through a `pub use` re-export.

Therefore, for `matches!` not to be in the prelude, we need it to be
inside of a module rather than at the root of `core` or `std`.

However, the only way to make a `macro_rules` macro public
outside of the crate where it is defined
appears to be `#[macro_export]`.
This exports the macro at the root of the crate
regardless of which module defines it.
See [macro scoping](
https://doc.rust-lang.org/reference/macros-by-example.html#scoping-exporting-and-importing)
in the reference.

Therefore, the macro needs to be defined in a crate
that is not `core` or `std`.

# Implementation

This PR adds a new `matches_macro` crate as a private implementation detail
of the standard library.
This crate is `#![no_core]` so that libcore can depend on it.
It contains a `macro_rules` definition with `#[macro_export]`.

libcore and libstd each have a new public `macros` module
that contains a `pub use` re-export of the macro.
Both the module and the macro are unstable, for now.

The existing private `macros` modules are renamed `prelude_macros`,
though their respective source remains in `macros.rs` files.
2019-10-23 15:35:34 +02:00
bors
4a8c5b20c7 Auto merge of #57545 - bovinebuddha:object_safe_for_dispatch, r=nikomatsakis
Object safe for dispatch

cc #43561
2019-10-23 13:34:27 +00:00
Guillaume Gomez
530d7098bf Update ui tests 2019-10-23 14:13:37 +02:00
Guillaume Gomez
aa733dacdf Add long error explanation for E0576 2019-10-23 13:07:47 +02:00
bors
f466f52c1b Auto merge of #65716 - JohnTitor:rollup-fkcr85k, r=JohnTitor
Rollup of 14 pull requests

Successful merges:

 - #64145 (Target-feature documented as unsafe)
 - #65007 (Mention keyword closing policy)
 - #65417 (Add more coherence tests)
 - #65507 (Fix test style in unused parentheses lint test)
 - #65591 (Add long error explanation for E0588)
 - #65617 (Fix WASI sleep impl)
 - #65656 (Add option to disable keyboard shortcuts in docs)
 - #65678 (Add long error explanation for E0728)
 - #65681 (Code cleanups following up on #65576.)
 - #65686 (refactor and move `maybe_append` )
 - #65688 (Add some tests for fixed ICEs)
 - #65689 (bring back some Debug instances for Miri)
 - #65695 (self-profiling: Remove module names from some event-ids in codegen backend.)
 - #65706 (Add missing space in librustdoc)

Failed merges:

r? @ghost
2019-10-23 09:53:32 +00:00
Yuki Okushi
1df9081413
Rollup merge of #65706 - popzxc:add-missing-space, r=Mark-Simulacrum
Add missing space in librustdoc

It just hurts my eyes...

r? @Centril
2019-10-23 17:14:47 +09:00
Yuki Okushi
41850dfea6
Rollup merge of #65695 - michaelwoerister:fix-self-profiling-work-item-event-names, r=wesleywiser
self-profiling: Remove module names from some event-ids in codegen backend.

Event-IDs are not supposed to contain argument values. Event-IDs are the equivalent of function names. Proper support for parameters will be added to self-profiling down the line.

This PR fixes an oversight from https://github.com/rust-lang/rust/pull/64840.

r? @wesleywiser
2019-10-23 17:14:46 +09:00
Yuki Okushi
12f32c2f29
Rollup merge of #65689 - RalfJung:miri-debug, r=Centril
bring back some Debug instances for Miri

These were erroneously removed in https://github.com/rust-lang/rust/pull/65647, but Miri needs them.

r? @Centril Cc @nnethercote @oli-obk
2019-10-23 17:14:44 +09:00
Yuki Okushi
c3e5413813
Rollup merge of #65688 - JohnTitor:add-some-tests, r=Dylan-DPC
Add some tests for fixed ICEs

Fixes #41366 from 1.35.0
Fixes #51431 from 1.31.0-nightly (77af31408 2018-10-11) (on my local)
Fixes #52437 from nightly
Fixes #63496 from nightly

r? @Centril
2019-10-23 17:14:43 +09:00
Yuki Okushi
5bac361776
Rollup merge of #65686 - yjhmelody:yjhmelody-patch-1, r=Centril
refactor and move `maybe_append`
2019-10-23 17:14:42 +09:00
Yuki Okushi
7fc6ce9db2
Rollup merge of #65681 - sunfishcode:followup, r=Centril
Code cleanups following up on #65576.

This makes a few code cleanups to follow up on the review comments in
https://github.com/rust-lang/rust/pull/65576.

r? @Centril
2019-10-23 17:14:40 +09:00
Yuki Okushi
b7994653a1
Rollup merge of #65678 - JohnTitor:add-e0728-explanation, r=GuilliaumeGomez
Add long error explanation for E0728

Part of #61137

r? @GuillaumeGomez
2019-10-23 17:14:39 +09:00
Yuki Okushi
88e3ae2eb4
Rollup merge of #65656 - GuillaumeGomez:option-disable-shortcut, r=Dylan-DPC
Add option to disable keyboard shortcuts in docs

Fixes #65211.

r? @Manishearth
2019-10-23 17:14:37 +09:00
Yuki Okushi
ff2442ff36
Rollup merge of #65617 - newpavlov:patch-2, r=alexcrichton
Fix WASI sleep impl

Closes #65607

@sunfishcode
Is it fine to use 0 for the `identifier` field? What is this field used for?
2019-10-23 17:14:36 +09:00
Yuki Okushi
6f6f3e8cd7
Rollup merge of #65591 - GuillaumeGomez:long-err-explanation-E0588, r=Dylan-DPC
Add long error explanation for E0588

Part of #61137.

r? @kinnison
2019-10-23 17:14:34 +09:00
Yuki Okushi
1dbb010c9a
Rollup merge of #65507 - polyedre:master, r=nikomatsakis
Fix test style in unused parentheses lint test

I think this fixes #63237
I'm not sure if I had to add text after the `//~ ERROR` comments.
This is my first pull request, so I'm open to feedback.
This issues already received one pull request [here](https://github.com/rust-lang/rust/pull/63257) but it was marked as closed for inactivity.

r?  @nikomatsakis
2019-10-23 17:14:33 +09:00
Yuki Okushi
557d27637d
Rollup merge of #65417 - weiznich:more_coherence_tests, r=nikomatsakis
Add more coherence tests

I've wrote the missing test cases listed in [this google doc](https://docs.google.com/spreadsheets/d/1WlroTEXE6qxxGvEOhICkUpqguYZP9YOZEvnmEtSNtM0/edit#gid=0)

> The other thing that might be useful is to rename the existing tests so they all fit the new naming scheme we were using.

I'm not entirely sure how to do this. If everything from the google sheet is covered could I just remove the remaining tests in `src/test/ui/coherence` or is there something in there that should remain?

cc #63599

r? @nikomatsakis
2019-10-23 17:14:31 +09:00
Yuki Okushi
bd82de0de6
Rollup merge of #65007 - BO41:keywords, r=nikomatsakis
Mention keyword closing policy

closes #59233 / https://github.com/rust-lang/rust/issues/59233#issuecomment-478362693

rewording suggestions welcome

> Also in the referenced issue, the commit number of the new commit
> that could close that issue is not really informative. The PR number itself appeared in the issue
> is more informative and concise.

@lzutao what do you mean with that? Is this fixed by the new "May be fixed by #XXXXX"?
2019-10-23 17:14:29 +09:00
Yuki Okushi
86992272d5
Rollup merge of #64145 - togiberlin:feature/target-features-doc, r=ehuss
Target-feature documented as unsafe

@nikomatsakis asked me to help out on the docs on this issue: https://github.com/rust-lang/rust/issues/63597

The following docs have been modified
- ```rustc -C help``` text for `target-feature`
- RustC book:

## Preview of src/doc/rustc/src/targets/index.md
![Screenshot 2019-09-17 at 12 22 45](https://user-images.githubusercontent.com/13764830/65033746-f7826700-d945-11e9-9dd2-d8f9b08f45de.png)

## Preview of src/doc/rustc/src/targets/known-issues.md
![Screenshot 2019-09-17 at 12 22 25](https://user-images.githubusercontent.com/13764830/65033774-00733880-d946-11e9-9398-90f01f3938d5.png)

Fixes #63597
2019-10-23 17:14:27 +09:00
bors
d6e4028a0d Auto merge of #65713 - lzutao:clippy-up, r=Manishearth
Update clippy

Replaces #65690
cc  #65503
Closes #65683
2019-10-23 06:07:49 +00:00
Lzu Tao
557cbd0fd5 Public some types for compiletest_rs 2019-10-23 03:49:42 +00:00
Lzu Tao
7e0ef6e92e update compiletest 2019-10-23 02:46:10 +00:00
Clar Fon
eeb549bfc3 Add Cow::is_borrowed and Cow::is_owned 2019-10-22 19:56:41 -04:00
Eric Huss
fe3dc31710 Update cargo 2019-10-22 15:22:57 -07:00
Mark Rousskov
4e8d1b2292 Add some documentation 2019-10-22 16:53:28 -04:00
Esteban Küber
580a93e2b6 Fix rebase 2019-10-22 13:24:30 -07:00
Esteban Küber
669a4035ef review comments: move code, fix indentation and change span 2019-10-22 12:43:04 -07:00
Esteban Küber
0118278cde Drive-by formatting 2019-10-22 12:42:15 -07:00
Esteban Küber
5b58095f68 Handle projection obligation errors 2019-10-22 12:42:15 -07:00
Esteban Küber
88e4e2a208 fix compile-fail test 2019-10-22 12:42:15 -07:00
Esteban Küber
58c6591cde Point at associated type for some obligations 2019-10-22 12:42:15 -07:00
Mathias Blikstad
ef5acdeceb RFC 2027: "first draft" of implementation
These are a squashed series of commits.
2019-10-22 15:24:33 -04:00
flip1995
6bc16ef3c7 Update Clippy 2019-10-22 19:11:28 +00:00
flip1995
76f9b3b4c9 Readd some PartialEq and Hash derives used by Clippy 2019-10-22 19:11:28 +00:00
oxalica
10f1bc77b3
Some tweaks 2019-10-23 02:43:45 +08:00
Mateusz Mikuła
bedbf3bacb Apply clippy::single_match suggestion 2019-10-22 19:23:10 +02:00
Mateusz Mikuła
7491468278 Apply clippy::while_let_on_iterator suggestions 2019-10-22 19:23:10 +02:00
Mateusz Mikuła
e1aa297b8b Apply clippy::redundant_pattern_matching suggestion 2019-10-22 19:23:10 +02:00
Mateusz Mikuła
95c06a2970 Apply clippy::needless_return suggestions 2019-10-22 19:23:10 +02:00
Igor Aleksanov
8497f793d5 Add missing space in librustdoc 2019-10-22 20:14:34 +03:00
Mateusz Mikuła
dffc1b3282 Apply clippy::useless_let_if_seq suggestion 2019-10-22 19:14:22 +02:00
Stefan Lankes
ddcd157d03
Merge branch 'master' into rusty-hermit 2019-10-22 19:01:09 +02:00
Ralf Jung
fe84809394 relax ExactSizeIterator bound on write_bytes: too many iterators don't have that bound 2019-10-22 18:08:21 +02:00
togiberlin
de3fd021f5 Target-feature documented as unsafe. rustc book and rustc -C help have been modified. 2019-10-22 17:16:45 +02:00
varkor
51c687446d Add regression test for #65675 2019-10-22 15:49:43 +01:00
varkor
9220558c24 Fix an issue with const inference variables sticking around under Chalk + NLL 2019-10-22 15:49:43 +01:00
Santiago Pastorino
5f5903df31
Add ignore-tidy-filelength on ty/context
This is so we avoid a massive break of other people's code. Gonna run
rustfmt and split the file on a different PR.
2019-10-22 10:33:37 -03:00