From 991919e71f048f9321e702512248e11c6c5fef70 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 22:37:03 +0300 Subject: internal: add index to minicore --- crates/hir_ty/src/tests/traits.rs | 45 ++++++--------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index dd1ea817f..0b6a3a1e9 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -567,11 +567,11 @@ fn indexing_arrays() { fn infer_ops_index() { check_types( r#" -//- /main.rs crate:main deps:std +//- minicore: index struct Bar; struct Foo; -impl std::ops::Index for Bar { +impl core::ops::Index for Bar { type Output = Foo; } @@ -580,15 +580,6 @@ fn test() { let b = a[1u32]; b; } //^ Foo - -//- /std.rs crate:std -#[prelude_import] use ops::*; -mod ops { - #[lang = "index"] - pub trait Index { - type Output; - } -} "#, ); } @@ -597,16 +588,16 @@ mod ops { fn infer_ops_index_int() { check_types( r#" -//- /main.rs crate:main deps:std +//- minicore: index struct Bar; struct Foo; -impl std::ops::Index for Bar { +impl core::ops::Index for Bar { type Output = Foo; } struct Range; -impl std::ops::Index for Bar { +impl core::ops::Index for Bar { type Output = Bar; } @@ -616,15 +607,6 @@ fn test() { b; //^ Foo } - -//- /std.rs crate:std -#[prelude_import] use ops::*; -mod ops { - #[lang = "index"] - pub trait Index { - type Output; - } -} "#, ); } @@ -633,25 +615,12 @@ mod ops { fn infer_ops_index_autoderef() { check_types( r#" -//- /main.rs crate:main deps:std +//- minicore: index, slice fn test() { let a = &[1u32, 2, 3]; - let b = a[1u32]; + let b = a[1]; b; } //^ u32 - -//- /std.rs crate:std -impl ops::Index for [T] { - type Output = T; -} - -#[prelude_import] use ops::*; -mod ops { - #[lang = "index"] - pub trait Index { - type Output; - } -} "#, ); } -- cgit v1.2.3 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/regression.rs | 42 +++++------ crates/hir_ty/src/tests/traits.rs | 138 ++++++++++++---------------------- 2 files changed, 67 insertions(+), 113 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 94b628fb8..0f418ea49 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -792,6 +792,7 @@ fn issue_4800() { fn issue_4966() { check_infer( r#" + //- minicore: deref pub trait IntoIterator { type Item; } @@ -802,12 +803,7 @@ fn issue_4966() { struct Vec {} - #[lang = "deref"] - pub trait Deref { - type Target; - } - - impl Deref for Vec { + impl core::ops::Deref for Vec { type Target = [T]; } @@ -824,23 +820,23 @@ fn issue_4966() { } "#, expect![[r#" - 270..274 'iter': T - 289..291 '{}': () - 303..447 '{ ...r(); }': () - 313..318 'inner': Map<|&f64| -> f64> - 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64> - 330..343 '|_: &f64| 0.0': |&f64| -> f64 - 331..332 '_': &f64 - 340..343 '0.0': f64 - 356..362 'repeat': Repeat f64>> - 365..390 'Repeat...nner }': Repeat f64>> - 383..388 'inner': Map<|&f64| -> f64> - 401..404 'vec': Vec f64>>>> - 407..416 'from_iter': fn from_iter f64>>>, Repeat f64>>>(Repeat f64>>) -> Vec f64>>>> - 407..424 'from_i...epeat)': Vec f64>>>> - 417..423 'repeat': Repeat f64>> - 431..434 'vec': Vec f64>>>> - 431..444 'vec.foo_bar()': {unknown} + 225..229 'iter': T + 244..246 '{}': () + 258..402 '{ ...r(); }': () + 268..273 'inner': Map<|&f64| -> f64> + 276..300 'Map { ... 0.0 }': Map<|&f64| -> f64> + 285..298 '|_: &f64| 0.0': |&f64| -> f64 + 286..287 '_': &f64 + 295..298 '0.0': f64 + 311..317 'repeat': Repeat f64>> + 320..345 'Repeat...nner }': Repeat f64>> + 338..343 'inner': Map<|&f64| -> f64> + 356..359 'vec': Vec f64>>>> + 362..371 'from_iter': fn from_iter f64>>>, Repeat f64>>>(Repeat f64>>) -> Vec f64>>>> + 362..379 'from_i...epeat)': Vec f64>>>> + 372..378 'repeat': Repeat f64>> + 386..389 'vec': Vec f64>>>> + 386..399 'vec.foo_bar()': {unknown} "#]], ); } 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