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:
bors[bot] 2021-10-20 21:02:46 +00:00 committed by GitHub
commit 6877240fdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 386 additions and 62 deletions

View file

@ -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