aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-18 20:47:02 +0100
committerAleksey Kladov <[email protected]>2021-06-18 20:47:02 +0100
commit89a0e58393de0ae39fc1f33a33cec87bc084a9f1 (patch)
tree2ab97438a45f9dc6cf72d42209923df19aa5d789 /crates
parent991919e71f048f9321e702512248e11c6c5fef70 (diff)
internal: use minicore deref more
Diffstat (limited to 'crates')
-rw-r--r--crates/base_db/src/fixture.rs4
-rw-r--r--crates/hir_ty/src/tests/regression.rs42
-rw-r--r--crates/hir_ty/src/tests/traits.rs138
-rw-r--r--crates/ide/src/hover.rs4
-rw-r--r--crates/ide_completion/src/render.rs20
5 files changed, 81 insertions, 127 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs
index d56b20b83..d0c946d83 100644
--- a/crates/base_db/src/fixture.rs
+++ b/crates/base_db/src/fixture.rs
@@ -114,6 +114,9 @@ impl ChangeFixture {
114 114
115 let meta = FileMeta::from(entry); 115 let meta = FileMeta::from(entry);
116 assert!(meta.path.starts_with(&source_root_prefix)); 116 assert!(meta.path.starts_with(&source_root_prefix));
117 if !meta.deps.is_empty() {
118 assert!(meta.krate.is_some(), "can't specify deps without naming the crate")
119 }
117 120
118 if meta.introduce_new_source_root { 121 if meta.introduce_new_source_root {
119 roots.push(SourceRoot::new_local(mem::take(&mut file_set))); 122 roots.push(SourceRoot::new_local(mem::take(&mut file_set)));
@@ -199,6 +202,7 @@ impl ChangeFixture {
199 } 202 }
200} 203}
201 204
205#[derive(Debug)]
202struct FileMeta { 206struct FileMeta {
203 path: String, 207 path: String,
204 krate: Option<String>, 208 krate: Option<String>,
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() {
792fn issue_4966() { 792fn issue_4966() {
793 check_infer( 793 check_infer(
794 r#" 794 r#"
795 //- minicore: deref
795 pub trait IntoIterator { 796 pub trait IntoIterator {
796 type Item; 797 type Item;
797 } 798 }
@@ -802,12 +803,7 @@ fn issue_4966() {
802 803
803 struct Vec<T> {} 804 struct Vec<T> {}
804 805
805 #[lang = "deref"] 806 impl<T> core::ops::Deref for Vec<T> {
806 pub trait Deref {
807 type Target;
808 }
809
810 impl<T> Deref for Vec<T> {
811 type Target = [T]; 807 type Target = [T];
812 } 808 }
813 809
@@ -824,23 +820,23 @@ fn issue_4966() {
824 } 820 }
825 "#, 821 "#,
826 expect![[r#" 822 expect![[r#"
827 270..274 'iter': T 823 225..229 'iter': T
828 289..291 '{}': () 824 244..246 '{}': ()
829 303..447 '{ ...r(); }': () 825 258..402 '{ ...r(); }': ()
830 313..318 'inner': Map<|&f64| -> f64> 826 268..273 'inner': Map<|&f64| -> f64>
831 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64> 827 276..300 'Map { ... 0.0 }': Map<|&f64| -> f64>
832 330..343 '|_: &f64| 0.0': |&f64| -> f64 828 285..298 '|_: &f64| 0.0': |&f64| -> f64
833 331..332 '_': &f64 829 286..287 '_': &f64
834 340..343 '0.0': f64 830 295..298 '0.0': f64
835 356..362 'repeat': Repeat<Map<|&f64| -> f64>> 831 311..317 'repeat': Repeat<Map<|&f64| -> f64>>
836 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> 832 320..345 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
837 383..388 'inner': Map<|&f64| -> f64> 833 338..343 'inner': Map<|&f64| -> f64>
838 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 834 356..359 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
839 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 835 362..371 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
840 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 836 362..379 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
841 417..423 'repeat': Repeat<Map<|&f64| -> f64>> 837 372..378 'repeat': Repeat<Map<|&f64| -> f64>>
842 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> 838 386..389 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
843 431..444 'vec.foo_bar()': {unknown} 839 386..399 'vec.foo_bar()': {unknown}
844 "#]], 840 "#]],
845 ); 841 );
846} 842}
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) { t.foo(); }
853fn generic_param_env_deref() { 853fn generic_param_env_deref() {
854 check_types( 854 check_types(
855 r#" 855 r#"
856#[lang = "deref"] 856//- minicore: deref
857trait Deref {
858 type Target;
859}
860trait Trait {} 857trait Trait {}
861impl<T> Deref for T where T: Trait { 858impl<T> core::ops::Deref for T where T: Trait {
862 type Target = i128; 859 type Target = i128;
863} 860}
864fn test<T: Trait>(t: T) { (*t); } 861fn test<T: Trait>(t: T) { (*t); }
@@ -1727,20 +1724,7 @@ fn test() {
1727fn fn_trait_deref_with_ty_default() { 1724fn fn_trait_deref_with_ty_default() {
1728 check_infer( 1725 check_infer(
1729 r#" 1726 r#"
1730#[lang = "deref"] 1727//- minicore: deref, fn
1731trait Deref {
1732 type Target;
1733
1734 fn deref(&self) -> &Self::Target;
1735}
1736
1737#[lang="fn_once"]
1738trait FnOnce<Args> {
1739 type Output;
1740
1741 fn call_once(self, args: Args) -> Self::Output;
1742}
1743
1744struct Foo; 1728struct Foo;
1745 1729
1746impl Foo { 1730impl Foo {
@@ -1753,7 +1737,7 @@ impl<T, F> Lazy<T, F> {
1753 pub fn new(f: F) -> Lazy<T, F> {} 1737 pub fn new(f: F) -> Lazy<T, F> {}
1754} 1738}
1755 1739
1756impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { 1740impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
1757 type Target = T; 1741 type Target = T;
1758} 1742}
1759 1743
@@ -1767,32 +1751,29 @@ fn test() {
1767 let r2 = lazy2.foo(); 1751 let r2 = lazy2.foo();
1768}"#, 1752}"#,
1769 expect![[r#" 1753 expect![[r#"
1770 64..68 'self': &Self 1754 36..40 'self': &Foo
1771 165..169 'self': Self 1755 51..53 '{}': ()
1772 171..175 'args': Args 1756 131..132 'f': F
1773 239..243 'self': &Foo 1757 151..153 '{}': ()
1774 254..256 '{}': () 1758 251..497 '{ ...o(); }': ()
1775 334..335 'f': F 1759 261..266 'lazy1': Lazy<Foo, || -> Foo>
1776 354..356 '{}': () 1760 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1777 443..689 '{ ...o(); }': () 1761 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1778 453..458 'lazy1': Lazy<Foo, || -> Foo> 1762 293..299 '|| Foo': || -> Foo
1779 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> 1763 296..299 'Foo': Foo
1780 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> 1764 310..312 'r1': usize
1781 485..491 '|| Foo': || -> Foo 1765 315..320 'lazy1': Lazy<Foo, || -> Foo>
1782 488..491 'Foo': Foo 1766 315..326 'lazy1.foo()': usize
1783 502..504 'r1': usize 1767 368..383 'make_foo_fn_ptr': fn() -> Foo
1784 507..512 'lazy1': Lazy<Foo, || -> Foo> 1768 399..410 'make_foo_fn': fn make_foo_fn() -> Foo
1785 507..518 'lazy1.foo()': usize 1769 420..425 'lazy2': Lazy<Foo, fn() -> Foo>
1786 560..575 'make_foo_fn_ptr': fn() -> Foo 1770 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1787 591..602 'make_foo_fn': fn make_foo_fn() -> Foo 1771 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1788 612..617 'lazy2': Lazy<Foo, fn() -> Foo> 1772 452..467 'make_foo_fn_ptr': fn() -> Foo
1789 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> 1773 478..480 'r2': usize
1790 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> 1774 483..488 'lazy2': Lazy<Foo, fn() -> Foo>
1791 644..659 'make_foo_fn_ptr': fn() -> Foo 1775 483..494 'lazy2.foo()': usize
1792 670..672 'r2': usize 1776 357..359 '{}': ()
1793 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1794 675..686 'lazy2.foo()': usize
1795 549..551 '{}': ()
1796 "#]], 1777 "#]],
1797 ); 1778 );
1798} 1779}
@@ -2941,28 +2922,13 @@ fn infer_box_fn_arg() {
2941 // The type mismatch is because we don't define Unsize and CoerceUnsized 2922 // The type mismatch is because we don't define Unsize and CoerceUnsized
2942 check_infer_with_mismatches( 2923 check_infer_with_mismatches(
2943 r#" 2924 r#"
2944//- /lib.rs deps:std 2925//- minicore: fn, deref, option
2945
2946#[lang = "fn_once"]
2947pub trait FnOnce<Args> {
2948 type Output;
2949
2950 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
2951}
2952
2953#[lang = "deref"]
2954pub trait Deref {
2955 type Target: ?Sized;
2956
2957 fn deref(&self) -> &Self::Target;
2958}
2959
2960#[lang = "owned_box"] 2926#[lang = "owned_box"]
2961pub struct Box<T: ?Sized> { 2927pub struct Box<T: ?Sized> {
2962 inner: *mut T, 2928 inner: *mut T,
2963} 2929}
2964 2930
2965impl<T: ?Sized> Deref for Box<T> { 2931impl<T: ?Sized> core::ops::Deref for Box<T> {
2966 type Target = T; 2932 type Target = T;
2967 2933
2968 fn deref(&self) -> &T { 2934 fn deref(&self) -> &T {
@@ -2970,38 +2936,30 @@ impl<T: ?Sized> Deref for Box<T> {
2970 } 2936 }
2971} 2937}
2972 2938
2973enum Option<T> {
2974 None,
2975 Some(T)
2976}
2977
2978fn foo() { 2939fn foo() {
2979 let s = Option::None; 2940 let s = None;
2980 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); 2941 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
2981 f(&s); 2942 f(&s);
2982}"#, 2943}"#,
2983 expect![[r#" 2944 expect![[r#"
2984 100..104 'self': Self 2945 154..158 'self': &Box<T>
2985 106..110 'args': Args 2946 166..193 '{ ... }': &T
2986 214..218 'self': &Self 2947 176..187 '&self.inner': &*mut T
2987 384..388 'self': &Box<T> 2948 177..181 'self': &Box<T>
2988 396..423 '{ ... }': &T 2949 177..187 'self.inner': *mut T
2989 406..417 '&self.inner': &*mut T 2950 206..296 '{ ...&s); }': ()
2990 407..411 'self': &Box<T> 2951 216..217 's': Option<i32>
2991 407..417 'self.inner': *mut T 2952 220..224 'None': Option<i32>
2992 478..576 '{ ...&s); }': () 2953 234..235 'f': Box<dyn FnOnce(&Option<i32>)>
2993 488..489 's': Option<i32> 2954 269..282 'box (|ps| {})': Box<|{unknown}| -> ()>
2994 492..504 'Option::None': Option<i32> 2955 274..281 '|ps| {}': |{unknown}| -> ()
2995 514..515 'f': Box<dyn FnOnce(&Option<i32>)> 2956 275..277 'ps': {unknown}
2996 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> 2957 279..281 '{}': ()
2997 554..561 '|ps| {}': |{unknown}| -> () 2958 288..289 'f': Box<dyn FnOnce(&Option<i32>)>
2998 555..557 'ps': {unknown} 2959 288..293 'f(&s)': ()
2999 559..561 '{}': () 2960 290..292 '&s': &Option<i32>
3000 568..569 'f': Box<dyn FnOnce(&Option<i32>)> 2961 291..292 's': Option<i32>
3001 568..573 'f(&s)': () 2962 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3002 570..572 '&s': &Option<i32>
3003 571..572 's': Option<i32>
3004 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
3005 "#]], 2963 "#]],
3006 ); 2964 );
3007} 2965}
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 4705fae08..05a2b1293 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -3014,8 +3014,8 @@ fn foo() {
3014 file_id: FileId( 3014 file_id: FileId(
3015 1, 3015 1,
3016 ), 3016 ),
3017 full_range: 250..432, 3017 full_range: 251..433,
3018 focus_range: 289..295, 3018 focus_range: 290..296,
3019 name: "Future", 3019 name: "Future",
3020 kind: Trait, 3020 kind: Trait,
3021 description: "pub trait Future", 3021 description: "pub trait Future",
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 4b55f7504..9bec03e17 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -1269,16 +1269,11 @@ fn bar(t: &Foo) {}
1269 fn suggest_deref_fn_ret() { 1269 fn suggest_deref_fn_ret() {
1270 check_relevance( 1270 check_relevance(
1271 r#" 1271 r#"
1272#[lang = "deref"] 1272//- minicore: deref
1273trait Deref {
1274 type Target;
1275 fn deref(&self) -> &Self::Target;
1276}
1277
1278struct S; 1273struct S;
1279struct T(S); 1274struct T(S);
1280 1275
1281impl Deref for T { 1276impl core::ops::Deref for T {
1282 type Target = S; 1277 type Target = S;
1283 1278
1284 fn deref(&self) -> &Self::Target { 1279 fn deref(&self) -> &Self::Target {
@@ -1292,15 +1287,16 @@ fn bar() -> T {}
1292fn main() { 1287fn main() {
1293 foo($0); 1288 foo($0);
1294} 1289}
1295 "#, 1290"#,
1296 expect![[r#" 1291 expect![[r#"
1297 tt Deref []
1298 fn bar() []
1299 fn &bar() [type]
1300 fn foo(…) []
1301 st T [] 1292 st T []
1302 st S [] 1293 st S []
1303 fn main() [] 1294 fn main() []
1295 fn bar() []
1296 fn &bar() [type]
1297 fn foo(…) []
1298 md core []
1299 tt Sized []
1304 "#]], 1300 "#]],
1305 ) 1301 )
1306 } 1302 }