Commit Graph

788 Commits

Author SHA1 Message Date
Esteban Küber
15dfd7eb61 Fix test 2017-11-25 10:15:36 -08:00
Esteban Küber
2461b7a264 Use get_parent_node instead of using spans 2017-11-24 08:26:45 -08:00
Esteban Küber
7c2526a9d7 Be more obvious when suggesting dereference
Include enclosing span when suggesting dereference on a span that is
already a reference:

```
error: non-reference pattern used to match a reference (see issue #42640)
  --> dont-suggest-dereference-on-arg.rs:16:19
   |
16 |         .filter(|&(ref a, _)| foo(a))
   |                  ^^^^^^^^^^^ help: consider using: `&&(ref k, _)`
   |
   = help: add #![feature(match_default_bindings)] to the crate attributes to enable
```
2017-11-24 08:26:01 -08:00
Oliver Schneider
8937d6a6cf
Merge cfail and ui tests into ui tests 2017-11-24 11:32:35 +01:00
bors
93426613a7 Auto merge of #45942 - Menschenkindlein:master, r=estebank
Add hints for the case of confusing enum with its variants

A solution for https://github.com/rust-lang/rust/issues/43871. When one uses an enum in a place that accepts variants (e.g., `Option(result)` instead of `Some(result)`), suggest one of this enum's variants.

cc @estebank
2017-11-24 01:44:19 +00:00
Maxim Zholobak
39f848efb0 Add module population and case of enum in place of expression 2017-11-23 15:10:23 +02:00
bors
247d98ec37 Auto merge of #46051 - cramertj:in-band-lifetimes, r=nikomatsakis
Implement in-band lifetime bindings

TODO (perhaps in a future PR): Should we ban explicit instantiation of generics with in-band lifetimes, or is it uncontroversial to just append them to the end of the lifetimes list?

Fixes #46042, cc #44524.

r? @nikomatsakis
2017-11-23 08:20:33 +00:00
bors
a6031a2ccf Auto merge of #46024 - estebank:no-variant, r=petrochenkov
Use the proper term when using non-existing variant

When using a non-existing variant, function or associated item, refer to
the proper term, instead of defaulting to "associated item" in
diagnostics.

Fix #28972.

```
error[E0599]: no variant named `Quux` found for type `Foo` in the current scope
 --> file.rs:7:9
  |
7 |         Foo::Quux(..) =>(),
  |         ^^^^^^^^^^^^^
```
2017-11-23 05:53:08 +00:00
Taylor Cramer
91b7920c09 Implement in-band lifetime bindings 2017-11-22 12:44:09 -05:00
bors
45594d5dec Auto merge of #46035 - oli-obk:use_suggestions, r=petrochenkov
Add structured suggestions for various "use" suggestions

r? @petrochenkov
2017-11-22 16:14:13 +00:00
bors
1dc0b573e7 Auto merge of #45198 - oli-obk:fmt_args, r=sfackler
Prevent fmt::Arguments from being shared across threads

Fixes #45197

This is a **breaking change**! Without doing this it's very easy to create race conditions.

There's probably a way to do this without breaking valid use cases, but it would require quite an overhaul of the formatting machinery.
2017-11-22 12:34:56 +00:00
bors
96e9cee77f Auto merge of #46040 - zilbuz:mir-misc, r=nikomatsakis
MIR-borrowck: Some minor fixes

- Remove parens when printing dereference (fix #45185)
- Change argument type of `autoderef` to `bool`
- Change argument type of `field_index` to `Field`
2017-11-22 07:27:54 +00:00
bors
d6d09e0b4d Auto merge of #45879 - nikomatsakis:nll-kill-cyclic-closures, r=arielb1
move closure kind, signature into `ClosureSubsts`

Instead of using side-tables, store the closure-kind and signature in the substitutions themselves. This has two key effects:

- It means that the closure's type changes as inference finds out more things, which is very nice.
    - As a result, it avoids the need for the `freshen_closure_like` code (though we still use it for generators).
- It avoids cyclic closures calls.
    - These were never meant to be supported, precisely because they make a lot of the fancy inference that we do much more complicated. However, due to an oversight, it was previously possible -- if challenging -- to create a setup where a closure *directly* called itself (see e.g. #21410).

We have to see what the effect of this change is, though. Needs a crater run. Marking as [WIP] until that has been assessed.

r? @arielb1
2017-11-21 22:52:19 +00:00
kennytm
0af67a4df0 Rollup merge of #46052 - oli-obk:rendered_diagnostics_in_json, r=petrochenkov
Include rendered diagnostic in json

r? @petrochenkov
2017-11-22 01:12:59 +08:00
bors
ebda7662db Auto merge of #45701 - cramertj:impl-trait-this-time, r=eddyb
impl Trait Lifetime Handling

This PR implements the updated strategy for handling `impl Trait` lifetimes, as described in [RFC 1951](https://github.com/rust-lang/rfcs/blob/master/text/1951-expand-impl-trait.md) (cc #42183).

With this PR, the `impl Trait` desugaring works as follows:
```rust
fn foo<T, 'a, 'b, 'c>(...) -> impl Foo<'a, 'b> { ... }
// desugars to
exists type MyFoo<ParentT, 'parent_a, 'parent_b, 'parent_c, 'a, 'b>: Foo<'a, 'b>;
fn foo<T, 'a, 'b, 'c>(...) -> MyFoo<T, 'static, 'static, 'static, 'a, 'b> { ... }
```
All of the in-scope (parent) generics are listed as parent generics of the anonymous type, with parent regions being replaced by `'static`. Parent regions referenced in the `impl Trait` return type are duplicated into the anonymous type's generics and mapped appropriately.

One case came up that wasn't specified in the RFC: it's possible to write a return type that contains multiple regions, neither of which outlives the other. In that case, it's not clear what the required lifetime of the output type should be, so we generate an error.

There's one remaining FIXME in one of the tests: `-> impl Foo<'a, 'b> + 'c` should be able to outlive both `'a` and `'b`, but not `'c`. Currently, it can't outlive any of them. @nikomatsakis and I have discussed this, and there are some complex interactions here if we ever allow `impl<'a, 'b> SomeTrait for AnonType<'a, 'b> { ... }`, so the plan is to hold off on this until we've got a better idea of what the interactions are here.

cc #34511.
Fixes #44727.
2017-11-21 10:00:18 +00:00
bors
bac7c53bc3 Auto merge of #45545 - durka:macro-backtrace, r=nrc
show macro backtrace with -Z flag

Fixes #39413 by adding a facility to restore the "old school" macro expansion backtraces (previously removed in 61865384b8).

The restored functionality is accessed through the flag `-Z external-macro-backtrace`. Errors showing the truncated backtraces will suggest this flag.

### Example

Code: <details>
`a/src/lib.rs`
```rust
#[macro_export]
macro_rules! a {
    () => { a!(@) };
    (@) => { a!(@@) };
    (@@) => {
        syntax error;
    }
}
```
`b/src/main.rs`
```rust
#[macro_use] extern crate a;

macro_rules! b {
    () => { b!(@) };
    (@) => { b!(@@) };
    (@@) => {
        syntax error;
    }
}

fn main() {
    a!();
    b!();
}
```
</details>

<br/><br/>
Running without env var (note: first error is from remote macro, second from local macro):

<details>

```
$ cargo +custom run
   Compiling b v0.1.0
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
  --> src/main.rs:12:5
   |
12 |     a!();
   |     ^^^^^
   |     |
   |     expected one of 8 possible tokens here
   |     unexpected token
   |
   = note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
  --> src/main.rs:7:16
   |
7  |         syntax error;
   |               -^^^^^ unexpected token
   |               |
   |               expected one of 8 possible tokens here
...
13 |     b!();
   |     ----- in this macro invocation

error: aborting due to 2 previous errors

error: Could not compile `b`.

To learn more, run the command again with --verbose.
```
</details>
The output is the same as today, except for an addition to the note which aids discoverability of the new environment variable.

<br/><br/>
Running _with_ env var:
<details>

```
$ RUST_MACRO_BACKTRACE=1 cargo +custom run
   Compiling b v0.1.0
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
 --> <a macros>:1:72
  |
1 | (  ) => { a ! ( @ ) } ; ( @ ) => { a ! ( @ @ ) } ; ( @ @ ) => { syntax error ;
  |                                                                       -^^^^^ unexpected token
  |                                                                       |
  |                                                                       expected one of 8 possible tokens here
src/main.rs:12:5: 12:10 note: in this expansion of a! (defined in <a macros>)
<a macros>:1:11: 1:20 note: in this expansion of a! (defined in <a macros>)
<a macros>:1:36: 1:47 note: in this expansion of a! (defined in <a macros>)

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
 --> src/main.rs:7:16
  |
7 |         syntax error;
  |               -^^^^^ unexpected token
  |               |
  |               expected one of 8 possible tokens here
src/main.rs:12:5: 12:10 note: in this expansion of a! (defined in <a macros>)
<a macros>:1:11: 1:20 note: in this expansion of a! (defined in <a macros>)
<a macros>:1:36: 1:47 note: in this expansion of a! (defined in <a macros>)

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
 --> src/main.rs:7:16
  |
7 |         syntax error;
  |               -^^^^^ unexpected token
  |               |
  |               expected one of 8 possible tokens here
src/main.rs:13:5: 13:10 note: in this expansion of b! (defined in src/main.rs)
src/main.rs:4:13: 4:18 note: in this expansion of b! (defined in src/main.rs)
src/main.rs:5:14: 5:20 note: in this expansion of b! (defined in src/main.rs)

error: aborting due to 2 previous errors

error: Could not compile `b`.

To learn more, run the command again with --verbose.
```
</details>

The output is hard to read, but better than nothing (and it's exactly what we used to have before the infamous `fix_multispans_in_std_macros`).

<br/><br/>
Wishlist:

- Save the actual source of macros in crate metadata, not just AST, so the output can be improved
    - Hopefully this would allow line numbers in the trace as well
- Show the actual macro invocations in the traces

r? @nrc
2017-11-21 06:42:14 +00:00
Alex Burka
b34a7ffb25 address review comments 2017-11-20 18:03:20 +00:00
Oliver Schneider
e7b2702172
Update ui test to rustc master 2017-11-20 12:42:38 +01:00
Oliver Schneider
78e269ee0b
Include rendered diagnostic in json 2017-11-20 09:37:54 +01:00
Oliver Schneider
2c2891b9f5
Add structured suggestions for proc macro use imports 2017-11-20 09:36:49 +01:00
Oliver Schneider
a24edb9bce
Add structured suggestions for trait imports 2017-11-20 09:17:27 +01:00
Alex Burka
7a5a1f9857 use -Z flag instead of env var 2017-11-19 22:30:14 +00:00
Alex Burka
bec62c2f12 update UI tests 2017-11-19 22:22:22 +00:00
Alex Burka
bcd1fedf03 add UI test 2017-11-19 22:22:22 +00:00
bors
f50fd075c2 Auto merge of #45225 - eddyb:trans-abi, r=arielb1
Refactor type memory layouts and ABIs, to be more general and easier to optimize.

To combat combinatorial explosion, type layouts are now described through 3 orthogonal properties:
* `Variants` describes the plurality of sum types (where applicable)
  * `Single` is for one inhabited/active variant, including all C `struct`s and `union`s
  * `Tagged` has its variants discriminated by an integer tag, including C `enum`s
  * `NicheFilling` uses otherwise-invalid values ("niches") for all but one of its inhabited variants
* `FieldPlacement` describes the number and memory offsets of fields (if any)
  * `Union` has all its fields at offset `0`
  * `Array` has offsets that are a multiple of its `stride`; guarantees all fields have one type
  * `Arbitrary` records all the field offsets, which can be out-of-order
* `Abi` describes how values of the type should be passed around, including for FFI
  * `Uninhabited` corresponds to no values, associated with unreachable control-flow
  * `Scalar` is ABI-identical to its only integer/floating-point/pointer "scalar component"
  * `ScalarPair` has two "scalar components", but only applies to the Rust ABI
  * `Vector` is for SIMD vectors, typically `#[repr(simd)]` `struct`s in Rust
  * `Aggregate` has arbitrary contents, including all non-transparent C `struct`s and `union`s

Size optimizations implemented so far:
* ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.:
  * `Option<!>` is 0 bytes
  * `Result<T, !>` has the same size as `T`
* using arbitrary niches, not just `0`, to represent a data-less variant, e.g.:
  * `Option<bool>`, `Option<Option<bool>>`, `Option<Ordering>` are all 1 byte
  * `Option<char>` is 4 bytes
* using a range of niches to represent *multiple* data-less variants, e.g.:
  * `enum E { A(bool), B, C, D }` is 1 byte

Code generation now takes advantage of `Scalar` and `ScalarPair` to, in more cases, pass around scalar components as immediates instead of indirectly, through pointers into temporary memory, while avoiding LLVM's "first-class aggregates", and there's more untapped potential here.

Closes #44426, fixes #5977, fixes #14540, fixes #43278.
2017-11-19 22:12:22 +00:00
Basile Desloges
094d67ee37 mir-borrowck: Remove parens in the lvalue description of a deref 2017-11-19 20:19:10 +01:00
Eduard-Mihai Burtescu
8437d7c0f1 rustc: extend the niche-filling enum optimization past 2 variants. 2017-11-19 02:43:56 +02:00
Eduard-Mihai Burtescu
ced5e04e8b rustc: optimize out uninhabited types and variants. 2017-11-19 02:14:33 +02:00
Eduard-Mihai Burtescu
b203a26efb rustc: generalize layout::Variants::NicheFilling to niches other than 0. 2017-11-19 02:14:33 +02:00
Eduard-Mihai Burtescu
bd86f3739e rustc: make Layout::NullablePointer a lot more like Layout::General. 2017-11-19 02:14:30 +02:00
Eduard-Mihai Burtescu
02276e9f49 rustc: collapse Layout::{Raw,StructWrapped}NullablePointer into one variant. 2017-11-19 02:14:30 +02:00
Eduard-Mihai Burtescu
8c4d5af52b rustc: remove Ty::layout and move everything to layout_of. 2017-11-19 02:14:29 +02:00
Eduard-Mihai Burtescu
bc8e1f7efa rustc: use an offset instead of a field path in Layout::StructWrappedNullablePointer. 2017-11-19 02:14:29 +02:00
bors
6160040d85 Auto merge of #46039 - oli-obk:test_suggestions, r=petrochenkov
Remove left over dead code from suggestion diagnostic refactoring

More cleanups after #41876 and #45741
2017-11-18 20:52:19 +00:00
Niko Matsakis
27bedfa36b give better error messages when a cycle arises 2017-11-18 07:49:52 -05:00
Niko Matsakis
5e0e8ae291 rename issue-21410.rs to ui/unboxed-closure-no-cyclic-sig.rs 2017-11-18 07:47:39 -05:00
Niko Matsakis
d0bda669ea move the signature into the closure type 2017-11-18 07:47:37 -05:00
Taylor Cramer
bc4810d907 Fix impl Trait Lifetime Handling
After this change, impl Trait existentials are
desugared to a new `abstract type` definition
paired with a set of lifetimes to apply.

In-scope generics are included as parents of the
`abstract type` generics. Parent regions are
replaced with static, and parent regions
referenced in the `impl Trait` type are duplicated
at the end of the `abstract type`'s generics.
2017-11-17 10:01:54 -08:00
Niko Matsakis
b224397b7c issue better error message when LUB/GLB diverge under new behavior 2017-11-17 10:32:15 -05:00
Esteban Küber
055910779a Use local spans only 2017-11-16 16:21:24 -08:00
bors
d0f8e2913a Auto merge of #45825 - nikomatsakis:nll-factor-region-inference, r=arielb1
integrate MIR type-checker with NLL inference

This branch refactors NLL type inference so that it uses the MIR type-checker to gather constraints. Along the way, it also refactors how region constraints are gathered in the normal inference context mildly. The new setup is like this:

- What used to be `region_inference` is split into two parts:
    - `region_constraints`, which just collects up sets of constraints
    - `lexical_region_resolve`, which does the iterative, lexical region resolution
- When `resolve_regions_and_report_errors` is invoked, the inference engine converts the constraints into final values.
- In the MIR type checker, however, we do not invoke this method, but instead periodically take the region constraints and package them up for the NLL solver to use later.
    - This allows us to track when and where those constraints were incurred.
    - We also remove the central fulfillment context from the MIR type checker, instead instantiating new fulfillment contexts at each point. This allows us to capture the set of obligations that occurred at a particular point, and also to ensure that if the same obligation arises at two points, we will enforce the region constraints at both locations.
- The MIR type checker is also enhanced to instantiate late-bound-regions with fresh variables and handle a few other corner cases that arose.
- I also extracted some of the 'outlives' logic from the regionck, which will be needed later (see future work) to handle the type-outlives relationships.

One concern I have with this branch: since the MIR type checker is used even without the `-Znll` switch, I'm not sure if it will impact performance. One simple fix here would be to only enable the MIR type-checker if debug-assertions are enabled, since it just serves to validate the MIR. Longer term I hope to address this by improving the interface to the trait solver to be more query-based (ongoing work).

There is plenty of future work left. Here are two things that leap to mind:

- **Type-region outlives.** Currently, the NLL solver will ICE if it is required to handle a constraint like `T: 'a`. Fixing this will require a small amount of refactoring to extract the implied bounds code. I plan to follow a file-up bug on this (hopefully with mentoring instructions).
- **Testing.** It's a good idea to enumerate some of the tricky scenarios that need testing, but I think it'd be nice to try and parallelize some of the actual test writing (and resulting bug fixing):
    - Same obligation occurring at two points.
    - Well-formedness and trait obligations of various kinds (which are not all processed by the current MIR type-checker).
    - More tests for how subtyping and region inferencing interact.
    - More suggestions welcome!

r? @arielb1
2017-11-16 20:56:26 +00:00
bors
58d8761ab3 Auto merge of #46029 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 6 pull requests

- Successful merges: #45951, #45973, #45984, #45993, #46005, #46010
- Failed merges:
2017-11-16 18:24:17 +00:00
Oliver Schneider
47c7e430d3
Remove left over dead code from suggestion diagnostic refactoring 2017-11-16 16:36:49 +01:00
Niko Matsakis
4b743da596 integrate NLL with MIR type-checker 2017-11-16 05:57:47 -05:00
Niko Matsakis
bea6b94273 fix error messages relating to removing lint for E0276 2017-11-16 05:57:44 -05:00
Guillaume Gomez
b09af7064e Rollup merge of #46005 - GuillaumeGomez:short-unstable, r=nrc
Set short-message feature unstable

Fixes #45995.

r? @nrc
2017-11-16 10:05:06 +01:00
bors
edd9dbcdbb Auto merge of #45985 - arielb1:unsafe-dedup, r=eddyb
check_unsafety: fix unused unsafe block duplication

The duplicate error message is later removed by error message
deduplication, but it still appears on beta and is still a bug.

r? @eddyb
2017-11-16 08:31:59 +00:00
Esteban Küber
f796fcd623 Point to ADT definition when not finding variant, method, assoc type 2017-11-15 23:24:58 -08:00
Niko Matsakis
98d5db3350 add a new test featuring two impl traits to show what it looks like 2017-11-15 15:46:01 -05:00
Christopher Vittal
f710d41f77 Add/Fix stderr references for impl Trait ui tests 2017-11-15 15:46:01 -05:00