From a8193ca4c3204d6d8aafadab80ff5c6b284aa76e Mon Sep 17 00:00:00 2001 From: lcnr Date: Sun, 18 Apr 2021 19:35:23 +0200 Subject: fix suggestion for unsized function parameters --- src/test/ui/error-codes/E0277.stderr | 4 +- .../feature-gate-unsized_fn_params.stderr | 4 +- .../feature-gate-unsized_locals.stderr | 4 +- src/test/ui/issues/issue-5883.rs | 6 +- src/test/ui/issues/issue-5883.stderr | 17 ++- src/test/ui/resolve/issue-5035-2.stderr | 4 +- src/test/ui/suggestions/path-by-value.stderr | 4 +- src/test/ui/traits/bound/not-on-bare-trait.stderr | 4 +- src/test/ui/unsized-tuple-impls.rs | 21 --- src/test/ui/unsized.rs | 25 ---- src/test/ui/unsized/unsized-fn-arg.fixed | 6 + src/test/ui/unsized/unsized-fn-arg.rs | 6 + src/test/ui/unsized/unsized-fn-arg.stderr | 17 +++ src/test/ui/unsized/unsized-tuple-impls.rs | 21 +++ src/test/ui/unsized/unsized.rs | 25 ++++ src/test/ui/unsized/unsized2.rs | 97 +++++++++++++ src/test/ui/unsized/unsized3-rpass.rs | 96 +++++++++++++ src/test/ui/unsized/unsized3.rs | 51 +++++++ src/test/ui/unsized/unsized3.stderr | 109 ++++++++++++++ src/test/ui/unsized/unsized5.rs | 34 +++++ src/test/ui/unsized/unsized5.stderr | 116 +++++++++++++++ src/test/ui/unsized/unsized6.rs | 44 ++++++ src/test/ui/unsized/unsized6.stderr | 157 +++++++++++++++++++++ src/test/ui/unsized/unsized7.rs | 16 +++ src/test/ui/unsized/unsized7.stderr | 19 +++ src/test/ui/unsized2.rs | 97 ------------- src/test/ui/unsized3-rpass.rs | 96 ------------- src/test/ui/unsized3.rs | 51 ------- src/test/ui/unsized3.stderr | 109 -------------- src/test/ui/unsized5.rs | 34 ----- src/test/ui/unsized5.stderr | 116 --------------- src/test/ui/unsized6.rs | 44 ------ src/test/ui/unsized6.stderr | 157 --------------------- src/test/ui/unsized7.rs | 16 --- src/test/ui/unsized7.stderr | 19 --- src/tools/clippy/tests/ui/crashes/ice-6251.stderr | 4 +- 36 files changed, 839 insertions(+), 811 deletions(-) delete mode 100644 src/test/ui/unsized-tuple-impls.rs delete mode 100644 src/test/ui/unsized.rs create mode 100644 src/test/ui/unsized/unsized-fn-arg.fixed create mode 100644 src/test/ui/unsized/unsized-fn-arg.rs create mode 100644 src/test/ui/unsized/unsized-fn-arg.stderr create mode 100644 src/test/ui/unsized/unsized-tuple-impls.rs create mode 100644 src/test/ui/unsized/unsized.rs create mode 100644 src/test/ui/unsized/unsized2.rs create mode 100644 src/test/ui/unsized/unsized3-rpass.rs create mode 100644 src/test/ui/unsized/unsized3.rs create mode 100644 src/test/ui/unsized/unsized3.stderr create mode 100644 src/test/ui/unsized/unsized5.rs create mode 100644 src/test/ui/unsized/unsized5.stderr create mode 100644 src/test/ui/unsized/unsized6.rs create mode 100644 src/test/ui/unsized/unsized6.stderr create mode 100644 src/test/ui/unsized/unsized7.rs create mode 100644 src/test/ui/unsized/unsized7.stderr delete mode 100644 src/test/ui/unsized2.rs delete mode 100644 src/test/ui/unsized3-rpass.rs delete mode 100644 src/test/ui/unsized3.rs delete mode 100644 src/test/ui/unsized3.stderr delete mode 100644 src/test/ui/unsized5.rs delete mode 100644 src/test/ui/unsized5.stderr delete mode 100644 src/test/ui/unsized6.rs delete mode 100644 src/test/ui/unsized6.stderr delete mode 100644 src/test/ui/unsized7.rs delete mode 100644 src/test/ui/unsized7.stderr (limited to 'src') diff --git a/src/test/ui/error-codes/E0277.stderr b/src/test/ui/error-codes/E0277.stderr index 1f54af4d154..dea0bb259f5 100644 --- a/src/test/ui/error-codes/E0277.stderr +++ b/src/test/ui/error-codes/E0277.stderr @@ -9,8 +9,8 @@ LL | fn f(p: Path) { } = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn f(&p: Path) { } - | ^ +LL | fn f(p: &Path) { } + | ^ error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/E0277.rs:15:15 diff --git a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr index 71acbb174ac..3631a03938a 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr @@ -8,8 +8,8 @@ LL | fn foo(x: dyn Foo) { = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn foo(&x: dyn Foo) { - | ^ +LL | fn foo(x: &dyn Foo) { + | ^ error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time --> $DIR/feature-gate-unsized_fn_params.rs:24:5 diff --git a/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr b/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr index 52254220872..0919c2f3a1e 100644 --- a/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr +++ b/src/test/ui/feature-gates/feature-gate-unsized_locals.stderr @@ -8,8 +8,8 @@ LL | fn f(f: dyn FnOnce()) {} = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn f(&f: dyn FnOnce()) {} - | ^ +LL | fn f(f: &dyn FnOnce()) {} + | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-5883.rs b/src/test/ui/issues/issue-5883.rs index 0de53502397..82866b35557 100644 --- a/src/test/ui/issues/issue-5883.rs +++ b/src/test/ui/issues/issue-5883.rs @@ -4,9 +4,9 @@ struct Struct { r: dyn A + 'static } -fn new_struct(r: dyn A + 'static) - -> Struct { //~^ ERROR the size for values of type - //~^ ERROR the size for values of type +fn new_struct( + r: dyn A + 'static //~ ERROR the size for values of type +) -> Struct { //~ ERROR the size for values of type Struct { r: r } } diff --git a/src/test/ui/issues/issue-5883.stderr b/src/test/ui/issues/issue-5883.stderr index 48879eb798f..de598a70ee0 100644 --- a/src/test/ui/issues/issue-5883.stderr +++ b/src/test/ui/issues/issue-5883.stderr @@ -1,22 +1,21 @@ error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/issue-5883.rs:7:15 + --> $DIR/issue-5883.rs:8:5 | -LL | fn new_struct(r: dyn A + 'static) - | ^ doesn't have a size known at compile-time +LL | r: dyn A + 'static + | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn A + 'static)` = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn new_struct(&r: dyn A + 'static) - | ^ +LL | r: &dyn A + 'static + | ^ error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time - --> $DIR/issue-5883.rs:8:8 + --> $DIR/issue-5883.rs:9:6 | -LL | -> Struct { - | ^^^^^^ doesn't have a size known at compile-time -LL | +LL | ) -> Struct { + | ^^^^^^ doesn't have a size known at compile-time LL | Struct { r: r } | --------------- this returned value is of type `Struct` | diff --git a/src/test/ui/resolve/issue-5035-2.stderr b/src/test/ui/resolve/issue-5035-2.stderr index b2084a7a426..e94877fded7 100644 --- a/src/test/ui/resolve/issue-5035-2.stderr +++ b/src/test/ui/resolve/issue-5035-2.stderr @@ -8,8 +8,8 @@ LL | fn foo(_x: K) {} = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn foo(&_x: K) {} - | ^ +LL | fn foo(_x: &K) {} + | ^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/path-by-value.stderr b/src/test/ui/suggestions/path-by-value.stderr index 19fc3406ccf..5919a6f7492 100644 --- a/src/test/ui/suggestions/path-by-value.stderr +++ b/src/test/ui/suggestions/path-by-value.stderr @@ -9,8 +9,8 @@ LL | fn f(p: Path) { } = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn f(&p: Path) { } - | ^ +LL | fn f(p: &Path) { } + | ^ error: aborting due to previous error diff --git a/src/test/ui/traits/bound/not-on-bare-trait.stderr b/src/test/ui/traits/bound/not-on-bare-trait.stderr index e7fc0fa5ec0..b8ae88ace02 100644 --- a/src/test/ui/traits/bound/not-on-bare-trait.stderr +++ b/src/test/ui/traits/bound/not-on-bare-trait.stderr @@ -16,8 +16,8 @@ LL | fn foo(_x: Foo + Send) { = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn foo(&_x: Foo + Send) { - | ^ +LL | fn foo(_x: &Foo + Send) { + | ^ error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/unsized-tuple-impls.rs b/src/test/ui/unsized-tuple-impls.rs deleted file mode 100644 index 5e385f33bee..00000000000 --- a/src/test/ui/unsized-tuple-impls.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass - -#![feature(unsized_tuple_coercion)] - -use std::collections::HashSet; - -fn main() { - let x : &(i32, i32, [i32]) = &(0, 1, [2, 3]); - let y : &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]); - let mut a = [y, x]; - a.sort(); - assert_eq!(a, [x, y]); - - assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]"); - - let mut h = HashSet::new(); - h.insert(x); - h.insert(y); - assert!(h.contains(x)); - assert!(h.contains(y)); -} diff --git a/src/test/ui/unsized.rs b/src/test/ui/unsized.rs deleted file mode 100644 index 54304834d4b..00000000000 --- a/src/test/ui/unsized.rs +++ /dev/null @@ -1,25 +0,0 @@ -// run-pass - -#![allow(type_alias_bounds)] -#![allow(dead_code)] -// Test syntax checks for `?Sized` syntax. - -use std::marker::PhantomData; - -trait T1 { } -pub trait T2 { } -trait T3 : T2 { } -trait T4 { } -trait T5 { } -trait T6 { } -trait T7 { } -trait T8 { } -trait T9 { } -struct S1(PhantomData); -enum E { E1(PhantomData) } -impl T1 for S1 {} -fn f() {} -type TT = T; - -pub fn main() { -} diff --git a/src/test/ui/unsized/unsized-fn-arg.fixed b/src/test/ui/unsized/unsized-fn-arg.fixed new file mode 100644 index 00000000000..2c686c6c2b2 --- /dev/null +++ b/src/test/ui/unsized/unsized-fn-arg.fixed @@ -0,0 +1,6 @@ +// run-rustfix +#![crate_type="lib"] +#![allow(unused)] + +fn f(t: &T) {} +//~^ ERROR the size for values of type `T` cannot be known at compilation time diff --git a/src/test/ui/unsized/unsized-fn-arg.rs b/src/test/ui/unsized/unsized-fn-arg.rs new file mode 100644 index 00000000000..9fc08bd6d3e --- /dev/null +++ b/src/test/ui/unsized/unsized-fn-arg.rs @@ -0,0 +1,6 @@ +// run-rustfix +#![crate_type="lib"] +#![allow(unused)] + +fn f(t: T) {} +//~^ ERROR the size for values of type `T` cannot be known at compilation time diff --git a/src/test/ui/unsized/unsized-fn-arg.stderr b/src/test/ui/unsized/unsized-fn-arg.stderr new file mode 100644 index 00000000000..6b802ddf542 --- /dev/null +++ b/src/test/ui/unsized/unsized-fn-arg.stderr @@ -0,0 +1,17 @@ +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/unsized-fn-arg.rs:5:17 + | +LL | fn f(t: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn f(t: &T) {} + | ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized-tuple-impls.rs b/src/test/ui/unsized/unsized-tuple-impls.rs new file mode 100644 index 00000000000..5e385f33bee --- /dev/null +++ b/src/test/ui/unsized/unsized-tuple-impls.rs @@ -0,0 +1,21 @@ +// run-pass + +#![feature(unsized_tuple_coercion)] + +use std::collections::HashSet; + +fn main() { + let x : &(i32, i32, [i32]) = &(0, 1, [2, 3]); + let y : &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]); + let mut a = [y, x]; + a.sort(); + assert_eq!(a, [x, y]); + + assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]"); + + let mut h = HashSet::new(); + h.insert(x); + h.insert(y); + assert!(h.contains(x)); + assert!(h.contains(y)); +} diff --git a/src/test/ui/unsized/unsized.rs b/src/test/ui/unsized/unsized.rs new file mode 100644 index 00000000000..54304834d4b --- /dev/null +++ b/src/test/ui/unsized/unsized.rs @@ -0,0 +1,25 @@ +// run-pass + +#![allow(type_alias_bounds)] +#![allow(dead_code)] +// Test syntax checks for `?Sized` syntax. + +use std::marker::PhantomData; + +trait T1 { } +pub trait T2 { } +trait T3 : T2 { } +trait T4 { } +trait T5 { } +trait T6 { } +trait T7 { } +trait T8 { } +trait T9 { } +struct S1(PhantomData); +enum E { E1(PhantomData) } +impl T1 for S1 {} +fn f() {} +type TT = T; + +pub fn main() { +} diff --git a/src/test/ui/unsized/unsized2.rs b/src/test/ui/unsized/unsized2.rs new file mode 100644 index 00000000000..be4406399fd --- /dev/null +++ b/src/test/ui/unsized/unsized2.rs @@ -0,0 +1,97 @@ +// run-pass + +#![allow(unconditional_recursion)] +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_imports)] +#![feature(box_syntax)] + +// Test sized-ness checking in substitution. + +use std::marker; + +// Unbounded. +fn f1(x: &X) { + f1::(x); +} +fn f2(x: &X) { + f1::(x); + f2::(x); +} + +// Bounded. +trait T { fn dummy(&self) { } } +fn f3(x: &X) { + f3::(x); +} +fn f4(x: &X) { + f3::(x); + f4::(x); +} + +// Self type. +trait T2 { + fn f() -> Box; +} +struct S; +impl T2 for S { + fn f() -> Box { + box S + } +} +fn f5(x: &X) { + let _: Box = T2::f(); +} +fn f6(x: &X) { + let _: Box = T2::f(); +} + +trait T3 { + fn f() -> Box; +} +impl T3 for S { + fn f() -> Box { + box S + } +} +fn f7(x: &X) { + // This is valid, but the unsized bound on X is irrelevant because any type + // which implements T3 must have statically known size. + let _: Box = T3::f(); +} + +trait T4 { + fn dummy(&self) { } + fn m1(&self, x: &dyn T4, y: X); + fn m2(&self, x: &dyn T5, y: X); +} +trait T5 { + fn dummy(&self) { } + // not an error (for now) + fn m1(&self, x: &dyn T4); + fn m2(&self, x: &dyn T5); +} + +trait T6 { + fn dummy(&self) { } + fn m1(&self, x: &dyn T4); + fn m2(&self, x: &dyn T5); +} +trait T7 { + fn dummy(&self) { } + // not an error (for now) + fn m1(&self, x: &dyn T4); + fn m2(&self, x: &dyn T5); +} + +// The last field in a struct may be unsized +struct S2 { + f: X, +} +struct S3 { + f1: isize, + f2: X, +} + +pub fn main() { +} diff --git a/src/test/ui/unsized/unsized3-rpass.rs b/src/test/ui/unsized/unsized3-rpass.rs new file mode 100644 index 00000000000..65efbd6b520 --- /dev/null +++ b/src/test/ui/unsized/unsized3-rpass.rs @@ -0,0 +1,96 @@ +// run-pass +// Test structs with always-unsized fields. + + +#![allow(warnings)] +#![feature(box_syntax, unsize, raw)] + +use std::mem; +use std::raw; +use std::slice; + +struct Foo { + f: [T], +} + +struct Bar { + f1: usize, + f2: [usize], +} + +struct Baz { + f1: usize, + f2: str, +} + +trait Tr { + fn foo(&self) -> usize; +} + +struct St { + f: usize +} + +impl Tr for St { + fn foo(&self) -> usize { + self.f + } +} + +struct Qux<'a> { + f: Tr+'a +} + +pub fn main() { + let _: &Foo; + let _: &Bar; + let _: &Baz; + + let _: Box>; + let _: Box; + let _: Box; + + let _ = mem::size_of::>>(); + let _ = mem::size_of::>(); + let _ = mem::size_of::>(); + + unsafe { + struct Foo_ { + f: [T; 3] + } + + let data: Box> = box Foo_{f: [1, 2, 3] }; + let x: &Foo = mem::transmute(slice::from_raw_parts(&*data, 3)); + assert_eq!(x.f.len(), 3); + assert_eq!(x.f[0], 1); + + struct Baz_ { + f1: usize, + f2: [u8; 5], + } + + let data: Box<_> = box Baz_ { + f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] }; + let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5)); + assert_eq!(x.f1, 42); + let chs: Vec = x.f2.chars().collect(); + assert_eq!(chs.len(), 5); + assert_eq!(chs[0], 'a'); + assert_eq!(chs[1], 'b'); + assert_eq!(chs[2], 'c'); + assert_eq!(chs[3], 'd'); + assert_eq!(chs[4], 'e'); + + struct Qux_ { + f: St + } + + let obj: Box = box St { f: 42 }; + let obj: &Tr = &*obj; + let obj: raw::TraitObject = mem::transmute(&*obj); + let data: Box<_> = box Qux_{ f: St { f: 234 } }; + let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable, + data: mem::transmute(&*data) }); + assert_eq!(x.f.foo(), 234); + } +} diff --git a/src/test/ui/unsized/unsized3.rs b/src/test/ui/unsized/unsized3.rs new file mode 100644 index 00000000000..f5b5d025931 --- /dev/null +++ b/src/test/ui/unsized/unsized3.rs @@ -0,0 +1,51 @@ +// Test sized-ness checking in substitution within fn bodies.. + +use std::marker; + +// Unbounded. +fn f1(x: &X) { + f2::(x); + //~^ ERROR the size for values of type +} +fn f2(x: &X) { +} + +// Bounded. +trait T { + fn foo(&self) { } +} +fn f3(x: &X) { + f4::(x); + //~^ ERROR the size for values of type +} +fn f4(x: &X) { +} + +fn f5(x: &Y) {} +fn f6(x: &X) {} + +// Test with unsized struct. +struct S { + x: X, +} + +fn f8(x1: &S, x2: &S) { + f5(x1); + //~^ ERROR the size for values of type + f6(x2); // ok +} + +// Test some tuples. +fn f9(x1: Box>) { + f5(&(*x1, 34)); + //~^ ERROR the size for values of type +} + +fn f10(x1: Box>) { + f5(&(32, *x1)); + //~^ ERROR the size for values of type + //~| ERROR the size for values of type +} + +pub fn main() { +} diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr new file mode 100644 index 00000000000..bd36008aca0 --- /dev/null +++ b/src/test/ui/unsized/unsized3.stderr @@ -0,0 +1,109 @@ +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:7:13 + | +LL | fn f1(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +LL | f2::(x); + | ^ doesn't have a size known at compile-time +... +LL | fn f2(x: &X) { + | - required by this bound in `f2` + | +help: consider relaxing the implicit `Sized` restriction + | +LL | fn f2(x: &X) { + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:18:13 + | +LL | fn f3(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +LL | f4::(x); + | ^ doesn't have a size known at compile-time +... +LL | fn f4(x: &X) { + | - required by this bound in `f4` + | +help: consider relaxing the implicit `Sized` restriction + | +LL | fn f4(x: &X) { + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:33:8 + | +LL | fn f5(x: &Y) {} + | - required by this bound in `f5` +... +LL | fn f8(x1: &S, x2: &S) { + | - this type parameter needs to be `std::marker::Sized` +LL | f5(x1); + | ^^ doesn't have a size known at compile-time + | +note: required because it appears within the type `S` + --> $DIR/unsized3.rs:28:8 + | +LL | struct S { + | ^ +help: consider relaxing the implicit `Sized` restriction + | +LL | fn f5(x: &Y) {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:40:8 + | +LL | fn f9(x1: Box>) { + | - this type parameter needs to be `std::marker::Sized` +LL | f5(&(*x1, 34)); + | ^^^^^^^^^^ doesn't have a size known at compile-time + | +note: required because it appears within the type `S` + --> $DIR/unsized3.rs:28:8 + | +LL | struct S { + | ^ + = note: only the last element of a tuple may have a dynamically sized type + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:45:9 + | +LL | fn f10(x1: Box>) { + | - this type parameter needs to be `std::marker::Sized` +LL | f5(&(32, *x1)); + | ^^^^^^^^^ doesn't have a size known at compile-time + | +note: required because it appears within the type `S` + --> $DIR/unsized3.rs:28:8 + | +LL | struct S { + | ^ + = note: required because it appears within the type `({integer}, S)` + = note: tuples must have a statically known size to be initialized + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized3.rs:45:8 + | +LL | fn f5(x: &Y) {} + | - required by this bound in `f5` +... +LL | fn f10(x1: Box>) { + | - this type parameter needs to be `std::marker::Sized` +LL | f5(&(32, *x1)); + | ^^^^^^^^^^ doesn't have a size known at compile-time + | +note: required because it appears within the type `S` + --> $DIR/unsized3.rs:28:8 + | +LL | struct S { + | ^ + = note: required because it appears within the type `({integer}, S)` +help: consider relaxing the implicit `Sized` restriction + | +LL | fn f5(x: &Y) {} + | ^^^^^^^^ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized5.rs b/src/test/ui/unsized/unsized5.rs new file mode 100644 index 00000000000..befd2244d97 --- /dev/null +++ b/src/test/ui/unsized/unsized5.rs @@ -0,0 +1,34 @@ +// Test `?Sized` types not allowed in fields (except the last one). + +struct S1 { + f1: X, + //~^ ERROR the size for values of type + f2: isize, +} +struct S2 { + f: isize, + g: X, + //~^ ERROR the size for values of type + h: isize, +} +struct S3 { + f: str, + //~^ ERROR the size for values of type + g: [usize] +} +struct S4 { + f: [u8], + //~^ ERROR the size for values of type + g: usize +} +enum E { + V1(X, isize), + //~^ ERROR the size for values of type +} +enum F { + V2{f1: X, f: isize}, + //~^ ERROR the size for values of type +} + +pub fn main() { +} diff --git a/src/test/ui/unsized/unsized5.stderr b/src/test/ui/unsized/unsized5.stderr new file mode 100644 index 00000000000..0bfd4565529 --- /dev/null +++ b/src/test/ui/unsized/unsized5.stderr @@ -0,0 +1,116 @@ +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized5.rs:4:9 + | +LL | struct S1 { + | - this type parameter needs to be `std::marker::Sized` +LL | f1: X, + | ^ doesn't have a size known at compile-time + | + = note: only the last field of a struct may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | f1: &X, + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | f1: Box, + | ^^^^ ^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized5.rs:10:8 + | +LL | struct S2 { + | - this type parameter needs to be `std::marker::Sized` +LL | f: isize, +LL | g: X, + | ^ doesn't have a size known at compile-time + | + = note: only the last field of a struct may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | g: &X, + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | g: Box, + | ^^^^ ^ + +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/unsized5.rs:15:8 + | +LL | f: str, + | ^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `str` + = note: only the last field of a struct may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | f: &str, + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | f: Box, + | ^^^^ ^ + +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/unsized5.rs:20:8 + | +LL | f: [u8], + | ^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[u8]` + = note: only the last field of a struct may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | f: &[u8], + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | f: Box<[u8]>, + | ^^^^ ^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized5.rs:25:8 + | +LL | enum E { + | - this type parameter needs to be `std::marker::Sized` +LL | V1(X, isize), + | ^ doesn't have a size known at compile-time + | + = note: no field of an enum variant may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | V1(&X, isize), + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | V1(Box, isize), + | ^^^^ ^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized5.rs:29:12 + | +LL | enum F { + | - this type parameter needs to be `std::marker::Sized` +LL | V2{f1: X, f: isize}, + | ^ doesn't have a size known at compile-time + | + = note: no field of an enum variant may have a dynamically sized type + = help: change the field's type to have a statically known size +help: borrowed types always have a statically known size + | +LL | V2{f1: &X, f: isize}, + | ^ +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | V2{f1: Box, f: isize}, + | ^^^^ ^ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized6.rs b/src/test/ui/unsized/unsized6.rs new file mode 100644 index 00000000000..79133554d54 --- /dev/null +++ b/src/test/ui/unsized/unsized6.rs @@ -0,0 +1,44 @@ +// Test `?Sized` local variables. + +trait T {} + +fn f1(x: &X) { + let _: W; // <-- this is OK, no bindings created, no initializer. + let _: (isize, (X, isize)); + //~^ ERROR the size for values of type + let y: Y; + //~^ ERROR the size for values of type + let y: (isize, (Z, usize)); + //~^ ERROR the size for values of type +} +fn f2(x: &X) { + let y: X; + //~^ ERROR the size for values of type + let y: (isize, (Y, isize)); + //~^ ERROR the size for values of type +} + +fn f3(x1: Box, x2: Box, x3: Box) { + let y: X = *x1; + //~^ ERROR the size for values of type + let y = *x2; + //~^ ERROR the size for values of type + let (y, z) = (*x3, 4); + //~^ ERROR the size for values of type +} +fn f4(x1: Box, x2: Box, x3: Box) { + let y: X = *x1; + //~^ ERROR the size for values of type + let y = *x2; + //~^ ERROR the size for values of type + let (y, z) = (*x3, 4); + //~^ ERROR the size for values of type +} + +fn g1(x: X) {} +//~^ ERROR the size for values of type +fn g2(x: X) {} +//~^ ERROR the size for values of type + +pub fn main() { +} diff --git a/src/test/ui/unsized/unsized6.stderr b/src/test/ui/unsized/unsized6.stderr new file mode 100644 index 00000000000..8e5734dffb1 --- /dev/null +++ b/src/test/ui/unsized/unsized6.stderr @@ -0,0 +1,157 @@ +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized6.rs:9:9 + | +LL | fn f1(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let y: Y; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:7:12 + | +LL | fn f1(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +LL | let _: W; // <-- this is OK, no bindings created, no initializer. +LL | let _: (isize, (X, isize)); + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = note: only the last element of a tuple may have a dynamically sized type + +error[E0277]: the size for values of type `Z` cannot be known at compilation time + --> $DIR/unsized6.rs:11:12 + | +LL | fn f1(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let y: (isize, (Z, usize)); + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = note: only the last element of a tuple may have a dynamically sized type + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:15:9 + | +LL | fn f2(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +LL | let y: X; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized6.rs:17:12 + | +LL | fn f2(x: &X) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let y: (isize, (Y, isize)); + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = note: only the last element of a tuple may have a dynamically sized type + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:22:9 + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +LL | let y: X = *x1; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:24:9 + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let y = *x2; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:26:10 + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let (y, z) = (*x3, 4); + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:30:9 + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +LL | let y: X = *x1; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:32:9 + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let y = *x2; + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:34:10 + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | - this type parameter needs to be `std::marker::Sized` +... +LL | let (y, z) = (*x3, 4); + | ^ doesn't have a size known at compile-time + | + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:38:18 + | +LL | fn g1(x: X) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn g1(x: &X) {} + | ^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized6.rs:40:22 + | +LL | fn g2(x: X) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn g2(x: &X) {} + | ^ + +error: aborting due to 13 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized7.rs b/src/test/ui/unsized/unsized7.rs new file mode 100644 index 00000000000..422a784814e --- /dev/null +++ b/src/test/ui/unsized/unsized7.rs @@ -0,0 +1,16 @@ +// Test sized-ness checking in substitution in impls. + +trait T {} + +// I would like these to fail eventually. +// impl - bounded +trait T1 { + fn dummy(&self) -> Z; +} + +struct S3(Box); +impl T1 for S3 { + //~^ ERROR the size for values of type +} + +fn main() { } diff --git a/src/test/ui/unsized/unsized7.stderr b/src/test/ui/unsized/unsized7.stderr new file mode 100644 index 00000000000..7dbddd4ed24 --- /dev/null +++ b/src/test/ui/unsized/unsized7.stderr @@ -0,0 +1,19 @@ +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized7.rs:12:21 + | +LL | trait T1 { + | - required by this bound in `T1` +... +LL | impl T1 for S3 { + | - ^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +help: consider relaxing the implicit `Sized` restriction + | +LL | trait T1 { + | ^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized2.rs b/src/test/ui/unsized2.rs deleted file mode 100644 index be4406399fd..00000000000 --- a/src/test/ui/unsized2.rs +++ /dev/null @@ -1,97 +0,0 @@ -// run-pass - -#![allow(unconditional_recursion)] -#![allow(dead_code)] -#![allow(unused_variables)] -#![allow(unused_imports)] -#![feature(box_syntax)] - -// Test sized-ness checking in substitution. - -use std::marker; - -// Unbounded. -fn f1(x: &X) { - f1::(x); -} -fn f2(x: &X) { - f1::(x); - f2::(x); -} - -// Bounded. -trait T { fn dummy(&self) { } } -fn f3(x: &X) { - f3::(x); -} -fn f4(x: &X) { - f3::(x); - f4::(x); -} - -// Self type. -trait T2 { - fn f() -> Box; -} -struct S; -impl T2 for S { - fn f() -> Box { - box S - } -} -fn f5(x: &X) { - let _: Box = T2::f(); -} -fn f6(x: &X) { - let _: Box = T2::f(); -} - -trait T3 { - fn f() -> Box; -} -impl T3 for S { - fn f() -> Box { - box S - } -} -fn f7(x: &X) { - // This is valid, but the unsized bound on X is irrelevant because any type - // which implements T3 must have statically known size. - let _: Box = T3::f(); -} - -trait T4 { - fn dummy(&self) { } - fn m1(&self, x: &dyn T4, y: X); - fn m2(&self, x: &dyn T5, y: X); -} -trait T5 { - fn dummy(&self) { } - // not an error (for now) - fn m1(&self, x: &dyn T4); - fn m2(&self, x: &dyn T5); -} - -trait T6 { - fn dummy(&self) { } - fn m1(&self, x: &dyn T4); - fn m2(&self, x: &dyn T5); -} -trait T7 { - fn dummy(&self) { } - // not an error (for now) - fn m1(&self, x: &dyn T4); - fn m2(&self, x: &dyn T5); -} - -// The last field in a struct may be unsized -struct S2 { - f: X, -} -struct S3 { - f1: isize, - f2: X, -} - -pub fn main() { -} diff --git a/src/test/ui/unsized3-rpass.rs b/src/test/ui/unsized3-rpass.rs deleted file mode 100644 index 65efbd6b520..00000000000 --- a/src/test/ui/unsized3-rpass.rs +++ /dev/null @@ -1,96 +0,0 @@ -// run-pass -// Test structs with always-unsized fields. - - -#![allow(warnings)] -#![feature(box_syntax, unsize, raw)] - -use std::mem; -use std::raw; -use std::slice; - -struct Foo { - f: [T], -} - -struct Bar { - f1: usize, - f2: [usize], -} - -struct Baz { - f1: usize, - f2: str, -} - -trait Tr { - fn foo(&self) -> usize; -} - -struct St { - f: usize -} - -impl Tr for St { - fn foo(&self) -> usize { - self.f - } -} - -struct Qux<'a> { - f: Tr+'a -} - -pub fn main() { - let _: &Foo; - let _: &Bar; - let _: &Baz; - - let _: Box>; - let _: Box; - let _: Box; - - let _ = mem::size_of::>>(); - let _ = mem::size_of::>(); - let _ = mem::size_of::>(); - - unsafe { - struct Foo_ { - f: [T; 3] - } - - let data: Box> = box Foo_{f: [1, 2, 3] }; - let x: &Foo = mem::transmute(slice::from_raw_parts(&*data, 3)); - assert_eq!(x.f.len(), 3); - assert_eq!(x.f[0], 1); - - struct Baz_ { - f1: usize, - f2: [u8; 5], - } - - let data: Box<_> = box Baz_ { - f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] }; - let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5)); - assert_eq!(x.f1, 42); - let chs: Vec = x.f2.chars().collect(); - assert_eq!(chs.len(), 5); - assert_eq!(chs[0], 'a'); - assert_eq!(chs[1], 'b'); - assert_eq!(chs[2], 'c'); - assert_eq!(chs[3], 'd'); - assert_eq!(chs[4], 'e'); - - struct Qux_ { - f: St - } - - let obj: Box = box St { f: 42 }; - let obj: &Tr = &*obj; - let obj: raw::TraitObject = mem::transmute(&*obj); - let data: Box<_> = box Qux_{ f: St { f: 234 } }; - let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable, - data: mem::transmute(&*data) }); - assert_eq!(x.f.foo(), 234); - } -} diff --git a/src/test/ui/unsized3.rs b/src/test/ui/unsized3.rs deleted file mode 100644 index f5b5d025931..00000000000 --- a/src/test/ui/unsized3.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Test sized-ness checking in substitution within fn bodies.. - -use std::marker; - -// Unbounded. -fn f1(x: &X) { - f2::(x); - //~^ ERROR the size for values of type -} -fn f2(x: &X) { -} - -// Bounded. -trait T { - fn foo(&self) { } -} -fn f3(x: &X) { - f4::(x); - //~^ ERROR the size for values of type -} -fn f4(x: &X) { -} - -fn f5(x: &Y) {} -fn f6(x: &X) {} - -// Test with unsized struct. -struct S { - x: X, -} - -fn f8(x1: &S, x2: &S) { - f5(x1); - //~^ ERROR the size for values of type - f6(x2); // ok -} - -// Test some tuples. -fn f9(x1: Box>) { - f5(&(*x1, 34)); - //~^ ERROR the size for values of type -} - -fn f10(x1: Box>) { - f5(&(32, *x1)); - //~^ ERROR the size for values of type - //~| ERROR the size for values of type -} - -pub fn main() { -} diff --git a/src/test/ui/unsized3.stderr b/src/test/ui/unsized3.stderr deleted file mode 100644 index bd36008aca0..00000000000 --- a/src/test/ui/unsized3.stderr +++ /dev/null @@ -1,109 +0,0 @@ -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:7:13 - | -LL | fn f1(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -LL | f2::(x); - | ^ doesn't have a size known at compile-time -... -LL | fn f2(x: &X) { - | - required by this bound in `f2` - | -help: consider relaxing the implicit `Sized` restriction - | -LL | fn f2(x: &X) { - | ^^^^^^^^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:18:13 - | -LL | fn f3(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -LL | f4::(x); - | ^ doesn't have a size known at compile-time -... -LL | fn f4(x: &X) { - | - required by this bound in `f4` - | -help: consider relaxing the implicit `Sized` restriction - | -LL | fn f4(x: &X) { - | ^^^^^^^^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:33:8 - | -LL | fn f5(x: &Y) {} - | - required by this bound in `f5` -... -LL | fn f8(x1: &S, x2: &S) { - | - this type parameter needs to be `std::marker::Sized` -LL | f5(x1); - | ^^ doesn't have a size known at compile-time - | -note: required because it appears within the type `S` - --> $DIR/unsized3.rs:28:8 - | -LL | struct S { - | ^ -help: consider relaxing the implicit `Sized` restriction - | -LL | fn f5(x: &Y) {} - | ^^^^^^^^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:40:8 - | -LL | fn f9(x1: Box>) { - | - this type parameter needs to be `std::marker::Sized` -LL | f5(&(*x1, 34)); - | ^^^^^^^^^^ doesn't have a size known at compile-time - | -note: required because it appears within the type `S` - --> $DIR/unsized3.rs:28:8 - | -LL | struct S { - | ^ - = note: only the last element of a tuple may have a dynamically sized type - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:45:9 - | -LL | fn f10(x1: Box>) { - | - this type parameter needs to be `std::marker::Sized` -LL | f5(&(32, *x1)); - | ^^^^^^^^^ doesn't have a size known at compile-time - | -note: required because it appears within the type `S` - --> $DIR/unsized3.rs:28:8 - | -LL | struct S { - | ^ - = note: required because it appears within the type `({integer}, S)` - = note: tuples must have a statically known size to be initialized - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized3.rs:45:8 - | -LL | fn f5(x: &Y) {} - | - required by this bound in `f5` -... -LL | fn f10(x1: Box>) { - | - this type parameter needs to be `std::marker::Sized` -LL | f5(&(32, *x1)); - | ^^^^^^^^^^ doesn't have a size known at compile-time - | -note: required because it appears within the type `S` - --> $DIR/unsized3.rs:28:8 - | -LL | struct S { - | ^ - = note: required because it appears within the type `({integer}, S)` -help: consider relaxing the implicit `Sized` restriction - | -LL | fn f5(x: &Y) {} - | ^^^^^^^^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized5.rs b/src/test/ui/unsized5.rs deleted file mode 100644 index befd2244d97..00000000000 --- a/src/test/ui/unsized5.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Test `?Sized` types not allowed in fields (except the last one). - -struct S1 { - f1: X, - //~^ ERROR the size for values of type - f2: isize, -} -struct S2 { - f: isize, - g: X, - //~^ ERROR the size for values of type - h: isize, -} -struct S3 { - f: str, - //~^ ERROR the size for values of type - g: [usize] -} -struct S4 { - f: [u8], - //~^ ERROR the size for values of type - g: usize -} -enum E { - V1(X, isize), - //~^ ERROR the size for values of type -} -enum F { - V2{f1: X, f: isize}, - //~^ ERROR the size for values of type -} - -pub fn main() { -} diff --git a/src/test/ui/unsized5.stderr b/src/test/ui/unsized5.stderr deleted file mode 100644 index 0bfd4565529..00000000000 --- a/src/test/ui/unsized5.stderr +++ /dev/null @@ -1,116 +0,0 @@ -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized5.rs:4:9 - | -LL | struct S1 { - | - this type parameter needs to be `std::marker::Sized` -LL | f1: X, - | ^ doesn't have a size known at compile-time - | - = note: only the last field of a struct may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | f1: &X, - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | f1: Box, - | ^^^^ ^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized5.rs:10:8 - | -LL | struct S2 { - | - this type parameter needs to be `std::marker::Sized` -LL | f: isize, -LL | g: X, - | ^ doesn't have a size known at compile-time - | - = note: only the last field of a struct may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | g: &X, - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | g: Box, - | ^^^^ ^ - -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/unsized5.rs:15:8 - | -LL | f: str, - | ^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `str` - = note: only the last field of a struct may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | f: &str, - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | f: Box, - | ^^^^ ^ - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized5.rs:20:8 - | -LL | f: [u8], - | ^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: only the last field of a struct may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | f: &[u8], - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | f: Box<[u8]>, - | ^^^^ ^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized5.rs:25:8 - | -LL | enum E { - | - this type parameter needs to be `std::marker::Sized` -LL | V1(X, isize), - | ^ doesn't have a size known at compile-time - | - = note: no field of an enum variant may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | V1(&X, isize), - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | V1(Box, isize), - | ^^^^ ^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized5.rs:29:12 - | -LL | enum F { - | - this type parameter needs to be `std::marker::Sized` -LL | V2{f1: X, f: isize}, - | ^ doesn't have a size known at compile-time - | - = note: no field of an enum variant may have a dynamically sized type - = help: change the field's type to have a statically known size -help: borrowed types always have a statically known size - | -LL | V2{f1: &X, f: isize}, - | ^ -help: the `Box` type always has a statically known size and allocates its contents in the heap - | -LL | V2{f1: Box, f: isize}, - | ^^^^ ^ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized6.rs b/src/test/ui/unsized6.rs deleted file mode 100644 index 79133554d54..00000000000 --- a/src/test/ui/unsized6.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Test `?Sized` local variables. - -trait T {} - -fn f1(x: &X) { - let _: W; // <-- this is OK, no bindings created, no initializer. - let _: (isize, (X, isize)); - //~^ ERROR the size for values of type - let y: Y; - //~^ ERROR the size for values of type - let y: (isize, (Z, usize)); - //~^ ERROR the size for values of type -} -fn f2(x: &X) { - let y: X; - //~^ ERROR the size for values of type - let y: (isize, (Y, isize)); - //~^ ERROR the size for values of type -} - -fn f3(x1: Box, x2: Box, x3: Box) { - let y: X = *x1; - //~^ ERROR the size for values of type - let y = *x2; - //~^ ERROR the size for values of type - let (y, z) = (*x3, 4); - //~^ ERROR the size for values of type -} -fn f4(x1: Box, x2: Box, x3: Box) { - let y: X = *x1; - //~^ ERROR the size for values of type - let y = *x2; - //~^ ERROR the size for values of type - let (y, z) = (*x3, 4); - //~^ ERROR the size for values of type -} - -fn g1(x: X) {} -//~^ ERROR the size for values of type -fn g2(x: X) {} -//~^ ERROR the size for values of type - -pub fn main() { -} diff --git a/src/test/ui/unsized6.stderr b/src/test/ui/unsized6.stderr deleted file mode 100644 index f9f7877d542..00000000000 --- a/src/test/ui/unsized6.stderr +++ /dev/null @@ -1,157 +0,0 @@ -error[E0277]: the size for values of type `Y` cannot be known at compilation time - --> $DIR/unsized6.rs:9:9 - | -LL | fn f1(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y: Y; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:7:12 - | -LL | fn f1(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -LL | let _: W; // <-- this is OK, no bindings created, no initializer. -LL | let _: (isize, (X, isize)); - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = note: only the last element of a tuple may have a dynamically sized type - -error[E0277]: the size for values of type `Z` cannot be known at compilation time - --> $DIR/unsized6.rs:11:12 - | -LL | fn f1(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y: (isize, (Z, usize)); - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = note: only the last element of a tuple may have a dynamically sized type - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:15:9 - | -LL | fn f2(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -LL | let y: X; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `Y` cannot be known at compilation time - --> $DIR/unsized6.rs:17:12 - | -LL | fn f2(x: &X) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y: (isize, (Y, isize)); - | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = note: only the last element of a tuple may have a dynamically sized type - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:22:9 - | -LL | fn f3(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -LL | let y: X = *x1; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:24:9 - | -LL | fn f3(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y = *x2; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:26:10 - | -LL | fn f3(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let (y, z) = (*x3, 4); - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:30:9 - | -LL | fn f4(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -LL | let y: X = *x1; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:32:9 - | -LL | fn f4(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let y = *x2; - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:34:10 - | -LL | fn f4(x1: Box, x2: Box, x3: Box) { - | - this type parameter needs to be `std::marker::Sized` -... -LL | let (y, z) = (*x3, 4); - | ^ doesn't have a size known at compile-time - | - = note: all local variables must have a statically known size - = help: unsized locals are gated as an unstable feature - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:38:18 - | -LL | fn g1(x: X) {} - | - ^ doesn't have a size known at compile-time - | | - | this type parameter needs to be `std::marker::Sized` - | - = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | fn g1(&x: X) {} - | ^ - -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized6.rs:40:22 - | -LL | fn g2(x: X) {} - | - ^ doesn't have a size known at compile-time - | | - | this type parameter needs to be `std::marker::Sized` - | - = help: unsized fn params are gated as an unstable feature -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | fn g2(&x: X) {} - | ^ - -error: aborting due to 13 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized7.rs b/src/test/ui/unsized7.rs deleted file mode 100644 index 422a784814e..00000000000 --- a/src/test/ui/unsized7.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Test sized-ness checking in substitution in impls. - -trait T {} - -// I would like these to fail eventually. -// impl - bounded -trait T1 { - fn dummy(&self) -> Z; -} - -struct S3(Box); -impl T1 for S3 { - //~^ ERROR the size for values of type -} - -fn main() { } diff --git a/src/test/ui/unsized7.stderr b/src/test/ui/unsized7.stderr deleted file mode 100644 index 7dbddd4ed24..00000000000 --- a/src/test/ui/unsized7.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0277]: the size for values of type `X` cannot be known at compilation time - --> $DIR/unsized7.rs:12:21 - | -LL | trait T1 { - | - required by this bound in `T1` -... -LL | impl T1 for S3 { - | - ^^^^^ doesn't have a size known at compile-time - | | - | this type parameter needs to be `std::marker::Sized` - | -help: consider relaxing the implicit `Sized` restriction - | -LL | trait T1 { - | ^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr index 9a7cf4b0919..8498c040780 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr @@ -16,8 +16,8 @@ LL | fn bug() -> impl Iterator { = help: unsized fn params are gated as an unstable feature help: function arguments must have a statically known size, borrowed types always have a known size | -LL | fn bug() -> impl Iterator { - | ^ +LL | fn bug() -> impl Iterator { + | ^ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/ice-6251.rs:4:54 -- cgit 1.4.1-3-g733a5