about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-02 18:27:06 +0000
committerMichael Goulet <michael@errs.io>2023-03-02 18:27:06 +0000
commit4b01a1a07a4cd1a1dee16ffae384905989f1a60a (patch)
tree630d73eec1b18e28301c2c9411a724371959de07
parent31f858d9a511f24fedb8ed997b28304fec809630 (diff)
downloadrust-4b01a1a07a4cd1a1dee16ffae384905989f1a60a.tar.gz
rust-4b01a1a07a4cd1a1dee16ffae384905989f1a60a.zip
Fix another ICE in point_at_expr_source_of_inferred_type
-rw-r--r--compiler/rustc_hir_typeck/src/demand.rs2
-rw-r--r--tests/ui/typeck/bad-type-in-vec-contains.rs7
-rw-r--r--tests/ui/typeck/bad-type-in-vec-contains.stderr19
3 files changed, 27 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs
index 34d62987c3b..7ba57b3b7a2 100644
--- a/compiler/rustc_hir_typeck/src/demand.rs
+++ b/compiler/rustc_hir_typeck/src/demand.rs
@@ -315,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     probe::ProbeScope::TraitsInScope,
                     None,
                 ) {
-                    Ok(pick) => pick.self_ty,
+                    Ok(pick) => eraser.fold_ty(pick.self_ty),
                     Err(_) => rcvr_ty,
                 };
                 // Remove one layer of references to account for `&mut self` and
diff --git a/tests/ui/typeck/bad-type-in-vec-contains.rs b/tests/ui/typeck/bad-type-in-vec-contains.rs
new file mode 100644
index 00000000000..4433047b75a
--- /dev/null
+++ b/tests/ui/typeck/bad-type-in-vec-contains.rs
@@ -0,0 +1,7 @@
+// The error message here still is pretty confusing.
+
+fn main() {
+    let primes = Vec::new();
+    primes.contains(3);
+    //~^ ERROR mismatched types
+}
diff --git a/tests/ui/typeck/bad-type-in-vec-contains.stderr b/tests/ui/typeck/bad-type-in-vec-contains.stderr
new file mode 100644
index 00000000000..0e03388d2d5
--- /dev/null
+++ b/tests/ui/typeck/bad-type-in-vec-contains.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+  --> $DIR/bad-type-in-vec-contains.rs:5:21
+   |
+LL |     primes.contains(3);
+   |            -------- ^
+   |            |        |
+   |            |        expected `&_`, found integer
+   |            |        help: consider borrowing here: `&3`
+   |            arguments to this method are incorrect
+   |            here the type of `primes` is inferred to be `[_]`
+   |
+   = note: expected reference `&_`
+                   found type `{integer}`
+note: method defined here
+  --> $SRC_DIR/core/src/slice/mod.rs:LL:COL
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.