mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-15 13:52:59 +00:00
Insert #[must_use] in generate_getter
This commit is contained in:
parent
98143da799
commit
e5adbd88e9
@ -39,6 +39,7 @@ use crate::{
|
|||||||
//
|
//
|
||||||
// impl Person {
|
// impl Person {
|
||||||
// /// Get a reference to the person's name.
|
// /// Get a reference to the person's name.
|
||||||
|
// #[must_use]
|
||||||
// fn $0name(&self) -> &str {
|
// fn $0name(&self) -> &str {
|
||||||
// self.name.as_ref()
|
// self.name.as_ref()
|
||||||
// }
|
// }
|
||||||
@ -65,6 +66,7 @@ pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<
|
|||||||
//
|
//
|
||||||
// impl Person {
|
// impl Person {
|
||||||
// /// Get a mutable reference to the person's name.
|
// /// Get a mutable reference to the person's name.
|
||||||
|
// #[must_use]
|
||||||
// fn $0name_mut(&mut self) -> &mut String {
|
// fn $0name_mut(&mut self) -> &mut String {
|
||||||
// &mut self.name
|
// &mut self.name
|
||||||
// }
|
// }
|
||||||
@ -143,6 +145,7 @@ pub(crate) fn generate_getter_impl(
|
|||||||
format_to!(
|
format_to!(
|
||||||
buf,
|
buf,
|
||||||
" /// Get {}the {}'s {}.
|
" /// Get {}the {}'s {}.
|
||||||
|
#[must_use]
|
||||||
{}fn {}(&{}self) -> {} {{
|
{}fn {}(&{}self) -> {} {{
|
||||||
{}
|
{}
|
||||||
}}",
|
}}",
|
||||||
@ -195,6 +198,7 @@ struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a reference to the context's data.
|
/// Get a reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
fn $0data(&self) -> &Data {
|
fn $0data(&self) -> &Data {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
@ -216,6 +220,7 @@ struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a mutable reference to the context's data.
|
/// Get a mutable reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
fn $0data_mut(&mut self) -> &mut Data {
|
fn $0data_mut(&mut self) -> &mut Data {
|
||||||
&mut self.data
|
&mut self.data
|
||||||
}
|
}
|
||||||
@ -249,6 +254,7 @@ struct Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
#[must_use]
|
||||||
fn data_mut(&mut self) -> &mut Data {
|
fn data_mut(&mut self) -> &mut Data {
|
||||||
&mut self.data
|
&mut self.data
|
||||||
}
|
}
|
||||||
@ -273,6 +279,7 @@ pub(crate) struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a reference to the context's data.
|
/// Get a reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
pub(crate) fn $0data(&self) -> &Data {
|
pub(crate) fn $0data(&self) -> &Data {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
@ -293,6 +300,7 @@ struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a reference to the context's data.
|
/// Get a reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
fn data(&self) -> &Data {
|
fn data(&self) -> &Data {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
@ -306,11 +314,13 @@ struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a reference to the context's data.
|
/// Get a reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
fn data(&self) -> &Data {
|
fn data(&self) -> &Data {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to the context's count.
|
/// Get a reference to the context's count.
|
||||||
|
#[must_use]
|
||||||
fn $0count(&self) -> &usize {
|
fn $0count(&self) -> &usize {
|
||||||
&self.count
|
&self.count
|
||||||
}
|
}
|
||||||
@ -337,6 +347,7 @@ struct S { foo: String }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get a reference to the s's foo.
|
/// Get a reference to the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> &String {
|
fn $0foo(&self) -> &String {
|
||||||
&self.foo
|
&self.foo
|
||||||
}
|
}
|
||||||
@ -361,6 +372,7 @@ struct S { foo: bool }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get the s's foo.
|
/// Get the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> bool {
|
fn $0foo(&self) -> bool {
|
||||||
self.foo
|
self.foo
|
||||||
}
|
}
|
||||||
@ -394,6 +406,7 @@ struct S { foo: String }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get a reference to the s's foo.
|
/// Get a reference to the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> &str {
|
fn $0foo(&self) -> &str {
|
||||||
self.foo.as_ref()
|
self.foo.as_ref()
|
||||||
}
|
}
|
||||||
@ -431,6 +444,7 @@ struct S { foo: Box<Sweets> }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get a reference to the s's foo.
|
/// Get a reference to the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> &Sweets {
|
fn $0foo(&self) -> &Sweets {
|
||||||
self.foo.as_ref()
|
self.foo.as_ref()
|
||||||
}
|
}
|
||||||
@ -464,6 +478,7 @@ struct S { foo: Vec<()> }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get a reference to the s's foo.
|
/// Get a reference to the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> &[()] {
|
fn $0foo(&self) -> &[()] {
|
||||||
self.foo.as_ref()
|
self.foo.as_ref()
|
||||||
}
|
}
|
||||||
@ -487,6 +502,7 @@ struct S { foo: Option<Failure> }
|
|||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
/// Get a reference to the s's foo.
|
/// Get a reference to the s's foo.
|
||||||
|
#[must_use]
|
||||||
fn $0foo(&self) -> Option<&Failure> {
|
fn $0foo(&self) -> Option<&Failure> {
|
||||||
self.foo.as_ref()
|
self.foo.as_ref()
|
||||||
}
|
}
|
||||||
@ -510,6 +526,7 @@ struct Context {
|
|||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
/// Get a reference to the context's data.
|
/// Get a reference to the context's data.
|
||||||
|
#[must_use]
|
||||||
fn $0data(&self) -> Result<&bool, &i32> {
|
fn $0data(&self) -> Result<&bool, &i32> {
|
||||||
self.data.as_ref()
|
self.data.as_ref()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1036,6 +1036,7 @@ struct Person {
|
|||||||
|
|
||||||
impl Person {
|
impl Person {
|
||||||
/// Get a reference to the person's name.
|
/// Get a reference to the person's name.
|
||||||
|
#[must_use]
|
||||||
fn $0name(&self) -> &str {
|
fn $0name(&self) -> &str {
|
||||||
self.name.as_ref()
|
self.name.as_ref()
|
||||||
}
|
}
|
||||||
@ -1060,6 +1061,7 @@ struct Person {
|
|||||||
|
|
||||||
impl Person {
|
impl Person {
|
||||||
/// Get a mutable reference to the person's name.
|
/// Get a mutable reference to the person's name.
|
||||||
|
#[must_use]
|
||||||
fn $0name_mut(&mut self) -> &mut String {
|
fn $0name_mut(&mut self) -> &mut String {
|
||||||
&mut self.name
|
&mut self.name
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user