Do not emit a suggestion that causes the E0632 error
This commit is contained in:
parent
7750402c5e
commit
7e6fd40614
3 changed files with 47 additions and 6 deletions
|
@ -287,6 +287,7 @@ pub struct InferenceDiagnosticsData {
|
|||
pub struct InferenceDiagnosticsParentData {
|
||||
pub prefix: &'static str,
|
||||
pub name: String,
|
||||
pub def_id: DefId,
|
||||
}
|
||||
|
||||
pub enum UnderspecifiedArgKind {
|
||||
|
@ -328,6 +329,7 @@ impl InferenceDiagnosticsParentData {
|
|||
Some(InferenceDiagnosticsParentData {
|
||||
prefix: tcx.def_kind(parent_def_id).descr(parent_def_id),
|
||||
name: parent_name,
|
||||
def_id: parent_def_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -754,12 +756,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) =
|
||||
(&arg_data.kind, &arg_data.parent)
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
"consider specifying the const argument",
|
||||
format!("{}::<{}>", parent_data.name, arg_data.name),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
let has_impl_trait =
|
||||
self.tcx.generics_of(parent_data.def_id).params.iter().any(|param| {
|
||||
matches!(
|
||||
param.kind,
|
||||
ty::GenericParamDefKind::Type {
|
||||
synthetic: Some(
|
||||
hir::SyntheticTyParamKind::ImplTrait
|
||||
| hir::SyntheticTyParamKind::FromAttr,
|
||||
),
|
||||
..
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
// (#83606): Do not emit a suggestion if the parent has an `impl Trait`
|
||||
// as an argument otherwise it will cause the E0282 error.
|
||||
if !has_impl_trait {
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
"consider specifying the const argument",
|
||||
format!("{}::<{}>", parent_data.name, arg_data.name),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
err.span_label(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue