about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-10 10:15:37 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-17 10:57:52 +0000
commit94f549502f4bf6fae35f17c823924f041217c8f4 (patch)
tree4b8fa126b69cb8f5ca9004849a9aff16fce0b5eb /tests
parente23ae72ac7a393961886ea62df065ebb6def7d51 (diff)
downloadrust-94f549502f4bf6fae35f17c823924f041217c8f4.tar.gz
rust-94f549502f4bf6fae35f17c823924f041217c8f4.zip
Use subtyping instead of equality, since method resolution also uses subtyping
Diffstat (limited to 'tests')
-rw-r--r--tests/crashes/126062.rs11
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs10
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr12
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs17
-rw-r--r--tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr20
-rw-r--r--tests/ui/coercion/coerce-issue-49593-box-never.fallback.stderr11
-rw-r--r--tests/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr8
-rw-r--r--tests/ui/coercion/coerce-issue-49593-box-never.rs9
-rw-r--r--tests/ui/const-generics/generic_arg_infer/issue-91614.stderr2
-rw-r--r--tests/ui/inference/need_type_info/type-alias-indirect.stderr2
-rw-r--r--tests/ui/inference/need_type_info/type-alias.stderr6
-rw-r--r--tests/ui/suggestions/mut-borrow-needed-by-trait.rs1
-rw-r--r--tests/ui/suggestions/mut-borrow-needed-by-trait.stderr16
13 files changed, 98 insertions, 27 deletions
diff --git a/tests/crashes/126062.rs b/tests/crashes/126062.rs
deleted file mode 100644
index 9f1bec1d46e..00000000000
--- a/tests/crashes/126062.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-//@ known-bug: rust-lang/rust#126062
-struct Fail<T>(Fail);
-impl<T> Fail<i32> {
-    const C: () = panic!();
-}
-
-fn f<T>() {
-    if false {
-        let _val = &Fail::<T>::C;
-    }
-}
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs
new file mode 100644
index 00000000000..e2fc2961a44
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.rs
@@ -0,0 +1,10 @@
+struct Fail<T>;
+//~^ ERROR: type parameter `T` is never used
+
+impl Fail<i32> {
+    const C: () = ();
+}
+
+fn main() {
+    Fail::<()>::C
+}
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr
new file mode 100644
index 00000000000..f0a6ccf243a
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr
@@ -0,0 +1,12 @@
+error[E0392]: type parameter `T` is never used
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg.rs:1:13
+   |
+LL | struct Fail<T>;
+   |             ^ unused type parameter
+   |
+   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
+   = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0392`.
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs
new file mode 100644
index 00000000000..cb53d902ba1
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.rs
@@ -0,0 +1,17 @@
+trait Proj {
+    type Assoc;
+}
+impl<T> Proj for T {
+    type Assoc = T;
+}
+
+struct Fail<T: Proj<Assoc = U>, U>(T);
+
+impl Fail<i32, i32> {
+    const C: () = ();
+}
+
+fn main() {
+    Fail::<i32, u32>::C
+    //~^ ERROR: type mismatch
+}
diff --git a/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr
new file mode 100644
index 00000000000..0d63b7f5b29
--- /dev/null
+++ b/tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg2.stderr
@@ -0,0 +1,20 @@
+error[E0271]: type mismatch resolving `<i32 as Proj>::Assoc == u32`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:5
+   |
+LL |     Fail::<i32, u32>::C
+   |     ^^^^^^^^^^^^^^^^ type mismatch resolving `<i32 as Proj>::Assoc == u32`
+   |
+note: expected this to be `u32`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:5:18
+   |
+LL |     type Assoc = T;
+   |                  ^
+note: required by a bound in `Fail`
+  --> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:8:21
+   |
+LL | struct Fail<T: Proj<Assoc = U>, U>(T);
+   |                     ^^^^^^^^^ required by this bound in `Fail`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/tests/ui/coercion/coerce-issue-49593-box-never.fallback.stderr b/tests/ui/coercion/coerce-issue-49593-box-never.fallback.stderr
new file mode 100644
index 00000000000..e9b43d6145c
--- /dev/null
+++ b/tests/ui/coercion/coerce-issue-49593-box-never.fallback.stderr
@@ -0,0 +1,11 @@
+error[E0277]: the trait bound `(): std::error::Error` is not satisfied
+  --> $DIR/coerce-issue-49593-box-never.rs:19:5
+   |
+LL |     Box::<_ /* ! */>::new(x)
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
+   |
+   = note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr b/tests/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr
index 0d98fa93e5a..1215f5f9d88 100644
--- a/tests/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr
+++ b/tests/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr
@@ -1,13 +1,13 @@
 error[E0277]: the trait bound `(): std::error::Error` is not satisfied
-  --> $DIR/coerce-issue-49593-box-never.rs:18:53
+  --> $DIR/coerce-issue-49593-box-never.rs:19:5
    |
-LL |     /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
-   |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
+LL |     Box::<_ /* ! */>::new(x)
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
    |
    = note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
 
 error[E0277]: the trait bound `(): std::error::Error` is not satisfied
-  --> $DIR/coerce-issue-49593-box-never.rs:23:49
+  --> $DIR/coerce-issue-49593-box-never.rs:24:49
    |
 LL |     /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
    |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
diff --git a/tests/ui/coercion/coerce-issue-49593-box-never.rs b/tests/ui/coercion/coerce-issue-49593-box-never.rs
index 19a2c036fbc..f93fbb70dce 100644
--- a/tests/ui/coercion/coerce-issue-49593-box-never.rs
+++ b/tests/ui/coercion/coerce-issue-49593-box-never.rs
@@ -1,7 +1,6 @@
 //@ revisions: nofallback fallback
 //@ ignore-windows - the number of `Error` impls is platform-dependent
-//@[fallback] check-pass
-//@[nofallback] check-fail
+//@check-fail
 
 #![feature(never_type)]
 #![cfg_attr(fallback, feature(never_type_fallback))]
@@ -15,8 +14,10 @@ fn raw_ptr_box<T>(t: T) -> *mut T {
 }
 
 fn foo(x: !) -> Box<dyn Error> {
-    /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
-    //[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
+    // Subtyping during method resolution will generate new inference vars and
+    // subtype them. Thus fallback will not fall back to `!`, but `()` instead.
+    Box::<_ /* ! */>::new(x)
+    //~^ ERROR trait bound `(): std::error::Error` is not satisfied
 }
 
 fn foo_raw_ptr(x: !) -> *mut dyn Error {
diff --git a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr
index 5ee42c19dd3..563406ad5ea 100644
--- a/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr
+++ b/tests/ui/const-generics/generic_arg_infer/issue-91614.stderr
@@ -15,7 +15,7 @@ note: required by a bound in `Mask::<T, N>::splat`
   --> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
 help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
    |
-LL |     let y: Mask<_, N> = Mask::<_, _>::splat(false);
+LL |     let y: Mask<T, N> = Mask::<_, _>::splat(false);
    |          ++++++++++++
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/inference/need_type_info/type-alias-indirect.stderr b/tests/ui/inference/need_type_info/type-alias-indirect.stderr
index 535c0044aec..5c5b4c149c1 100644
--- a/tests/ui/inference/need_type_info/type-alias-indirect.stderr
+++ b/tests/ui/inference/need_type_info/type-alias-indirect.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/type-alias-indirect.rs:14:5
    |
 LL |     IndirectAlias::new();
-   |     ^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
+   |     ^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/inference/need_type_info/type-alias.stderr b/tests/ui/inference/need_type_info/type-alias.stderr
index 2c39a3f5646..fd9bcf2fe3f 100644
--- a/tests/ui/inference/need_type_info/type-alias.stderr
+++ b/tests/ui/inference/need_type_info/type-alias.stderr
@@ -2,19 +2,19 @@ error[E0282]: type annotations needed
   --> $DIR/type-alias.rs:12:5
    |
 LL |     DirectAlias::new()
-   |     ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
+   |     ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `DirectAlias`
 
 error[E0282]: type annotations needed
   --> $DIR/type-alias.rs:18:5
    |
 LL |     IndirectAlias::new();
-   |     ^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
+   |     ^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`
 
 error[E0282]: type annotations needed
   --> $DIR/type-alias.rs:32:5
    |
 LL |     DirectButWithDefaultAlias::new();
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `DirectButWithDefaultAlias`
 
 error: aborting due to 3 previous errors
 
diff --git a/tests/ui/suggestions/mut-borrow-needed-by-trait.rs b/tests/ui/suggestions/mut-borrow-needed-by-trait.rs
index 66e1e77c905..924bfd82eb8 100644
--- a/tests/ui/suggestions/mut-borrow-needed-by-trait.rs
+++ b/tests/ui/suggestions/mut-borrow-needed-by-trait.rs
@@ -17,6 +17,7 @@ fn main() {
     let fp = BufWriter::new(fp);
     //~^ ERROR the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
     //~| ERROR the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
+    //~| ERROR the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
 
     writeln!(fp, "hello world").unwrap(); //~ ERROR the method
 }
diff --git a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr
index 09a9b1d3b34..b2f9150142f 100644
--- a/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr
+++ b/tests/ui/suggestions/mut-borrow-needed-by-trait.stderr
@@ -14,6 +14,16 @@ error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satis
   --> $DIR/mut-borrow-needed-by-trait.rs:17:14
    |
 LL |     let fp = BufWriter::new(fp);
+   |              ^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
+   |
+   = note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write`
+note: required by a bound in `BufWriter`
+  --> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL
+
+error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
+  --> $DIR/mut-borrow-needed-by-trait.rs:17:14
+   |
+LL |     let fp = BufWriter::new(fp);
    |              ^^^^^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
    |
    = note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write`
@@ -21,13 +31,13 @@ note: required by a bound in `BufWriter`
   --> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL
 
 error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn Write>`, but its trait bounds were not satisfied
-  --> $DIR/mut-borrow-needed-by-trait.rs:21:14
+  --> $DIR/mut-borrow-needed-by-trait.rs:22:14
    |
 LL |     writeln!(fp, "hello world").unwrap();
    |     ---------^^---------------- method cannot be called on `BufWriter<&dyn Write>` due to unsatisfied trait bounds
    |
 note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method
-  --> $DIR/mut-borrow-needed-by-trait.rs:21:14
+  --> $DIR/mut-borrow-needed-by-trait.rs:22:14
    |
 LL |     writeln!(fp, "hello world").unwrap();
    |              ^^
@@ -35,7 +45,7 @@ LL |     writeln!(fp, "hello world").unwrap();
            `&dyn std::io::Write: std::io::Write`
            which is required by `BufWriter<&dyn std::io::Write>: std::io::Write`
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
 Some errors have detailed explanations: E0277, E0599.
 For more information about an error, try `rustc --explain E0277`.