about summary refs log tree commit diff
path: root/src/test/ui/error-codes
diff options
context:
space:
mode:
authorMatthew Kelly <matthew.kelly2@gmail.com>2022-08-19 06:27:31 -0400
committerMatthew Kelly <matthew.kelly2@gmail.com>2022-08-19 06:46:37 -0400
commitfa91980d2d686d3f426a2cae1d0e8fd6825d2d94 (patch)
tree721f3338bfe28410f3378bfc56f5a6f41b838913 /src/test/ui/error-codes
parent6c943bad02626dddc5e5135b23c77429b6e4a063 (diff)
downloadrust-fa91980d2d686d3f426a2cae1d0e8fd6825d2d94.tar.gz
rust-fa91980d2d686d3f426a2cae1d0e8fd6825d2d94.zip
Add long description and test for E0311
Adds a long description and unit test for the E0311 compiler error.
Diffstat (limited to 'src/test/ui/error-codes')
-rw-r--r--src/test/ui/error-codes/E0311.rs18
-rw-r--r--src/test/ui/error-codes/E0311.stderr45
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/ui/error-codes/E0311.rs b/src/test/ui/error-codes/E0311.rs
new file mode 100644
index 00000000000..eb9a473e9a2
--- /dev/null
+++ b/src/test/ui/error-codes/E0311.rs
@@ -0,0 +1,18 @@
+use std::borrow::BorrowMut;
+
+trait NestedBorrowMut<U, V> {
+    fn nested_borrow_mut(&mut self) -> &mut V;
+}
+
+impl<T, U, V> NestedBorrowMut<U, V> for T
+where
+    T: BorrowMut<U>,
+    U: BorrowMut<V>, // Error is caused by missing lifetime here
+{
+    fn nested_borrow_mut(&mut self) -> &mut V {
+        let u_ref = self.borrow_mut(); //~ ERROR E0311
+        u_ref.borrow_mut() //~ ERROR E0311
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/error-codes/E0311.stderr b/src/test/ui/error-codes/E0311.stderr
new file mode 100644
index 00000000000..a219a6352ad
--- /dev/null
+++ b/src/test/ui/error-codes/E0311.stderr
@@ -0,0 +1,45 @@
+error[E0311]: the parameter type `U` may not live long enough
+  --> $DIR/E0311.rs:13:21
+   |
+LL |         let u_ref = self.borrow_mut();
+   |                     ^^^^^^^^^^^^^^^^^
+   |
+note: the parameter type `U` must be valid for the anonymous lifetime defined here...
+  --> $DIR/E0311.rs:12:26
+   |
+LL |     fn nested_borrow_mut(&mut self) -> &mut V {
+   |                          ^^^^^^^^^
+note: ...so that the type `U` will meet its required lifetime bounds
+  --> $DIR/E0311.rs:13:21
+   |
+LL |         let u_ref = self.borrow_mut();
+   |                     ^^^^^^^^^^^^^^^^^
+help: consider adding an explicit lifetime bound...
+   |
+LL |     U: BorrowMut<V> + 'a, // Error is caused by missing lifetime here
+   |                     ++++
+
+error[E0311]: the parameter type `U` may not live long enough
+  --> $DIR/E0311.rs:14:9
+   |
+LL |         u_ref.borrow_mut()
+   |         ^^^^^^^^^^^^^^^^^^
+   |
+note: the parameter type `U` must be valid for the anonymous lifetime defined here...
+  --> $DIR/E0311.rs:12:26
+   |
+LL |     fn nested_borrow_mut(&mut self) -> &mut V {
+   |                          ^^^^^^^^^
+note: ...so that the type `U` will meet its required lifetime bounds
+  --> $DIR/E0311.rs:14:9
+   |
+LL |         u_ref.borrow_mut()
+   |         ^^^^^^^^^^^^^^^^^^
+help: consider adding an explicit lifetime bound...
+   |
+LL |     U: BorrowMut<V> + 'a, // Error is caused by missing lifetime here
+   |                     ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0311`.