rust/compiler
Esteban Küber 0487500776 Provide better suggestions when encountering a bare trait as a type
Add the following suggestions:

```
error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/not-on-bare-trait-2021.rs:11:11
   |
LL | fn bar(x: Foo) -> Foo {
   |           ^^^
   |
help: use a generic type parameter, constrained by the trait `Foo`
   |
LL | fn bar<T: Foo>(x: T) -> Foo {
   |       ++++++++    ~
help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference
   |
LL | fn bar(x: impl Foo) -> Foo {
   |           ++++
help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch
   |
LL | fn bar(x: &dyn Foo) -> Foo {
   |           ++++

error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/not-on-bare-trait-2021.rs:11:19
   |
LL | fn bar(x: Foo) -> Foo {
   |                   ^^^
   |
help: use `impl Foo` to return an opaque type, as long as you return a single underlying type
   |
LL | fn bar(x: Foo) -> impl Foo {
   |                   ++++
help: alternatively, you can return an owned trait object
   |
LL | fn bar(x: Foo) -> Box<dyn Foo> {
   |                   +++++++    +
```
2024-01-03 18:59:42 +00:00
..
rustc Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_abi Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_arena rustc_arena: add alloc_str 2023-12-05 17:52:51 -08:00
rustc_ast Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_ast_lowering Auto merge of #119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillot 2023-12-30 22:44:33 +00:00
rustc_ast_passes Introduce const Trait (always-const trait bounds) 2023-12-27 12:51:32 +01:00
rustc_ast_pretty Auto merge of #119105 - dtolnay:paren, r=WaffleLapkin 2023-12-27 21:27:26 +00:00
rustc_attr Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_builtin_macros Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_codegen_cranelift Merge commit '6d355f6844323db03bfd608899613e363e701951' into sync_cg_clif-2023-12-31 2023-12-31 13:29:53 +00:00
rustc_codegen_gcc Auto merge of #118705 - WaffleLapkin:codegen-atomic-exhange-untuple, r=cjgillot 2023-12-30 07:42:19 +00:00
rustc_codegen_llvm Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_codegen_ssa Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_const_eval Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_data_structures Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank 2023-12-26 12:27:29 +00:00
rustc_error_codes rustc_error_codes: Update expected error in E0453.md 2023-12-28 19:46:40 +01:00
rustc_error_messages Remove rustc_error_messages/messages.ftl. 2023-11-26 08:37:27 +11:00
rustc_errors rustc_lint: Make LintLevelsProvider::current_specs() return &FxIndexMap 2023-12-31 14:35:28 +01:00
rustc_expand Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_feature Rollup merge of #119235 - Urgau:missing-feature-gate-sanitizer-cfi-cfgs, r=Nilstrieb 2023-12-26 13:29:13 -05:00
rustc_fluent_macro Add a useful comment. 2023-11-26 08:38:02 +11:00
rustc_fs_util Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_graphviz remove unused pub fn 2023-11-23 14:11:02 +03:00
rustc_hir Auto merge of #119259 - cjgillot:single-crate-id, r=Mark-Simulacrum 2023-12-29 14:37:40 +00:00
rustc_hir_analysis Provide better suggestions when encountering a bare trait as a type 2024-01-03 18:59:42 +00:00
rustc_hir_pretty Make closures carry their own ClosureKind, rather than deducing what it is from movability 2023-12-25 16:29:15 +00:00
rustc_hir_typeck Auto merge of #118911 - Young-Flash:fix_issue_118819, r=fmease 2023-12-29 18:39:23 +00:00
rustc_incremental Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_index Mention the relevant tracking issue next to my bit_set hack 2023-12-23 00:04:20 +01:00
rustc_index_macros Put backticks around some attributes in doc comments. 2023-11-27 09:37:01 +11:00
rustc_infer Auto merge of #116012 - cjgillot:gvn-const, r=oli-obk 2023-12-30 03:45:58 +00:00
rustc_interface Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank 2023-12-26 12:27:29 +00:00
rustc_lexer Rename some unescaping functions. 2023-12-13 14:17:50 +11:00
rustc_lint rustc_lint: Enforce rustc::potential_query_instability lint 2023-12-31 14:50:57 +01:00
rustc_lint_defs Auto merge of #116274 - RalfJung:soft_unstable, r=cjgillot 2023-12-25 16:26:15 +00:00
rustc_llvm Rollup merge of #118941 - krasimirgg:llvm-cov, r=nikic 2023-12-18 17:03:11 +01:00
rustc_log rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
rustc_macros Add level arg to into_diagnostic. 2023-12-19 09:19:25 +11:00
rustc_metadata Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_middle rustc_lint: Make LintLevelsProvider::current_specs() return &FxIndexMap 2023-12-31 14:35:28 +01:00
rustc_mir_build Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_mir_dataflow Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_mir_transform Auto merge of #119438 - Zalathar:prepare-mappings, r=cjgillot 2023-12-30 13:39:44 +00:00
rustc_monomorphize Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
rustc_next_trait_solver Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_parse Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_parse_format Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstrieb 2023-11-15 14:55:35 +00:00
rustc_passes Rollup merge of #119402 - est31:fix_if_guard_unused, r=compiler-errors 2023-12-29 11:19:28 +01:00
rustc_pattern_analysis Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_privacy Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_query_impl Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank 2023-12-26 12:27:29 +00:00
rustc_query_system Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors 2023-12-26 02:24:39 +00:00
rustc_resolve Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_serialize Call FileEncoder::finish in rmeta encoding 2023-11-22 22:49:22 -05:00
rustc_session Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_smir Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_span Rollup merge of #119235 - Urgau:missing-feature-gate-sanitizer-cfi-cfgs, r=Nilstrieb 2023-12-26 13:29:13 -05:00
rustc_symbol_mangling Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_target Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
rustc_trait_selection Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_traits add unused NormalizesTo predicate 2023-12-07 17:52:51 +01:00
rustc_transmute Update itertools to 0.11. 2023-11-22 08:13:21 +11:00
rustc_ty_utils Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_type_ir Update to bitflags 2 in the compiler 2023-12-30 18:17:28 +01:00
stable_mir Restore movability to SMIR 2023-12-28 16:35:01 +00:00