summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_typeck/src/op.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir_typeck/src/op.rs')
-rw-r--r--compiler/rustc_hir_typeck/src/op.rs38
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs
index 78cea1f4d..80279ed96 100644
--- a/compiler/rustc_hir_typeck/src/op.rs
+++ b/compiler/rustc_hir_typeck/src/op.rs
@@ -13,7 +13,7 @@ use rustc_middle::ty::adjustment::{
};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
- self, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable,
+ self, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned;
@@ -297,7 +297,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method.sig.output()
}
// error types are considered "builtin"
- Err(_) if lhs_ty.references_error() || rhs_ty.references_error() => self.tcx.ty_error(),
+ Err(_) if lhs_ty.references_error() || rhs_ty.references_error() => {
+ self.tcx.ty_error_misc()
+ }
Err(errors) => {
let (_, trait_def_id) =
lang_item_for_op(self.tcx, Op::Binary(op, is_assign), op.span);
@@ -335,7 +337,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("cannot divide `{lhs_ty}` by `{rhs_ty}`")
}
hir::BinOpKind::Rem => {
- format!("cannot mod `{lhs_ty}` by `{rhs_ty}`")
+ format!(
+ "cannot calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`"
+ )
}
hir::BinOpKind::BitAnd => {
format!("no implementation for `{lhs_ty} & {rhs_ty}`")
@@ -488,9 +492,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(output_def_id) = output_def_id
&& let Some(trait_def_id) = trait_def_id
&& self.tcx.parent(output_def_id) == trait_def_id
- && output_ty.is_suggestable(self.tcx, false)
+ && let Some(output_ty) = output_ty.make_suggestable(self.tcx, false)
{
- Some(("Output", *output_ty))
+ Some(("Output", output_ty))
} else {
None
}
@@ -516,7 +520,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
let reported = err.emit();
- self.tcx.ty_error_with_guaranteed(reported)
+ self.tcx.ty_error(reported)
}
};
@@ -629,7 +633,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
Err(errors) => {
let actual = self.resolve_vars_if_possible(operand_ty);
- if !actual.references_error() {
+ let guar = actual.error_reported().err().unwrap_or_else(|| {
let mut err = struct_span_err!(
self.tcx.sess,
ex.span,
@@ -699,9 +703,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
- err.emit();
- }
- self.tcx.ty_error()
+ err.emit()
+ });
+ self.tcx.ty_error(guar)
}
}
}
@@ -745,14 +749,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
let opname = Ident::with_dummy_span(opname);
- let input_types =
- opt_rhs.as_ref().map(|(_, ty)| std::slice::from_ref(ty)).unwrap_or_default();
+ let (opt_rhs_expr, opt_rhs_ty) = opt_rhs.unzip();
+ let input_types = opt_rhs_ty.as_slice();
let cause = self.cause(
span,
traits::BinOp {
- rhs_span: opt_rhs.map(|(expr, _)| expr.span),
- is_lit: opt_rhs
- .map_or(false, |(expr, _)| matches!(expr.kind, hir::ExprKind::Lit(_))),
+ rhs_span: opt_rhs_expr.map(|expr| expr.span),
+ is_lit: opt_rhs_expr
+ .map_or(false, |expr| matches!(expr.kind, hir::ExprKind::Lit(_))),
output_ty: expected.only_has_type(self),
},
);
@@ -961,8 +965,8 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span);
-impl<'tcx> TypeFolder<'tcx> for TypeParamEraser<'_, 'tcx> {
- fn tcx(&self) -> TyCtxt<'tcx> {
+impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TypeParamEraser<'_, 'tcx> {
+ fn interner(&self) -> TyCtxt<'tcx> {
self.0.tcx
}