rust/src/test
Dylan DPC ce14d6db5a
Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis
Provide suggestions for type parameters missing bounds for associated types

When implementing the binary operator traits it is easy to forget to restrict the `Output` associated type. `rustc` now accounts for different cases to lead users in the right direction to add the necessary restrictions. The structured suggestions in the following output are new:

```
error: equality constraints are not yet supported in `where` clauses
  --> $DIR/missing-bounds.rs:37:33
   |
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
   |                                 ^^^^^^^^^^^^^^^^^^^^^^ not supported
   |
   = note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
help: if `Output` is an associated type you're trying to set, use the associated type binding syntax
   |
LL | impl<B: Add> Add for E<B> where B: Add<Output = B> {
   |                                 ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
  --> $DIR/missing-bounds.rs:11:11
   |
7  | impl<B> Add for A<B> where B: Add {
   |      - this type parameter
...
11 |         A(self.0 + rhs.0)
   |           ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type
   |
   = note: expected type parameter `B`
             found associated type `<B as std::ops::Add>::Output`
help: consider further restricting this bound
   |
7  | impl<B> Add for A<B> where B: Add + std::ops::Add<Output = B> {
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0369]: cannot add `B` to `B`
  --> $DIR/missing-bounds.rs:31:21
   |
31 |         Self(self.0 + rhs.0)
   |              ------ ^ ----- B
   |              |
   |              B
   |
help: consider restricting type parameter `B`
   |
27 | impl<B: std::ops::Add<Output = B>> Add for D<B> {
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

That output is given for the following cases:

```rust
struct A<B>(B);
impl<B> Add for A<B> where B: Add {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        A(self.0 + rhs.0) //~ ERROR mismatched types
    }
}

struct D<B>(B);
impl<B> Add for D<B> {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Self(self.0 + rhs.0) //~ ERROR cannot add `B` to `B`
    }
}

struct E<B>(B);
impl<B: Add> Add for E<B> where <B as Add>::Output = B {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        Self(self.0 + rhs.0)
    }
}
```
2020-05-06 22:36:43 +02:00
..
assembly
auxiliary
codegen Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
codegen-units Keep codegen units unmerged when building compiler builtins 2020-04-06 00:00:00 +00:00
compile-fail Add Option to Force Unwind Tables 2020-05-04 12:08:35 +01:00
debuginfo Update the minimum external LLVM to 8 2020-04-14 12:44:41 -07:00
incremental Moving more build-pass tests to check-pass 2020-04-23 20:21:38 -07:00
mir-opt Rollup merge of #71697 - felix91gr:new_prop_into_fn_call, r=wesleywiser 2020-05-04 16:15:28 +02:00
pretty Update tests to use llvm_asm! 2020-03-26 15:49:22 +00:00
run-fail Auto merge of #70175 - Amanieu:remove_nlp, r=pnkfelix 2020-04-30 07:04:43 +00:00
run-make Use Cell::take in a couple places 2020-04-26 11:50:53 +02:00
run-make-fulldeps Auto merge of #70674 - cjgillot:query-arena-all, r=matthewjasper 2020-05-01 01:38:05 +00:00
run-pass-valgrind
rustdoc rustdoc supports const re-exports 2020-04-29 11:52:02 -04:00
rustdoc-js
rustdoc-js-std Add tests for new of variables 2020-03-16 18:30:26 +01:00
rustdoc-ui Add rustdoc regression test for the unused_braces lint 2020-04-24 19:15:07 +02:00
rustfix
ui Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
ui-fulldeps Remove support for self-opening 2020-04-25 10:55:20 -04:00
COMPILER_TESTS.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00