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
1083 fn bare_dyn_trait_binders_9639() {
1084 check_no_mismatches(
1086 //- minicore: fn, coerce_unsized
1087 fn infix_parse<T, S>(_state: S, _level_code: &Fn(S)) -> T {
1092 infix_parse((), &(|_recurse| ()))
1099 fn call_expected_type_closure() {
1102 //- minicore: fn, option
1104 fn map<T, U>(o: Option<T>, f: impl FnOnce(T) -> U) -> Option<U> { loop {} }
1110 let o = Some(S { field: 2 });
1111 let _: Option<()> = map(o, |s| { s.field; });
1119 fn coerce_diesel_panic() {
1120 check_no_mismatches(
1122 //- minicore: option
1124 trait TypeMetadata {
1125 type MetadataLookup;
1128 pub struct Output<'a, T, DB>
1131 DB::MetadataLookup: 'a,
1134 metadata_lookup: Option<&'a DB::MetadataLookup>,
1137 impl<'a, T, DB: TypeMetadata> Output<'a, T, DB> {
1138 pub fn new(out: T, metadata_lookup: &'a DB::MetadataLookup) -> Self {
1141 metadata_lookup: Some(metadata_lookup),
1150 fn bitslice_panic() {
1151 check_no_mismatches(
1153 //- minicore: option, deref
1161 pub struct BitArray<V: BitView> { }
1163 pub struct BitSlice<T> { }
1165 impl<V: BitView> core::ops::Deref for BitArray<V> {
1166 type Target = BitSlice<V::Store>;
1169 impl<T> BitSlice<T> {
1170 pub fn split_first(&self) -> Option<(T, &Self)> { loop {} }
1173 fn multiexp_inner() {
1174 let exp: &BitArray<Foo>;
1182 fn macro_expands_to_impl_trait() {
1183 check_no_mismatches(
1203 fn nested_macro_in_fn_params() {
1204 check_no_mismatches(
1206 macro_rules! U32Inner {
1218 fn mamba(a: U32!(), p: u32) -> u32 {
1226 fn for_loop_block_expr_iterable() {
1230 for _ in { let x = 0; } {
1236 10..68 '{ ... } }': ()
1237 16..66 'for _ ... }': ()
1238 20..21 '_': {unknown}
1239 25..39 '{ let x = 0; }': ()
1242 40..66 '{ ... }': ()
1250 fn while_loop_block_expr_iterable() {
1260 10..59 '{ ... } }': ()
1261 16..57 'while ... }': ()
1262 22..30 '{ true }': bool
1264 31..57 '{ ... }': ()
1273 // FIXME: wrong, should be u32
1278 A: IntoIterator<Item = u32>,
1279 B: IntoIterator<Item = usize>,
1281 let _x: <A as IntoIterator>::Item;
1285 pub trait Iterator {
1289 pub trait IntoIterator {
1291 type IntoIter: Iterator<Item = Self::Item>;
1294 impl<I: Iterator> IntoIterator for I {
1295 type Item = I::Item;
1304 check_no_mismatches(
1306 struct LinkArray<const N: usize, LD>(LD);
1307 fn f<const N: usize, LD>(x: LD) -> LinkArray<N, LD> {
1308 let r = LinkArray::<N, LD>(x);
1313 let x = f::<2, i32>(5);
1314 let y = LinkArray::<52, LinkArray<2, i32>>(x);
1318 check_no_mismatches(
1320 struct LinkArray<LD, const N: usize>(LD);
1321 fn f<const N: usize, LD>(x: LD) -> LinkArray<LD, N> {
1322 let r = LinkArray::<LD, N>(x);
1327 let x = f::<i32, 2>(5);
1328 let y = LinkArray::<LinkArray<i32, 2>, 52>(x);
1335 fn const_generic_error_tolerance() {
1336 check_no_mismatches(
1341 struct CT<const N: usize, T>(T);
1342 struct TC<T, const N: usize>(T);
1343 fn f<const N: usize, T>(x: T) -> (CT<N, T>, TC<T, N>) {
1344 let l = CT::<N, T>(x);
1345 let r = TC::<N, T>(x);
1349 trait TR1<const N: usize>;
1350 trait TR2<const N: usize>;
1352 impl<const N: usize, T> TR1<N> for CT<N, T>;
1353 impl<const N: usize, T> TR1<5> for TC<T, N>;
1354 impl<const N: usize, T> TR2<N> for CT<T, N>;
1356 trait TR3<const N: usize> {
1357 fn tr3(&self) -> &Self;
1360 impl<const N: usize, T> TR3<5> for TC<T, N> {
1361 fn tr3(&self) -> &Self {
1366 impl<const N: usize, T> TR3<Item = 5> for TC<T, N> {}
1367 impl<const N: usize, T> TR3<T> for TC<T, N> {}
1369 fn impl_trait<const N: usize>(inp: impl TR1<N>) {}
1370 fn dyn_trait<const N: usize>(inp: &dyn TR2<N>) {}
1371 fn impl_trait_bad<'a, const N: usize>(inp: impl TR1<i32>) -> impl TR1<'a, i32> {}
1372 fn impl_trait_very_bad<const N: usize>(inp: impl TR1<Item = i32>) -> impl TR1<'a, Item = i32, 5, Foo = N> {}
1379 CT::<52, CT<2, i32>>(x);
1380 CT::<CT<2, i32>>(x);
1384 TR3<{ 2+3 }>::tr3();
1385 TC::<i32, 10>(5).tr3();
1386 TC::<i32, 20>(5).tr3();
1387 TC::<i32, i32>(5).tr3();
1388 TC::<i32, { 7 + 3 }>(5).tr3();
1395 fn const_generic_impl_trait() {
1396 check_no_mismatches(
1400 struct Foo<T, const M: usize>;
1406 impl<T, const M: usize> Tr<[T; M]> for Foo<T, M> {
1407 fn f(_: [T; M]) -> Self {
1413 Foo::f([1, 2, 7, 10]);
1420 fn nalgebra_factorial() {
1421 check_no_mismatches(
1423 const FACTORIAL: [u128; 4] = [1, 1, 2, 6];
1425 fn factorial(n: usize) -> u128 {
1426 match FACTORIAL.get(n) {
1428 None => panic!("{}! is greater than u128::MAX", n),
1436 fn regression_11688_1() {
1437 check_no_mismatches(
1439 pub struct Buffer<T>(T);
1440 type Writer = Buffer<u8>;
1442 fn extend_from_array<const N: usize>(&mut self, xs: &[T; N]) {
1447 fn encode(self, w: &mut Writer, s: &mut S);
1449 impl<S> Encode<S> for u8 {
1450 fn encode(self, w: &mut Writer, _: &mut S) {
1451 w.extend_from_array(&self.to_le_bytes());
1459 fn regression_11688_2() {
1462 union MaybeUninit<T> {
1467 impl<T> MaybeUninit<T> {
1468 fn uninit_array<const LEN: usize>() -> [Self; LEN] {
1474 let x = MaybeUninit::<i32>::uninit_array::<1>();
1475 //^ [MaybeUninit<i32>; 1]