about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authormejrs <>2022-09-26 00:55:35 +0200
committermejrs <>2022-09-27 21:42:09 +0200
commitc4c94151321b8018ceb06ccff359109b8fed6bfe (patch)
treee9572b4e96cee41a8934626b50b98e22305b19c8 /src
parent57ee5cf5a93923dae9c98bffb11545fc3a31368d (diff)
downloadrust-c4c94151321b8018ceb06ccff359109b8fed6bfe.tar.gz
rust-c4c94151321b8018ceb06ccff359109b8fed6bfe.zip
Wrapper suggestions
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/suggestions/inner_type.fixed30
-rw-r--r--src/test/ui/suggestions/inner_type.rs30
-rw-r--r--src/test/ui/suggestions/inner_type.stderr51
-rw-r--r--src/test/ui/suggestions/inner_type2.rs26
-rw-r--r--src/test/ui/suggestions/inner_type2.stderr29
5 files changed, 166 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/inner_type.fixed b/src/test/ui/suggestions/inner_type.fixed
new file mode 100644
index 00000000000..f6dc7c4ce17
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.fixed
@@ -0,0 +1,30 @@
+// compile-flags: --edition=2021
+// run-rustfix
+
+pub struct Struct<T> {
+    pub p: T,
+}
+
+impl<T> Struct<T> {
+    pub fn method(&self) {}
+
+    pub fn some_mutable_method(&mut self) {}
+}
+
+fn main() {
+    let other_item = std::cell::RefCell::new(Struct { p: 42_u32 });
+
+    other_item.borrow().method();
+    //~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
+    //~| HELP use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
+
+    other_item.borrow_mut().some_mutable_method();
+    //~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
+    //~| HELP use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
+
+    let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
+
+    another_item.lock().unwrap().method();
+    //~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
+    //~| HELP use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
+}
\ No newline at end of file
diff --git a/src/test/ui/suggestions/inner_type.rs b/src/test/ui/suggestions/inner_type.rs
new file mode 100644
index 00000000000..b42067c047c
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.rs
@@ -0,0 +1,30 @@
+// compile-flags: --edition=2021
+// run-rustfix
+
+pub struct Struct<T> {
+    pub p: T,
+}
+
+impl<T> Struct<T> {
+    pub fn method(&self) {}
+
+    pub fn some_mutable_method(&mut self) {}
+}
+
+fn main() {
+    let other_item = std::cell::RefCell::new(Struct { p: 42_u32 });
+
+    other_item.method();
+    //~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
+    //~| HELP use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
+
+    other_item.some_mutable_method();
+    //~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
+    //~| HELP use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
+
+    let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
+
+    another_item.method();
+    //~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
+    //~| HELP use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
+}
\ No newline at end of file
diff --git a/src/test/ui/suggestions/inner_type.stderr b/src/test/ui/suggestions/inner_type.stderr
new file mode 100644
index 00000000000..f2b25944c8b
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.stderr
@@ -0,0 +1,51 @@
+error[E0599]: no method named `method` found for struct `RefCell` in the current scope
+  --> $DIR/inner_type.rs:17:16
+   |
+LL |     other_item.method();
+   |                ^^^^^^ method not found in `RefCell<Struct<u32>>`
+   |
+note: the method `method` exists on the type `Struct<u32>`
+  --> $DIR/inner_type.rs:9:5
+   |
+LL |     pub fn method(&self) {}
+   |     ^^^^^^^^^^^^^^^^^^^^
+help: use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
+   |
+LL |     other_item.borrow().method();
+   |               +++++++++
+
+error[E0599]: no method named `some_mutable_method` found for struct `RefCell` in the current scope
+  --> $DIR/inner_type.rs:21:16
+   |
+LL |     other_item.some_mutable_method();
+   |                ^^^^^^^^^^^^^^^^^^^ method not found in `RefCell<Struct<u32>>`
+   |
+note: the method `some_mutable_method` exists on the type `Struct<u32>`
+  --> $DIR/inner_type.rs:11:5
+   |
+LL |     pub fn some_mutable_method(&mut self) {}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
+   |
+LL |     other_item.borrow_mut().some_mutable_method();
+   |               +++++++++++++
+
+error[E0599]: no method named `method` found for struct `Mutex` in the current scope
+  --> $DIR/inner_type.rs:27:18
+   |
+LL |     another_item.method();
+   |                  ^^^^^^ method not found in `Mutex<Struct<u32>>`
+   |
+note: the method `method` exists on the type `Struct<u32>`
+  --> $DIR/inner_type.rs:9:5
+   |
+LL |     pub fn method(&self) {}
+   |     ^^^^^^^^^^^^^^^^^^^^
+help: use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
+   |
+LL |     another_item.lock().unwrap().method();
+   |                 ++++++++++++++++
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/suggestions/inner_type2.rs b/src/test/ui/suggestions/inner_type2.rs
new file mode 100644
index 00000000000..694c0adfd06
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type2.rs
@@ -0,0 +1,26 @@
+pub struct Struct<T> {
+    pub p: T,
+}
+
+impl<T> Struct<T> {
+    pub fn method(&self) {}
+
+    pub fn some_mutable_method(&mut self) {}
+}
+
+thread_local! {
+    static STRUCT: Struct<u32> = Struct {
+        p: 42_u32
+    };
+}
+
+fn main() {
+    STRUCT.method();
+    //~^ ERROR no method named `method` found for struct `LocalKey` in the current scope [E0599]
+    //~| HELP use `with` or `try_with` to access the contents of threadlocals
+
+    let item = std::mem::MaybeUninit::new(Struct { p: 42_u32 });
+    item.method();
+    //~^ ERROR no method named `method` found for union `MaybeUninit` in the current scope [E0599]
+    //~| HELP if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
+}
\ No newline at end of file
diff --git a/src/test/ui/suggestions/inner_type2.stderr b/src/test/ui/suggestions/inner_type2.stderr
new file mode 100644
index 00000000000..40e7a7ab41e
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type2.stderr
@@ -0,0 +1,29 @@
+error[E0599]: no method named `method` found for struct `LocalKey` in the current scope
+  --> $DIR/inner_type2.rs:18:12
+   |
+LL |     STRUCT.method();
+   |            ^^^^^^ method not found in `LocalKey<Struct<u32>>`
+   |
+   = help: use `with` or `try_with` to access the contents of threadlocals
+note: the method `method` exists on the type `Struct<u32>`
+  --> $DIR/inner_type2.rs:6:5
+   |
+LL |     pub fn method(&self) {}
+   |     ^^^^^^^^^^^^^^^^^^^^
+
+error[E0599]: no method named `method` found for union `MaybeUninit` in the current scope
+  --> $DIR/inner_type2.rs:23:10
+   |
+LL |     item.method();
+   |          ^^^^^^ method not found in `MaybeUninit<Struct<u32>>`
+   |
+   = help: if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
+note: the method `method` exists on the type `Struct<u32>`
+  --> $DIR/inner_type2.rs:6:5
+   |
+LL |     pub fn method(&self) {}
+   |     ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.