Add missing diagnostics and flesh out tests
This commit is contained in:
parent
7c8e281f73
commit
174c3f9519
25 changed files with 508 additions and 19 deletions
|
@ -460,7 +460,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
[] => (generics.span, format!("<{lt_name}>")),
|
||||
[bound, ..] => (bound.span.shrink_to_lo(), format!("{lt_name}, ")),
|
||||
};
|
||||
mpart_sugg = Some(errors::AssociatedTypeTraitUninferredGenericParamsMultipartSuggestion {
|
||||
mpart_sugg = Some(errors::AssociatedItemTraitUninferredGenericParamsMultipartSuggestion {
|
||||
fspan: lt_sp,
|
||||
first: sugg,
|
||||
sspan: span.with_hi(item_segment.ident.span.lo()),
|
||||
|
@ -502,7 +502,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
}
|
||||
Ty::new_error(
|
||||
self.tcx(),
|
||||
self.tcx().dcx().emit_err(errors::AssociatedTypeTraitUninferredGenericParams {
|
||||
self.tcx().dcx().emit_err(errors::AssociatedItemTraitUninferredGenericParams {
|
||||
span,
|
||||
inferred_sugg,
|
||||
bound,
|
||||
|
|
|
@ -1886,10 +1886,11 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
)
|
||||
}) =>
|
||||
{
|
||||
let Res::Def(DefKind::AssocFn, item_def_id) = path.res else {
|
||||
bug!();
|
||||
};
|
||||
(vec![], item_def_id, item_segment)
|
||||
match path.res {
|
||||
Res::Err => return,
|
||||
Res::Def(DefKind::AssocFn, item_def_id) => (vec![], item_def_id, item_segment),
|
||||
_ => bug!("only expected method resolution for fully qualified RTN"),
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a type-dependent path, then we do need to do some lookup.
|
||||
|
|
|
@ -780,7 +780,7 @@ pub(crate) struct PlaceholderNotAllowedItemSignatures {
|
|||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_associated_type_trait_uninferred_generic_params, code = E0212)]
|
||||
pub(crate) struct AssociatedTypeTraitUninferredGenericParams {
|
||||
pub(crate) struct AssociatedItemTraitUninferredGenericParams {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion(style = "verbose", applicability = "maybe-incorrect", code = "{bound}")]
|
||||
|
@ -796,7 +796,7 @@ pub(crate) struct AssociatedTypeTraitUninferredGenericParams {
|
|||
hir_analysis_associated_type_trait_uninferred_generic_params_multipart_suggestion,
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub(crate) struct AssociatedTypeTraitUninferredGenericParamsMultipartSuggestion {
|
||||
pub(crate) struct AssociatedItemTraitUninferredGenericParamsMultipartSuggestion {
|
||||
#[suggestion_part(code = "{first}")]
|
||||
pub fspan: Span,
|
||||
pub first: String,
|
||||
|
|
|
@ -487,8 +487,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
let _ =
|
||||
self.prohibit_generic_args(mod_segments.iter(), GenericsArgsErrExtend::None);
|
||||
|
||||
let Res::Def(DefKind::AssocFn, item_def_id) = path.res else {
|
||||
bug!("expected RTN to resolve to associated fn");
|
||||
let item_def_id = match path.res {
|
||||
Res::Def(DefKind::AssocFn, item_def_id) => item_def_id,
|
||||
Res::Err => {
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
hir_ty.span,
|
||||
"failed to resolve RTN",
|
||||
);
|
||||
}
|
||||
_ => bug!("only expected method resolution for fully qualified RTN"),
|
||||
};
|
||||
let trait_def_id = tcx.parent(item_def_id);
|
||||
|
||||
|
@ -605,7 +613,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
assoc_ident,
|
||||
span,
|
||||
)?,
|
||||
_ => todo!(),
|
||||
_ => {
|
||||
if let Err(reported) = qself_ty.error_reported() {
|
||||
return Err(reported);
|
||||
} else {
|
||||
// FIXME(return_type_notation): Provide some structured suggestion here.
|
||||
let err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
E0223,
|
||||
"ambiguous associated function"
|
||||
);
|
||||
return Err(err.emit());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Don't let `T::method` resolve to some `for<'a> <T as Tr<'a>>::method`,
|
||||
|
|
|
@ -813,7 +813,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
}
|
||||
}
|
||||
|
||||
/// Search for a trait bound on a type parameter whose trait defines the associated type given by `assoc_name`.
|
||||
/// Search for a trait bound on a type parameter whose trait defines the associated item
|
||||
/// given by `assoc_name` and `kind`.
|
||||
///
|
||||
/// This fails if there is no such bound in the list of candidates or if there are multiple
|
||||
/// candidates in which case it reports ambiguity.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue