File tree Expand file tree Collapse file tree 3 files changed +65
-2
lines changed Expand file tree Collapse file tree 3 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -108,8 +108,13 @@ fn builtin_deref(ty: &Ty) -> Option<&Ty> {
108
108
}
109
109
110
110
fn deref_by_trait ( table : & mut InferenceTable , ty : Ty ) -> Option < Ty > {
111
- let db = table. db ;
112
111
let _p = profile:: span ( "deref_by_trait" ) ;
112
+ if table. resolve_ty_shallow ( & ty) . inference_var ( Interner ) . is_some ( ) {
113
+ // don't try to deref unknown variables
114
+ return None ;
115
+ }
116
+
117
+ let db = table. db ;
113
118
let deref_trait = db
114
119
. lang_item ( table. trait_env . krate , SmolStr :: new_inline ( "deref" ) )
115
120
. and_then ( |l| l. as_trait ( ) ) ?;
Original file line number Diff line number Diff line change @@ -681,6 +681,11 @@ fn iterate_method_candidates_with_autoref(
681
681
name : Option < & Name > ,
682
682
mut callback : & mut dyn FnMut ( ReceiverAdjustments , AssocItemId ) -> ControlFlow < ( ) > ,
683
683
) -> ControlFlow < ( ) > {
684
+ if receiver_ty. value . is_general_var ( Interner , & receiver_ty. binders ) {
685
+ // don't try to resolve methods on unknown types
686
+ return ControlFlow :: Continue ( ( ) ) ;
687
+ }
688
+
684
689
iterate_method_candidates_by_receiver (
685
690
receiver_ty,
686
691
first_adjustment. clone ( ) ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use expect_test::expect;
2
2
3
3
use crate :: tests:: check;
4
4
5
- use super :: { check_infer, check_types} ;
5
+ use super :: { check_infer, check_no_mismatches , check_types} ;
6
6
7
7
#[ test]
8
8
fn infer_slice_method ( ) {
@@ -1697,3 +1697,56 @@ fn test() {
1697
1697
"# ,
1698
1698
) ;
1699
1699
}
1700
+
1701
+ #[ test]
1702
+ fn bad_inferred_reference_1 ( ) {
1703
+ check_no_mismatches (
1704
+ r#"
1705
+ //- minicore: sized
1706
+ pub trait Into<T>: Sized {
1707
+ fn into(self) -> T;
1708
+ }
1709
+ impl<T> Into<T> for T {
1710
+ fn into(self) -> T { self }
1711
+ }
1712
+
1713
+ trait ExactSizeIterator {
1714
+ fn len(&self) -> usize;
1715
+ }
1716
+
1717
+ pub struct Foo;
1718
+ impl Foo {
1719
+ fn len(&self) -> usize { 0 }
1720
+ }
1721
+
1722
+ pub fn test(generic_args: impl Into<Foo>) {
1723
+ let generic_args = generic_args.into();
1724
+ generic_args.len();
1725
+ let _: Foo = generic_args;
1726
+ }
1727
+ "# ,
1728
+ ) ;
1729
+ }
1730
+
1731
+ #[ test]
1732
+ fn bad_inferred_reference_2 ( ) {
1733
+ check_no_mismatches (
1734
+ r#"
1735
+ //- minicore: deref
1736
+ trait ExactSizeIterator {
1737
+ fn len(&self) -> usize;
1738
+ }
1739
+
1740
+ pub struct Foo;
1741
+ impl Foo {
1742
+ fn len(&self) -> usize { 0 }
1743
+ }
1744
+
1745
+ pub fn test() {
1746
+ let generic_args;
1747
+ generic_args.len();
1748
+ let _: Foo = generic_args;
1749
+ }
1750
+ "# ,
1751
+ ) ;
1752
+ }
You can’t perform that action at this time.
0 commit comments