about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-06-04 08:25:47 +0100
committerGitHub <noreply@github.com>2024-06-04 08:25:47 +0100
commit0dc65501cb987993a38544bafcf243ec421f53e4 (patch)
tree04fa7fa48b3ed1040b923df550e3628c0f6f4a76 /tests/ui
parentd5a04221efa2cc1ec2833411f9a3f0c51a30d9a5 (diff)
parentd498eb59373a71a166f31b1a9b70a7d8ac9cd4a3 (diff)
downloadrust-0dc65501cb987993a38544bafcf243ec421f53e4.tar.gz
rust-0dc65501cb987993a38544bafcf243ec421f53e4.zip
Rollup merge of #125608 - oli-obk:subsequent_lifetime_errors, r=BoxyUwU
Avoid follow-up errors if the number of generic parameters already doesn't match

fixes #125604

best reviewed commit-by-commit
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs1
-rw-r--r--tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr19
-rw-r--r--tests/ui/lifetimes/noisy-follow-up-erro.rs23
-rw-r--r--tests/ui/lifetimes/noisy-follow-up-erro.stderr27
-rw-r--r--tests/ui/polymorphization/abi_mismatch.rs20
-rw-r--r--tests/ui/polymorphization/abi_mismatch.stderr11
-rw-r--r--tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs2
-rw-r--r--tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr32
-rw-r--r--tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.rs27
-rw-r--r--tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.stderr19
-rw-r--r--tests/ui/traits/issue-78372.stderr12
-rw-r--r--tests/ui/transmutability/issue-101739-2.rs1
-rw-r--r--tests/ui/transmutability/issue-101739-2.stderr20
13 files changed, 147 insertions, 67 deletions
diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs
index 68b8b489816..569e57fa326 100644
--- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs
+++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs
@@ -24,7 +24,6 @@ fn via_associated_const() {
     trait Trait {
         const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
         //~^ ERROR mismatched types
-        //~| ERROR `Src` cannot be safely transmuted into `Dst`
         //~| ERROR mismatched types
     }
 }
diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr
index 1dbacaee3c2..a8fc742e89f 100644
--- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr
+++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr
@@ -12,28 +12,13 @@ error[E0308]: mismatched types
 LL |         const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
    |                                                                          ^^ expected `Assume`, found `()`
 
-error[E0277]: `Src` cannot be safely transmuted into `Dst`
-  --> $DIR/transmutable-ice-110969.rs:25:60
-   |
-LL |         const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
-   |                                                            ^^^ `Dst` may carry safety invariants
-   |
-note: required by a bound in `is_transmutable`
-  --> $DIR/transmutable-ice-110969.rs:11:14
-   |
-LL |     pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
-   |            --------------- required by a bound in this function
-LL |     where
-LL |         Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable`
-
 error[E0308]: mismatched types
   --> $DIR/transmutable-ice-110969.rs:25:29
    |
 LL |         const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
 
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0107, E0277, E0308.
+Some errors have detailed explanations: E0107, E0308.
 For more information about an error, try `rustc --explain E0107`.
diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.rs b/tests/ui/lifetimes/noisy-follow-up-erro.rs
new file mode 100644
index 00000000000..47a87068d8f
--- /dev/null
+++ b/tests/ui/lifetimes/noisy-follow-up-erro.rs
@@ -0,0 +1,23 @@
+struct Foo<'c, 'd>(&'c (), &'d ());
+
+impl<'c, 'd> Foo<'c, 'd> {
+    fn acc(&mut self, _bar: &Bar) -> &'d () {
+        todo!()
+    }
+}
+
+struct Bar;
+
+impl<'a> Bar {
+    fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
+        //~^ ERROR: struct takes 2 lifetime arguments but 3 lifetime arguments were supplied
+        self.bar().map_err(|()| foo.acc(self))?;
+        //~^ ERROR: explicit lifetime required in the type of `foo`
+        Ok(())
+    }
+    fn bar(&self) -> Result<(), &'a ()> {
+        todo!()
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.stderr b/tests/ui/lifetimes/noisy-follow-up-erro.stderr
new file mode 100644
index 00000000000..f549009a87c
--- /dev/null
+++ b/tests/ui/lifetimes/noisy-follow-up-erro.stderr
@@ -0,0 +1,27 @@
+error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were supplied
+  --> $DIR/noisy-follow-up-erro.rs:12:30
+   |
+LL |     fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
+   |                              ^^^         -- help: remove this lifetime argument
+   |                              |
+   |                              expected 2 lifetime arguments
+   |
+note: struct defined here, with 2 lifetime parameters: `'c`, `'d`
+  --> $DIR/noisy-follow-up-erro.rs:1:8
+   |
+LL | struct Foo<'c, 'd>(&'c (), &'d ());
+   |        ^^^ --  --
+
+error[E0621]: explicit lifetime required in the type of `foo`
+  --> $DIR/noisy-follow-up-erro.rs:14:9
+   |
+LL |     fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> {
+   |                         -------------------- help: add explicit lifetime `'a` to the type of `foo`: `&mut Foo<'_, 'a>`
+LL |
+LL |         self.bar().map_err(|()| foo.acc(self))?;
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0107, E0621.
+For more information about an error, try `rustc --explain E0107`.
diff --git a/tests/ui/polymorphization/abi_mismatch.rs b/tests/ui/polymorphization/abi_mismatch.rs
new file mode 100644
index 00000000000..22c2c162d1c
--- /dev/null
+++ b/tests/ui/polymorphization/abi_mismatch.rs
@@ -0,0 +1,20 @@
+//! This test used to ICE: #123917
+//! The reason was that while the AST knows about two fields
+//! named `ptr`, only one exists at the layout level, so accessing
+//! `_extra_field` would use an oob index
+//@ compile-flags: -Zmir-opt-level=5 -Zpolymorphize=on
+
+struct NonNull<T>(*mut T);
+
+struct Token<T> {
+    ptr: *mut T,
+    ptr: NonNull<T>,
+    //~^ ERROR: `ptr` is already declared
+    _extra_field: (),
+}
+
+fn tokenize<T>(item: *mut T) -> Token<T> {
+    Token { ptr: NonNull(item), _extra_field: () }
+}
+
+fn main() {}
diff --git a/tests/ui/polymorphization/abi_mismatch.stderr b/tests/ui/polymorphization/abi_mismatch.stderr
new file mode 100644
index 00000000000..e96c737f777
--- /dev/null
+++ b/tests/ui/polymorphization/abi_mismatch.stderr
@@ -0,0 +1,11 @@
+error[E0124]: field `ptr` is already declared
+  --> $DIR/abi_mismatch.rs:11:5
+   |
+LL |     ptr: *mut T,
+   |     ----------- `ptr` first declared here
+LL |     ptr: NonNull<T>,
+   |     ^^^^^^^^^^^^^^^ field already declared
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0124`.
diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs
index cab484a120c..445ea2de610 100644
--- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs
+++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs
@@ -14,14 +14,12 @@ impl<T, S> Trait<T> for i32 {
 // Should not not trigger suggestion here...
 impl<T, S> Trait<T, S> for () {}
 //~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied
-//~| ERROR `S` is not constrained
 
 //... but should do so in all of the below cases except the last one
 fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
 //~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied
 //~| ERROR trait takes 1 generic argument but 2 generic arguments were supplied
 //~| ERROR trait takes 1 generic argument but 2 generic arguments were supplied
-//~| ERROR type annotations needed
     3
 }
 
diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr
index 99e81a9039e..06e2fa5d4d1 100644
--- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr
+++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr
@@ -16,14 +16,8 @@ note: trait defined here, with 1 generic parameter: `T`
 LL | pub trait Trait<T> {
    |           ^^^^^ -
 
-error[E0207]: the type parameter `S` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:15:9
-   |
-LL | impl<T, S> Trait<T, S> for () {}
-   |         ^ unconstrained type parameter
-
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:12
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:12
    |
 LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
    |            ^^^^^ expected 1 generic argument
@@ -39,7 +33,7 @@ LL | fn func<T: Trait<u32, Assoc = String>>(t: T) -> impl Trait<(), i32> {
    |                       +++++++
 
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:46
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
    |
 LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
    |                                              ^^^^^ expected 1 generic argument
@@ -55,7 +49,7 @@ LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
    |                                                        +++++++
 
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:46
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
    |
 LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
    |                                              ^^^^^ expected 1 generic argument
@@ -71,14 +65,8 @@ help: replace the generic bound with the associated type
 LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
    |                                                        +++++++
 
-error[E0282]: type annotations needed
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:20:41
-   |
-LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
-   |                                         ^^^^^^^^^^^^^^^^^^^ cannot infer type
-
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:28:18
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:18
    |
 LL | struct Struct<T: Trait<u32, String>> {
    |                  ^^^^^ expected 1 generic argument
@@ -94,7 +82,7 @@ LL | struct Struct<T: Trait<u32, Assoc = String>> {
    |                             +++++++
 
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:33:23
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:31:23
    |
 LL | trait AnotherTrait<T: Trait<T, i32>> {}
    |                       ^^^^^ expected 1 generic argument
@@ -110,7 +98,7 @@ LL | trait AnotherTrait<T: Trait<T, Assoc = i32>> {}
    |                                +++++++
 
 error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:36:9
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:34:9
    |
 LL | impl<T: Trait<u32, String>> Struct<T> {}
    |         ^^^^^ expected 1 generic argument
@@ -126,7 +114,7 @@ LL | impl<T: Trait<u32, Assoc = String>> Struct<T> {}
    |                    +++++++
 
 error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:42:58
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:40:58
    |
 LL | impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {}
    |                                                          ^^^^^^    - help: remove this generic argument
@@ -134,12 +122,12 @@ LL | impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {}
    |                                                          expected 1 generic argument
    |
 note: struct defined here, with 1 generic parameter: `T`
-  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:28:8
+  --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:8
    |
 LL | struct Struct<T: Trait<u32, String>> {
    |        ^^^^^^ -
 
-error: aborting due to 11 previous errors
+error: aborting due to 9 previous errors
 
-Some errors have detailed explanations: E0107, E0207, E0282.
+Some errors have detailed explanations: E0107, E0207.
 For more information about an error, try `rustc --explain E0107`.
diff --git a/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.rs b/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.rs
new file mode 100644
index 00000000000..bf1278f992b
--- /dev/null
+++ b/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.rs
@@ -0,0 +1,27 @@
+//! This test used to ICE: #121134
+//! The issue is that we're trying to prove a projection, but there's
+//! no bound for the projection's trait, and the projection has the wrong
+//! kind of generic parameter (lifetime vs type).
+//! When actually calling the function with those broken bounds, trying to
+//! instantiate the bounds with inference vars would ICE.
+#![feature(unboxed_closures)]
+
+trait Output<'a> {
+    type Type;
+}
+
+struct Wrapper;
+
+impl Wrapper {
+    fn do_something_wrapper<O, F>(&mut self, _: F)
+    where
+        F: for<'a> FnOnce(<F as Output<i32>>::Type),
+        //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied
+    {
+    }
+}
+
+fn main() {
+    let mut wrapper = Wrapper;
+    wrapper.do_something_wrapper(|value| ());
+}
diff --git a/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.stderr b/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.stderr
new file mode 100644
index 00000000000..acda3418894
--- /dev/null
+++ b/tests/ui/traits/generic_param_mismatch_in_unsatisfied_projection.stderr
@@ -0,0 +1,19 @@
+error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
+  --> $DIR/generic_param_mismatch_in_unsatisfied_projection.rs:18:33
+   |
+LL |         F: for<'a> FnOnce(<F as Output<i32>>::Type),
+   |                                 ^^^^^^ expected 0 generic arguments
+   |
+note: trait defined here, with 0 generic parameters
+  --> $DIR/generic_param_mismatch_in_unsatisfied_projection.rs:9:7
+   |
+LL | trait Output<'a> {
+   |       ^^^^^^
+help: replace the generic bound with the associated type
+   |
+LL |         F: for<'a> FnOnce(<F as Output<Type = i32>>::Type),
+   |                                        ++++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0107`.
diff --git a/tests/ui/traits/issue-78372.stderr b/tests/ui/traits/issue-78372.stderr
index 58a4c229e5e..cdcb0cdf259 100644
--- a/tests/ui/traits/issue-78372.stderr
+++ b/tests/ui/traits/issue-78372.stderr
@@ -55,12 +55,6 @@ LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
    = help: add `#![feature(dispatch_from_dyn)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error[E0378]: the trait `DispatchFromDyn` may only be implemented for a coercion between structures
-  --> $DIR/issue-78372.rs:3:1
-   |
-LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
 error[E0038]: the trait `Foo` cannot be made into an object
   --> $DIR/issue-78372.rs:12:17
    |
@@ -88,6 +82,12 @@ LL |     fn foo(self: Smaht<Self, T>);
    = note: type of `self` must be `Self` or a type that dereferences to it
    = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
 
+error[E0378]: the trait `DispatchFromDyn` may only be implemented for a coercion between structures
+  --> $DIR/issue-78372.rs:3:1
+   |
+LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
 error: aborting due to 8 previous errors
 
 Some errors have detailed explanations: E0038, E0307, E0378, E0412, E0658.
diff --git a/tests/ui/transmutability/issue-101739-2.rs b/tests/ui/transmutability/issue-101739-2.rs
index e2cec24aac1..1c0bd29d707 100644
--- a/tests/ui/transmutability/issue-101739-2.rs
+++ b/tests/ui/transmutability/issue-101739-2.rs
@@ -15,7 +15,6 @@ mod assert {
     >()
     where
         Dst: BikeshedIntrinsicFrom< //~ ERROR trait takes at most 2 generic arguments but 5 generic arguments were supplied
-        //~^ ERROR: the constant `ASSUME_ALIGNMENT` is not of type `Assume`
             Src,
             ASSUME_ALIGNMENT, //~ ERROR: mismatched types
             ASSUME_LIFETIMES,
diff --git a/tests/ui/transmutability/issue-101739-2.stderr b/tests/ui/transmutability/issue-101739-2.stderr
index 639b4460892..38912696c18 100644
--- a/tests/ui/transmutability/issue-101739-2.stderr
+++ b/tests/ui/transmutability/issue-101739-2.stderr
@@ -9,29 +9,13 @@ LL | |             ASSUME_VALIDITY,
 LL | |             ASSUME_VISIBILITY,
    | |_____________________________- help: remove these generic arguments
 
-error: the constant `ASSUME_ALIGNMENT` is not of type `Assume`
-  --> $DIR/issue-101739-2.rs:17:14
-   |
-LL |           Dst: BikeshedIntrinsicFrom<
-   |  ______________^
-LL | |
-LL | |             Src,
-LL | |             ASSUME_ALIGNMENT,
-...  |
-LL | |             ASSUME_VISIBILITY,
-LL | |         >,
-   | |_________^ expected `Assume`, found `bool`
-   |
-note: required by a bound in `BikeshedIntrinsicFrom`
-  --> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL
-
 error[E0308]: mismatched types
-  --> $DIR/issue-101739-2.rs:20:13
+  --> $DIR/issue-101739-2.rs:19:13
    |
 LL |             ASSUME_ALIGNMENT,
    |             ^^^^^^^^^^^^^^^^ expected `Assume`, found `bool`
 
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
 Some errors have detailed explanations: E0107, E0308.
 For more information about an error, try `rustc --explain E0107`.