Skip to content

Commit 8f41ec0

Browse files
committed
WIP: suggest how to fix with unconstrained type parameters
Unconstrained type parameters made no suggestion and it makes difficult to know how to fix (#107295). To make fixing easier, we output suggestions how to fix.
1 parent 4847d6a commit 8f41ec0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler/rustc_hir_analysis/src/impl_wf_check.rs

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::assert_matches::debug_assert_matches;
1212

1313
use min_specialization::check_min_specialization;
1414
use rustc_data_structures::fx::FxHashSet;
15+
use rustc_errors::Applicability;
1516
use rustc_errors::codes::*;
1617
use rustc_hir::def::DefKind;
1718
use rustc_hir::def_id::LocalDefId;
@@ -149,6 +150,21 @@ fn enforce_impl_params_are_constrained(
149150
const_param_note2: const_param_note,
150151
});
151152
diag.code(E0207);
153+
154+
diag.multipart_suggestions(
155+
format!(
156+
"either remove the type parameter (<{0}>) or make use of it, for example \
157+
`{1}<{0}>`",
158+
param.name, impl_self_ty,
159+
),
160+
// FIXME: I'm not sure the way of getting the span of `<{param.name}>`.
161+
[vec![(tcx.def_span(param.def_id), "".into())], vec![(
162+
// FIXME: I'm not sure the way of getting the span of `impl_self_ty`.
163+
tcx.def_span(param.def_id).shrink_to_hi(),
164+
format!("<{}>", param.name),
165+
)]],
166+
Applicability::MachineApplicable,
167+
);
152168
res = Err(diag.emit());
153169
}
154170
}

0 commit comments

Comments
 (0)