mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +00:00 
			
		
		
		
	Add test cases
This commit is contained in:
		
							parent
							
								
									96ed889cdf
								
							
						
					
					
						commit
						dc075fd692
					
				
					 2 changed files with 130 additions and 2 deletions
				
			
		|  | @ -3102,6 +3102,105 @@ impl From<A> for B { | |||
| fn f() { | ||||
|     let a = A; | ||||
|     let b: B = a.into$0(); | ||||
| } | ||||
|         "#,
 | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|     fn goto_into_definition_if_exists() { | ||||
|         check( | ||||
|             r#" | ||||
| //- minicore: from
 | ||||
| struct A; | ||||
| 
 | ||||
| struct B; | ||||
| 
 | ||||
| impl Into<B> for A { | ||||
|     fn into(self) -> B { | ||||
|      //^^^^
 | ||||
|         B | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn f() { | ||||
|     let a = A; | ||||
|     let b: B = a.into$0(); | ||||
| } | ||||
|         "#,
 | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|     fn try_into_call_to_try_from_definition() { | ||||
|         check( | ||||
|             r#" | ||||
| //- minicore: from
 | ||||
| struct A; | ||||
| 
 | ||||
| struct B; | ||||
| 
 | ||||
| impl TryFrom<A> for B { | ||||
|     type Error = String; | ||||
| 
 | ||||
|     fn try_from(value: A) -> Result<Self, Self::Error> { | ||||
|      //^^^^^^^^
 | ||||
|         Ok(B) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn f() { | ||||
|     let a = A; | ||||
|     let b: Result<B, _> = a.try_into$0(); | ||||
| } | ||||
|         "#,
 | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|     fn goto_try_into_definition_if_exists() { | ||||
|         check( | ||||
|             r#" | ||||
| //- minicore: from
 | ||||
| struct A; | ||||
| 
 | ||||
| struct B; | ||||
| 
 | ||||
| impl TryInto<B> for A { | ||||
|     type Error = String; | ||||
| 
 | ||||
|     fn try_into(self) -> Result<B, Self::Error> { | ||||
|      //^^^^^^^^
 | ||||
|         Ok(B) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn f() { | ||||
|     let a = A; | ||||
|     let b: Result<B, _> = a.try_into$0(); | ||||
| } | ||||
|         "#,
 | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|     fn parse_call_to_from_str_definition() { | ||||
|         check( | ||||
|             r#" | ||||
| //- minicore: from, str
 | ||||
| struct A; | ||||
| 
 | ||||
| impl FromStr for A { | ||||
|     type Error = String; | ||||
| 
 | ||||
|     fn from_str(value: &str) -> Result<Self, Self::Error> { | ||||
|      //^^^^^^^^
 | ||||
|         Ok(A) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn f() { | ||||
|     let a: Result<A, _> = "aaaaaa".parse$0(); | ||||
| } | ||||
|         "#,
 | ||||
|         ); | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ | |||
| //!     error: fmt
 | ||||
| //!     fmt: option, result, transmute, coerce_unsized, copy, clone, derive
 | ||||
| //!     fn: tuple
 | ||||
| //!     from: sized
 | ||||
| //!     from: sized, result
 | ||||
| //!     future: pin
 | ||||
| //!     coroutine: pin
 | ||||
| //!     dispatch_from_dyn: unsize, pin
 | ||||
|  | @ -332,6 +332,25 @@ pub mod convert { | |||
|             t | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub trait TryFrom<T>: Sized { | ||||
|         type Error; | ||||
|         fn try_from(value: T) -> Result<Self, Self::Error>; | ||||
|     } | ||||
|     pub trait TryInto<T>: Sized { | ||||
|         type Error; | ||||
|         fn try_into(self) -> Result<T, Self::Error>; | ||||
|     } | ||||
| 
 | ||||
|     impl<T, U> TryInto<U> for T | ||||
|     where | ||||
|         U: TryFrom<T>, | ||||
|     { | ||||
|         type Error = U::Error; | ||||
|         fn try_into(self) -> Result<U, U::Error> { | ||||
|             U::try_from(self) | ||||
|         } | ||||
|     } | ||||
|     // endregion:from
 | ||||
| 
 | ||||
|     // region:as_ref
 | ||||
|  | @ -1532,6 +1551,15 @@ pub mod str { | |||
|     pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { | ||||
|         "" | ||||
|     } | ||||
|     pub trait FromStr: Sized { | ||||
|         type Err; | ||||
|         fn from_str(s: &str) -> Result<Self, Self::Err>; | ||||
|     } | ||||
|     impl str { | ||||
|         pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> { | ||||
|             FromStr::from_str(self) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| // endregion:str
 | ||||
| 
 | ||||
|  | @ -1791,7 +1819,7 @@ pub mod prelude { | |||
|             cmp::{Eq, PartialEq},                    // :eq
 | ||||
|             cmp::{Ord, PartialOrd},                  // :ord
 | ||||
|             convert::AsRef,                          // :as_ref
 | ||||
|             convert::{From, Into},                   // :from
 | ||||
|             convert::{From, Into, TryFrom, TryInto}, // :from
 | ||||
|             default::Default,                        // :default
 | ||||
|             iter::{IntoIterator, Iterator},          // :iterator
 | ||||
|             macros::builtin::{derive, derive_const}, // :derive
 | ||||
|  | @ -1806,6 +1834,7 @@ pub mod prelude { | |||
|             option::Option::{self, None, Some},      // :option
 | ||||
|             panic,                                   // :panic
 | ||||
|             result::Result::{self, Err, Ok},         // :result
 | ||||
|             str::FromStr,                            // :from
 | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 1hakusai1
						1hakusai1