Skip to content

Commit

Permalink
Rollup merge of #134506 - oli-obk:push-mrrulszyuslt, r=jieyouxu
Browse files Browse the repository at this point in the history
Remove a duplicated check that doesn't do anything anymore.

fixes #134005

This code didn't actually `lub` the type of the previous expressions, but just the current type over and over again. Changing it to using the actual expression type does not change anything either, so may as well remove the entire loop.
  • Loading branch information
matthiaskrgr authored Dec 19, 2024
2 parents bfbe72e + 987656f commit 4f053b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 42 deletions.
37 changes: 0 additions & 37 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,43 +1315,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

// Then try to coerce the previous expressions to the type of the new one.
// This requires ensuring there are no coercions applied to *any* of the
// previous expressions, other than noop reborrows (ignoring lifetimes).
for expr in exprs {
let expr = expr.as_coercion_site();
let noop = match self.typeck_results.borrow().expr_adjustments(expr) {
&[
Adjustment { kind: Adjust::Deref(_), .. },
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl_adj)), .. },
] => {
match *self.node_ty(expr.hir_id).kind() {
ty::Ref(_, _, mt_orig) => {
let mutbl_adj: hir::Mutability = mutbl_adj.into();
// Reborrow that we can safely ignore, because
// the next adjustment can only be a Deref
// which will be merged into it.
mutbl_adj == mt_orig
}
_ => false,
}
}
&[Adjustment { kind: Adjust::NeverToAny, .. }] | &[] => true,
_ => false,
};

if !noop {
debug!(
"coercion::try_find_coercion_lub: older expression {:?} had adjustments, requiring LUB",
expr,
);

return Err(self
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
.unwrap_err());
}
}

match self.commit_if_ok(|_| coerce.coerce(prev_ty, new_ty)) {
Err(_) => {
// Avoid giving strange errors on failed attempts.
Expand Down
5 changes: 0 additions & 5 deletions tests/crashes/134005.rs

This file was deleted.

6 changes: 6 additions & 0 deletions tests/ui/function-pointer/signature-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! This test used to hit an assertion instead of erroring and bailing out.
fn main() {
let _ = [std::ops::Add::add, std::ops::Mul::mul, std::ops::Mul::mul as fn(_, &_)];
//~^ ERROR: mismatched types
}
12 changes: 12 additions & 0 deletions tests/ui/function-pointer/signature-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/signature-mismatch.rs:4:54
|
LL | let _ = [std::ops::Add::add, std::ops::Mul::mul, std::ops::Mul::mul as fn(_, &_)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected fn pointer `fn(_, _) -> _`
found fn pointer `for<'a> fn(_, &'a _) -> ()`

error: aborting due to 1 previous error

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

0 comments on commit 4f053b1

Please sign in to comment.