#[test]
fn coerce_autoderef_generic() {
check_infer_with_mismatches(
- r"
- struct Foo;
- fn takes_ref<T>(x: &T) -> T { *x }
- fn test() {
- takes_ref(&Foo);
- takes_ref(&&Foo);
- takes_ref(&&&Foo);
- }
- ",
+ r#"
+struct Foo;
+fn takes_ref<T>(x: &T) -> T { *x }
+fn test() {
+ takes_ref(&Foo);
+ takes_ref(&&Foo);
+ takes_ref(&&&Foo);
+}
+"#,
expect![[r"
28..29 'x': &T
40..46 '{ *x }': T
fn coerce_autoderef_block() {
check_infer_with_mismatches(
r#"
- struct String {}
- #[lang = "deref"]
- trait Deref { type Target; }
- impl Deref for String { type Target = str; }
- fn takes_ref_str(x: &str) {}
- fn returns_string() -> String { loop {} }
- fn test() {
- takes_ref_str(&{ returns_string() });
- }
- "#,
- expect![[r"
- 126..127 'x': &str
- 135..137 '{}': ()
- 168..179 '{ loop {} }': String
- 170..177 'loop {}': !
- 175..177 '{}': ()
- 190..235 '{ ... }); }': ()
- 196..209 'takes_ref_str': fn takes_ref_str(&str)
- 196..232 'takes_...g() })': ()
- 210..231 '&{ ret...ng() }': &String
- 211..231 '{ retu...ng() }': String
- 213..227 'returns_string': fn returns_string() -> String
- 213..229 'return...ring()': String
- "]],
+//- minicore: deref
+struct String {}
+impl core::ops::Deref for String { type Target = str; }
+fn takes_ref_str(x: &str) {}
+fn returns_string() -> String { loop {} }
+fn test() {
+ takes_ref_str(&{ returns_string() });
+}
+"#,
+ expect![[r#"
+ 90..91 'x': &str
+ 99..101 '{}': ()
+ 132..143 '{ loop {} }': String
+ 134..141 'loop {}': !
+ 139..141 '{}': ()
+ 154..199 '{ ... }); }': ()
+ 160..173 'takes_ref_str': fn takes_ref_str(&str)
+ 160..196 'takes_...g() })': ()
+ 174..195 '&{ ret...ng() }': &String
+ 175..195 '{ retu...ng() }': String
+ 177..191 'returns_string': fn returns_string() -> String
+ 177..193 'return...ring()': String
+ "#]],
);
}
fn method_resolution_unsize_array() {
check_types(
r#"
-#[lang = "slice"]
-impl<T> [T] {
- fn len(&self) -> usize { loop {} }
-}
+//- minicore: slice
fn test() {
let a = [1, 2, 3];
a.len();
fn autoderef_visibility_field() {
check_infer(
r#"
-#[lang = "deref"]
-pub trait Deref {
- type Target;
- fn deref(&self) -> &Self::Target;
-}
+//- minicore: deref
mod a {
pub struct Foo(pub char);
pub struct Bar(i32);
Self(0)
}
}
- impl super::Deref for Bar {
+ impl core::ops::Deref for Bar {
type Target = Foo;
fn deref(&self) -> &Foo {
&Foo('z')
}
"#,
expect![[r#"
- 67..71 'self': &Self
- 200..231 '{ ... }': Bar
- 214..218 'Self': Bar(i32) -> Bar
- 214..221 'Self(0)': Bar
- 219..220 '0': i32
- 315..319 'self': &Bar
- 329..362 '{ ... }': &Foo
- 343..352 '&Foo('z')': &Foo
- 344..347 'Foo': Foo(char) -> Foo
- 344..352 'Foo('z')': Foo
- 348..351 ''z'': char
- 392..439 '{ ... }': ()
- 406..407 'x': char
- 410..428 'super:...r::new': fn new() -> Bar
- 410..430 'super:...:new()': Bar
- 410..432 'super:...ew().0': char
+ 107..138 '{ ... }': Bar
+ 121..125 'Self': Bar(i32) -> Bar
+ 121..128 'Self(0)': Bar
+ 126..127 '0': i32
+ 226..230 'self': &Bar
+ 240..273 '{ ... }': &Foo
+ 254..263 '&Foo('z')': &Foo
+ 255..258 'Foo': Foo(char) -> Foo
+ 255..263 'Foo('z')': Foo
+ 259..262 ''z'': char
+ 303..350 '{ ... }': ()
+ 317..318 'x': char
+ 321..339 'super:...r::new': fn new() -> Bar
+ 321..341 'super:...:new()': Bar
+ 321..343 'super:...ew().0': char
"#]],
)
}
//!
//! Available flags:
//! sized:
+//! slice:
//! unsize: sized
+//! deref: sized
//! coerce_unsized: unsize
pub mod marker {
}
pub mod ops {
+ // region:coerce_unsized
mod unsize {
- // region:coerce_unsized
use crate::marker::Unsize;
#[lang = "coerce_unsized"]
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
- // endregion:coerce_unsized
}
+ pub use self::unsize::CoerceUnsized;
+ // endregion:coerce_unsized
- pub use self::unsize::CoerceUnsized; // :coerce_unsized
+ // region:deref
+ mod deref {
+ #[lang = "deref"]
+ pub trait Deref {
+ #[lang = "deref_target"]
+ type Target: ?Sized;
+ fn deref(&self) -> &Self::Target;
+ }
+ }
+ pub use self::deref::Deref;
+ // endregion:deref
+}
+
+// region:slice
+pub mod slice {
+ #[lang = "slice"]
+ impl<T> [T] {
+ pub fn len(&self) -> usize { loop {} }
+ }
}
+// endregion:slice
pub mod prelude {
pub mod v1 {