Commit Graph

107185 Commits

Author SHA1 Message Date
Ralf Jung 4b8c784968 add test for issue 69020 2020-02-15 11:00:14 +01:00
Ralf Jung 9c7639492f more revisions and use them for another test 2020-02-15 10:52:49 +01:00
Ralf Jung bd48522314 fix tests, and use variants to test debug and release builds together 2020-02-15 10:47:27 +01:00
Dylan DPC e9db0613ac
Rollup merge of #69180 - Aaron1011:feature/comma-struct-init, r=petrochenkov
Suggest a comma if a struct initializer field fails to parse

Currently, we emit a "try adding a comma" suggestion if a comma is
missing in a struct definition. However, we emit no such suggestion if a
comma is missing in a struct initializer.

This commit adds a "try adding a comma" suggestion when we don't find a
comma during the parsing of a struct initializer field.

The change to `src/test/ui/parser/removed-syntax-with-1.stderr` isn't
great, but I don't see a good way of avoiding it.
2020-02-15 09:45:49 +01:00
Dylan DPC 09d6a657b1
Rollup merge of #69166 - JohnTitor:ice-const-enum, r=matthewjasper
Check `has_typeck_tables` before calling `typeck_tables_of`

Fixes #68684

r? @matthewjasper
2020-02-15 09:45:48 +01:00
Dylan DPC c115ad927a
Rollup merge of #69154 - JohnTitor:fix-macro-ices, r=petrochenkov
Avoid calling `fn_sig` on closures

Fixes #68060

r? @petrochenkov
2020-02-15 09:45:46 +01:00
Dylan DPC 728be34ebc
Rollup merge of #69106 - RReverser:wasi-fs-copy, r=KodrAus
Fix std::fs::copy on WASI target

Previously `std::fs::copy` on wasm32-wasi would reuse code from the `sys_common` module and would successfully copy contents of the file just to fail right before closing it.

This was happening because `sys_common::copy` tries to copy permissions of the file, but permissions are not a thing in WASI (at least yet) and `set_permissions` is implemented as an unconditional runtime error.

This change instead adds a custom working implementation of `std::fs::copy` (like Rust already has on some other targets) that doesn't try to call `set_permissions` and is essentially a thin wrapper around `std::io::copy`.

Fixes #68560.
2020-02-15 09:45:45 +01:00
Dylan DPC afea30dc27
Rollup merge of #66721 - maxbla:exp-format-integers, r=KodrAus
implement LowerExp and UpperExp for integers

Addresses https://github.com/rust-lang/rust/issues/39479

This implementation is heavily based on the preexisting `macro_rules! impl_Display` in the same file. I don't like the liberal use of unsafe in that macro and would like to modify it so `unsafe` is only present where necessary. What is Rust's policy on doing such modifications?

Also, I couldn't figure out where to put tests, can I have some help with that?
2020-02-15 09:45:43 +01:00
Dylan DPC d28b35812f
Rollup merge of #64069 - danielhenrymantilla:feature/cstring_from_vec_of_nonzerou8, r=KodrAus
Added From<Vec<NonZeroU8>> for CString

Added a `From<Vec<NonZeroU8>>` `impl` for `CString`

# Rationale

  - `CString::from_vec_unchecked` is a subtle function, that makes `unsafe` code harder to audit when the generated `Vec`'s creation is non-trivial. This `impl` allows to write safer `unsafe` code thanks to the very explicit semantics of the `Vec<NonZeroU8>` type.

  - One such situation is when trying to `.read()` a `CString`, see issue #59229.

      - this lead to a PR: #59314, that was closed for being too specific / narrow (it only targetted being able to `.read()` a `CString`, when this pattern could have been generalized).

     - the issue suggested another route, based on `From<Vec<NonZeroU8>>`, which is indeed a less general and more concise code pattern.

  - quoting @shnatsel:

      - >  For me the main thing about making this safe is simplifying auditing - people have spent like an hour looking at just this one unsafe block in libflate because it's not clear what exactly is unchecked, so you have to look it up when auditing anyway. This has distracted us from much more serious memory safety issues the library had.
Having this trivial impl in stdlib would turn this into safe code with compiler more or less guaranteeing that it's fine, and save anyone auditing the code a whole lot of time.
2020-02-15 09:45:38 +01:00
Ben Lewis 821f4a9dfb Monomorphize const type during codegen. 2020-02-15 17:43:14 +13:00
Aaron Hill 98757f14d0
Suggest a comma if a struct initializer field fails to parse
Currently, we emit a "try adding a comma" suggestion if a comma is
missing in a struct definition. However, we emit no such suggestion if a
comma is missing in a struct initializer.

This commit adds a "try adding a comma" suggestion when we don't find a
comma during the parsing of a struct initializer field.

The change to `src/test/ui/parser/removed-syntax-with-1.stderr` isn't
great, but I don't see a good way of avoiding it.
2020-02-14 22:28:13 -05:00
Max Blachman a8fe47d175 implement LowerExp and UpperExp for integers 2020-02-14 18:42:51 -08:00
bors 19288ddfd6 Auto merge of #67681 - matthewjasper:infer-regions-in-borrowck, r=nikomatsakis
Infer regions for opaque types in borrowck

This is a step towards the goal of typeck not doing region inference.

The commits up to `Arena allocate the result of mir_borrowck` are various bug fixes and prerequisites.
The remaining commits move opaque type inference to borrow checking.

r? @nikomatsakis
2020-02-15 02:24:04 +00:00
Ben Lewis 99a864be39 Fix emulate intrinsics return type. 2020-02-15 14:45:36 +13:00
Ben Lewis c7aadcfa56 Change `const_field` and `const_caller_location` to return `ConstValue` instead of `Const` as the type
in the returned const isn't needed.
2020-02-15 12:57:46 +13:00
bors b92c6ee882 Auto merge of #69172 - JohnTitor:rollup-6cbmwcw, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #68129 (Correct inference of primitive operand type behind binary operation)
 - #68475 (Use a `ParamEnvAnd<Predicate>` for caching in `ObligationForest`)
 - #68856 (typeck: clarify def_bm adjustments & add tests for or-patterns)
 - #69051 (simplify_try: address some of eddyb's comments)
 - #69128 (Fix extra subslice lowering)
 - #69150 (Follow-up to #68848)
 - #69164 (Update pulldown-cmark dependency)

Failed merges:

r? @ghost
2020-02-14 23:11:03 +00:00
Ben Lewis c423a8649c Change const eval to return `ConstValue`, instead of `Const` as the type inside it shouldn't be used. 2020-02-15 11:56:23 +13:00
Matthew Jasper d863978f89 Fix tests after rebase 2020-02-14 22:40:03 +00:00
Matthew Jasper edddb62099 Split `type_of` out of collect.rs 2020-02-14 22:40:03 +00:00
Matthew Jasper 223a2ee306 Add fast path to eq_opaque_type_and_type 2020-02-14 22:40:03 +00:00
Matthew Jasper 6d9e270a4d Fix and test nested impl Trait 2020-02-14 22:40:03 +00:00
Matthew Jasper 78e0ab53fb Update tests 2020-02-14 22:40:03 +00:00
Matthew Jasper e3e5d27f23 Use member constraint for most opaque types in NLL
This ensures that NLL will infer suitable values for regions in opaque
types when it's possible.
2020-02-14 22:40:03 +00:00
Matthew Jasper dd1687ef41 Always check upper bounds when choosing member regions
Also correctly calculate what the upper bounds are.
2020-02-14 22:40:03 +00:00
Matthew Jasper 2bd16f3c81 Improve opaque type lifetime errors
* Use better span for member constraint errors
* Avoid a bad suggestion
* Don't report member constraint errors if we have other universal
  region errors.
2020-02-14 22:40:03 +00:00
Matthew Jasper 5cfa7d1dfb Handle equal regions in opaque type inference 2020-02-14 22:40:03 +00:00
Matthew Jasper 728224d1e0 Show inferred opaque types with `#[rustc_regions]` 2020-02-14 22:40:03 +00:00
Matthew Jasper f23bca79d4 Address review comments 2020-02-14 22:40:03 +00:00
Matthew Jasper 93ac5bc7de Update tests 2020-02-14 22:40:03 +00:00
Matthew Jasper bb8c9911f5 Erase regions in opaque types in typeck 2020-02-14 22:40:03 +00:00
Matthew Jasper 2fb02549b8 Ensure RPIT types get recorded in borrowck 2020-02-14 22:40:03 +00:00
Matthew Jasper edee23ee25 Avoid unnecessary opaque type errors in borrowck 2020-02-14 22:40:03 +00:00
Matthew Jasper d9b9f00109 Infer opaque type regions in borrow checking
We want type checking for function bodies to ignore/erase regions. As
such, we need to infer the regions in opaque types in borrow check
instead.
2020-02-14 22:40:02 +00:00
Matthew Jasper 75ac0cca36 Prepare to use borrowck to resolve opaque types 2020-02-14 22:40:02 +00:00
Matthew Jasper 43a3348fd9 Arena allocate the result of mir_borrowck 2020-02-14 22:40:02 +00:00
Matthew Jasper 378b5b4ca0 Generate more accurate MIR in `construct_error` 2020-02-14 22:40:02 +00:00
Yuki Okushi 47aa2b5bfd Avoid calling `fn_sig` on closures 2020-02-15 07:33:48 +09:00
Yuki Okushi a6ff1dbaa4
Rollup merge of #69164 - GuillaumeGomez:update-pulldown-cmark, r=Dylan-DPC
Update pulldown-cmark dependency

r? @kinnison

cc @ollie27

Reopening of  #65894.
2020-02-15 07:17:53 +09:00
Yuki Okushi 72def9a3f5
Rollup merge of #69150 - nnethercote:68848-follow-up, r=petrochenkov
Follow-up to #68848

This PR contains some late changes to #68848 that somehow didn't get included when that PR was merged in a roll-up.

r? @petrochenkov
2020-02-15 07:17:52 +09:00
Yuki Okushi 940fff7250
Rollup merge of #69128 - Centril:fix-69103, r=davidtwco
Fix extra subslice lowering

We are currently ICEing on e.g.
```rust
fn main() {
    let [.., b @ ..] = [1, 2];
    b;
}
```
This happens because `b @ ..` registers a binding such that `b;` is OK, but then we forget to lower that binding in `rustc_ast_lowering`.

Fixes #69103.

r? @davidtwco
2020-02-15 07:17:50 +09:00
Yuki Okushi e0ea1e759f
Rollup merge of #69051 - Centril:st-fixes, r=eddyb
simplify_try: address some of eddyb's comments

Addresses only https://github.com/rust-lang/rust/pull/66282#discussion_r376730986 and https://github.com/rust-lang/rust/pull/66282#discussion_r376730824.

r? @eddyb
cc @oli-obk
2020-02-15 07:17:49 +09:00
Yuki Okushi 829a3635e4
Rollup merge of #68856 - Centril:or-pat-ref-pat, r=matthewjasper
typeck: clarify def_bm adjustments & add tests for or-patterns

Clarify the adjustment algorithm for the expected type / default binding-modes when type checking patterns with more documentation and tweaks that make the algorithm more independent of the pattern forms.

Also resolve the FIXME noted for or-patterns by deciding that the current implementation is correct, noting the rationale and adding tests for the current implementation.

cc https://github.com/rust-lang/rust/issues/54883

r? @oli-obk @varkor
2020-02-15 07:17:47 +09:00
Yuki Okushi 2c5bdee9e4
Rollup merge of #68475 - Aaron1011:fix/forest-caching, r=nikomatsakis
Use a `ParamEnvAnd<Predicate>` for caching in `ObligationForest`

Previously, we used a plain `Predicate` to cache results (e.g. successes
and failures) in ObligationForest. However, fulfillment depends on the
precise `ParamEnv` used, so this is unsound in general.

This commit changes the impl of `ForestObligation` for
`PendingPredicateObligation` to use `ParamEnvAnd<Predicate>` instead of
`Predicate` for the associated type. The associated type and method are
renamed from 'predicate' to 'cache_key' to reflect the fact that type is
no longer just a predicate.
2020-02-15 07:17:45 +09:00
Yuki Okushi 3f7ed88fdc
Rollup merge of #68129 - varkor:infer-binary-operand-behind-reference, r=nikomatsakis
Correct inference of primitive operand type behind binary operation

Fixes https://github.com/rust-lang/rust/issues/57447.

r? @nikomatsakis
2020-02-15 07:17:43 +09:00
Ralf Jung ad4b3f3e17 const-prop: use one helper method for all lints; consistently lint overflow on BinOps and not on Assert 2020-02-14 22:49:01 +01:00
Guillaume Gomez d8589de1f0 Update pulldown-cmark dependency 2020-02-14 22:39:45 +01:00
Matthew Jasper 9664122b1f Simplify function signature in opaque_types 2020-02-14 20:12:46 +00:00
Matthew Jasper 43dae91821 Give some more queries descriptions 2020-02-14 20:12:46 +00:00
Matthew Jasper 60970be1fd Distinguish RPIT from other impl trait 2020-02-14 20:12:46 +00:00
Matthew Jasper 4af0952961 Call `is_freeze` less in unsafety-checking
This is to avoid cycles when calling `is_freeze` on an opaque type.
2020-02-14 20:12:46 +00:00