From fa91980d2d686d3f426a2cae1d0e8fd6825d2d94 Mon Sep 17 00:00:00 2001 From: Matthew Kelly Date: Fri, 19 Aug 2022 06:27:31 -0400 Subject: Add long description and test for E0311 Adds a long description and unit test for the E0311 compiler error. --- src/test/ui/error-codes/E0311.rs | 18 +++++++++++++++ src/test/ui/error-codes/E0311.stderr | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/ui/error-codes/E0311.rs create mode 100644 src/test/ui/error-codes/E0311.stderr (limited to 'src') 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 { + fn nested_borrow_mut(&mut self) -> &mut V; +} + +impl NestedBorrowMut for T +where + T: BorrowMut, + U: BorrowMut, // 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 + '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 + '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`. -- cgit 1.4.1-3-g733a5