mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Merge #10563
10563: feat: Make "Generate getter" assist use semantic info r=agluszak a=agluszak This PR makes "Generate getter" assist use semantic info instead of dealing with types encoded as strings. Getters for types which are: - `Copy` no longer return references - `AsRef<str>` (i.e. `String`) return `&str` (instead of `&String`) - `AsRef<[T]>` (i.e. `Vec<T>`) return `&[T]` (instead of `&Vec<T>`) - `AsRef<T>` (i.e. `Box<T>`) return `&T` (instead of `&Box<T>`) - `Option<T>` return `Option<&T>` (instead of `&Option<T>`) - `Result<T, E>` return `Result<&T, &E>` (instead of `&Result<T, E>`) String, Vec, Box and Option were previously handled as special cases. Closes #10295 Co-authored-by: Andrzej Głuszak <gluszak.andrzej@gmail.com>
This commit is contained in:
commit
6877240fdf
9 changed files with 386 additions and 62 deletions
|
@ -35,6 +35,7 @@
|
|||
//! fmt: result
|
||||
//! bool_impl: option, fn
|
||||
//! add:
|
||||
//! as_ref: sized
|
||||
|
||||
pub mod marker {
|
||||
// region:sized
|
||||
|
@ -117,8 +118,9 @@ pub mod clone {
|
|||
}
|
||||
// endregion:clone
|
||||
|
||||
// region:from
|
||||
|
||||
pub mod convert {
|
||||
// region:from
|
||||
pub trait From<T>: Sized {
|
||||
fn from(_: T) -> Self;
|
||||
}
|
||||
|
@ -140,8 +142,14 @@ pub mod convert {
|
|||
t
|
||||
}
|
||||
}
|
||||
// endregion:from
|
||||
|
||||
// region:as_ref
|
||||
pub trait AsRef<T: ?Sized> {
|
||||
fn as_ref(&self) -> &T;
|
||||
}
|
||||
// endregion:as_ref
|
||||
}
|
||||
// endregion:from
|
||||
|
||||
pub mod ops {
|
||||
// region:coerce_unsized
|
||||
|
@ -613,6 +621,7 @@ pub mod prelude {
|
|||
cmp::{Eq, PartialEq}, // :eq
|
||||
cmp::{Ord, PartialOrd}, // :ord
|
||||
convert::{From, Into}, // :from
|
||||
convert::AsRef, // :as_ref
|
||||
default::Default, // :default
|
||||
iter::{IntoIterator, Iterator}, // :iterator
|
||||
macros::builtin::derive, // :derive
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue