mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
fix generated docs issue
This commit is contained in:
parent
6594235dd8
commit
1f9e02c74e
3 changed files with 72 additions and 23 deletions
|
@ -2,29 +2,29 @@ use crate::{AssistContext, AssistId, Assists};
|
||||||
use ra_syntax::{ast, ast::TypeParamsOwner, AstNode, SyntaxKind};
|
use ra_syntax::{ast, ast::TypeParamsOwner, AstNode, SyntaxKind};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
/// Assist: change_lifetime_anon_to_named
|
// Assist: change_lifetime_anon_to_named
|
||||||
///
|
//
|
||||||
/// Change an anonymous lifetime to a named lifetime.
|
// Change an anonymous lifetime to a named lifetime.
|
||||||
///
|
//
|
||||||
/// ```
|
// ```
|
||||||
/// impl Cursor<'_<|>> {
|
// impl Cursor<'_<|>> {
|
||||||
/// fn node(self) -> &SyntaxNode {
|
// fn node(self) -> &SyntaxNode {
|
||||||
/// match self {
|
// match self {
|
||||||
/// Cursor::Replace(node) | Cursor::Before(node) => node,
|
// Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
/// }
|
// }
|
||||||
/// }
|
// }
|
||||||
/// }
|
// }
|
||||||
/// ```
|
// ```
|
||||||
/// ->
|
// ->
|
||||||
/// ```
|
// ```
|
||||||
/// impl<'a> Cursor<'a> {
|
// impl<'a> Cursor<'a> {
|
||||||
/// fn node(self) -> &SyntaxNode {
|
// fn node(self) -> &SyntaxNode {
|
||||||
/// match self {
|
// match self {
|
||||||
/// Cursor::Replace(node) | Cursor::Before(node) => node,
|
// Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
/// }
|
// }
|
||||||
/// }
|
// }
|
||||||
/// }
|
// }
|
||||||
/// ```
|
// ```
|
||||||
// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
|
// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
|
||||||
pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||||
let lifetime_token = ctx.find_token_at_offset(SyntaxKind::LIFETIME)?;
|
let lifetime_token = ctx.find_token_at_offset(SyntaxKind::LIFETIME)?;
|
||||||
|
|
|
@ -268,6 +268,31 @@ pub mod std { pub mod collections { pub struct HashMap { } } }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn doctest_change_lifetime_anon_to_named() {
|
||||||
|
check_doc_test(
|
||||||
|
"change_lifetime_anon_to_named",
|
||||||
|
r#####"
|
||||||
|
impl Cursor<'_<|>> {
|
||||||
|
fn node(self) -> &SyntaxNode {
|
||||||
|
match self {
|
||||||
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#####,
|
||||||
|
r#####"
|
||||||
|
impl<'a> Cursor<'a> {
|
||||||
|
fn node(self) -> &SyntaxNode {
|
||||||
|
match self {
|
||||||
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#####,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn doctest_change_return_type_to_result() {
|
fn doctest_change_return_type_to_result() {
|
||||||
check_doc_test(
|
check_doc_test(
|
||||||
|
|
|
@ -259,6 +259,30 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `change_lifetime_anon_to_named`
|
||||||
|
|
||||||
|
Change an anonymous lifetime to a named lifetime.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// BEFORE
|
||||||
|
impl Cursor<'_┃> {
|
||||||
|
fn node(self) -> &SyntaxNode {
|
||||||
|
match self {
|
||||||
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AFTER
|
||||||
|
impl<'a> Cursor<'a> {
|
||||||
|
fn node(self) -> &SyntaxNode {
|
||||||
|
match self {
|
||||||
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## `change_return_type_to_result`
|
## `change_return_type_to_result`
|
||||||
|
|
||||||
Change the function's return type to Result.
|
Change the function's return type to Result.
|
||||||
|
|
Loading…
Reference in a new issue