about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2020-12-31Rustdoc render public underscore_imports as Re-exportsbors-0/+20
Fixes #61592
2020-12-21Auto merge of #79270 - RalfJung:array-repeat-consts, r=oli-obkbors-37/+41
Acknowledge that `[CONST; N]` is stable When `const_in_array_repeat_expressions` (RFC 2203) got unstably implemented as part of https://github.com/rust-lang/rust/pull/61749, accidentally, the special case of repeating a *constant* got stabilized immediately. That is why the following code works on stable: ```rust const EMPTY: Vec<i32> = Vec::new(); pub const fn bar() -> [Vec<i32>; 2] { [EMPTY; 2] } fn main() { let x = bar(); } ``` In contrast, if we had written `[expr; 2]` for some expression that is not *literally* a constant but could be evaluated at compile-time (e.g. `(EMPTY,).0`), this would have failed. We could take back this stabilization as it was clearly accidental. However, I propose we instead just officially accept this and stabilize a small subset of RFC 2203, while leaving the more complex case of general expressions that could be evaluated at compile-time unstable. Making that case work well is pretty much blocked on inline `const` expressions (to avoid relying too much on [implicit promotion](https://github.com/rust-lang/const-eval/blob/master/promotion.md)), so it could take a bit until it comes to full fruition. `[CONST; N]` is an uncontroversial subset of this feature that has no semantic ambiguities, does not rely on promotion, and basically provides the full expressive power of RFC 2203 but without the convenience (people have to define constants to repeat them, possibly using associated consts if generics are involved). Well, I said "no semantic ambiguities", that is only almost true... the one point I am not sure about is `[CONST; 0]`. There are two possible behaviors here: either this is equivalent to `let x = CONST; [x; 0]`, or it is a NOP (if we argue that the constant is never actually instantiated). The difference between the two is that if `CONST` has a destructor, it should run in the former case (but currently doesn't, due to https://github.com/rust-lang/rust/issues/74836); but should not run if it is considered a NOP. For regular `[x; 0]` there seems to be consensus on running drop (there isn't really an alternative); any opinions for the `CONST` special case? Should this instantiate the const only to immediately run its destructors? That seems somewhat silly to me. After all, the `let`-expansion does *not* work in general, for `N > 1`. Cc `@rust-lang/lang` `@rust-lang/wg-const-eval` Cc https://github.com/rust-lang/rust/issues/49147
2020-12-21Auto merge of #80205 - tomprogrammer:prettyprint-pattern-mut-binding, ↵bors-1/+9
r=davidtwco Fix pretty printing an AST representing `&(mut ident)` The PR fixes a misguiding help diagnostic in the parser that I reported in #80186. I discovered that the parsers recovery and reporting logic was correct but the pretty printer produced wrong code for the example. (Details in https://github.com/rust-lang/rust/issues/80186#issuecomment-748498676) Example: ```rust #![allow(unused_variables)] fn main() { let mut &x = &0; } ``` The AST fragment `PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), Mutability::Not)` was printed to be `&mut ident`. But this wouldn't round trip through parsing again, because then it would be: `PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Not), ..), Mutability::Mut)` Now the pretty-printer prints `&(mut ident)`. Reparsing that code results in the AST fragment `PatKind::Ref(PatKind::Paren(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..)), Mutability::Not)` which I think should behave like the original pattern. Old diagnostic: ``` error: `mut` must be attached to each individual binding --> src/main.rs:3:9 | 3 | let mut &x = &0; | ^^^^^^ help: add `mut` to each binding: `&mut x` | = note: `mut` may be followed by `variable` and `variable @ pattern` ``` New diagnostic: ``` error: `mut` must be attached to each individual binding --> src/main.rs:3:9 | 3 | let mut &x = &0; | ^^^^^^ help: add `mut` to each binding: `&(mut x)` | = note: `mut` may be followed by `variable` and `variable @ pattern` ``` Fixes #80186
2020-12-21Rollup merge of #80250 - bugadani:resolver-cleanup, r=petrochenkovDylan DPC-36/+29
Minor cleanups in LateResolver - Avoid calculating hash twice - Avoid creating a closure in every iteration of a loop - Reserve space for path in advance - Some readability changes
2020-12-21Rollup merge of #80236 - tmiasko:atomic-swap, r=oli-obkDylan DPC-2/+13
Use pointer type in AtomicPtr::swap implementation Closes #80234.
2020-12-21Rollup merge of #80211 - wabain:async-fn-trait-bound-suggestion, r=petrochenkovDylan DPC-12/+6
Handle desugaring in impl trait bound suggestion Fixes #79843. When an associated type of a generic function parameter needs extra bounds, the diagnostics may suggest replacing an `impl Trait` with a named type parameter so that it can be referenced in the where clause. On stable and nightly, the suggestion can be malformed, for instance transforming: ```rust async fn run(_: &(), foo: impl Foo) -> std::io::Result<()> ``` Into: ```rust async fn run(_: &, F: Foo(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send ^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Where we want something like: ```rust async fn run<F: Foo>(_: &(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send ^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` The problem is that the elided lifetime of `&()` is added as a generic parameter when desugaring the async fn; the suggestion code sees this as an existing generic parameter and tries to use its span as an anchor to inject `F` into the parameter list. There doesn't seem to be an entirely principled way to check which generic parameters in the HIR were explicitly named in the source, so this commit changes the heuristics when generating the suggestion to only consider type parameters whose spans are contained within the span of the `Generics` when determining how to insert an additional type parameter into the declaration. (And to be safe it also excludes parameters whose spans are marked as originating from desugaring, although that doesn't seem to handle this elided lifetime.)
2020-12-21Rollup merge of #80199 - RalfJung:const-fake, r=oli-obkDylan DPC-6/+5
also const-check FakeRead We need to const-check all statements, including `FakeRead`, to avoid issues like https://github.com/rust-lang/rust/issues/77694. Fixes https://github.com/rust-lang/rust/issues/77694. r? ``@oli-obk``
2020-12-21Rollup merge of #80171 - pierwill:pierwill-rustcmiddle-tykind, r=lcnrDylan DPC-3/+5
Edit rustc_middle::ty::TyKind docs - Add a definition for this enum. - Fix typo and missing punctuation. - Spell out "algebraic data type".
2020-12-21Rollup merge of #80170 - ldm0:fixice, r=lcnrDylan DPC-3/+9
Fix ICE when lookup method in trait for type that have bound vars Closes #77910
2020-12-21Rollup merge of #80166 - pierwill:pierwill-rustcmiddle-place, r=petrochenkovDylan DPC-10/+10
Edit rustc_middle docs Re-word doc comment for rustc_middle::hir::place::Projection. Also adds: - Missing end stop punctuation, and - Documentation links to `rustc_middle::mir::Place`.
2020-12-20Move std_path construction into conditionDániel Buga-5/+4
2020-12-20Inline a single-use closureDániel Buga-2/+2
2020-12-20Create closure outside of the loopDániel Buga-4/+4
2020-12-20Add missing semicolonDániel Buga-1/+1
2020-12-20Remove unnecessary clonedDániel Buga-1/+1
2020-12-20Precompute vector length in smart_resolve_path_fragmentDániel Buga-1/+2
2020-12-20Clean up with_generic_param_rib, avoid double hashingDániel Buga-24/+17
2020-12-20Auto merge of #78317 - est31:linear_in_impl_count, r=matthewjasperbors-16/+159
Turn quadratic time on number of impl blocks into linear time Previously, if you had a lot of inherent impl blocks on a type like: ```Rust struct Foo; impl Foo { fn foo_1() {} } // ... impl Foo { fn foo_100_000() {} } ``` The compiler would be very slow at processing it, because an internal algorithm would run in O(n^2), where n is the number of impl blocks. Now, we add a new algorithm that allocates but is faster asymptotically. Comparing rustc nightly with a local build of rustc as of this PR (results in seconds): | N | real time before | real time after | | - | - | - | | 4_000 | 0.57 | 0.46 | | 8_000 | 1.31 | 0.84 | | 16_000 | 3.56 | 1.69 | | 32_000 | 10.60 | 3.73 | I've tuned up the numbers to make the effect larger than the startup noise of rustc, but the asymptotic difference should hold for smaller n as well. Note: current state of the PR omits error messages if there are other errors present already. For now, I'm mainly interested in a perf run to study whether this issue is present at all. Please queue one for this PR. Thanks!
2020-12-20Edit rustc_middle docspierwill-10/+10
Re-word doc comment for rustc_middle::hir::place::Projection. Also adds: - Missing end stop punctuation, and - Documentation links to `rustc_middle::mir::Place`.
2020-12-20Edit rustc_middle::ty::TyKind docspierwill-3/+5
- Add a definition for this enum. - Fix typo and missing punctuation. - Spell out "algebraic data type".
2020-12-20use exhaustive match for checking Rvalue::RepeatRalf Jung-37/+41
2020-12-20Update compiler/rustc_typeck/src/check/op.rsDonough Liu-1/+0
Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-12-20Fix pretty printing an AST representing `&(mut ident)`Thomas Bahn-1/+9
`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), ..)` is an AST representing `&(mut ident)`. It was errorneously printed as `&mut ident` which reparsed into a syntactically different AST. This affected help diagnostics in the parser.
2020-12-20Fix ICE on suggesting calling functionDonough Liu-2/+9
2020-12-20Auto merge of #80163 - jackh726:binder-refactor-part-3, r=lcnrbors-164/+162
Make BoundRegion have a kind of BoungRegionKind Split from #76814 Also includes making `replace_escaping_bound_vars` only return `T` Going to r? `@lcnr` Feel free to reassign
2020-12-20Auto merge of #80100 - mark-i-m:pattORns-2, r=petrochenkovbors-19/+67
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-19Handle desugaring in impl trait bound suggestionWilliam Bain-12/+6
2020-12-20Auto merge of #79635 - lcnr:const-eval-idk, r=oli-obkbors-2/+23
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-20Use pointer type in AtomicPtr::swap implementationTomasz Miąsko-2/+13
2020-12-19also const-check FakeReadRalf Jung-6/+5
2020-12-19Auto merge of #80104 - Nadrieril:usefulness-merging, r=varkorbors-114/+185
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`](https://github.com/rust-lang/rust/pull/80104/commits/616ba9f9f7f5845777a36e1a41a515e6c33a8776) 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-19Auto merge of #80132 - matthewjasper:revert-eval-order, r=nikomatsakisbors-3/+3
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-19implement edition-specific :pat behavior for 2015/18mark-19/+67
2020-12-19Auto merge of #80106 - jackh726:binder-refactor-part-2, r=lcnrbors-147/+165
A lot of refactoring to remove more `Binder::bind`s Split out from #76814
2020-12-19More rebindsJack Huey-138/+142
2020-12-19Auto merge of #80180 - JohnTitor:rollup-a31s996, r=JohnTitorbors-14/+10
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-19Rollup merge of #80155 - matsujika:matsujika-patch-1, r=jonas-schievinkYuki Okushi-1/+1
Fix typo
2020-12-19Rollup merge of #80133 - Aaron1011:fix/const-mut-deref, r=estebankYuki Okushi-3/+5
Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere Fixes #79971
2020-12-19Rollup merge of #80129 - pierwill:patch-6, r=estebankYuki Okushi-1/+1
docs: Edit rustc_ast::token::Token Add missing punctuation.
2020-12-19Rollup merge of #79612 - jyn514:compiler-links, r=Aaron1011Yuki Okushi-8/+2
Switch some links in compiler/ to intra-doc links
2020-12-19Rollup merge of #78083 - ChaiTRex:master, r=m-ou-seYuki Okushi-1/+1
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-19Auto merge of #79073 - davidtwco:issue-78957-const-param-attrs, r=lcnrbors-0/+35
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-19Auto merge of #77035 - mibac138:fn-fat-arrow-return, r=davidtwcobors-17/+107
Gracefully handle mistyping -> as => in function return type Fixes #77019
2020-12-18Change potentially_qualified to be defined on Binder<PredicateAtom>Jack Huey-27/+41
2020-12-18Make BoundRegion have a kind of BoungRegionKindJack Huey-164/+162
2020-12-18Switch compiler/ to intra-doc linksJoshua Nelson-8/+2
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-18Unify the two kinds of usefulness mergingNadrieril-63/+35
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-18Merge unreachable subpatterns correctlyNadrieril-3/+28
2020-12-18Keep all witnesses of non-exhaustivenessNadrieril-27/+37
2020-12-18Rewrite usefulness merging using `SpanSet`Nadrieril-65/+114
`SpanSet` is heavily inspired from `DefIdForest`.