From 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:43 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/inference/array-len-mismatch.rs | 12 ++++ tests/ui/inference/array-len-mismatch.stderr | 21 ++++++ tests/ui/inference/deref-suggestion.stderr | 6 +- tests/ui/inference/inference_unstable.rs | 8 +-- tests/ui/inference/inference_unstable.stderr | 8 +-- .../inference/inference_unstable_featured.stderr | 4 +- tests/ui/inference/issue-107090.rs | 25 +++++++ tests/ui/inference/issue-107090.stderr | 84 ++++++++++++++++++++++ tests/ui/inference/issue-71732.stderr | 2 +- ...issue-107745-avoid-expr-from-macro-expansion.rs | 19 +++++ ...e-107745-avoid-expr-from-macro-expansion.stderr | 11 +++ tests/ui/inference/question-mark-type-infer.stderr | 2 +- 12 files changed, 187 insertions(+), 15 deletions(-) create mode 100644 tests/ui/inference/array-len-mismatch.rs create mode 100644 tests/ui/inference/array-len-mismatch.stderr create mode 100644 tests/ui/inference/issue-107090.rs create mode 100644 tests/ui/inference/issue-107090.stderr create mode 100644 tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs create mode 100644 tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr (limited to 'tests/ui/inference') diff --git a/tests/ui/inference/array-len-mismatch.rs b/tests/ui/inference/array-len-mismatch.rs new file mode 100644 index 000000000..149d06102 --- /dev/null +++ b/tests/ui/inference/array-len-mismatch.rs @@ -0,0 +1,12 @@ +fn returns_arr() -> [u8; 2] { + [1, 2] +} + +fn main() { + let wrong: [u8; 3] = [10, 20]; + //~^ ERROR mismatched types + //~^^ HELP consider specifying the actual array length + let wrong: [u8; 3] = returns_arr(); + //~^ ERROR mismatched types + //~^^ HELP consider specifying the actual array length +} diff --git a/tests/ui/inference/array-len-mismatch.stderr b/tests/ui/inference/array-len-mismatch.stderr new file mode 100644 index 000000000..7358e4783 --- /dev/null +++ b/tests/ui/inference/array-len-mismatch.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/array-len-mismatch.rs:6:26 + | +LL | let wrong: [u8; 3] = [10, 20]; + | ------- ^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements + | | | + | | help: consider specifying the actual array length: `2` + | expected due to this + +error[E0308]: mismatched types + --> $DIR/array-len-mismatch.rs:9:26 + | +LL | let wrong: [u8; 3] = returns_arr(); + | ------- ^^^^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements + | | | + | | help: consider specifying the actual array length: `2` + | expected due to this + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/inference/deref-suggestion.stderr b/tests/ui/inference/deref-suggestion.stderr index 3db67cdb5..1626032ae 100644 --- a/tests/ui/inference/deref-suggestion.stderr +++ b/tests/ui/inference/deref-suggestion.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | foo(s); | --- ^- help: try using a conversion method: `.to_string()` | | | - | | expected struct `String`, found `&String` + | | expected `String`, found `&String` | arguments to this function are incorrect | note: function defined here @@ -35,7 +35,7 @@ error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:30:9 | LL | foo(&"aaa".to_owned()); - | --- ^^^^^^^^^^^^^^^^^ expected struct `String`, found `&String` + | --- ^^^^^^^^^^^^^^^^^ expected `String`, found `&String` | | | arguments to this function are incorrect | @@ -54,7 +54,7 @@ error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:32:9 | LL | foo(&mut "aaa".to_owned()); - | --- ^^^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `&mut String` + | --- ^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `&mut String` | | | arguments to this function are incorrect | diff --git a/tests/ui/inference/inference_unstable.rs b/tests/ui/inference/inference_unstable.rs index daf0cf042..ad7649959 100644 --- a/tests/ui/inference/inference_unstable.rs +++ b/tests/ui/inference/inference_unstable.rs @@ -14,16 +14,16 @@ use inference_unstable_itertools::IpuItertools; fn main() { assert_eq!('x'.ipu_flatten(), 1); -//~^ WARN an associated function with this name may be added to the standard library in the future +//~^ WARN a method with this name may be added to the standard library in the future //~| WARN once this associated item is added to the standard library, the ambiguity may cause an assert_eq!('x'.ipu_by_value_vs_by_ref(), 1); -//~^ WARN an associated function with this name may be added to the standard library in the future +//~^ WARN a method with this name may be added to the standard library in the future //~| WARN once this associated item is added to the standard library, the ambiguity may cause an assert_eq!('x'.ipu_by_ref_vs_by_ref_mut(), 1); -//~^ WARN an associated function with this name may be added to the standard library in the future +//~^ WARN a method with this name may be added to the standard library in the future //~| WARN once this associated item is added to the standard library, the ambiguity may cause an assert_eq!((&mut 'x' as *mut char).ipu_by_mut_ptr_vs_by_const_ptr(), 1); -//~^ WARN an associated function with this name may be added to the standard library in the future +//~^ WARN a method with this name may be added to the standard library in the future //~| WARN once this associated item is added to the standard library, the ambiguity may cause an assert_eq!(char::C, 1); //~^ WARN an associated constant with this name may be added to the standard library in the future diff --git a/tests/ui/inference/inference_unstable.stderr b/tests/ui/inference/inference_unstable.stderr index ecbf2641b..c48aaf9f4 100644 --- a/tests/ui/inference/inference_unstable.stderr +++ b/tests/ui/inference/inference_unstable.stderr @@ -1,4 +1,4 @@ -warning: an associated function with this name may be added to the standard library in the future +warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:16:20 | LL | assert_eq!('x'.ipu_flatten(), 1); @@ -10,7 +10,7 @@ LL | assert_eq!('x'.ipu_flatten(), 1); = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten` = note: `#[warn(unstable_name_collisions)]` on by default -warning: an associated function with this name may be added to the standard library in the future +warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:19:20 | LL | assert_eq!('x'.ipu_by_value_vs_by_ref(), 1); @@ -21,7 +21,7 @@ LL | assert_eq!('x'.ipu_by_value_vs_by_ref(), 1); = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_by_value_vs_by_ref(...)` to keep using the current method = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_value_vs_by_ref` -warning: an associated function with this name may be added to the standard library in the future +warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:22:20 | LL | assert_eq!('x'.ipu_by_ref_vs_by_ref_mut(), 1); @@ -32,7 +32,7 @@ LL | assert_eq!('x'.ipu_by_ref_vs_by_ref_mut(), 1); = help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_by_ref_vs_by_ref_mut(...)` to keep using the current method = help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_by_ref_vs_by_ref_mut` -warning: an associated function with this name may be added to the standard library in the future +warning: a method with this name may be added to the standard library in the future --> $DIR/inference_unstable.rs:25:40 | LL | assert_eq!((&mut 'x' as *mut char).ipu_by_mut_ptr_vs_by_const_ptr(), 1); diff --git a/tests/ui/inference/inference_unstable_featured.stderr b/tests/ui/inference/inference_unstable_featured.stderr index 4ddede29c..dc43abf52 100644 --- a/tests/ui/inference/inference_unstable_featured.stderr +++ b/tests/ui/inference/inference_unstable_featured.stderr @@ -6,11 +6,11 @@ LL | assert_eq!('x'.ipu_flatten(), 0); | = note: candidate #1 is defined in an impl of the trait `IpuIterator` for the type `char` = note: candidate #2 is defined in an impl of the trait `IpuItertools` for the type `char` -help: disambiguate the associated function for candidate #1 +help: disambiguate the method for candidate #1 | LL | assert_eq!(IpuIterator::ipu_flatten(&'x'), 0); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: disambiguate the associated function for candidate #2 +help: disambiguate the method for candidate #2 | LL | assert_eq!(IpuItertools::ipu_flatten(&'x'), 0); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/ui/inference/issue-107090.rs b/tests/ui/inference/issue-107090.rs new file mode 100644 index 000000000..a22e12c6d --- /dev/null +++ b/tests/ui/inference/issue-107090.rs @@ -0,0 +1,25 @@ +use std::marker::PhantomData; +struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>) +where + Foo<'short, 'out, T>: Convert<'a, 'b>; + //~^ ERROR use of undeclared lifetime name + //~| ERROR use of undeclared lifetime name `'out` + +trait Convert<'a, 'b>: Sized { + fn cast(&'a self) -> &'b Self; +} +impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> { + //~^ ERROR use of undeclared lifetime name + //~^^ ERROR use of undeclared lifetime name `'out` + fn cast(&'long self) -> &'short Foo<'short, 'out, T> { + //~^ ERROR use of undeclared lifetime name + self + } +} + +fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T { + //~^ ERROR use of undeclared lifetime name + sadness.cast() //~ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/inference/issue-107090.stderr b/tests/ui/inference/issue-107090.stderr new file mode 100644 index 000000000..6233b629a --- /dev/null +++ b/tests/ui/inference/issue-107090.stderr @@ -0,0 +1,84 @@ +error[E0261]: use of undeclared lifetime name `'short` + --> $DIR/issue-107090.rs:4:9 + | +LL | Foo<'short, 'out, T>: Convert<'a, 'b>; + | ^^^^^^ undeclared lifetime + | + = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html +help: consider making the bound lifetime-generic with a new `'short` lifetime + | +LL | for<'short> Foo<'short, 'out, T>: Convert<'a, 'b>; + | +++++++++++ +help: consider introducing lifetime `'short` here + | +LL | struct Foo<'short, 'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>) + | +++++++ + +error[E0261]: use of undeclared lifetime name `'out` + --> $DIR/issue-107090.rs:4:17 + | +LL | Foo<'short, 'out, T>: Convert<'a, 'b>; + | ^^^^ undeclared lifetime + | +help: consider making the bound lifetime-generic with a new `'out` lifetime + | +LL | for<'out> Foo<'short, 'out, T>: Convert<'a, 'b>; + | +++++++++ +help: consider introducing lifetime `'out` here + | +LL | struct Foo<'out, 'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>) + | +++++ + +error[E0261]: use of undeclared lifetime name `'b` + --> $DIR/issue-107090.rs:11:47 + | +LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> { + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'b` here: `'b,` + +error[E0261]: use of undeclared lifetime name `'out` + --> $DIR/issue-107090.rs:11:67 + | +LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> { + | - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime + +error[E0261]: use of undeclared lifetime name `'out` + --> $DIR/issue-107090.rs:14:49 + | +LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> { + | ^^^^ undeclared lifetime + | +help: consider introducing lifetime `'out` here + | +LL | fn cast<'out>(&'long self) -> &'short Foo<'short, 'out, T> { + | ++++++ +help: consider introducing lifetime `'out` here + | +LL | impl<'out, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> { + | +++++ + +error[E0261]: use of undeclared lifetime name `'short` + --> $DIR/issue-107090.rs:20:68 + | +LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T { + | - ^^^^^^ undeclared lifetime + | | + | help: consider introducing lifetime `'short` here: `'short,` + +error[E0308]: mismatched types + --> $DIR/issue-107090.rs:22:5 + | +LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T { + | - this type parameter ------- expected `&'out T` because of return type +LL | +LL | sadness.cast() + | ^^^^^^^^^^^^^^ expected `&T`, found `&Foo<'_, '_, T>` + | + = note: expected reference `&'out T` + found reference `&Foo<'_, '_, T>` + +error: aborting due to 7 previous errors + +Some errors have detailed explanations: E0261, E0308. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/inference/issue-71732.stderr b/tests/ui/inference/issue-71732.stderr index 01b37f2ac..e89e4dca6 100644 --- a/tests/ui/inference/issue-71732.stderr +++ b/tests/ui/inference/issue-71732.stderr @@ -4,7 +4,7 @@ error[E0283]: type annotations needed LL | .get(&"key".into()) | ^^^ ------------- type must be known at this point | | - | cannot infer type of the type parameter `Q` declared on the associated function `get` + | cannot infer type of the type parameter `Q` declared on the method `get` | = note: multiple `impl`s satisfying `String: Borrow<_>` found in the following crates: `alloc`, `core`: - impl Borrow for String; diff --git a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs new file mode 100644 index 000000000..7f6758f47 --- /dev/null +++ b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs @@ -0,0 +1,19 @@ +// ignore-tidy-linelength + +// Regression test for #107745. +// Previously need_type_info::update_infer_source will consider expressions originating from +// macro expressions as candiate "previous sources". This unfortunately can mean that +// for macros expansions such as `format!()` internal implementation details can leak, such as: +// +// ``` +// error[E0282]: type annotations needed +// --> src/main.rs:2:22 +// | +//2 | println!("{:?}", []); +// | ^^ cannot infer type of the type parameter `T` declared on the associated function `new_debug` +// ``` + +fn main() { + println!("{:?}", []); + //~^ ERROR type annotations needed +} diff --git a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr new file mode 100644 index 000000000..464655bbc --- /dev/null +++ b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed + --> $DIR/issue-107745-avoid-expr-from-macro-expansion.rs:17:22 + | +LL | println!("{:?}", []); + | ^^ cannot infer type + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/inference/question-mark-type-infer.stderr b/tests/ui/inference/question-mark-type-infer.stderr index a9cb7e525..7a1e850d1 100644 --- a/tests/ui/inference/question-mark-type-infer.stderr +++ b/tests/ui/inference/question-mark-type-infer.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/question-mark-type-infer.rs:10:21 | LL | l.iter().map(f).collect()? - | ^^^^^^^ cannot infer type of the type parameter `B` declared on the associated function `collect` + | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | help: consider specifying the generic argument | -- cgit v1.2.3