use crate::infer::{SubregionOrigin, TypeTrace};
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
use rustc_data_structures::stable_set::FxHashSet;
-use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
+use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_ty, Visitor};
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
pub fn suggest_new_region_bound(
tcx: TyCtxt<'_>,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
fn_returns: Vec<&rustc_hir::Ty<'_>>,
lifetime_name: String,
arg: Option<String>,
/// `'static` obligation. Suggest relaxing that implicit bound.
fn find_impl_on_dyn_trait(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
ty: Ty<'_>,
ctxt: &UnifyReceiverContext<'tcx>,
) -> bool {
let tcx = self.tcx();
// Find the method being called.
- let instance = match ty::Instance::resolve(
+ let Ok(Some(instance)) = ty::Instance::resolve(
tcx,
ctxt.param_env,
ctxt.assoc_item.def_id,
self.infcx.resolve_vars_if_possible(ctxt.substs),
- ) {
- Ok(Some(instance)) => instance,
- _ => return false,
+ ) else {
+ return false;
};
let mut v = TraitObjectVisitor(FxHashSet::default());
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
// `Bar` in `impl Foo for dyn Bar {}` and the definition of the method being called).
- let (ident, self_ty) =
- match self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &v.0) {
- Some((ident, self_ty)) => (ident, self_ty),
- None => return false,
- };
+ let Some((ident, self_ty)) = self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &v.0) else {
+ return false;
+ };
// Find the trait object types in the argument, so we point at *only* the trait object.
self.suggest_constrain_dyn_trait_in_impl(err, &v.0, ident, self_ty)
fn suggest_constrain_dyn_trait_in_impl(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
found_dids: &FxHashSet<DefId>,
ident: Ident,
self_ty: &hir::Ty<'_>,