diff options
Diffstat (limited to 'compiler/rustc_trait_selection/src')
5 files changed, 36 insertions, 34 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 6510dbbbe9d..40f8af1f691 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -2026,7 +2026,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } LetVisitor { span }.visit_body(body).break_value() } - hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }) => { + hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, ty, _, _), .. }) => { Some(&ty.peel_refs().kind) } _ => None, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index d673e5672a0..59c93db9c8f 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -338,7 +338,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .. }, hir::PathSegment { - ident: assoc_item_name, + ident: assoc_item_ident, res: Res::Def(_, item_id), .. }, @@ -368,17 +368,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if let Some(local_def_id) = data.trait_ref.def_id.as_local() && let hir::Node::Item(hir::Item { - ident: trait_name, - kind: hir::ItemKind::Trait(_, _, _, _, trait_item_refs), + kind: hir::ItemKind::Trait(_, _, trait_ident, _, _, trait_item_refs), .. }) = self.tcx.hir_node_by_def_id(local_def_id) && let Some(method_ref) = trait_item_refs .iter() - .find(|item_ref| item_ref.ident == *assoc_item_name) + .find(|item_ref| item_ref.ident == *assoc_item_ident) { err.span_label( method_ref.span, - format!("`{trait_name}::{assoc_item_name}` defined here"), + format!("`{trait_ident}::{assoc_item_ident}` defined here"), ); } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 4d87a93be0c..98df09b6f7b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -419,7 +419,12 @@ pub fn report_dyn_incompatibility<'tcx>( ) -> Diag<'tcx> { let trait_str = tcx.def_path_str(trait_def_id); let trait_span = tcx.hir_get_if_local(trait_def_id).and_then(|node| match node { - hir::Node::Item(item) => Some(item.ident.span), + hir::Node::Item(item) => match item.kind { + hir::ItemKind::Trait(_, _, ident, ..) | hir::ItemKind::TraitAlias(ident, _, _) => { + Some(ident.span) + } + _ => unreachable!(), + }, _ => None, }); diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 9383b82ff3c..f3ee28fe82f 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -267,8 +267,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let node = self.tcx.hir_node_by_def_id(body_id); match node { hir::Node::Item(hir::Item { - ident, - kind: hir::ItemKind::Trait(_, _, generics, bounds, _), + kind: hir::ItemKind::Trait(_, _, ident, generics, bounds, _), .. }) if self_ty == self.tcx.types.self_param => { assert!(param_ty); @@ -282,7 +281,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { None, projection, trait_pred, - Some((ident, bounds)), + Some((&ident, bounds)), ); return; } @@ -331,7 +330,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } hir::Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, generics, ..) + hir::ItemKind::Trait(_, _, _, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }), .. }) if projection.is_some() => { @@ -352,15 +351,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::Node::Item(hir::Item { kind: - hir::ItemKind::Struct(_, generics) - | hir::ItemKind::Enum(_, generics) - | hir::ItemKind::Union(_, generics) - | hir::ItemKind::Trait(_, _, generics, ..) + hir::ItemKind::Struct(_, _, generics) + | hir::ItemKind::Enum(_, _, generics) + | hir::ItemKind::Union(_, _, generics) + | hir::ItemKind::Trait(_, _, _, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } - | hir::ItemKind::TyAlias(_, generics) - | hir::ItemKind::Const(_, generics, _) - | hir::ItemKind::TraitAlias(generics, _), + | hir::ItemKind::TyAlias(_, _, generics) + | hir::ItemKind::Const(_, _, generics, _) + | hir::ItemKind::TraitAlias(_, generics, _), .. }) | hir::Node::TraitItem(hir::TraitItem { generics, .. }) @@ -417,15 +416,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { hir::Node::Item(hir::Item { kind: - hir::ItemKind::Struct(_, generics) - | hir::ItemKind::Enum(_, generics) - | hir::ItemKind::Union(_, generics) - | hir::ItemKind::Trait(_, _, generics, ..) + hir::ItemKind::Struct(_, _, generics) + | hir::ItemKind::Enum(_, _, generics) + | hir::ItemKind::Union(_, _, generics) + | hir::ItemKind::Trait(_, _, _, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn { generics, .. } - | hir::ItemKind::TyAlias(_, generics) - | hir::ItemKind::Const(_, generics, _) - | hir::ItemKind::TraitAlias(generics, _), + | hir::ItemKind::TyAlias(_, _, generics) + | hir::ItemKind::Const(_, _, generics, _) + | hir::ItemKind::TraitAlias(_, generics, _), .. }) if !param_ty => { // Missing generic type parameter bound. @@ -847,7 +846,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { name.to_string() } Some(hir::Node::Item(hir::Item { - ident, kind: hir::ItemKind::Fn { .. }, .. + kind: hir::ItemKind::Fn { ident, .. }, .. })) => { err.span_label(ident.span, "consider calling this function"); ident.to_string() @@ -1593,20 +1592,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if let Some(typeck_results) = &self.typeck_results && let ty = typeck_results.expr_ty_adjusted(base) && let ty::FnDef(def_id, _args) = ty.kind() - && let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) = - self.tcx.hir_get_if_local(*def_id) + && let Some(hir::Node::Item(item)) = self.tcx.hir_get_if_local(*def_id) { + let (ident, _, _, _) = item.expect_fn(); let msg = format!("alternatively, consider making `fn {ident}` asynchronous"); - if vis_span.is_empty() { + if item.vis_span.is_empty() { err.span_suggestion_verbose( - span.shrink_to_lo(), + item.span.shrink_to_lo(), msg, "async ", Applicability::MaybeIncorrect, ); } else { err.span_suggestion_verbose( - vis_span.shrink_to_hi(), + item.vis_span.shrink_to_hi(), msg, " async", Applicability::MaybeIncorrect, @@ -3308,8 +3307,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let mut is_auto_trait = false; match tcx.hir_get_if_local(data.impl_or_alias_def_id) { Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(is_auto, ..), - ident, + kind: hir::ItemKind::Trait(is_auto, _, ident, ..), .. })) => { // FIXME: we should do something else so that it works even on crate foreign diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index fe859eb53cd..7159397c4b1 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -516,7 +516,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope)) { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, generics, ..), + kind: hir::ItemKind::Trait(_, _, _, generics, ..), .. }) | hir::Node::Item(hir::Item { |
