about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-01-13 15:10:29 +0100
committerGitHub <noreply@github.com>2024-01-13 15:10:29 +0100
commit9696ef7c12ad112f1f6efc0d94b1585af24ab874 (patch)
tree1d6e0706d4cb9439333551749efc21ee2b9c99c3
parent2c7ce1c45389aedd5719ee9aa429448d99a6f9a1 (diff)
parent4586fdce47e70ed4fe8568a6578bde2ed9faa31e (diff)
downloadrust-9696ef7c12ad112f1f6efc0d94b1585af24ab874.tar.gz
rust-9696ef7c12ad112f1f6efc0d94b1585af24ab874.zip
Rollup merge of #119896 - oli-obk:variance_ice, r=compiler-errors
Taint `_` placeholder types in trait impl method signatures

We report an error right below for them, but that kind of broken type can cause subsequent ICEs.

fixes #119867
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/mod.rs8
-rw-r--r--tests/ui/traits/method-argument-mismatch-variance-ice-119867.rs13
-rw-r--r--tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr24
3 files changed, 43 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs
index 78740ac33ca..9f4f1413650 100644
--- a/compiler/rustc_hir_analysis/src/astconv/mod.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs
@@ -2659,7 +2659,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                         self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i))
                     {
                         infer_replacements.push((a.span, suggested_ty.to_string()));
-                        return suggested_ty;
+                        return Ty::new_error_with_message(
+                            self.tcx(),
+                            a.span,
+                            suggested_ty.to_string(),
+                        );
                     }
                 }
 
@@ -2677,7 +2681,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                         self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None)
                 {
                     infer_replacements.push((output.span, suggested_ty.to_string()));
-                    suggested_ty
+                    Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string())
                 } else {
                     visitor.visit_ty(output);
                     self.ast_ty_to_ty(output)
diff --git a/tests/ui/traits/method-argument-mismatch-variance-ice-119867.rs b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.rs
new file mode 100644
index 00000000000..4b7862abc91
--- /dev/null
+++ b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.rs
@@ -0,0 +1,13 @@
+trait Deserialize {
+    fn deserialize(&self);
+}
+
+struct ArchivedVec<T>(T);
+
+impl<T> Deserialize for ArchivedVec<T> {
+    fn deserialize(s: _) {}
+    //~^ ERROR: `_` is not allowed within types on item signatures
+    //~| ERROR: has a `&self` declaration in the trait, but not in the impl
+}
+
+fn main() {}
diff --git a/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr
new file mode 100644
index 00000000000..e63cc522dd1
--- /dev/null
+++ b/tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr
@@ -0,0 +1,24 @@
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
+  --> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:23
+   |
+LL |     fn deserialize(s: _) {}
+   |                       ^ not allowed in type signatures
+   |
+help: try replacing `_` with the type in the corresponding trait method signature
+   |
+LL |     fn deserialize(s: &ArchivedVec<T>) {}
+   |                       ~~~~~~~~~~~~~~~
+
+error[E0186]: method `deserialize` has a `&self` declaration in the trait, but not in the impl
+  --> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:5
+   |
+LL |     fn deserialize(&self);
+   |     ---------------------- `&self` used in trait
+...
+LL |     fn deserialize(s: _) {}
+   |     ^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0121, E0186.
+For more information about an error, try `rustc --explain E0121`.