1 use expect_test::expect;
3 use super::{check_infer, check_no_mismatches, check_types};
14 10..37 '{ ... {}; }': ()
16 24..34 'if true {}': ()
24 fn no_panic_on_field_of_enum() {
35 25..46 '{ ...eld; }': ()
37 31..43 'x.some_field': {unknown}
55 10..88 '{ ... } }': ()
56 16..20 'X {}': {unknown}
57 26..86 'match ... }': ()
59 44..51 'A::B {}': {unknown}
61 67..73 'A::Y()': {unknown}
77 10..40 '{ ...+ y; }': ()
97 10..47 '{ ...&y]; }': ()
99 24..31 'unknown': {unknown}
100 37..44 '[y, &y]': [{unknown}; 2]
101 38..39 'y': {unknown}
102 41..43 '&y': &{unknown}
103 42..43 'y': {unknown}
109 fn recursive_vars_2() {
119 10..79 '{ ...x)]; }': ()
120 20..21 'x': &{unknown}
121 24..31 'unknown': &{unknown}
122 41..42 'y': {unknown}
123 45..52 'unknown': {unknown}
124 58..76 '[(x, y..., &x)]': [(&{unknown}, {unknown}); 2]
125 59..65 '(x, y)': (&{unknown}, {unknown})
126 60..61 'x': &{unknown}
127 63..64 'y': {unknown}
128 67..75 '(&y, &x)': (&{unknown}, {unknown})
129 68..70 '&y': &{unknown}
130 69..70 'y': {unknown}
131 72..74 '&x': &&{unknown}
132 73..74 'x': &{unknown}
138 fn array_elements_expected_type() {
142 let x: [[u32; 2]; 2] = [[1, 2], [3, 4]];
149 fn infer_std_crash_1() {
150 // caused stack overflow, taken from std
159 match something_unknown {
160 Maybe::Real(ref mut something) => (),
165 53..138 '{ ... } }': ()
166 59..136 'match ... }': ()
167 65..82 'someth...nknown': Maybe<{unknown}>
168 93..123 'Maybe:...thing)': Maybe<{unknown}>
169 105..122 'ref mu...ething': &mut {unknown}
176 fn infer_std_crash_2() {
177 // caused "equating two type variables, ...", taken from std
180 fn test_line_buffer() {
181 &[0, b'\n', 1, b'\n'];
185 22..52 '{ ...n']; }': ()
186 28..49 '&[0, b...b'\n']': &[u8; 4]
187 29..49 '[0, b'...b'\n']': [u8; 4]
197 fn infer_std_crash_3() {
203 SizeSkeleton::Pointer { non_zero: true, tail } => {}
208 17..107 '{ ... } }': ()
209 23..105 'match ... }': ()
210 29..36 'nope!()': {unknown}
211 47..93 'SizeSk...tail }': {unknown}
214 87..91 'tail': {unknown}
221 fn infer_std_crash_4() {
225 pub fn primitive_type() {
227 BorrowedRef { type_: Primitive(p), ..} => {},
232 24..105 '{ ... } }': ()
233 30..103 'match ... }': ()
234 36..41 '*self': {unknown}
235 37..41 'self': {unknown}
236 52..90 'Borrow...), ..}': {unknown}
237 73..85 'Primitive(p)': {unknown}
238 83..84 'p': {unknown}
245 fn infer_std_crash_5() {
249 fn extra_compiler_flags() {
250 for content in doesnt_matter {
251 let name = if doesnt_matter {
257 let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) {
266 26..322 '{ ... } }': ()
267 32..320 'for co... }': ()
268 36..43 'content': {unknown}
269 47..60 'doesnt_matter': {unknown}
270 61..320 '{ ... }': ()
271 75..79 'name': &{unknown}
272 82..166 'if doe... }': &{unknown}
273 85..98 'doesnt_matter': bool
274 99..128 '{ ... }': &{unknown}
275 113..118 'first': &{unknown}
276 134..166 '{ ... }': &{unknown}
277 148..156 '&content': &{unknown}
278 149..156 'content': {unknown}
279 181..188 'content': &{unknown}
280 191..313 'if ICE... }': &{unknown}
281 194..231 'ICE_RE..._VALUE': {unknown}
282 194..247 'ICE_RE...&name)': bool
283 241..246 '&name': &&{unknown}
284 242..246 'name': &{unknown}
285 248..276 '{ ... }': &{unknown}
286 262..266 'name': &{unknown}
287 282..313 '{ ... }': {unknown}
288 296..303 'content': {unknown}
294 fn infer_nested_generics_crash() {
295 // another crash found typechecking rustc
298 struct Canonical<V> {
301 struct QueryResponse<V> {
304 fn test<R>(query_response: Canonical<QueryResponse<R>>) {
305 &query_response.value;
309 91..105 'query_response': Canonical<QueryResponse<R>>
310 136..166 '{ ...lue; }': ()
311 142..163 '&query....value': &QueryResponse<R>
312 143..157 'query_response': Canonical<QueryResponse<R>>
313 143..163 'query_....value': QueryResponse<R>
319 fn infer_paren_macro_call() {
322 macro_rules! bar { () => {0u32} }
329 44..69 '{ ...()); }': ()
336 fn infer_array_macro_call() {
339 macro_rules! bar { () => {0u32} }
346 44..69 '{ ...()]; }': ()
348 58..66 '[bar!()]': [u32; 1]
357 struct HashSet<T, H>;
359 type FxHashSet<T> = HashSet<T, FxHasher>;
361 impl<T, H> HashSet<T, H> {
362 fn default() -> HashSet<T, H> {}
366 FxHashSet::default();
371 168..197 '{ ...t(); }': ()
372 174..192 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher>
373 174..194 'FxHash...ault()': HashSet<{unknown}, FxHasher>
384 struct Response<T> {}
390 impl<T:A> D for Response<T> {
400 119..214 '{ ... }': ()
401 129..132 'end': fn end<{unknown}>()
403 163..208 '{ ... }': ()
405 190..197 'loop {}': !
421 25..52 '{ ...oo() }': ()
422 31..48 '<Trait...>::foo': {unknown}
423 31..50 '<Trait...:foo()': ()
429 fn issue_2683_chars_impl() {
432 //- minicore: iterator
433 pub struct Chars<'a> {}
434 impl<'a> Iterator for Chars<'a> {
436 fn next(&mut self) -> Option<char> { loop {} }
440 let chars: Chars<'_>;
441 (chars.next(), chars.nth(1));
442 } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (Option<char>, Option<char>)
448 fn issue_3642_bad_macro_stackover() {
452 macro_rules! match_ast {
453 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
455 (match ($node:expr) {
456 $( ast::$ast:ident($it:ident) => $res:expr, )*
457 _ => $catch_all:expr $(,)?
459 $( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*
465 let anchor = match_ast! {
476 fn issue_3999_slice() {
479 fn foo(params: &[usize]) {
486 7..13 'params': &[usize]
487 25..80 '{ ... } }': ()
488 31..78 'match ... }': ()
489 37..43 'params': &[usize]
490 54..66 '[ps @ .., _]': [usize]
491 55..62 'ps @ ..': &[usize]
500 fn issue_3999_struct() {
501 // rust-analyzer should not panic on seeing this malformed
516 43..95 '{ ... } }': ()
517 49..93 'match ... }': ()
519 67..80 'Bar { a: .. }': Bar
527 fn issue_4235_name_conflicts() {
531 static FOO:FOO = FOO {};
546 85..119 '{ ...o(); }': ()
551 109..116 'a.foo()': ()
557 fn issue_4465_dollar_crate_at_type() {
561 pub fn anything<T>() -> T {
566 let r: $crate::Foo = anything();
575 44..59 '{ loop {} }': T
578 !0..31 '{letr:...g();r}': Foo
580 !18..26 'anything': fn anything<Foo>() -> Foo
581 !18..28 'anything()': Foo
583 163..187 '{ ...!(); }': ()
593 macro_rules! profile_function {
608 103..131 '{ ...!(); }': ()
614 fn issue_4053_diesel_where_clauses() {
619 fn internal_into_boxed(self) -> Self::Output;
622 struct SelectStatement<From, Select, Distinct, Where, Order, LimitOffset, GroupBy, Locking> {
626 trait QueryFragment<DB: Backend> {}
628 trait Into<T> { fn into(self) -> T; }
630 impl<F, S, D, W, O, LOf, DB> BoxedDsl<DB>
631 for SelectStatement<F, S, D, W, O, LOf, G>
633 O: Into<dyn QueryFragment<DB>>,
637 fn internal_into_boxed(self) -> Self::Output {
644 267..271 'self': Self
645 466..470 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
646 488..522 '{ ... }': ()
647 498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
648 498..508 'self.order': O
649 498..515 'self.o...into()': dyn QueryFragment<DB>
658 pub struct Foo(pub i64);
660 fn test() -> Self { Self(0i64) }
664 58..72 '{ Self(0i64) }': Foo
665 60..64 'Self': Foo(i64) -> Foo
666 60..70 'Self(0i64)': Foo
672 pub struct Foo<T>(pub T);
674 fn test() -> Self { Self(0i64) }
678 64..78 '{ Self(0i64) }': Foo<i64>
679 66..70 'Self': Foo<i64>(i64) -> Foo<i64>
680 66..76 'Self(0i64)': Foo<i64>
694 trait CheckedDiv: Div<()> {}
696 trait PrimInt: CheckedDiv<Output = ()> {
700 fn check<T: PrimInt>(i: T) {
705 117..121 'self': Self
707 154..170 '{ ...w(); }': ()
709 160..167 'i.pow()': ()
718 //- minicore: coerce_unsized, future
719 use core::future::Future;
723 fn foo<R, K>(key: &K) -> impl Future<Output = K::Bar>
729 fn bar<R, K>(key: &K) -> impl Future<Output = K::Bar>
737 132..148 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar>
738 138..141 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar>
739 138..146 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar>
755 type E1<T> = (T, T, T);
756 type E2<T> = E1<E1<E1<(T, T, T)>>>;
758 impl Debug for Foo<E2<()>> {}
766 pub struct PeerSet<D>;
768 impl<D> Service<Request> for PeerSet<D>
774 type Future = dyn Future<Output = Self::Error>;
776 fn call(&mut self) -> Self::Future {
785 pub trait Service<Request> {
787 type Future: Future<Output = Self::Error>;
788 fn call(&mut self) -> Self::Future;
792 379..383 'self': &mut PeerSet<D>
793 401..424 '{ ... }': dyn Future<Output = ()>
794 411..418 'loop {}': !
796 575..579 'self': &mut Self
806 pub trait IntoIterator {
810 struct Repeat<A> { element: A }
812 struct Map<F> { f: F }
816 impl<T> core::ops::Deref for Vec<T> {
820 fn from_iter<A, T: IntoIterator<Item = A>>(iter: T) -> Vec<A> {}
823 let inner = Map { f: |_: &f64| 0.0 };
825 let repeat = Repeat { element: inner };
827 let vec = from_iter(repeat);
835 258..402 '{ ...r(); }': ()
836 268..273 'inner': Map<|&f64| -> f64>
837 276..300 'Map { ... 0.0 }': Map<|&f64| -> f64>
838 285..298 '|_: &f64| 0.0': |&f64| -> f64
841 311..317 'repeat': Repeat<Map<|&f64| -> f64>>
842 320..345 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
843 338..343 'inner': Map<|&f64| -> f64>
844 356..359 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
845 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>>>>
846 362..379 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
847 372..378 'repeat': Repeat<Map<|&f64| -> f64>>
848 386..389 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
849 386..399 'vec.foo_bar()': {unknown}
861 fn f(&self, _t: T) {}
862 fn g<F: FnOnce(&T)>(&self, _f: F) {}
877 109..160 '{ ...10); }': ()
879 123..124 'S': S<i32>() -> S<i32>
880 123..126 'S()': S<i32>
882 132..144 's.g(|_x| {})': ()
883 136..143 '|_x| {}': |&i32| -> ()
887 150..157 's.f(10)': ()
898 use core::ops::Deref;
903 struct MutexGuard<'a, T> {}
905 fn lock(&self) -> MutexGuard<'_, T> {}
907 impl<'a, T: 'a> Deref for MutexGuard<'a, T> {
911 let w: &Mutex<BufWriter>;
916 123..127 'self': &Mutex<T>
918 234..238 'self': &{unknown}
919 240..290 '{ ...()); }': ()
920 250..251 'w': &Mutex<BufWriter>
921 276..287 '*(w.lock())': BufWriter
922 278..279 'w': &Mutex<BufWriter>
923 278..286 'w.lock()': MutexGuard<BufWriter>
929 fn param_overrides_fn() {
932 fn example(example: i32) {
942 fn lifetime_from_chalk_during_deref() {
946 struct Box<T: ?Sized> {}
947 impl<T: ?Sized> core::ops::Deref for Box<T> {
950 fn deref(&self) -> &Self::Target {
959 pub struct Iter<'a, T: 'a> {
960 inner: Box<dyn IterTrait<'a, T, Item = &'a T> + 'a>,
963 trait IterTrait<'a, T: 'a>: Iterator<Item = &'a T> {
967 fn clone_iter<T>(s: Iter<T>) {
969 //^^^^^^^^^^^^^^^^^^^ ()
979 pub trait Try: FromResidual {
983 pub trait FromResidual<R = <Self as Try>::Residual> {
984 fn from_residual(residual: R) -> Self;
987 struct ControlFlow<B, C>;
988 impl<B, C> Try for ControlFlow<B, C> {
990 type Residual = ControlFlow<B, !>;
992 impl<B, C> FromResidual for ControlFlow<B, C> {
993 fn from_residual(r: ControlFlow<B, !>) -> Self { ControlFlow }
997 ControlFlow::from_residual(ControlFlow::<u32, !>);
1001 144..152 'residual': R
1002 365..366 'r': ControlFlow<B, !>
1003 395..410 '{ ControlFlow }': ControlFlow<B, C>
1004 397..408 'ControlFlow': ControlFlow<B, C>
1005 424..482 '{ ...!>); }': ()
1006 430..456 'Contro...sidual': fn from_residual<ControlFlow<u32, {unknown}>, ControlFlow<u32, !>>(ControlFlow<u32, !>) -> ControlFlow<u32, {unknown}>
1007 430..479 'Contro...2, !>)': ControlFlow<u32, {unknown}>
1008 457..478 'Contro...32, !>': ControlFlow<u32, !>
1015 // https://github.com/rust-analyzer/rust-analyzer/issues/8378
1026 #[cfg(never)] { 11 }
1030 fn no_normal_tail(){
1035 fn no_actual_tail(){
1042 14..53 '{ ...)] 9 }': &str
1043 20..31 '{ "first" }': &str
1044 22..29 '"first"': &str
1045 72..190 '{ ...] 13 }': &str
1046 78..88 '{ "fake" }': &str
1047 80..86 '"fake"': &str
1048 93..103 '{ "fake" }': &str
1049 95..101 '"fake"': &str
1050 108..120 '{ "second" }': &str
1051 110..118 '"second"': &str
1052 210..273 '{ ... 15; }': &str
1053 216..227 '{ "third" }': &str
1054 218..225 '"third"': &str
1055 293..357 '{ ...] 15 }': ()
1056 299..311 '{ "fourth" }': &str
1057 301..309 '"fourth"': &str
1063 fn impl_trait_in_option_9530() {
1069 fn unwrap(self) -> T { loop {} }
1071 fn make() -> Option<impl Copy> { Option }
1076 //^^^^^^^^^^ impl Copy