mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
Rollup merge of #134506 - oli-obk:push-mrrulszyuslt, r=jieyouxu
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.
This commit is contained in:
@@ -1315,43 +1315,6 @@ fn try_find_coercion_lub<E>(
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
//@ known-bug: #134005
|
||||
|
||||
fn main() {
|
||||
let _ = [std::ops::Add::add, std::ops::Mul::mul, main as fn(_, &_)];
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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`.
|
||||
Reference in New Issue
Block a user