summaryrefslogtreecommitdiffstats
path: root/tests/ui/explicit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/explicit
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/explicit')
-rw-r--r--tests/ui/explicit/explicit-call-to-dtor.fixed16
-rw-r--r--tests/ui/explicit/explicit-call-to-dtor.rs16
-rw-r--r--tests/ui/explicit/explicit-call-to-dtor.stderr12
-rw-r--r--tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed26
-rw-r--r--tests/ui/explicit/explicit-call-to-supertrait-dtor.rs26
-rw-r--r--tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr12
-rw-r--r--tests/ui/explicit/explicit-self-lifetime-mismatch.rs20
-rw-r--r--tests/ui/explicit/explicit-self-lifetime-mismatch.stderr41
8 files changed, 169 insertions, 0 deletions
diff --git a/tests/ui/explicit/explicit-call-to-dtor.fixed b/tests/ui/explicit/explicit-call-to-dtor.fixed
new file mode 100644
index 000000000..91a4ca608
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-dtor.fixed
@@ -0,0 +1,16 @@
+// run-rustfix
+struct Foo {
+ x: isize
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+
+fn main() {
+ let x = Foo { x: 3 };
+ println!("{}", x.x);
+ drop(x); //~ ERROR explicit use of destructor method
+}
diff --git a/tests/ui/explicit/explicit-call-to-dtor.rs b/tests/ui/explicit/explicit-call-to-dtor.rs
new file mode 100644
index 000000000..0656871eb
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-dtor.rs
@@ -0,0 +1,16 @@
+// run-rustfix
+struct Foo {
+ x: isize
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+
+fn main() {
+ let x = Foo { x: 3 };
+ println!("{}", x.x);
+ x.drop(); //~ ERROR explicit use of destructor method
+}
diff --git a/tests/ui/explicit/explicit-call-to-dtor.stderr b/tests/ui/explicit/explicit-call-to-dtor.stderr
new file mode 100644
index 000000000..f3c9bf6cc
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-dtor.stderr
@@ -0,0 +1,12 @@
+error[E0040]: explicit use of destructor method
+ --> $DIR/explicit-call-to-dtor.rs:15:7
+ |
+LL | x.drop();
+ | --^^^^--
+ | | |
+ | | explicit destructor calls not allowed
+ | help: consider using `drop` function: `drop(x)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0040`.
diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed b/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed
new file mode 100644
index 000000000..47c4c9f67
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed
@@ -0,0 +1,26 @@
+// run-rustfix
+struct Foo {
+ x: isize
+}
+
+#[allow(drop_bounds)]
+trait Bar: Drop {
+ fn blah(&self);
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+
+impl Bar for Foo {
+ fn blah(&self) {
+ drop(self); //~ ERROR explicit use of destructor method
+ }
+}
+
+fn main() {
+ let x = Foo { x: 3 };
+ println!("{}", x.x);
+}
diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs b/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs
new file mode 100644
index 000000000..c698de50c
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs
@@ -0,0 +1,26 @@
+// run-rustfix
+struct Foo {
+ x: isize
+}
+
+#[allow(drop_bounds)]
+trait Bar: Drop {
+ fn blah(&self);
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("kaboom");
+ }
+}
+
+impl Bar for Foo {
+ fn blah(&self) {
+ self.drop(); //~ ERROR explicit use of destructor method
+ }
+}
+
+fn main() {
+ let x = Foo { x: 3 };
+ println!("{}", x.x);
+}
diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr
new file mode 100644
index 000000000..7f5106eb5
--- /dev/null
+++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr
@@ -0,0 +1,12 @@
+error[E0040]: explicit use of destructor method
+ --> $DIR/explicit-call-to-supertrait-dtor.rs:19:14
+ |
+LL | self.drop();
+ | -----^^^^--
+ | | |
+ | | explicit destructor calls not allowed
+ | help: consider using `drop` function: `drop(self)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0040`.
diff --git a/tests/ui/explicit/explicit-self-lifetime-mismatch.rs b/tests/ui/explicit/explicit-self-lifetime-mismatch.rs
new file mode 100644
index 000000000..a9a6f50fb
--- /dev/null
+++ b/tests/ui/explicit/explicit-self-lifetime-mismatch.rs
@@ -0,0 +1,20 @@
+struct Foo<'a,'b> {
+ x: &'a isize,
+ y: &'b isize,
+}
+
+impl<'a,'b> Foo<'a,'b> {
+ fn bar(self:
+ Foo<'b,'a>
+ //~^ ERROR mismatched `self` parameter type
+ //~| expected struct `Foo<'a, 'b>`
+ //~| found struct `Foo<'b, 'a>`
+ //~| lifetime mismatch
+ //~| ERROR mismatched `self` parameter type
+ //~| expected struct `Foo<'a, 'b>`
+ //~| found struct `Foo<'b, 'a>`
+ //~| lifetime mismatch
+ ) {}
+}
+
+fn main() {}
diff --git a/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr b/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr
new file mode 100644
index 000000000..d5ffa8f1b
--- /dev/null
+++ b/tests/ui/explicit/explicit-self-lifetime-mismatch.stderr
@@ -0,0 +1,41 @@
+error[E0308]: mismatched `self` parameter type
+ --> $DIR/explicit-self-lifetime-mismatch.rs:8:12
+ |
+LL | Foo<'b,'a>
+ | ^^^^^^^^^^ lifetime mismatch
+ |
+ = note: expected struct `Foo<'a, 'b>`
+ found struct `Foo<'b, 'a>`
+note: the lifetime `'b` as defined here...
+ --> $DIR/explicit-self-lifetime-mismatch.rs:6:9
+ |
+LL | impl<'a,'b> Foo<'a,'b> {
+ | ^^
+note: ...does not necessarily outlive the lifetime `'a` as defined here
+ --> $DIR/explicit-self-lifetime-mismatch.rs:6:6
+ |
+LL | impl<'a,'b> Foo<'a,'b> {
+ | ^^
+
+error[E0308]: mismatched `self` parameter type
+ --> $DIR/explicit-self-lifetime-mismatch.rs:8:12
+ |
+LL | Foo<'b,'a>
+ | ^^^^^^^^^^ lifetime mismatch
+ |
+ = note: expected struct `Foo<'a, 'b>`
+ found struct `Foo<'b, 'a>`
+note: the lifetime `'a` as defined here...
+ --> $DIR/explicit-self-lifetime-mismatch.rs:6:6
+ |
+LL | impl<'a,'b> Foo<'a,'b> {
+ | ^^
+note: ...does not necessarily outlive the lifetime `'b` as defined here
+ --> $DIR/explicit-self-lifetime-mismatch.rs:6:9
+ |
+LL | impl<'a,'b> Foo<'a,'b> {
+ | ^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.