Commit Graph

398 Commits

Author SHA1 Message Date
Esteban Küber 10d9bf1767 Use note for requirement source span 2020-06-15 09:06:58 -07:00
Esteban Küber 31ea589a06 review comments: wording 2020-06-15 09:06:58 -07:00
Esteban Küber 539e9783df Tweak wording and add error code 2020-06-15 09:06:57 -07:00
Esteban Küber bc15790609 Tweak output for overlapping required/captured spans 2020-06-15 09:06:57 -07:00
Esteban Küber e75588934c Move overlapping span to a note 2020-06-15 09:06:57 -07:00
Esteban Küber 921f35fe73 Reduce verbosity of suggestion message and mention lifetime in label 2020-06-15 09:06:57 -07:00
Esteban Küber 4e90f177cc When `'static` is explicit, suggest constraining argument with it 2020-06-15 09:06:57 -07:00
Esteban Küber 81c909488e Suggest substituting `'static` lifetime in impl/dyn `Trait + 'static` return types 2020-06-15 09:06:57 -07:00
Matthew Jasper f97070db90 Forbid lifetime elision in let position impl Trait
This is consistent with types.
2020-06-11 16:24:01 +01:00
Matthew Jasper 4e49e67c44 Stop special casing top level TAIT 2020-06-11 16:24:01 +01:00
Dylan DPC 024f025934
Rollup merge of #73005 - Aaron1011:fix/error-overflow, r=estebank
Don't create impl candidates when obligation contains errors

Fixes #72839

In PR #72621, trait selection was modified to no longer bail out early
when an error type was encountered. This allowed us treat `ty::Error` as
`Sized`, causing us to avoid emitting a spurious "not sized" error after
a type error had already occured.

However, this means that we may now try to match an impl candidate
against the error type. Since the error type will unify with almost
anything, this can cause us to infinitely recurse (eventually triggering
an overflow) when trying to verify certain `where` clauses.

This commit causes us to skip generating any impl candidates when an
error type is involved.
2020-06-10 11:03:43 +02:00
Dylan DPC 14dc34dd89
Rollup merge of #72260 - csmoe:issue-69276, r=estebank
Spell out `Self` in async function return

Closes #69276
r? @tmandry
2020-06-05 13:07:03 +02:00
Aaron Hill 3295c262ae
Treat selection error as ambiguous when error type is present 2020-06-04 21:09:31 -04:00
csmoe 9be635306c resolve error code e0760 2020-06-04 09:37:32 +08:00
Matthew Jasper 8894bd220b Add descriptions for all queries 2020-05-31 20:15:32 +01:00
Esteban Küber 83f6f22358 Tweak wording and spans of `'static` `dyn Trait`/`impl Trait` requirements 2020-05-30 10:22:27 -07:00
Esteban Küber 8f7ee34379 Tweak type parameter errors to reduce verbosity 2020-05-30 10:22:26 -07:00
Esteban Küber 731ea85f21 review comment: tweak wording and account for span overlap 2020-05-30 10:22:26 -07:00
Esteban Küber 65f492be12 Account for returned `dyn Trait` evaluating to `'static` lifetime
Provide a suggestion for `dyn Trait + '_` when possible.
2020-05-30 10:22:26 -07:00
Yuki Okushi 125f0abb42
Add test for #68532 2020-05-27 00:48:37 +09:00
Yuki Okushi ca722b9358
Add test for #56445 2020-05-27 00:48:37 +09:00
Matthew Jasper f9f3063cfa Update tests 2020-05-22 18:03:08 +01:00
csmoe 2f311b07c8 Merge branch 'master' into issue-69276 2020-05-19 11:02:29 +08:00
csmoe 8841ede364 bless suggestion on spell out 2020-05-18 08:44:38 +08:00
Ralf Jung aecab5e603
Rollup merge of #72045 - RalfJung:incomplete-unsound, r=petrochenkov
Incomplete features can also be unsound

Some incomplete features do not just ICE, they are also currently unsound (e.g. https://github.com/rust-lang/rust/pull/72029, and also `specialization` -- which is not yet marked incomplete but [should be](https://github.com/rust-lang/rust/pull/71420)). This makes the message reflect that.

While at it I also added a link to the tracking issue, which hopefully should explain what is incomplete/unsound about the feature.
2020-05-16 19:46:29 +02:00
bors ed084b0b83 Auto merge of #69659 - CAD97:step-rework-take-3, r=Amanieu
Rework the std::iter::Step trait

Previous attempts: #43127 #62886 #68807
Tracking issue: #42168

This PR reworks the `Step` trait to be phrased in terms of the *successor* and *predecessor* operations. With this, `Step` hopefully has a consistent identity that can have a path towards stabilization. The proposed trait:

```rust
/// Objects that have a notion of *successor* and *predecessor* operations.
///
/// The *successor* operation moves towards values that compare greater.
/// The *predecessor* operation moves towards values that compare lesser.
///
/// # Safety
///
/// This trait is `unsafe` because its implementation must be correct for
/// the safety of `unsafe trait TrustedLen` implementations, and the results
/// of using this trait can otherwise be trusted by `unsafe` code to be correct
/// and fulful the listed obligations.
pub unsafe trait Step: Clone + PartialOrd + Sized {
    /// Returns the number of *successor* steps required to get from `start` to `end`.
    ///
    /// Returns `None` if the number of steps would overflow `usize`
    /// (or is infinite, or if `end` would never be reached).
    ///
    /// # Invariants
    ///
    /// For any `a`, `b`, and `n`:
    ///
    /// * `steps_between(&a, &b) == Some(n)` if and only if `Step::forward(&a, n) == Some(b)`
    /// * `steps_between(&a, &b) == Some(n)` if and only if `Step::backward(&a, n) == Some(a)`
    /// * `steps_between(&a, &b) == Some(n)` only if `a <= b`
    ///   * Corollary: `steps_between(&a, &b) == Some(0)` if and only if `a == b`
    ///   * Note that `a <= b` does _not_ imply `steps_between(&a, &b) != None`;
    ///     this is the case wheen it would require more than `usize::MAX` steps to get to `b`
    /// * `steps_between(&a, &b) == None` if `a > b`
    fn steps_between(start: &Self, end: &Self) -> Option<usize>;

    /// Returns the value that would be obtained by taking the *successor*
    /// of `self` `count` times.
    ///
    /// If this would overflow the range of values supported by `Self`, returns `None`.
    ///
    /// # Invariants
    ///
    /// For any `a`, `n`, and `m`:
    ///
    /// * `Step::forward_checked(a, n).and_then(|x| Step::forward_checked(x, m)) == Step::forward_checked(a, m).and_then(|x| Step::forward_checked(x, n))`
    ///
    /// For any `a`, `n`, and `m` where `n + m` does not overflow:
    ///
    /// * `Step::forward_checked(a, n).and_then(|x| Step::forward_checked(x, m)) == Step::forward_checked(a, n + m)`
    ///
    /// For any `a` and `n`:
    ///
    /// * `Step::forward_checked(a, n) == (0..n).try_fold(a, |x, _| Step::forward_checked(&x, 1))`
    ///   * Corollary: `Step::forward_checked(&a, 0) == Some(a)`
    fn forward_checked(start: Self, count: usize) -> Option<Self>;

    /// Returns the value that would be obtained by taking the *successor*
    /// of `self` `count` times.
    ///
    /// If this would overflow the range of values supported by `Self`,
    /// this function is allowed to panic, wrap, or saturate.
    /// The suggested behavior is to panic when debug assertions are enabled,
    /// and to wrap or saturate otherwise.
    ///
    /// Unsafe code should not rely on the correctness of behavior after overflow.
    ///
    /// # Invariants
    ///
    /// For any `a`, `n`, and `m`, where no overflow occurs:
    ///
    /// * `Step::forward(Step::forward(a, n), m) == Step::forward(a, n + m)`
    ///
    /// For any `a` and `n`, where no overflow occurs:
    ///
    /// * `Step::forward_checked(a, n) == Some(Step::forward(a, n))`
    /// * `Step::forward(a, n) == (0..n).fold(a, |x, _| Step::forward(x, 1))`
    ///   * Corollary: `Step::forward(a, 0) == a`
    /// * `Step::forward(a, n) >= a`
    /// * `Step::backward(Step::forward(a, n), n) == a`
    fn forward(start: Self, count: usize) -> Self {
        Step::forward_checked(start, count).expect("overflow in `Step::forward`")
    }

    /// Returns the value that would be obtained by taking the *successor*
    /// of `self` `count` times.
    ///
    /// # Safety
    ///
    /// It is undefined behavior for this operation to overflow the
    /// range of values supported by `Self`. If you cannot guarantee that this
    /// will not overflow, use `forward` or `forward_checked` instead.
    ///
    /// # Invariants
    ///
    /// For any `a`:
    ///
    /// * if there exists `b` such that `b > a`, it is safe to call `Step::forward_unchecked(a, 1)`
    /// * if there exists `b`, `n` such that `steps_between(&a, &b) == Some(n)`,
    ///   it is safe to call `Step::forward_unchecked(a, m)` for any `m <= n`.
    ///
    /// For any `a` and `n`, where no overflow occurs:
    ///
    /// * `Step::forward_unchecked(a, n)` is equivalent to `Step::forward(a, n)`
    #[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
    unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
        Step::forward(start, count)
    }

    /// Returns the value that would be obtained by taking the *successor*
    /// of `self` `count` times.
    ///
    /// If this would overflow the range of values supported by `Self`, returns `None`.
    ///
    /// # Invariants
    ///
    /// For any `a`, `n`, and `m`:
    ///
    /// * `Step::backward_checked(a, n).and_then(|x| Step::backward_checked(x, m)) == n.checked_add(m).and_then(|x| Step::backward_checked(a, x))`
    /// * `Step::backward_checked(a, n).and_then(|x| Step::backward_checked(x, m)) == try { Step::backward_checked(a, n.checked_add(m)?) }`
    ///
    /// For any `a` and `n`:
    ///
    /// * `Step::backward_checked(a, n) == (0..n).try_fold(a, |x, _| Step::backward_checked(&x, 1))`
    ///   * Corollary: `Step::backward_checked(&a, 0) == Some(a)`
    fn backward_checked(start: Self, count: usize) -> Option<Self>;

    /// Returns the value that would be obtained by taking the *predecessor*
    /// of `self` `count` times.
    ///
    /// If this would overflow the range of values supported by `Self`,
    /// this function is allowed to panic, wrap, or saturate.
    /// The suggested behavior is to panic when debug assertions are enabled,
    /// and to wrap or saturate otherwise.
    ///
    /// Unsafe code should not rely on the correctness of behavior after overflow.
    ///
    /// # Invariants
    ///
    /// For any `a`, `n`, and `m`, where no overflow occurs:
    ///
    /// * `Step::backward(Step::backward(a, n), m) == Step::backward(a, n + m)`
    ///
    /// For any `a` and `n`, where no overflow occurs:
    ///
    /// * `Step::backward_checked(a, n) == Some(Step::backward(a, n))`
    /// * `Step::backward(a, n) == (0..n).fold(a, |x, _| Step::backward(x, 1))`
    ///   * Corollary: `Step::backward(a, 0) == a`
    /// * `Step::backward(a, n) <= a`
    /// * `Step::forward(Step::backward(a, n), n) == a`
    fn backward(start: Self, count: usize) -> Self {
        Step::backward_checked(start, count).expect("overflow in `Step::backward`")
    }

    /// Returns the value that would be obtained by taking the *predecessor*
    /// of `self` `count` times.
    ///
    /// # Safety
    ///
    /// It is undefined behavior for this operation to overflow the
    /// range of values supported by `Self`. If you cannot guarantee that this
    /// will not overflow, use `backward` or `backward_checked` instead.
    ///
    /// # Invariants
    ///
    /// For any `a`:
    ///
    /// * if there exists `b` such that `b < a`, it is safe to call `Step::backward_unchecked(a, 1)`
    /// * if there exists `b`, `n` such that `steps_between(&b, &a) == Some(n)`,
    ///   it is safe to call `Step::backward_unchecked(a, m)` for any `m <= n`.
    ///
    /// For any `a` and `n`, where no overflow occurs:
    ///
    /// * `Step::backward_unchecked(a, n)` is equivalent to `Step::backward(a, n)`
    #[unstable(feature = "unchecked_math", reason = "niche optimization path", issue = "none")]
    unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
        Step::backward(start, count)
    }
}
```

Note that all of these are associated functions and not callable via method syntax; the calling syntax is always `Step::forward(start, n)`. This version of the trait additionally changes the stepping functions to talk their arguments by value.

As opposed to previous attempts which provided a "step by one" method directly, this version of the trait only exposes "step by n". There are a few reasons for this:

- `Range*`, the primary consumer of `Step`, assumes that the "step by n" operation is cheap. If a single step function is provided, it will be a lot more enticing to implement "step by n" as n repeated calls to "step by one". While this is not strictly incorrect, this behavior would be surprising for anyone used to using `Range<{primitive integer}>`.
- With a trivial default impl, this can be easily added backwards-compatibly later.
- The debug-wrapping "step by n" needs to exist for `RangeFrom` to be consistent between "step by n" and "step by one" operation. (Note: the behavior is not changed by this PR, but making the behavior consistent is made tenable by this PR.)

Three "kinds" of step are provided: `_checked`, which returns an `Option` indicating attempted overflow; (unsuffixed), which provides "safe overflow" behavior (is allowed to panic, wrap, or saturate, depending on what is most convenient for a given type); and `_unchecked`, which is a version which assumes overflow does not happen.

Review is appreciated to check that:

- The invariants as described on the `Step` functions are enough to specify the "common sense" consistency for successor/predecessor.
- Implementation of `Step` functions is correct in the face of overflow and the edges of representable integers.
- Added tests of `Step` functions are asserting the correct behavior (and not just the implemented behavior).
2020-05-15 11:24:50 +00:00
Ralf Jung 6a8cf4a17c adjust tests 2020-05-09 14:40:17 +02:00
Andy Russell 9f88d75710
reword "possible candidate" import suggestion 2020-05-07 00:33:25 -04:00
Esteban Küber 3a795fba03 On type mismatch involving associated type, suggest constraint
When an associated type is found when a specific type was expected, if
possible provide a structured suggestion constraining the associated
type in a bound.

```
error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
  --> $DIR/associated-types-multiple-types-one-trait.rs:13:5
   |
LL |     want_y(t);
   |     ^^^^^^ expected `i32`, found associated type
...
LL | fn want_y<T:Foo<Y=i32>>(t: &T) { }
   |                 ----- required by this bound in `want_y`
   |
   = note:         expected type `i32`
           found associated type `<T as Foo>::Y`
help: consider constraining the associated type `<T as Foo>::Y` to `i32`
   |
LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T)
   |                             ^^^^^^^^^
```

```
error[E0308]: mismatched types
  --> $DIR/trait-with-missing-associated-type-restriction.rs:12:9
   |
LL |     qux(x.func())
   |         ^^^^^^^^ expected `usize`, found associated type
   |
   = note:         expected type `usize`
           found associated type `<impl Trait as Trait>::A`
help: consider constraining the associated type `<impl Trait as Trait>::A` to `usize`
   |
LL | fn foo(x: impl Trait<A = usize>) {
   |                     ^^^^^^^^^^
```
2020-05-02 18:23:46 -07:00
Dylan DPC 09f3c908bb
Rollup merge of #70950 - nikomatsakis:leak-check-nll-2, r=matthewjasper
extend NLL checker to understand `'empty` combined with universes

This PR extends the NLL region checker to understand `'empty` combined with universes. In particular, it means that the NLL region checker no longer considers `exists<R2> { forall<R1> { R1: R2 } }` to be provable. This is work towards https://github.com/rust-lang/rust/issues/59490, but we're not all the way there. One thing in particular it does not address is error messages.

The modifications to the NLL region inference code turned out to be simpler than expected. The main change is to require that if `R1: R2` then `universe(R1) <= universe(R2)`.

This constraint follows from the region lattice (shown below), because we assume then that `R2` is "at least" `empty(Universe(R2))`, and hence if `R1: R2` (i.e., `R1 >= R2` on the lattice) then `R1` must be in some universe that can name `'empty(Universe(R2))`, which requires that `Universe(R1) <= Universe(R2)`.

```
static ----------+-----...------+       (greatest)
|                |              |
early-bound and  |              |
free regions     |              |
|                |              |
scope regions    |              |
|                |              |
empty(root)   placeholder(U1)   |
|            /                  |
|           /         placeholder(Un)
empty(U1) --         /
|                   /
...                /
|                 /
empty(Un) --------                      (smallest)
```

I also made what turned out to be a somewhat unrelated change to add a special region to represent `'empty(U0)`, which we use (somewhat hackily) to indicate well-formedness checks in some parts of the compiler. This fixes #68550.

I did some investigation into fixing the error message situation. That's a bit trickier: the existing "nice region error" code around placeholders relies on having better error tracing than NLL currently provides, so that it knows (e.g.) that the constraint arose from applying a trait impl and things like that. I feel like I was hoping *not* to do such fine-grained tracing in NLL, and it seems like we...largely...got away with that. I'm not sure yet if we'll have to add more tracing information or if there is some sort of alternative.

It's worth pointing out though that I've not kind of shifted my opinion on whose job it should be to enforce lifetimes: I tend to think we ought to be moving back towards *something like* the leak-check (just not the one we *had*). If we took that approach, it would actually resolve this aspect of the error message problem, because we would be resolving 'higher-ranked errors' in the trait solver itself, and hence we wouldn't have to thread as much causal information back to the region checker. I think it would also help us with removing the leak check while not breaking some of the existing crates out there.

Regardless, I think it's worth landing this change, because it was relatively simple and it aligns the set of programs that NLL accepts with those that are accepted by the main region checker, and hence should at least *help* us in migration (though I guess we still also have to resolve the existing crates that rely on leak check for coherence).

r? @matthewjasper
2020-04-30 20:15:20 +02:00
Esteban Küber e536257061 Ensure tail expression will have a `Ty` for E0746
When the return type is `!Sized` we look for all the returned
expressions in the body to fetch their types and provide a reasonable
suggestion. The tail expression of the body is normally evaluated after
checking whether the return type is `Sized`. Changing the order of the
evaluation produces undesirable knock down effects, so we detect the
specific case that newcomers are likely to encounter ,returning a single
bare trait object, and only in that case we evaluate the tail
expression's type so that the suggestion will be accurate.
2020-04-20 11:17:03 -07:00
Esteban Küber d3c96f03b5 Suggest `-> impl Trait` and `-> Box<dyn Trait>` on fn that doesn't return
During development, a function could have a return type set that is a
bare trait object by accident. We already suggest using either a boxed
trait object or `impl Trait` if the return paths will allow it. We now
do so too when there are *no* return paths or they all resolve to `!`.
We still don't handle cases where the trait object is *not* the entirety
of the return type gracefully.
2020-04-20 09:24:41 -07:00
Niko Matsakis b8caef423d reserve variable for empty root region 2020-04-16 11:03:41 +00:00
RoccoDev b85c64c3ea
rustc: Add a warning count upon completion 2020-04-11 16:15:24 +02:00
Mazdak Farrokhzad 1fe86f47d8
Rollup merge of #69745 - estebank:predicate-obligations-3, r=nikomatsakis,eddyb
Use `PredicateObligation`s instead of `Predicate`s

Keep more information about trait binding failures. Use more specific spans by pointing at bindings that introduce obligations.

Subset of #69709.

r? @eddyb
2020-04-10 18:15:16 +02:00
Esteban Küber d605a9d969 Small tweaks to required bound span 2020-04-08 14:40:51 -07:00
Alex Aktsipetrov aaebbe196b Suggest move for closures and async blocks in more cases. 2020-04-08 13:01:53 +02:00
CAD97 2fcfd233f7 Redesign the Step trait 2020-04-08 02:24:16 -04:00
Esteban Küber 0664b81915 Use smaller span for suggestion restricting lifetime 2020-04-05 16:16:55 -07:00
Eduard-Mihai Burtescu 8deff18529 tests: remove ignore directives from tests that mention core/alloc/std spans. 2020-04-02 11:48:34 +03:00
Dylan DPC b99db6ee10
Rollup merge of #70546 - lqd:polonius_update, r=nikomatsakis
Polonius: update to 0.12.1, fix more move errors false positives, update test expectations

This PR:
- updates `polonius-engine` to version 0.12.1 to fix some move errors false positives
- fixes a fact generation mistake creating the other move errors false positives
- updates the test expectations for the polonius compare-mode so that all (minus the 2 OOMs) ui tests pass again (matching the [analysis doc](https://hackmd.io/CjYB0fs4Q9CweyeTdKWyEg?view) starting at case 34)

In my opinion, this is safe to rollup.

r? @nikomatsakis
2020-03-30 16:24:49 +02:00
Remy Rakic 82424634a3 bless output of ui test impl-trait/multiple-lifetimes/error-handling.rs
Some impl Trait fixes lead to locating more accurately the cause of
a universal region error with a user annotation
2020-03-30 01:28:27 +02:00
Esteban Küber 2c71894657 Tweak `suggest_constraining_type_param`
Some of the bound restriction structured suggestions were incorrect
while others had subpar output.
2020-03-29 13:13:17 -07:00
Aaron Hill 96e2d03d4b
Store idents for `DefPathData` into crate metadata
Previously, we threw away the `Span` associated with a definition's
identifier when we encoded crate metadata, causing us to lose location
and hygiene information.

We now store the identifier's `Span` in the crate metadata.
When we decode items from the metadata, we combine
the name and span back into an `Ident`.

This improves the output of several tests, which previously had messages
suppressed due to dummy spans.

This is a prerequisite for #68686, since throwing away a `Span` means
that we lose hygiene information.
2020-03-22 23:40:19 -04:00
Yuki Okushi ef98ec055e
Add FIXMEs 2020-03-09 16:50:46 +09:00
Yuki Okushi 579ce86d4b
Add test for issue-67166 2020-03-09 09:12:53 +09:00
Yuki Okushi 0005f29d89
Add test for issue-60473 2020-03-09 09:12:25 +09:00
Yuki Okushi 437c07f662
Add test for issue-57201 2020-03-09 09:12:06 +09:00
Yuki Okushi fc8be08a8e
Add test for issue-57200 2020-03-09 09:11:58 +09:00
Matthias Krüger 136ad015b6 fix various typos 2020-03-06 15:19:31 +01:00
Esteban Küber c764a82310 keep predicate order and tweak output 2020-02-28 11:37:59 -08:00
Esteban Küber 1e7bcc733a Tweak wording 2020-02-28 11:37:59 -08:00
Esteban Küber 0387f0d19b Mention the full path of the implementing trait 2020-02-28 11:37:59 -08:00
Esteban Küber 8993b99ae2 On single local candidate, use span label 2020-02-28 11:37:58 -08:00
Esteban Küber c816430f99 Tweak binding lifetime suggestion text
We already have a structured suggestion, but the wording made it seem
like that wasn't the case.
Fix #65286. r? @varkor
2020-02-19 18:04:03 -08: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 5cfa7d1dfb Handle equal regions in opaque type inference 2020-02-14 22:40:03 +00:00
Matthew Jasper 93ac5bc7de Update tests 2020-02-14 22:40:03 +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
Matthew Jasper 033bd8c7af Explain a test 2020-02-14 20:12:45 +00:00
bors dc4242d905 Auto merge of #68929 - matprec:consistent-issue-references, r=Dylan-DPC
Make issue references consistent

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

cc https://github.com/rust-lang/rust/pull/63008

r? @varkor because you reviewed the original pr
2020-02-11 02:00:27 +00:00
bors 840bdc349d Auto merge of #67665 - Patryk27:master, r=zackmdavis
Improve reporting errors and suggestions for trait bounds

Fix #66802

- When printing errors for unsized function parameter, properly point at the parameter instead of function's body.
- Improve `consider further restricting this bound` (and related) messages by separating human-oriented hints from the machine-oriented ones.
2020-02-09 22:13:05 +00:00
Matthias Prechtl 7b555178ae --bless --compare-mode=nll 2020-02-09 20:43:49 +01:00
Patryk Wychowaniec a8d34c1062
Improve reporting errors and suggestions for trait bounds 2020-02-09 10:33:47 +01:00
Esteban Küber 3cdd7ae59e review comment 2020-02-08 21:08:59 -08:00
Esteban Küber a52ec87a17 Use more appropriate spans on object unsafe traits and provide structured suggestions when possible 2020-02-02 11:53:10 -08:00
Esteban Küber 413bfa4b98 Wording changes to object unsafe trait errors
Stemming from the thread at https://twitter.com/indygreg/status/1223279056398929920
2020-02-02 11:53:10 -08:00
Esteban Küber 0eb29d1a44 fix test 2020-02-02 11:52:34 -08:00
Mazdak Farrokhzad 3a7f1edd81
Rollup merge of #68760 - Tyg13:compile_fail_ui_test, r=Centril
Issue error on `compile-fail` header in UI test

Fixes #68732

r? @Centril
2020-02-02 14:15:49 +01:00
Tyler Lanphear f6c3894724 compiletest: error if `compile-fail` header in ui test. 2020-02-02 02:08:30 -05:00
Jonas Schievink 791123d2c4 Deduplicate generator interior types 2020-02-01 20:02:56 +01:00
Esteban Küber d493dccef7 Apply `resolve_vars_if_possible` to returned types for more accurate suggestions 2020-01-24 11:48:17 -08:00
Esteban Küber d14a323e74 Use more accurate return path spans
No longer suggest `Box::new(if foo { Type1 } else { Type2 })`, instead
suggesting `if foo { Box::new(Type1) } else { Box::new(Type2) }`.
2020-01-24 10:35:13 -08:00
Esteban Küber 55dce720b2 Account for `ty::Error` when suggesting `impl Trait` or `Box<dyn Trait>` 2020-01-23 17:04:09 -08:00
Esteban Küber 00e2626895 Account for object safety when suggesting `Box<dyn Trait>` 2020-01-16 09:49:14 -08:00
Esteban Küber d7a6212401 review comments 2020-01-16 09:49:14 -08:00
Esteban Küber 509cb33dbc review comments 2020-01-16 09:49:13 -08:00
Esteban Küber 5b36c187dc review comments 2020-01-16 09:49:13 -08:00
Esteban Küber 4c13d2555c Add E0746 explanation to the index 2020-01-16 09:37:24 -08:00
Esteban Küber e1dd8a9095 When trait bounds are missing for return values, point at them 2020-01-16 09:37:24 -08:00
Esteban Küber ea7e885204 Elide E0308 errors in favor of E0746
When a type error involves a `dyn Trait` as the return type, do not emit
the type error, as the "return type is not `Sized`" error will provide
enough information to the user.
2020-01-16 09:37:24 -08:00
Esteban Küber 75eabb17ae Account for diverging types in return `impl Trait` 2020-01-16 09:37:24 -08:00
Esteban Küber 6fd564112f Specific error for unsized `dyn Trait` return type
Suggest `impl Trait` when possible, and `Box<dyn Trait>` otherwise.
2020-01-16 09:37:24 -08:00
csmoe 4eb47ded54 wrap expr id into GeneratorInteriorTypeCause 2020-01-15 15:13:51 +08:00
Yuki Okushi a491100aa3
Rollup merge of #68014 - estebank:unify-e0599, r=cramertj
Unify output of "variant not found" errors

Fix #49566.
2020-01-11 04:50:48 +09:00
Mazdak Farrokhzad aabb03763d
Rollup merge of #66463 - estebank:point-at-closure-and-opaque-types, r=Centril
Point at opaque and closure type definitions in type errors

Fixes #57266, fixes #67117.
2020-01-10 02:47:29 +01:00
Vadim Petrochenkov 642669c74d Update tests 2020-01-09 21:23:12 +03:00
Esteban Küber 0dcdbaec0b Point at the def span of trait refs E0277 2020-01-08 09:30:27 -08:00
Esteban Küber c55615155d review comments 2020-01-08 09:29:47 -08:00
Esteban Küber 9c0000caca Point at opaque and closure type definitions in type errors 2020-01-08 09:29:47 -08:00
Esteban Küber 2c5766f2d4 Unify output of "variant not found" errors 2020-01-08 08:05:31 -08:00
Esteban Küber 2905f14b67 Account for `type X = impl Trait;` in lifetime suggestion 2020-01-06 13:36:06 -08:00
Ohad Ravid 1a4f6b85a7 Change wording for lifetime suggestion for opaque types from `constraint` to `bound` 2019-12-31 12:13:35 +01:00
Ohad Ravid d4fbb55c9c Suggest adding a lifetime constraint when opaque type is responsible for "does not live long enough" error 2019-12-30 18:10:46 +01:00
Esteban Küber 90bf0d2e33 Ignore i586-unknown-linux-gnu and i586-unknown-musl in tests 2019-12-28 12:26:48 -08:00
Remy Rakic 720716f9d0 bless polonius output due to lacking the 'static special-casing 2019-12-06 11:50:02 +01:00
Aaron Hill 4b57d2228b
Fix opaque types resulting from projections in function signature
When we normalize the types in a function signature, we may end up
resolving a projection to an opaque type (e.g. `Self::MyType` when
we have `type MyType = impl SomeTrait`). When the projection is
resolved, we will instantiate the generic parameters into fresh
inference variables.

While we do want to normalize projections to opaque types, we don't want
to replace the explicit generic parameters (e.g. `T` in `impl
MyTrait<T>`) with inference variables. We want the opaque type in the
function signature to be eligible to be a defining use of that opaque
type - adding inference variables prevents this, since the opaque type
substs now appears to refer to some specific type, rather than a generic
type.

To resolve this issue, we inspect the opaque types in the function
signature after normalization. Any inference variables in the substs are
replaced with the corresponding generic parameter in the identity substs
(e.g. `T` in `impl MyTrait<T>`). Note that normalization is the only way
that we can end up with inference variables in opaque substs in a
function signature - users have no way of getting inference variables
into a function signature.

Note that all of this refers to the opaque type (ty::Opaque) and its
subst - *not* to the underlying type.

Fixes #59342
2019-11-24 14:37:23 -05:00
Esteban Küber 34f03c01f6 Point at type in `let` assignment on type errors 2019-11-21 19:24:31 -08:00
bors 53712f8637 Auto merge of #66389 - estebank:type-err-labels, r=petrochenkov
Specific labels when referring to "expected" and "found" types
2019-11-21 17:53:19 +00:00