rust/compiler/rustc_middle/src
Matthias Krüger db77788dc5
Rollup merge of #132939 - uellenberg:suggest-deref, r=oli-obk
Suggest using deref in patterns

Fixes #132784

This changes the following code:
```rs
use std::sync::Arc;
fn main() {
    let mut x = Arc::new(Some(1));
    match x {
        Some(_) => {}
        None => {}
    }
}
```

to output
```rs
error[E0308]: mismatched types
  --> src/main.rs:5:9
   |
LL |     match x {
   |           - this expression has type `Arc<Option<{integer}>>`
...
LL |         Some(_) => {}
   |         ^^^^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>`
   |
   = note: expected struct `Arc<Option<{integer}>>`
                found enum `Option<_>`
help: consider dereferencing to access the inner value using the Deref trait
   |
LL |     match *x {
   |           ~~
```

instead of
```rs
error[E0308]: mismatched types
 --> src/main.rs:5:9
  |
4 |     match x {
  |           - this expression has type `Arc<Option<{integer}>>`
5 |         Some(_) => {}
  |         ^^^^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>`
  |
  = note: expected struct `Arc<Option<{integer}>>`
               found enum `Option<_>`
```

This makes it more obvious that a Deref is available, and gives a suggestion on how to use it in order to fix the issue at hand.
2024-12-14 23:56:28 +01:00
..
dep_graph Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
hir Remove hir::ArrayLen, introduce ConstArgKind::Infer 2024-11-30 21:00:31 +01:00
hooks Move some code from Compiler::enter to GlobalCtxt::finish 2024-11-09 17:55:39 +00:00
infer Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
middle Make dependency_formats an FxIndexMap rather than a list of tuples 2024-12-13 11:29:15 +00:00
mir Document the symbol Visibility enum 2024-12-13 19:14:10 +00:00
query Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
thir Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
traits Suggest using deref in patterns 2024-12-13 14:18:41 -08:00
ty (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
util Get rid of HIR const checker 2024-11-22 02:32:26 +00:00
arena.rs compiler: Directly use rustc_abi in metadata and middle 2024-11-03 13:38:47 -08:00
error.rs Move some code from Compiler::enter to GlobalCtxt::finish 2024-11-09 17:55:39 +00:00
lib.rs move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
lint.rs lints_that_dont_need_to_run: never skip future-compat-reported lints 2024-11-19 22:04:10 +01:00
macros.rs Improve const traits diagnostics for new desugaring 2024-10-02 19:45:17 +08:00
metadata.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
thir.rs Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
values.rs Rename ty_def_id so people will stop using it by accident 2024-12-13 16:36:38 +00:00