diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/mir-opt/simplify-locals.rs | 7 | ||||
| -rw-r--r-- | src/test/mir-opt/simplify_locals.expose_addr.SimplifyLocals.diff | 21 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/use_instead_of_import.fixed | 15 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/use_instead_of_import.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/use_instead_of_import.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/parser/match-arm-without-braces.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/parser/match-arm-without-braces.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/traits/vtable/issue-97381.rs | 30 | ||||
| -rw-r--r-- | src/test/ui/traits/vtable/issue-97381.stderr | 15 | ||||
| -rw-r--r-- | src/test/ui/type/type-unsatisfiable.rs | 59 | ||||
| -rw-r--r-- | src/test/ui/type/type-unsatisfiable.usage.stderr | 11 |
11 files changed, 193 insertions, 10 deletions
diff --git a/src/test/mir-opt/simplify-locals.rs b/src/test/mir-opt/simplify-locals.rs index 5862cf2eb29..f6bf396cd05 100644 --- a/src/test/mir-opt/simplify-locals.rs +++ b/src/test/mir-opt/simplify-locals.rs @@ -62,6 +62,12 @@ fn t4() -> u32 { unsafe { X + 1 } } +// EMIT_MIR simplify_locals.expose_addr.SimplifyLocals.diff +fn expose_addr(p: *const usize) { + // Used pointer to address cast. Has a side effect of exposing the provenance. + p as usize; +} + fn main() { c(); d1(); @@ -71,4 +77,5 @@ fn main() { t2(); t3(); t4(); + expose_addr(&0); } diff --git a/src/test/mir-opt/simplify_locals.expose_addr.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.expose_addr.SimplifyLocals.diff new file mode 100644 index 00000000000..93d77ad40aa --- /dev/null +++ b/src/test/mir-opt/simplify_locals.expose_addr.SimplifyLocals.diff @@ -0,0 +1,21 @@ +- // MIR for `expose_addr` before SimplifyLocals ++ // MIR for `expose_addr` after SimplifyLocals + + fn expose_addr(_1: *const usize) -> () { + debug p => _1; // in scope 0 at $DIR/simplify-locals.rs:66:16: 66:17 + let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:66:33: 66:33 + let _2: usize; // in scope 0 at $DIR/simplify-locals.rs:68:5: 68:15 + let mut _3: *const usize; // in scope 0 at $DIR/simplify-locals.rs:68:5: 68:6 + + bb0: { + StorageLive(_2); // scope 0 at $DIR/simplify-locals.rs:68:5: 68:15 + StorageLive(_3); // scope 0 at $DIR/simplify-locals.rs:68:5: 68:6 + _3 = _1; // scope 0 at $DIR/simplify-locals.rs:68:5: 68:6 + _2 = move _3 as usize (PointerExposeAddress); // scope 0 at $DIR/simplify-locals.rs:68:5: 68:15 + StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:68:14: 68:15 + StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:68:15: 68:16 + _0 = const (); // scope 0 at $DIR/simplify-locals.rs:66:33: 69:2 + return; // scope 0 at $DIR/simplify-locals.rs:69:2: 69:2 + } + } + diff --git a/src/test/ui/did_you_mean/use_instead_of_import.fixed b/src/test/ui/did_you_mean/use_instead_of_import.fixed new file mode 100644 index 00000000000..87d453e1565 --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +use std::{ + //~^ ERROR expected item, found `import` + io::Write, + rc::Rc, +}; + +pub use std::io; +//~^ ERROR expected item, found `using` + +fn main() { + let x = Rc::new(1); + let _ = write!(io::stdout(), "{:?}", x); +} diff --git a/src/test/ui/did_you_mean/use_instead_of_import.rs b/src/test/ui/did_you_mean/use_instead_of_import.rs new file mode 100644 index 00000000000..59e83732328 --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.rs @@ -0,0 +1,15 @@ +// run-rustfix + +import std::{ + //~^ ERROR expected item, found `import` + io::Write, + rc::Rc, +}; + +pub using std::io; +//~^ ERROR expected item, found `using` + +fn main() { + let x = Rc::new(1); + let _ = write!(io::stdout(), "{:?}", x); +} diff --git a/src/test/ui/did_you_mean/use_instead_of_import.stderr b/src/test/ui/did_you_mean/use_instead_of_import.stderr new file mode 100644 index 00000000000..b22954af80f --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.stderr @@ -0,0 +1,14 @@ +error: expected item, found `import` + --> $DIR/use_instead_of_import.rs:3:1 + | +LL | import std::{ + | ^^^^^^ help: items are imported using the `use` keyword + +error: expected item, found `using` + --> $DIR/use_instead_of_import.rs:9:5 + | +LL | pub using std::io; + | ^^^^^ help: items are imported using the `use` keyword + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/match-arm-without-braces.rs b/src/test/ui/parser/match-arm-without-braces.rs index 55a88742769..bba38fd0fa4 100644 --- a/src/test/ui/parser/match-arm-without-braces.rs +++ b/src/test/ui/parser/match-arm-without-braces.rs @@ -45,9 +45,9 @@ fn main() { 15; } match S::get(16) { - Some(Val::Foo) => 17 - _ => 18, //~ ERROR expected one of - } + Some(Val::Foo) => 17 //~ ERROR expected `,` following `match` arm + _ => 18, + }; match S::get(19) { Some(Val::Foo) => 20; //~ ERROR `match` arm body without braces diff --git a/src/test/ui/parser/match-arm-without-braces.stderr b/src/test/ui/parser/match-arm-without-braces.stderr index 4831d79ef2b..37d55aa53f8 100644 --- a/src/test/ui/parser/match-arm-without-braces.stderr +++ b/src/test/ui/parser/match-arm-without-braces.stderr @@ -52,15 +52,11 @@ LL ~ { 14; LL ~ 15; } | -error: expected one of `,`, `.`, `?`, `}`, or an operator, found reserved identifier `_` - --> $DIR/match-arm-without-braces.rs:49:9 +error: expected `,` following `match` arm + --> $DIR/match-arm-without-braces.rs:48:29 | LL | Some(Val::Foo) => 17 - | -- - expected one of `,`, `.`, `?`, `}`, or an operator - | | - | while parsing the `match` arm starting here -LL | _ => 18, - | ^ unexpected token + | ^ help: missing a comma here to end this `match` arm: `,` error: `match` arm body without braces --> $DIR/match-arm-without-braces.rs:53:11 diff --git a/src/test/ui/traits/vtable/issue-97381.rs b/src/test/ui/traits/vtable/issue-97381.rs new file mode 100644 index 00000000000..393cf91efc2 --- /dev/null +++ b/src/test/ui/traits/vtable/issue-97381.rs @@ -0,0 +1,30 @@ +use std::ops::Deref; +trait MyTrait: Deref<Target = u32> {} +struct MyStruct(u32); +impl MyTrait for MyStruct {} +impl Deref for MyStruct { + type Target = u32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} +fn get_concrete_value(i: u32) -> MyStruct { + MyStruct(i) +} +fn get_boxed_value(i: u32) -> Box<dyn MyTrait> { + Box::new(get_concrete_value(i)) +} +fn main() { + let v = [1, 2, 3] + .iter() + .map(|i| get_boxed_value(*i)) + .collect::<Vec<_>>(); + + let el = &v[0]; + + for _ in v { + //~^ ERROR cannot move out of `v` because it is borrowed + println!("{}", ***el > 0); + } +} diff --git a/src/test/ui/traits/vtable/issue-97381.stderr b/src/test/ui/traits/vtable/issue-97381.stderr new file mode 100644 index 00000000000..f88c8716ff7 --- /dev/null +++ b/src/test/ui/traits/vtable/issue-97381.stderr @@ -0,0 +1,15 @@ +error[E0505]: cannot move out of `v` because it is borrowed + --> $DIR/issue-97381.rs:26:14 + | +LL | let el = &v[0]; + | - borrow of `v` occurs here +LL | +LL | for _ in v { + | ^ move out of `v` occurs here +LL | +LL | println!("{}", ***el > 0); + | ---- borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/type/type-unsatisfiable.rs b/src/test/ui/type/type-unsatisfiable.rs new file mode 100644 index 00000000000..7fbbb50dc11 --- /dev/null +++ b/src/test/ui/type/type-unsatisfiable.rs @@ -0,0 +1,59 @@ +// revisions: lib usage +//[lib] compile-flags: --crate-type=lib +//[lib] build-pass + +use std::ops::Sub; +trait Vector2 { + type ScalarType; + + fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self + where + Self: Sized; + + fn x(&self) -> Self::ScalarType; + fn y(&self) -> Self::ScalarType; +} + +impl<T> Sub for dyn Vector2<ScalarType = T> +where + T: Sub<Output = T>, + (dyn Vector2<ScalarType = T>): Sized, +{ + type Output = dyn Vector2<ScalarType = T>; + + fn sub(self, rhs: Self) -> Self::Output { + Self::from_values(self.x() - rhs.x(), self.y() - rhs.y()) + } +} + +struct Vec2 { + x: i32, + y: i32, +} + +impl Vector2 for Vec2 { + type ScalarType = i32; + + fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self + where + Self: Sized, + { + Self { x, y } + } + + fn x(&self) -> Self::ScalarType { + self.x + } + fn y(&self) -> Self::ScalarType { + self.y + } +} + +#[cfg(usage)] +fn main() { + let hey: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 }); + let word: Box<dyn Vector2<ScalarType = i32>> = Box::new(Vec2 { x: 1, y: 2 }); + + let bar = *hey - *word; + //[usage]~^ ERROR cannot subtract +} diff --git a/src/test/ui/type/type-unsatisfiable.usage.stderr b/src/test/ui/type/type-unsatisfiable.usage.stderr new file mode 100644 index 00000000000..56e2e30afac --- /dev/null +++ b/src/test/ui/type/type-unsatisfiable.usage.stderr @@ -0,0 +1,11 @@ +error[E0369]: cannot subtract `(dyn Vector2<ScalarType = i32> + 'static)` from `dyn Vector2<ScalarType = i32>` + --> $DIR/type-unsatisfiable.rs:57:20 + | +LL | let bar = *hey - *word; + | ---- ^ ----- (dyn Vector2<ScalarType = i32> + 'static) + | | + | dyn Vector2<ScalarType = i32> + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. |
