about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-10-07 16:24:49 +0200
committerGitHub <noreply@github.com>2021-10-07 16:24:49 +0200
commitab276b82b020b5c68d4246641203faba6295dc69 (patch)
tree4e2fbe7e68dddd33da1cc65ffd314f58ee8484bf /src/test
parent1584b6a796098074208423418e4f12e03d778f3e (diff)
parent250d1260e6b45b82a07e5f7b28afe983d21fdef3 (diff)
downloadrust-ab276b82b020b5c68d4246641203faba6295dc69.tar.gz
rust-ab276b82b020b5c68d4246641203faba6295dc69.zip
Rollup merge of #89461 - crlf0710:dyn_upcasting_lint, r=nikomatsakis
Add `deref_into_dyn_supertrait` lint.

Initial implementation of #89460. Resolves #89190.
Maybe also worth a beta backport if necessary.

r? `@nikomatsakis`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs25
-rw-r--r--src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr16
2 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs
new file mode 100644
index 00000000000..c6725101858
--- /dev/null
+++ b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs
@@ -0,0 +1,25 @@
+#![deny(deref_into_dyn_supertrait)]
+
+extern crate core;
+
+use core::ops::Deref;
+
+// issue 89190
+trait A {}
+trait B: A {}
+impl<'a> Deref for dyn 'a + B {
+    type Target = dyn A;
+    fn deref(&self) -> &Self::Target {
+        todo!()
+    }
+}
+
+fn take_a(_: &dyn A) {}
+
+fn whoops(b: &dyn B) {
+    take_a(b)
+    //~^ ERROR `dyn B` implements `Deref` with supertrait `(dyn A + 'static)` as output
+    //~^^ WARN this was previously accepted by the compiler but is being phased out;
+}
+
+fn main() {}
diff --git a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr
new file mode 100644
index 00000000000..35af9112a27
--- /dev/null
+++ b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr
@@ -0,0 +1,16 @@
+error: `dyn B` implements `Deref` with supertrait `(dyn A + 'static)` as output
+  --> $DIR/migrate-lint-deny.rs:20:12
+   |
+LL |     take_a(b)
+   |            ^
+   |
+note: the lint level is defined here
+  --> $DIR/migrate-lint-deny.rs:1:9
+   |
+LL | #![deny(deref_into_dyn_supertrait)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>
+
+error: aborting due to previous error
+