Skip to content

Commit

Permalink
Use the right type when coercing fn items to pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 12, 2024
1 parent e08b80c commit a7d02aa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,9 +1989,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

let ty_fn_ptr_from = Ty::new_fn_ptr(tcx, fn_sig);

if let Err(terr) = self.eq_types(
*ty,
if let Err(terr) = self.sub_types(
ty_fn_ptr_from,
*ty,
location.to_locations(),
ConstraintCategory::Cast { unsize_to: None },
) {
Expand All @@ -2014,9 +2014,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_fn_ptr_from =
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, *safety));

if let Err(terr) = self.eq_types(
*ty,
if let Err(terr) = self.sub_types(
ty_fn_ptr_from,
*ty,
location.to_locations(),
ConstraintCategory::Cast { unsize_to: None },
) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
at.lub(DefineOpaqueTypes::Yes, b, a)
} else {
at.sup(DefineOpaqueTypes::Yes, b, a)
.map(|InferOk { value: (), obligations }| InferOk { value: a, obligations })
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
};

// In the new solver, lazy norm may allow us to shallowly equate
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/recursive-ice-101862.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ LL | vec![].append(&mut ice(x.as_ref()));
= note: `#[warn(unconditional_recursion)]` on by default

error[E0792]: expected generic type parameter, found `&str`
--> $DIR/recursive-ice-101862.rs:6:5
--> $DIR/recursive-ice-101862.rs:6:19
|
LL | pub fn ice(x: impl AsRef<str>) -> impl IntoIterator<Item = ()> {
| --------------- this generic parameter must be used with a generic type parameter
LL |
LL | vec![].append(&mut ice(x.as_ref()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 1 warning emitted

Expand Down
1 change: 1 addition & 0 deletions tests/ui/traits/next-solver/alias-bound-unsound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ fn main() {
//~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed`
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item == _`
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item == _`
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item == _`
println!("{x}");
}
8 changes: 7 additions & 1 deletion tests/ui/traits/next-solver/alias-bound-unsound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ LL | drop(<() as Foo>::copy_me(&x));
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 6 previous errors
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
--> $DIR/alias-bound-unsound.rs:24:31
|
LL | drop(<() as Foo>::copy_me(&x));
| ^^

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0275`.

0 comments on commit a7d02aa

Please sign in to comment.