about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/char.rs13
-rw-r--r--tests/ui/class-cast-to-trait.rs54
-rw-r--r--tests/ui/class-cast-to-trait.stderr9
-rw-r--r--tests/ui/class-method-missing.rs21
-rw-r--r--tests/ui/class-method-missing.stderr12
-rw-r--r--tests/ui/cleanup-rvalue-for-scope.rs60
-rw-r--r--tests/ui/drop/for-expr-temporary-drop-scope.rs33
-rw-r--r--tests/ui/enum/enum-drop-cast-error.rs (renamed from tests/ui/cenum_impl_drop_cast.rs)4
-rw-r--r--tests/ui/enum/enum-drop-cast-error.stderr (renamed from tests/ui/cenum_impl_drop_cast.stderr)2
-rw-r--r--tests/ui/privacy/trait-object-method-error.rs20
-rw-r--r--tests/ui/privacy/trait-object-method-error.stderr15
-rw-r--r--tests/ui/traits/trait-impl-missing-method.rs13
-rw-r--r--tests/ui/traits/trait-impl-missing-method.stderr12
13 files changed, 98 insertions, 170 deletions
diff --git a/tests/ui/char.rs b/tests/ui/char.rs
deleted file mode 100644
index a7842f16fa7..00000000000
--- a/tests/ui/char.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//@ run-pass
-
-pub fn main() {
-    let c: char = 'x';
-    let d: char = 'x';
-    assert_eq!(c, 'x');
-    assert_eq!('x', c);
-    assert_eq!(c, c);
-    assert_eq!(c, d);
-    assert_eq!(d, c);
-    assert_eq!(d, 'x');
-    assert_eq!('x', d);
-}
diff --git a/tests/ui/class-cast-to-trait.rs b/tests/ui/class-cast-to-trait.rs
deleted file mode 100644
index ca98e4c9003..00000000000
--- a/tests/ui/class-cast-to-trait.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-trait Noisy {
-  fn speak(&mut self);
-}
-
-struct Cat {
-  meows : usize,
-
-  how_hungry : isize,
-  name : String,
-}
-
-impl Cat {
-  pub fn eat(&mut self) -> bool {
-    if self.how_hungry > 0 {
-        println!("OM NOM NOM");
-        self.how_hungry -= 2;
-        return true;
-    }
-    else {
-        println!("Not hungry!");
-        return false;
-    }
-  }
-}
-
-impl Noisy for Cat {
-  fn speak(&mut self) { self.meow(); }
-
-}
-
-impl Cat {
-    fn meow(&mut self) {
-      println!("Meow");
-      self.meows += 1;
-      if self.meows % 5 == 0 {
-          self.how_hungry += 1;
-      }
-    }
-}
-
-fn cat(in_x : usize, in_y : isize, in_name: String) -> Cat {
-    Cat {
-        meows: in_x,
-        how_hungry: in_y,
-        name: in_name
-    }
-}
-
-
-
-fn main() {
-  let nyan: Box<dyn Noisy> = Box::new(cat(0, 2, "nyan".to_string())) as Box<dyn Noisy>;
-  nyan.eat(); //~ ERROR no method named `eat` found
-}
diff --git a/tests/ui/class-cast-to-trait.stderr b/tests/ui/class-cast-to-trait.stderr
deleted file mode 100644
index 4ea0f41c3ed..00000000000
--- a/tests/ui/class-cast-to-trait.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0599]: no method named `eat` found for struct `Box<dyn Noisy>` in the current scope
-  --> $DIR/class-cast-to-trait.rs:53:8
-   |
-LL |   nyan.eat();
-   |        ^^^ method not found in `Box<dyn Noisy>`
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/class-method-missing.rs b/tests/ui/class-method-missing.rs
deleted file mode 100644
index 5dc18328f31..00000000000
--- a/tests/ui/class-method-missing.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-trait Animal {
-  fn eat(&self);
-}
-
-struct Cat {
-  meows: usize,
-}
-
-impl Animal for Cat {
-    //~^ ERROR not all trait items implemented, missing: `eat`
-}
-
-fn cat(in_x : usize) -> Cat {
-    Cat {
-        meows: in_x
-    }
-}
-
-fn main() {
-  let nyan = cat(0);
-}
diff --git a/tests/ui/class-method-missing.stderr b/tests/ui/class-method-missing.stderr
deleted file mode 100644
index 42bd22e18a1..00000000000
--- a/tests/ui/class-method-missing.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0046]: not all trait items implemented, missing: `eat`
-  --> $DIR/class-method-missing.rs:9:1
-   |
-LL |   fn eat(&self);
-   |   -------------- `eat` from trait
-...
-LL | impl Animal for Cat {
-   | ^^^^^^^^^^^^^^^^^^^ missing `eat` in implementation
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0046`.
diff --git a/tests/ui/cleanup-rvalue-for-scope.rs b/tests/ui/cleanup-rvalue-for-scope.rs
deleted file mode 100644
index 8f5ee8723fd..00000000000
--- a/tests/ui/cleanup-rvalue-for-scope.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-//@ run-pass
-
-#![allow(non_snake_case)]
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// Test that the lifetime of rvalues in for loops is extended
-// to the for loop itself.
-static mut FLAGS: u64 = 0;
-
-struct Box<T> { f: T }
-struct AddFlags { bits: u64 }
-
-fn AddFlags(bits: u64) -> AddFlags {
-    AddFlags { bits: bits }
-}
-
-fn arg(exp: u64, _x: &AddFlags) {
-    check_flags(exp);
-}
-
-fn pass<T>(v: T) -> T {
-    v
-}
-
-fn check_flags(exp: u64) {
-    unsafe {
-        let x = FLAGS;
-        FLAGS = 0;
-        println!("flags {}, expected {}", x, exp);
-        assert_eq!(x, exp);
-    }
-}
-
-impl AddFlags {
-    fn check_flags(&self, exp: u64) -> &AddFlags {
-        check_flags(exp);
-        self
-    }
-
-    fn bits(&self) -> u64 {
-        self.bits
-    }
-}
-
-impl Drop for AddFlags {
-    fn drop(&mut self) {
-        unsafe {
-            FLAGS = FLAGS + self.bits;
-        }
-    }
-}
-
-pub fn main() {
-    // The array containing [AddFlags] should not be dropped until
-    // after the for loop:
-    for x in &[AddFlags(1)] {
-        check_flags(0);
-    }
-    check_flags(1);
-}
diff --git a/tests/ui/drop/for-expr-temporary-drop-scope.rs b/tests/ui/drop/for-expr-temporary-drop-scope.rs
new file mode 100644
index 00000000000..c6f80842ee6
--- /dev/null
+++ b/tests/ui/drop/for-expr-temporary-drop-scope.rs
@@ -0,0 +1,33 @@
+//! Check that temporaries in the for into-iterable expr are not dropped
+//! until the end of the for expr.
+
+//@ run-pass
+
+static mut FLAGS: u64 = 0;
+
+struct AddFlags {
+    bits: u64,
+}
+
+impl Drop for AddFlags {
+    fn drop(&mut self) {
+        unsafe {
+            FLAGS += self.bits;
+        }
+    }
+}
+
+fn check_flags(expected: u64) {
+    unsafe {
+        let actual = FLAGS;
+        FLAGS = 0;
+        assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
+    }
+}
+
+fn main() {
+    for _ in &[AddFlags { bits: 1 }] {
+        check_flags(0);
+    }
+    check_flags(1);
+}
diff --git a/tests/ui/cenum_impl_drop_cast.rs b/tests/ui/enum/enum-drop-cast-error.rs
index f681434dd86..36101573624 100644
--- a/tests/ui/cenum_impl_drop_cast.rs
+++ b/tests/ui/enum/enum-drop-cast-error.rs
@@ -1,3 +1,7 @@
+//! Check that trying to cast an enum with a Drop impl to an integer is rejected.
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/35941>
+
 enum E {
     A = 0,
 }
diff --git a/tests/ui/cenum_impl_drop_cast.stderr b/tests/ui/enum/enum-drop-cast-error.stderr
index 35c69f4b4b7..b58abbd39d3 100644
--- a/tests/ui/cenum_impl_drop_cast.stderr
+++ b/tests/ui/enum/enum-drop-cast-error.stderr
@@ -1,5 +1,5 @@
 error: cannot cast enum `E` into integer `u32` because it implements `Drop`
-  --> $DIR/cenum_impl_drop_cast.rs:13:13
+  --> $DIR/enum-drop-cast-error.rs:17:13
    |
 LL |     let i = e as u32;
    |             ^^^^^^^^
diff --git a/tests/ui/privacy/trait-object-method-error.rs b/tests/ui/privacy/trait-object-method-error.rs
new file mode 100644
index 00000000000..f0214dc6361
--- /dev/null
+++ b/tests/ui/privacy/trait-object-method-error.rs
@@ -0,0 +1,20 @@
+//! Trait objects only allow access to methods defined in the trait.
+
+trait MyTrait {
+    fn trait_method(&mut self);
+}
+
+struct ImplType;
+
+impl MyTrait for ImplType {
+    fn trait_method(&mut self) {}
+}
+
+impl ImplType {
+    fn struct_impl_method(&mut self) {}
+}
+
+fn main() {
+    let obj: Box<dyn MyTrait> = Box::new(ImplType);
+    obj.struct_impl_method(); //~ ERROR no method named `struct_impl_method` found
+}
diff --git a/tests/ui/privacy/trait-object-method-error.stderr b/tests/ui/privacy/trait-object-method-error.stderr
new file mode 100644
index 00000000000..40dde8fc47e
--- /dev/null
+++ b/tests/ui/privacy/trait-object-method-error.stderr
@@ -0,0 +1,15 @@
+error[E0599]: no method named `struct_impl_method` found for struct `Box<dyn MyTrait>` in the current scope
+  --> $DIR/trait-object-method-error.rs:19:9
+   |
+LL |     obj.struct_impl_method();
+   |         ^^^^^^^^^^^^^^^^^^
+   |
+help: there is a method `trait_method` with a similar name
+   |
+LL -     obj.struct_impl_method();
+LL +     obj.trait_method();
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/traits/trait-impl-missing-method.rs b/tests/ui/traits/trait-impl-missing-method.rs
new file mode 100644
index 00000000000..1f03a332c4a
--- /dev/null
+++ b/tests/ui/traits/trait-impl-missing-method.rs
@@ -0,0 +1,13 @@
+//! Trait impls must define all required methods.
+
+trait MyTrait {
+    fn trait_method(&self);
+}
+
+struct ImplType;
+
+impl MyTrait for ImplType {} //~ ERROR not all trait items implemented, missing: `trait_method`
+
+fn main() {
+    let _ = ImplType;
+}
diff --git a/tests/ui/traits/trait-impl-missing-method.stderr b/tests/ui/traits/trait-impl-missing-method.stderr
new file mode 100644
index 00000000000..ae11c3665ee
--- /dev/null
+++ b/tests/ui/traits/trait-impl-missing-method.stderr
@@ -0,0 +1,12 @@
+error[E0046]: not all trait items implemented, missing: `trait_method`
+  --> $DIR/trait-impl-missing-method.rs:9:1
+   |
+LL |     fn trait_method(&self);
+   |     ----------------------- `trait_method` from trait
+...
+LL | impl MyTrait for ImplType {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `trait_method` in implementation
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0046`.