From 89a0e58393de0ae39fc1f33a33cec87bc084a9f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 22:47:02 +0300 Subject: internal: use minicore deref more --- crates/hir_ty/src/tests/traits.rs | 138 +++++++++++++------------------------- 1 file changed, 48 insertions(+), 90 deletions(-) (limited to 'crates/hir_ty/src/tests/traits.rs') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 0b6a3a1e9..279a1354a 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -853,12 +853,9 @@ fn test(t: T) { t.foo(); } fn generic_param_env_deref() { check_types( r#" -#[lang = "deref"] -trait Deref { - type Target; -} +//- minicore: deref trait Trait {} -impl Deref for T where T: Trait { +impl core::ops::Deref for T where T: Trait { type Target = i128; } fn test(t: T) { (*t); } @@ -1727,20 +1724,7 @@ fn test() { fn fn_trait_deref_with_ty_default() { check_infer( r#" -#[lang = "deref"] -trait Deref { - type Target; - - fn deref(&self) -> &Self::Target; -} - -#[lang="fn_once"] -trait FnOnce { - type Output; - - fn call_once(self, args: Args) -> Self::Output; -} - +//- minicore: deref, fn struct Foo; impl Foo { @@ -1753,7 +1737,7 @@ impl Lazy { pub fn new(f: F) -> Lazy {} } -impl T> Deref for Lazy { +impl T> core::ops::Deref for Lazy { type Target = T; } @@ -1767,32 +1751,29 @@ fn test() { let r2 = lazy2.foo(); }"#, expect![[r#" - 64..68 'self': &Self - 165..169 'self': Self - 171..175 'args': Args - 239..243 'self': &Foo - 254..256 '{}': () - 334..335 'f': F - 354..356 '{}': () - 443..689 '{ ...o(); }': () - 453..458 'lazy1': Lazy Foo> - 475..484 'Lazy::new': fn new Foo>(|| -> Foo) -> Lazy Foo> - 475..492 'Lazy::...| Foo)': Lazy Foo> - 485..491 '|| Foo': || -> Foo - 488..491 'Foo': Foo - 502..504 'r1': usize - 507..512 'lazy1': Lazy Foo> - 507..518 'lazy1.foo()': usize - 560..575 'make_foo_fn_ptr': fn() -> Foo - 591..602 'make_foo_fn': fn make_foo_fn() -> Foo - 612..617 'lazy2': Lazy Foo> - 634..643 'Lazy::new': fn new Foo>(fn() -> Foo) -> Lazy Foo> - 634..660 'Lazy::...n_ptr)': Lazy Foo> - 644..659 'make_foo_fn_ptr': fn() -> Foo - 670..672 'r2': usize - 675..680 'lazy2': Lazy Foo> - 675..686 'lazy2.foo()': usize - 549..551 '{}': () + 36..40 'self': &Foo + 51..53 '{}': () + 131..132 'f': F + 151..153 '{}': () + 251..497 '{ ...o(); }': () + 261..266 'lazy1': Lazy Foo> + 283..292 'Lazy::new': fn new Foo>(|| -> Foo) -> Lazy Foo> + 283..300 'Lazy::...| Foo)': Lazy Foo> + 293..299 '|| Foo': || -> Foo + 296..299 'Foo': Foo + 310..312 'r1': usize + 315..320 'lazy1': Lazy Foo> + 315..326 'lazy1.foo()': usize + 368..383 'make_foo_fn_ptr': fn() -> Foo + 399..410 'make_foo_fn': fn make_foo_fn() -> Foo + 420..425 'lazy2': Lazy Foo> + 442..451 'Lazy::new': fn new Foo>(fn() -> Foo) -> Lazy Foo> + 442..468 'Lazy::...n_ptr)': Lazy Foo> + 452..467 'make_foo_fn_ptr': fn() -> Foo + 478..480 'r2': usize + 483..488 'lazy2': Lazy Foo> + 483..494 'lazy2.foo()': usize + 357..359 '{}': () "#]], ); } @@ -2941,28 +2922,13 @@ fn infer_box_fn_arg() { // The type mismatch is because we don't define Unsize and CoerceUnsized check_infer_with_mismatches( r#" -//- /lib.rs deps:std - -#[lang = "fn_once"] -pub trait FnOnce { - type Output; - - extern "rust-call" fn call_once(self, args: Args) -> Self::Output; -} - -#[lang = "deref"] -pub trait Deref { - type Target: ?Sized; - - fn deref(&self) -> &Self::Target; -} - +//- minicore: fn, deref, option #[lang = "owned_box"] pub struct Box { inner: *mut T, } -impl Deref for Box { +impl core::ops::Deref for Box { type Target = T; fn deref(&self) -> &T { @@ -2970,38 +2936,30 @@ impl Deref for Box { } } -enum Option { - None, - Some(T) -} - fn foo() { - let s = Option::None; + let s = None; let f: Box)> = box (|ps| {}); f(&s); }"#, expect![[r#" - 100..104 'self': Self - 106..110 'args': Args - 214..218 'self': &Self - 384..388 'self': &Box - 396..423 '{ ... }': &T - 406..417 '&self.inner': &*mut T - 407..411 'self': &Box - 407..417 'self.inner': *mut T - 478..576 '{ ...&s); }': () - 488..489 's': Option - 492..504 'Option::None': Option - 514..515 'f': Box)> - 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> - 554..561 '|ps| {}': |{unknown}| -> () - 555..557 'ps': {unknown} - 559..561 '{}': () - 568..569 'f': Box)> - 568..573 'f(&s)': () - 570..572 '&s': &Option - 571..572 's': Option - 549..562: expected Box)>, got Box<|{unknown}| -> ()> + 154..158 'self': &Box + 166..193 '{ ... }': &T + 176..187 '&self.inner': &*mut T + 177..181 'self': &Box + 177..187 'self.inner': *mut T + 206..296 '{ ...&s); }': () + 216..217 's': Option + 220..224 'None': Option + 234..235 'f': Box)> + 269..282 'box (|ps| {})': Box<|{unknown}| -> ()> + 274..281 '|ps| {}': |{unknown}| -> () + 275..277 'ps': {unknown} + 279..281 '{}': () + 288..289 'f': Box)> + 288..293 'f(&s)': () + 290..292 '&s': &Option + 291..292 's': Option + 269..282: expected Box)>, got Box<|{unknown}| -> ()> "#]], ); } -- cgit v1.2.3