From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/const-generics/infer/cannot-infer-const-args.rs | 7 +++++++ .../const-generics/infer/cannot-infer-const-args.stderr | 14 ++++++++++++++ tests/ui/const-generics/infer/issue-77092.rs | 14 ++++++++++++++ tests/ui/const-generics/infer/issue-77092.stderr | 14 ++++++++++++++ tests/ui/const-generics/infer/method-chain.rs | 16 ++++++++++++++++ tests/ui/const-generics/infer/method-chain.stderr | 14 ++++++++++++++ tests/ui/const-generics/infer/one-param-uninferred.rs | 11 +++++++++++ .../ui/const-generics/infer/one-param-uninferred.stderr | 14 ++++++++++++++ tests/ui/const-generics/infer/uninferred-consts.rs | 11 +++++++++++ tests/ui/const-generics/infer/uninferred-consts.stderr | 14 ++++++++++++++ 10 files changed, 129 insertions(+) create mode 100644 tests/ui/const-generics/infer/cannot-infer-const-args.rs create mode 100644 tests/ui/const-generics/infer/cannot-infer-const-args.stderr create mode 100644 tests/ui/const-generics/infer/issue-77092.rs create mode 100644 tests/ui/const-generics/infer/issue-77092.stderr create mode 100644 tests/ui/const-generics/infer/method-chain.rs create mode 100644 tests/ui/const-generics/infer/method-chain.stderr create mode 100644 tests/ui/const-generics/infer/one-param-uninferred.rs create mode 100644 tests/ui/const-generics/infer/one-param-uninferred.stderr create mode 100644 tests/ui/const-generics/infer/uninferred-consts.rs create mode 100644 tests/ui/const-generics/infer/uninferred-consts.stderr (limited to 'tests/ui/const-generics/infer') diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.rs b/tests/ui/const-generics/infer/cannot-infer-const-args.rs new file mode 100644 index 000000000..f85a72910 --- /dev/null +++ b/tests/ui/const-generics/infer/cannot-infer-const-args.rs @@ -0,0 +1,7 @@ +fn foo() -> usize { + 0 +} + +fn main() { + foo(); //~ ERROR type annotations needed +} diff --git a/tests/ui/const-generics/infer/cannot-infer-const-args.stderr b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr new file mode 100644 index 000000000..93e45a88a --- /dev/null +++ b/tests/ui/const-generics/infer/cannot-infer-const-args.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/cannot-infer-const-args.rs:6:5 + | +LL | foo(); + | ^^^ cannot infer the value of the const parameter `X` declared on the function `foo` + | +help: consider specifying the generic argument + | +LL | foo::(); + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/infer/issue-77092.rs b/tests/ui/const-generics/infer/issue-77092.rs new file mode 100644 index 000000000..fcf7d3282 --- /dev/null +++ b/tests/ui/const-generics/infer/issue-77092.rs @@ -0,0 +1,14 @@ +use std::convert::TryInto; + +fn take_array_from_mut(data: &mut [T], start: usize) -> &mut [T; N] { + (&mut data[start .. start + N]).try_into().unwrap() +} + +fn main() { + let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + + for i in 1 .. 4 { + println!("{:?}", take_array_from_mut(&mut arr, i)); + //~^ ERROR type annotations needed + } +} diff --git a/tests/ui/const-generics/infer/issue-77092.stderr b/tests/ui/const-generics/infer/issue-77092.stderr new file mode 100644 index 000000000..1682b26ac --- /dev/null +++ b/tests/ui/const-generics/infer/issue-77092.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/issue-77092.rs:11:26 + | +LL | println!("{:?}", take_array_from_mut(&mut arr, i)); + | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `take_array_from_mut` + | +help: consider specifying the generic arguments + | +LL | println!("{:?}", take_array_from_mut::(&mut arr, i)); + | ++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/infer/method-chain.rs b/tests/ui/const-generics/infer/method-chain.rs new file mode 100644 index 000000000..0c5eed489 --- /dev/null +++ b/tests/ui/const-generics/infer/method-chain.rs @@ -0,0 +1,16 @@ +struct Foo; + +impl Foo { + fn bar(self) -> Foo { + Foo + } + + fn baz(self) -> Foo { + println!("baz: {}", N); + Foo + } +} + +fn main() { + Foo.bar().bar().bar().bar().baz(); //~ ERROR type annotations needed +} diff --git a/tests/ui/const-generics/infer/method-chain.stderr b/tests/ui/const-generics/infer/method-chain.stderr new file mode 100644 index 000000000..ff6da535b --- /dev/null +++ b/tests/ui/const-generics/infer/method-chain.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/method-chain.rs:15:33 + | +LL | Foo.bar().bar().bar().bar().baz(); + | ^^^ cannot infer the value of the const parameter `N` declared on the associated function `baz` + | +help: consider specifying the generic argument + | +LL | Foo.bar().bar().bar().bar().baz::(); + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/infer/one-param-uninferred.rs b/tests/ui/const-generics/infer/one-param-uninferred.rs new file mode 100644 index 000000000..d6018650f --- /dev/null +++ b/tests/ui/const-generics/infer/one-param-uninferred.rs @@ -0,0 +1,11 @@ +// Test that we emit an error if we cannot properly infer a constant. +fn foo() -> [u8; N] { + todo!() +} + +fn main() { + // FIXME(const_generics): Currently this only suggests one const parameter, + // but instead it should suggest to provide all parameters. + let _: [u8; 17] = foo(); + //~^ ERROR type annotations needed +} diff --git a/tests/ui/const-generics/infer/one-param-uninferred.stderr b/tests/ui/const-generics/infer/one-param-uninferred.stderr new file mode 100644 index 000000000..cf70c2181 --- /dev/null +++ b/tests/ui/const-generics/infer/one-param-uninferred.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/one-param-uninferred.rs:9:23 + | +LL | let _: [u8; 17] = foo(); + | ^^^ cannot infer the value of the const parameter `M` declared on the function `foo` + | +help: consider specifying the generic arguments + | +LL | let _: [u8; 17] = foo::<17, M>(); + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/infer/uninferred-consts.rs b/tests/ui/const-generics/infer/uninferred-consts.rs new file mode 100644 index 000000000..657f4b513 --- /dev/null +++ b/tests/ui/const-generics/infer/uninferred-consts.rs @@ -0,0 +1,11 @@ +// Test that we emit an error if we cannot properly infer a constant. + +// taken from https://github.com/rust-lang/rust/issues/70507#issuecomment-615268893 +struct Foo; +impl Foo { + fn foo(self) {} +} +fn main() { + Foo.foo(); + //~^ ERROR type annotations needed +} diff --git a/tests/ui/const-generics/infer/uninferred-consts.stderr b/tests/ui/const-generics/infer/uninferred-consts.stderr new file mode 100644 index 000000000..3980ecea8 --- /dev/null +++ b/tests/ui/const-generics/infer/uninferred-consts.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/uninferred-consts.rs:9:9 + | +LL | Foo.foo(); + | ^^^ cannot infer the value of the const parameter `A` declared on the associated function `foo` + | +help: consider specifying the generic arguments + | +LL | Foo.foo::(); + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. -- cgit v1.2.3