Commit Graph

2595 Commits

Author SHA1 Message Date
bors 29e32120c3 Auto merge of #80100 - mark-i-m:pattORns-2, r=petrochenkov
or_patterns: implement :pat edition-specific behavior

cc #54883 `@joshtriplett`

This PR implements the edition-specific behavior of `:pat` wrt or-patterns, as determined by the crater runs and T-lang consensus in https://github.com/rust-lang/rust/issues/54883#issuecomment-745509090.

I believe this can unblock stabilization of or_patterns.

r? `@petrochenkov`
2020-12-20 04:10:44 +00:00
bors 0c11b93f5a Auto merge of #79635 - lcnr:const-eval-idk, r=oli-obk
const_evaluatable_checked: fix occurs check

fixes #79615

this is kind of a hack because we use `TypeRelation` for both the `Generalizer` and the `ConstInferUnifier` but i am not sure if there is a useful way to disentangle this without unnecessarily duplicating some code.

The error in the added test is kind of unavoidable until we erase the unused substs of `ConstKind::Unevaluated`. We talked a bit about this in the cg lazy norm meeting (https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/lazy_normalization_consts)
2020-12-20 00:50:46 +00:00
bors 1f5bc176b0 Auto merge of #80104 - Nadrieril:usefulness-merging, r=varkor
Improve and fix diagnostics of exhaustiveness checking

Primarily, this fixes https://github.com/rust-lang/rust/issues/56379. This also fixes incorrect interactions between or-patterns and slice patterns that I discovered while working on #56379. Those two examples show the incorrect diagnostics:

```rust
match &[][..] {
    [true] => {}
    [true // detected as unreachable but that's not true
        | false, ..] => {}
    _ => {}
}
match (true, None) {
    (true, Some(_)) => {}
    (false, Some(true)) => {}
    (true | false, None | Some(true // should be detected as unreachable
                               | false)) => {}
}
```

I did not measure any perf impact. However, I suspect that [`616ba9f`](616ba9f9f7) should have a negative impact on large or-patterns. I'll see what the perf run says; I have optimization ideas up my sleeve if needed.

EDIT: I initially had a noticeable perf impact that I thought unavoidable. I then proceeded to avoid it x)

r? `@varkor`
`@rustbot` label +A-exhaustiveness-checking
2020-12-19 19:14:04 +00:00
bors 1b6b06a03a Auto merge of #80132 - matthewjasper:revert-eval-order, r=nikomatsakis
Revert change to trait evaluation order

This change breaks some code and doesn't appear to enable any new code.

closes #79902

r? `@nikomatsakis`
2020-12-19 16:20:22 +00:00
mark 1a7d00a529 implement edition-specific :pat behavior for 2015/18 2020-12-19 07:13:36 -06:00
bors 8bb302d34d Auto merge of #80106 - jackh726:binder-refactor-part-2, r=lcnr
A lot of refactoring to remove more `Binder::bind`s

Split out from #76814
2020-12-19 10:13:52 +00:00
Jack Huey 5e7095850c More rebinds 2020-12-19 04:26:35 -05:00
bors e461b8137f Auto merge of #80180 - JohnTitor:rollup-a31s996, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #78083 (Stabilize or_insert_with_key)
 - #79211 (Add the "async" and "promise" doc aliases to `core::future::Future`)
 - #79612 (Switch some links in compiler/ to intra-doc links)
 - #80068 (Add `&mut` as an alias for 'reference' primitive)
 - #80129 (docs: Edit rustc_ast::token::Token)
 - #80133 (Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere)
 - #80155 (Fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-19 07:23:41 +00:00
Yuki Okushi b27c78390c
Rollup merge of #80155 - matsujika:matsujika-patch-1, r=jonas-schievink
Fix typo
2020-12-19 15:16:10 +09:00
Yuki Okushi 6b52475c68
Rollup merge of #80133 - Aaron1011:fix/const-mut-deref, r=estebank
Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere

Fixes #79971
2020-12-19 15:16:08 +09:00
Yuki Okushi 904c4c6df7
Rollup merge of #80129 - pierwill:patch-6, r=estebank
docs: Edit rustc_ast::token::Token

Add missing punctuation.
2020-12-19 15:16:07 +09:00
Yuki Okushi c111404cb5
Rollup merge of #79612 - jyn514:compiler-links, r=Aaron1011
Switch some links in compiler/ to intra-doc links
2020-12-19 15:16:03 +09:00
Yuki Okushi 0765536c0b
Rollup merge of #78083 - ChaiTRex:master, r=m-ou-se
Stabilize or_insert_with_key

Stabilizes the `or_insert_with_key` feature from https://github.com/rust-lang/rust/issues/71024. This allows inserting key-derived values when a `HashMap`/`BTreeMap` entry is vacant.

The difference between this and  `.or_insert_with(|| ... )` is that this provides a reference to the key to the closure after it is moved with `.entry(key_being_moved)`, avoiding the need to copy or clone the key.
2020-12-19 15:15:57 +09:00
bors 3d9ada686f Auto merge of #79073 - davidtwco:issue-78957-const-param-attrs, r=lcnr
passes: prohibit invalid attrs on generic params

Fixes #78957.

This PR modifies the `check_attr` pass so that attribute placement on generic parameters is checked for validity.

r? `@lcnr`
2020-12-19 04:32:50 +00:00
bors d1741e59cb Auto merge of #77035 - mibac138:fn-fat-arrow-return, r=davidtwco
Gracefully handle mistyping -> as => in function return type

Fixes #77019
2020-12-19 01:47:05 +00:00
Jack Huey af3b1cb0b5 Change potentially_qualified to be defined on Binder<PredicateAtom> 2020-12-18 15:57:12 -05:00
Joshua Nelson 35f16c60e7 Switch compiler/ to intra-doc links
rustc_lint and rustc_lint_defs weren't switched because they're included
in the compiler book and so can't use intra-doc links.
2020-12-18 15:22:51 -05:00
Nadrieril cefcadbe92 Unify the two kinds of usefulness merging
This is elegant but a bit of a perf gamble. That said, or-patterns
rarely have many branches and it's easy to optimize or revert if we ever
need to. In the meantime simpler code is worth it.
2020-12-18 16:21:39 +00:00
Nadrieril 6319d737e0 Merge unreachable subpatterns correctly 2020-12-18 16:21:39 +00:00
Nadrieril 2d71a0b9b9 Keep all witnesses of non-exhaustiveness 2020-12-18 16:21:38 +00:00
Nadrieril d7a6365b77 Rewrite usefulness merging using `SpanSet`
`SpanSet` is heavily inspired from `DefIdForest`.
2020-12-18 16:21:38 +00:00
Nadrieril 170fae2c18 Log the output of `is_useful` in the or-pattern case too 2020-12-18 16:21:38 +00:00
Nadrieril 7009d20290 Factor out or-pattern usefulness merging 2020-12-18 16:21:38 +00:00
Ralf Jung 22a26dbce7
Rollup merge of #80145 - pierwill:patch-8, r=lcnr
Fix typo in rustc_typeck docs
2020-12-18 16:22:11 +01:00
Ralf Jung 926999513e
Rollup merge of #80135 - camelid:const-macro-nt, r=petrochenkov
Don't allow `const` to begin a nonterminal

Fixes #79908.

Thanks to Vadim Petrochenkov who [told me what the fix was][z]!

[z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422

r? ``@petrochenkov``
2020-12-18 16:22:09 +01:00
Ralf Jung 5eb15267ae
Rollup merge of #80130 - pierwill:patch-7, r=oli-obk
docs: Edit rustc_span::symbol::Symbol method

Edit wording of the doc comment for [rustc_span::symbol::Symbol::can_be_raw](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html#method.can_be_raw) to match related methods.
2020-12-18 16:22:07 +01:00
Ralf Jung ea6cc5aab5
Rollup merge of #80121 - LeSeulArtichaut:if-let-experimental, r=davidtwco
Change the message for `if_let_guard` feature gate

`if-let` guards are now implemented by #79051 🎉
Thanks ``@camelid`` for pointing this out 🙂
2020-12-18 16:22:06 +01:00
Hirochika Matsumoto 56530a2f25 Fix typo 2020-12-18 22:13:25 +09:00
pierwill 605c978641
Fix typo in rustc_typeck docs 2020-12-17 20:47:05 -08:00
bors 8d006c06b5 Auto merge of #80036 - sivadeilra:syms_no_macro, r=petrochenkov
Stop using intermediate macros in definition of symbols

Currently, the rustc_macros::symbols macro generates two
`macro_rules!` macros as its output. These two macros are
used in rustc_span/src/symbol.rs.

This means that each Symbol that we define is represented
in the AST of rustc_symbols twice: once in the definition
of the `define_symbols!` macro (similarly for the
`keywords! macro), and once in the rustc_span::symbols
definition.

That would be OK if there were only a handful of symbols,
but currently we define over 1100 symbols. The definition
of the `define_symbols!` macro contains the expanded definition
of each symbol, so that's a lot of AST storage wasted on a
macro that is used exactly once.

This commit removes the `define_symbols` macro, and simply
allows the proc macro to directly generate the
`rustc_symbols::symbol::sym` module.

The benefit is mainly in reducing memory wasted during
compilation of rustc itself. It should also reduce memory used
by Rust Analyzer.

This commit also reduces the size of the AST for symbol
definitions, by moving two `#[allow(...)]` attributes from
the symbol constants to the `sym` module. This eliminates 2200+
attribute nodes.

This commit also eliminates the need for the `digits_array`
constant. There's no need to store an array of Symbol values
for digits. We can simply define a constant of the base value,
and add to that base value.

I left the `sym::integer` function in rustc_span/src/symbol.rs
instead of moving it into rustc_macros/src/symbols.rs for two
reasons. First, because it's human-written code; it doesn't need
to be generated by the proc-macro. Second, because I didn't want
the `#[allow(...)]` attributes that I moved to the `sym` module
scope to apply to this function. The `sym` module re-exports the
`integer` function from its parent module.
2020-12-18 03:01:14 +00:00
bors f3800db221 Auto merge of #80138 - Dylan-DPC:rollup-qamsfyh, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #78164 (Prefer regions with an `external_name` in `approx_universal_upper_bound`)
 - #80003 (Fix overflow when converting ZST Vec to VecDeque)
 - #80023 (Enhance error message when misspelled label to value in break expression)
 - #80046 (Add more documentation to `Diagnostic` and `DiagnosticBuilder`)
 - #80109 (Remove redundant and unreliable coverage test results)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-18 00:08:30 +00:00
Dylan DPC da89dbb41a
Rollup merge of #80046 - camelid:diag-docs, r=lcnr
Add more documentation to `Diagnostic` and `DiagnosticBuilder`

cc `@estebank`
2020-12-18 00:30:20 +01:00
Dylan DPC a4b95ee517
Rollup merge of #80023 - sasurau4:feature/enhance-error-message-when-wrongly-written-broken-label, r=lcnr
Enhance error message when misspelled label to value in break expression

Fix #79424
2020-12-18 00:30:18 +01:00
Dylan DPC 720b6941df
Rollup merge of #78164 - Aaron1011:fix/async-region-name, r=tmandry
Prefer regions with an `external_name` in `approx_universal_upper_bound`

Fixes #75785

When displaying a MIR borrowcheck error, we may need to find an upper
bound for a region, which gives us a region to point to in the error
message. However, a region might outlive multiple distinct universal
regions, in which case the only upper bound is 'static

To try to display a meaningful error message, we compute an
'approximate' upper bound by picking one of the universal regions.
Currently, we pick the region with the lowest index - however, this
caused us to produce a suboptimal error message in issue #75785

This PR `approx_universal_upper_bound` to prefer regions with an
`external_name`. This causes us to prefer regions from function
arguments/upvars, which seems to lead to a nicer error message in some
cases.
2020-12-18 00:30:09 +01:00
Arlie Davis 2b2462e8b0 Stop using intermediate macros in definition of symbols
Currently, the rustc_macros::symbols macro generates two
`macro_rules!` macros as its output. These two macros are
used in rustc_span/src/symbol.rs.

This means that each Symbol that we define is represented
in the AST of rustc_symbols twice: once in the definition
of the `define_symbols!` macro (similarly for the
`keywords! macro), and once in the rustc_span::symbols
definition.

That would be OK if there were only a handful of symbols,
but currently we define over 1100 symbols. The definition
of the `define_symbols!` macro contains the expanded definition
of each symbol, so that's a lot of AST storage wasted on a
macro that is used exactly once.

This commit removes the `define_symbols` macro, and simply
allows the proc macro to directly generate the
`rustc_symbols::symbol::sym` module.

The benefit is mainly in reducing memory wasted during
compilation of rustc itself. It should also reduce memory used
by Rust Analyzer.

This commit also reduces the size of the AST for symbol
definitions, by moving two `#[allow(...)]` attributes from
the symbol constants to the `sym` module. This eliminates 2200+
attribute nodes.

This commit also eliminates the need for the `digits_array`
constant. There's no need to store an array of Symbol values
for digits. We can simply define a constant of the base value,
and add to that base value.
2020-12-17 15:20:45 -08:00
Camelid d6f1787447 Don't allow `const` to begin a nonterminal
Thanks to Vadim Petrochenkov who [told me what the fix was][z]!

[z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422
2020-12-17 13:58:56 -08:00
bors 1954756aa5 Auto merge of #80122 - davidtwco:revert-76030, r=oli-obk
Revert "cg_llvm: `fewer_names` in `uncached_llvm_type`"

Fixes #76213 and fixes #79564.

This PR temporarily reverts commit fa01ce802f from #76030 to until the root issue can be resolved. Requested [in t-compiler meeting](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.20meeting.5D.202020-12-17.20.2354818/near/220261541).

*Note*: I was seeing some failing debuginfo-gdb tests locally but I wasn't sure if they were spurious.
2020-12-17 21:13:51 +00:00
Aaron Hill dea13632a8
Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere
Fixes #79971
2020-12-17 15:25:55 -05:00
Matthew Jasper 3e31ffda97 Revert change to evaluation order
This change breaks some code and doesn't appear to enable any new code.
2020-12-17 20:16:10 +00:00
pierwill 54cce72da5
docs: Edit rustc_span::symbol::Symbol method
Edit wording of the doc comment for rustc_span::symbol::Symbol::can_be_raw
to match related methods.
2020-12-17 12:02:34 -08:00
pierwill 30c9307bfc
docs: Edit rustc_ast::token::Token
Add missing punctuation.
2020-12-17 11:55:49 -08:00
Aaron Hill 419d3ae028
Prefer regions with an `external_name` in `approx_universal_upper_bound`
Fixes #75785

When displaying a MIR borrowcheck error, we may need to find an upper
bound for a region, which gives us a region to point to in the error
message. However, a region might outlive multiple distinct universal
regions, in which case the only upper bound is 'static

To try to display a meaningful error message, we compute an
'approximate' upper bound by picking one of the universal regions.
Currently, we pick the region with the lowest index - however, this
caused us to produce a suboptimal error message in issue #75785

This PR `approx_universal_upper_bound` to prefer regions with an
`external_name`. This causes us to prefer regions from function
arguments/upvars, which seems to lead to a nicer error message in some
cases.
2020-12-17 13:24:40 -05:00
bors eb4fc71dc9 Auto merge of #79945 - jackh726:existential_trait_ref, r=nikomatsakis
Move binder for dyn to each list item

This essentially changes `ty::Binder<&'tcx List<ExistentialTraitRef>>` to `&'tcx List<ty::Binder<ExistentialTraitRef>>`.

This is a first step in moving the `dyn Trait` representation closer to Chalk, which we've talked about in `@rust-lang/wg-traits.`

r? `@nikomatsakis`
2020-12-17 18:21:20 +00:00
David Wood 88dc58fc9b
Revert "cg_llvm: `fewer_names` in `uncached_llvm_type`"
This reverts commit fa01ce802f.
2020-12-17 16:40:47 +00:00
LeSeulArtichaut 46e9212ecb Change the message for `if_let_guard` feature gate 2020-12-17 17:08:18 +01:00
mibac138 e916641fd3 Address review comments 2020-12-17 14:12:48 +01:00
bors caeb3335c0 Auto merge of #80114 - GuillaumeGomez:rollup-gszr5kn, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #80006 (BTreeMap: more expressive local variables in merge)
 - #80022 (BTreeSet: simplify implementation of pop_first/pop_last)
 - #80035 (Optimization for bool's PartialOrd impl)
 - #80040 (Always run intrinsics lowering pass)
 - #80047 (Use more symbols in rustdoc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-17 12:02:29 +00:00
Daiki Ihara 7b9ee11a4c Enhance error message when misspelled label to value in break expression
Apply suggestions from code review

Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-12-17 20:22:22 +09:00
Guillaume Gomez 1f5d8de062
Rollup merge of #80040 - tmiasko:always-lower-intrinsics, r=Dylan-DPC
Always run intrinsics lowering pass

Move intrinsics lowering pass from the optimization phase (where it
would not run if -Zmir-opt-level=0), to the drop lowering phase where it
runs unconditionally.

The implementation of those intrinsics in code generation and
interpreter is unnecessary. Remove it.
2020-12-17 11:36:52 +01:00
bors 001bd7762c Auto merge of #79840 - dvtkrlbs:issue-79667, r=oli-obk
Remove memoization leftovers from constant evaluation machine

Closes #79667
2020-12-17 09:11:28 +00:00