about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-06-08 07:37:29 +0200
committerGitHub <noreply@github.com>2022-06-08 07:37:29 +0200
commit148a44a001ccffbcf0baca5ec0a4b160f41ef99d (patch)
tree333b0d6ac191ccfdb98567613b7139db920a5e77 /src
parent47aee31b2a89cb7de97d779869a30b046632b6af (diff)
parent8f1fff04a72f65bc991b0c76b7b7300384b0d33d (diff)
downloadrust-148a44a001ccffbcf0baca5ec0a4b160f41ef99d.tar.gz
rust-148a44a001ccffbcf0baca5ec0a4b160f41ef99d.zip
Rollup merge of #97595 - ouz-a:issue-97381, r=compiler-errors
Remove unwrap from get_vtable

This avoids ICE on issue #97381 I think the bug is a bit deeper though, it compiles fine when `v` is `&v` which makes me think `Deref` is causing some issue with borrowck but it's fine I guess since this thing crashes since `nightly-2020-09-17` 😅
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/traits/vtable/issue-97381.rs30
-rw-r--r--src/test/ui/traits/vtable/issue-97381.stderr15
-rw-r--r--src/test/ui/type/type-unsatisfiable.rs59
-rw-r--r--src/test/ui/type/type-unsatisfiable.usage.stderr11
4 files changed, 115 insertions, 0 deletions
diff --git a/src/test/ui/traits/vtable/issue-97381.rs b/src/test/ui/traits/vtable/issue-97381.rs
new file mode 100644
index 00000000000..393cf91efc2
--- /dev/null
+++ b/src/test/ui/traits/vtable/issue-97381.rs
@@ -0,0 +1,30 @@
+use std::ops::Deref;
+trait MyTrait: Deref<Target = u32> {}
+struct MyStruct(u32);
+impl MyTrait for MyStruct {}
+impl Deref for MyStruct {
+    type Target = u32;
+
+    fn deref(&self) -> &Self::Target {
+        &self.0
+    }
+}
+fn get_concrete_value(i: u32) -> MyStruct {
+    MyStruct(i)
+}
+fn get_boxed_value(i: u32) -> Box<dyn MyTrait> {
+    Box::new(get_concrete_value(i))
+}
+fn main() {
+    let v = [1, 2, 3]
+        .iter()
+        .map(|i| get_boxed_value(*i))
+        .collect::<Vec<_>>();
+
+    let el = &v[0];
+
+    for _ in v {
+        //~^ ERROR cannot move out of `v` because it is borrowed
+        println!("{}", ***el > 0);
+    }
+}
diff --git a/src/test/ui/traits/vtable/issue-97381.stderr b/src/test/ui/traits/vtable/issue-97381.stderr
new file mode 100644
index 00000000000..f88c8716ff7
--- /dev/null
+++ b/src/test/ui/traits/vtable/issue-97381.stderr
@@ -0,0 +1,15 @@
+error[E0505]: cannot move out of `v` because it is borrowed
+  --> $DIR/issue-97381.rs:26:14
+   |
+LL |     let el = &v[0];
+   |               - borrow of `v` occurs here
+LL | 
+LL |     for _ in v {
+   |              ^ move out of `v` occurs here
+LL |
+LL |         println!("{}", ***el > 0);
+   |                         ---- borrow later used here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0505`.
diff --git a/src/test/ui/type/type-unsatisfiable.rs b/src/test/ui/type/type-unsatisfiable.rs
new file mode 100644
index 00000000000..7fbbb50dc11
--- /dev/null
+++ b/src/test/ui/type/type-unsatisfiable.rs
@@ -0,0 +1,59 @@
+// revisions: lib usage
+//[lib] compile-flags: --crate-type=lib
+//[lib] build-pass
+
+use std::ops::Sub;
+trait Vector2 {
+    type ScalarType;
+
+    fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
+    where
+        Self: Sized;
+
+    fn x(&self) -> Self::ScalarType;
+    fn y(&self) -> Self::ScalarType;
+}
+
+impl<T> Sub for dyn Vector2<ScalarType = T>
+where
+    T: Sub<Output = T>,
+    (dyn Vector2<ScalarType = T>): Sized,
+{
+    type Output = dyn Vector2<ScalarType = T>;
+
+    fn sub(self, rhs: Self) -> Self::Output {
+        Self::from_values(self.x() - rhs.x(), self.y() - rhs.y())
+    }
+}
+
+struct Vec2 {
+    x: i32,
+    y: i32,
+}
+
+impl Vector2 for Vec2 {
+    type ScalarType = i32;
+
+    fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self
+    where
+        Self: Sized,
+    {
+        Self { x, y }
+    }
+
+    fn x(&self) -> Self::ScalarType {
+        self.x
+    }
+    fn y(&self) -> Self::ScalarType {
+        self.y
+    }
+}
+
+#[cfg(usage)]
+fn main() {
+    let hey: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
+    let word: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 });
+
+    let bar = *hey - *word;
+    //[usage]~^ ERROR cannot subtract
+}
diff --git a/src/test/ui/type/type-unsatisfiable.usage.stderr b/src/test/ui/type/type-unsatisfiable.usage.stderr
new file mode 100644
index 00000000000..56e2e30afac
--- /dev/null
+++ b/src/test/ui/type/type-unsatisfiable.usage.stderr
@@ -0,0 +1,11 @@
+error[E0369]: cannot subtract `(dyn Vector2<ScalarType = i32> + 'static)` from `dyn Vector2<ScalarType = i32>`
+  --> $DIR/type-unsatisfiable.rs:57:20
+   |
+LL |     let bar = *hey - *word;
+   |               ---- ^ ----- (dyn Vector2<ScalarType = i32> + 'static)
+   |               |
+   |               dyn Vector2<ScalarType = i32>
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.