rust/src
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
..
bootstrap Rollup merge of #71819 - jyn514:check-for-tools, r=Mark-Simulacrum 2020-05-06 16:58:57 +02:00
build_helper
ci ci: use bash when executing the "bors build finished" jobs 2020-04-29 16:32:32 +02:00
doc Rollup merge of #71897 - alexcrichton:embed-bitcode-docs, r=nnethercote 2020-05-05 12:55:13 +02:00
etc Enforce Python 3 as much as possible 2020-04-10 09:09:58 -04:00
liballoc Rollup merge of #71510 - ssomers:btreemap_iter_intertwined, r=Mark-Simulacrum 2020-05-06 13:22:05 +02:00
libarena
libcore Rollup merge of #71944 - ldm0:arrordhint, r=sfackler 2020-05-06 16:59:04 +02:00
libfmt_macros Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
libgraphviz
libpanic_abort Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
libpanic_unwind Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
libproc_macro Rollup merge of #68716 - petrochenkov:stabmixed, r=dtolnay 2020-04-27 03:26:05 +02:00
libprofiler_builtins Require compiler-rt root at ../src/llvm-project/compiler-rt 2020-04-11 17:49:16 -04:00
librustc_apfloat Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
librustc_ast Rollup merge of #71762 - tshepang:typo, r=jonas-schievink 2020-05-01 23:16:40 +02:00
librustc_ast_lowering Rollup merge of #71494 - flip1995:while_let_span, r=petrochenkov 2020-04-25 11:25:50 +02:00
librustc_ast_passes Add docstring to deny_equality_constraints 2020-05-04 11:09:10 -07:00
librustc_ast_pretty Remove unused dependencies 2020-04-20 17:59:27 +09:00
librustc_attr Add build script to rustc_attr because of cfg(version) 2020-05-03 02:42:12 +02:00
librustc_builtin_macros fix typo in function name 2020-05-04 18:27:23 -04:00
librustc_codegen_llvm Rollup merge of #69984 - lenary:lenary/force-uwtables, r=hanna-kruppe 2020-05-05 12:55:08 +02:00
librustc_codegen_ssa Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
librustc_data_structures perf: Lazily recive the Rollback argument in rollback_to 2020-05-05 11:24:36 +02:00
librustc_driver fix more clippy warnings 2020-04-26 02:24:01 +02:00
librustc_error_codes Add stability attribute to E0539 error examples 2020-05-03 00:25:45 +03:00
librustc_errors Rollup merge of #71489 - spastorino:fix-treat-err-as-bug-handling, r=eddyb 2020-04-28 13:12:14 +02:00
librustc_expand Implement confusable_idents lint. 2020-05-03 02:30:50 +08:00
librustc_feature Implement RFC 2523, #[cfg(version(..))] 2020-05-03 02:42:07 +02:00
librustc_fs_util
librustc_hir review comments: use or-pattern 2020-05-04 09:53:15 -07:00
librustc_hir_pretty Remove unused dependencies 2020-04-20 17:59:27 +09:00
librustc_incremental Don't copy bytecode files into the incr. comp. cache. 2020-05-01 08:14:39 -07:00
librustc_index Use assoc integer constants in librustc_* 2020-04-07 00:43:16 +02:00
librustc_infer Restore the snapshot/rollback optimization for region constraints 2020-05-05 11:25:12 +02:00
librustc_interface Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
librustc_lexer Revert "Rollup merge of #71372 - ayushmishra2005:shebang_stripping, r=estebank" 2020-04-28 13:02:58 +03:00
librustc_lint Rollup merge of #71773 - tshepang:links, r=davidtwco 2020-05-04 16:15:32 +02:00
librustc_llvm Don't skip building LLVM if already built 2020-05-02 18:43:55 -04:00
librustc_macros Monomorphise load_from_disk_and_cache_in_memory. 2020-05-01 14:29:35 +02:00
librustc_metadata Rollup merge of #71813 - ecstatic-morse:issue-71734, r=tmandry 2020-05-03 14:18:08 +05:30
librustc_middle Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
librustc_mir Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
librustc_mir_build Rollup merge of #71038 - lcnr:dyn_trait_structural_match, r=pnkfelix 2020-05-04 16:15:24 +02:00
librustc_parse Implement confusable_idents lint. 2020-05-03 02:30:50 +08:00
librustc_passes Rollup merge of #71777 - petrochenkov:crtype, r=Mark-Simulacrum 2020-05-02 18:27:39 +02:00
librustc_plugin_impl Remove support for self-opening 2020-04-25 10:55:20 -04:00
librustc_privacy Accept LocalDefId as key for check_mod_privacy query 2020-04-27 23:55:41 +01:00
librustc_query_system Auto merge of #71754 - alexcrichton:no-bitcode-in-cache, r=nnethercote 2020-05-04 14:14:55 +00:00
librustc_resolve resolve: Relax fresh binding disambiguation slightly to fix regression 2020-05-03 17:39:03 +03:00
librustc_save_analysis Accept LocalDefId as keyt for names_imported_by_glob_use 2020-04-27 21:50:17 +01:00
librustc_session Rollup merge of #71269 - Mark-Simulacrum:sat-float-casts, r=nikic 2020-05-06 16:58:50 +02:00
librustc_span Support liveness in rustc_peek tests 2020-05-03 11:36:11 -07:00
librustc_symbol_mangling Modify as_local_hir_id to return a bare HirId 2020-04-23 23:14:07 +01:00
librustc_target Auto merge of #71623 - petrochenkov:localink, r=estebank 2020-05-01 04:43:28 +00:00
librustc_trait_selection Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
librustc_traits Remove leftover chalk types 2020-05-01 14:39:05 -04:00
librustc_ty fix rustdoc warnings 2020-05-02 10:41:04 +02:00
librustc_typeck Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
librustdoc Rollup merge of #71787 - tshepang:rustdoc-warnings, r=varkor 2020-05-02 18:27:52 +02:00
libserialize Update src/libserialize/json.rs 2020-05-02 08:51:54 +02:00
libstd Rollup merge of #71591 - hermitcore:thread_create, r=hanna-kruppe 2020-05-06 16:58:53 +02:00
libterm Replace filter_map().next() calls with find_map() 2020-04-24 20:03:45 -07:00
libtest Add illumos triple 2020-04-14 20:36:07 +00:00
libunwind Use -fvisibility=hidden for libunwind 2020-05-05 12:41:23 -07:00
llvm-project@3ba91917e5 Store LLVM bitcode in object files, not compressed 2020-04-29 11:57:26 -07:00
rtstartup
rustc
rustllvm Auto merge of #71528 - alexcrichton:no-more-bitcode, r=nnethercote 2020-04-29 23:47:27 +00:00
stdarch@d10eefc622 Update stdarch submodule 2020-04-24 22:15:12 +01:00
test Rollup merge of #70908 - estebank:suggest-add, r=nikomatsakis 2020-05-06 22:36:43 +02:00
tools Auto merge of #71875 - Xanewok:update-rls, r=tmandry 2020-05-05 23:52:56 +00:00
README.md
stage0.txt Bump rustfmt to most recently shipped 2020-04-25 09:25:33 -04:00

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.