rust-analyzer/crates/hir_ty/src
bors[bot] 855b00cbe6
Merge #7570 #7571
7570: Add doc gen to the `generate_enum_match_method` assist r=yoshuawuyts a=yoshuawuyts

Implements a small extension to https://github.com/rust-analyzer/rust-analyzer/pull/7562, generating default comments. I wasn't sure if this would fit the goals of Rust-Analyzer, so I chose to split it into a separate PR. This is especially useful when writing code in a codebase which uses `#![warn(missing_docs)]` lint, as many production-grade libraries do.

The comments we're generating here are similar to the ones found on [`Option::is_some`](https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some) and [`Result::is_err`](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err). I briefly considered only generating these for `pub` types, but they seem small and unobtrusive enough that they're probably useful in the general case. Thanks!

## Example

__input__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```

__output__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    /// Returns `true` if the variant is [`Minor`].
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

This opens up the path to adding an assist for generating these comments on existing `is_` methods. This would make it both easy to document new code, and update existing code with documentation.

7571: Cleanup decl_check r=Veykril a=Veykril

bors r+

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-05 15:17:41 +00:00
..
diagnostics Merge #7570 #7571 2021-02-05 15:17:41 +00:00
infer Use block_def_map in body lowering 2021-02-03 14:21:15 +01:00
tests Handle box with allocator 2021-01-22 13:50:23 +01:00
traits Bump chalk 2021-02-02 17:40:01 +02:00
autoderef.rs Rename ra_hir_ty -> hir_ty 2020-08-13 16:35:29 +02:00
db.rs Remove map module from la-arena public API 2021-01-15 11:14:04 +11:00
diagnostics.rs Cleanup decl_check 2021-02-05 16:09:45 +01:00
display.rs Make ModuleId's krate field private 2021-01-22 18:09:55 +01:00
infer.rs Make ModPath's representation private 2021-02-04 20:49:24 +01:00
lib.rs Classify function calls as functions when shadowed by types 2021-01-28 19:08:55 +01:00
lower.rs Make ModuleId's krate field private 2021-01-22 18:09:55 +01:00
method_resolution.rs Make ModuleId's krate field private 2021-01-22 18:09:55 +01:00
op.rs Rename ra_hir_ty -> hir_ty 2020-08-13 16:35:29 +02:00
primitive.rs Rename ra_hir_ty -> hir_ty 2020-08-13 16:35:29 +02:00
test_db.rs Create all ModuleIds through a DefMap method 2021-01-25 15:21:33 +01:00
tests.rs Make ModuleId's krate field private 2021-01-22 18:09:55 +01:00
traits.rs Upgrade Chalk 2020-12-07 11:48:58 +01:00
utils.rs Higher-ranked trait bounds for where clauses 2020-12-17 22:01:42 +01:00