Skip to content

Commit 7485db9

Browse files
committed
fixed reviews
1 parent 9832267 commit 7485db9

9 files changed

+57
-140
lines changed

tests/ui/enum/enum-drop-cast-error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! Ensures safe handling of enums with `Drop` by preventing integer casts.
1+
//! Check that trying to cast an enum with a Drop impl to an integer is rejected.
2+
//!
3+
//! Issue: <https://github.com/rust-lang/rust/issues/35941>
24
35
enum E {
46
A = 0,

tests/ui/lifetimes/rvalue-lifetime-for-loop.rs

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,32 @@
1-
//! Test that the lifetime of rvalues in for loops is extended
2-
//! to the for loop itself.
1+
//! Check that temporaries in the for into-iterable expr are not dropped
2+
//! until the end of the for expr.
33
44
//@ run-pass
55

6-
#![allow(non_snake_case)]
7-
#![allow(dead_code)]
8-
#![allow(unused_variables)]
9-
106
static mut FLAGS: u64 = 0;
117

12-
struct Box<T> {
13-
f: T,
14-
}
158
struct AddFlags {
169
bits: u64,
1710
}
1811

19-
fn AddFlags(bits: u64) -> AddFlags {
20-
AddFlags { bits }
21-
}
22-
23-
fn arg(exp: u64, _x: &AddFlags) {
24-
check_flags(exp);
25-
}
26-
27-
fn pass<T>(v: T) -> T {
28-
v
29-
}
30-
31-
fn check_flags(exp: u64) {
32-
unsafe {
33-
let x = FLAGS;
34-
FLAGS = 0;
35-
println!("flags {}, expected {}", x, exp);
36-
assert_eq!(x, exp);
37-
}
38-
}
39-
40-
impl AddFlags {
41-
fn check_flags(&self, exp: u64) -> &AddFlags {
42-
check_flags(exp);
43-
self
44-
}
45-
46-
fn bits(&self) -> u64 {
47-
self.bits
48-
}
49-
}
50-
5112
impl Drop for AddFlags {
5213
fn drop(&mut self) {
5314
unsafe {
54-
FLAGS = FLAGS + self.bits;
15+
FLAGS += self.bits;
5516
}
5617
}
5718
}
5819

59-
pub fn main() {
60-
// The array containing [AddFlags] should not be dropped until
61-
// after the for loop:
62-
for x in &[AddFlags(1)] {
20+
fn check_flags(expected: u64) {
21+
unsafe {
22+
let actual = FLAGS;
23+
FLAGS = 0;
24+
assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
25+
}
26+
}
27+
28+
fn main() {
29+
for _ in &[AddFlags { bits: 1 }] {
6330
check_flags(0);
6431
}
6532
check_flags(1);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Trait objects only allow access to methods defined in the trait.
2+
3+
trait MyTrait {
4+
fn do_something(&mut self);
5+
}
6+
7+
struct ImplType;
8+
9+
impl MyTrait for ImplType {
10+
fn do_something(&mut self) {}
11+
}
12+
13+
impl ImplType {
14+
fn extra_method(&mut self) {}
15+
}
16+
17+
fn main() {
18+
let obj: Box<dyn MyTrait> = Box::new(ImplType);
19+
obj.extra_method(); //~ ERROR no method named `extra_method` found
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0599]: no method named `extra_method` found for struct `Box<dyn MyTrait>` in the current scope
2+
--> $DIR/trait-object-method-error.rs:19:9
3+
|
4+
LL | obj.extra_method();
5+
| ^^^^^^^^^^^^ method not found in `Box<dyn MyTrait>`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0599`.
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
//! Ensures trait implementations provide all required methods.
1+
//! Trait impls must define all required methods.
22
3-
trait Animal {
4-
fn eat(&self);
3+
trait MyTrait {
4+
fn do_something(&self);
55
}
66

7-
struct Cat {
8-
meows: usize,
9-
}
10-
11-
impl Animal for Cat {
12-
//~^ ERROR not all trait items implemented, missing: `eat`
13-
}
7+
struct ImplType;
148

15-
fn cat(in_x: usize) -> Cat {
16-
Cat { meows: in_x }
17-
}
9+
impl MyTrait for ImplType {} //~ ERROR not all trait items implemented, missing: `do_something`
1810

1911
fn main() {
20-
let nyan = cat(0);
12+
let _ = ImplType;
2113
}

tests/ui/traits/trait-impl-missing-method.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0046]: not all trait items implemented, missing: `eat`
2-
--> $DIR/trait-impl-missing-method.rs:11:1
1+
error[E0046]: not all trait items implemented, missing: `do_something`
2+
--> $DIR/trait-impl-missing-method.rs:9:1
33
|
4-
LL | fn eat(&self);
5-
| -------------- `eat` from trait
4+
LL | fn do_something(&self);
5+
| ----------------------- `do_something` from trait
66
...
7-
LL | impl Animal for Cat {
8-
| ^^^^^^^^^^^^^^^^^^^ missing `eat` in implementation
7+
LL | impl MyTrait for ImplType {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `do_something` in implementation
99

1010
error: aborting due to 1 previous error
1111

tests/ui/traits/trait-object-method-error.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/ui/traits/trait-object-method-error.stderr

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/ui/typeck/char-equality.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)