Don't suggest unnameable generic arguments
This commit is contained in:
parent
af7ab34470
commit
c98399f5eb
12 changed files with 90 additions and 22 deletions
|
@ -86,7 +86,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let param_type = tcx.infer_ctxt().enter(|infcx| {
|
||||
infcx.resolve_numeric_literals_with_default(tcx.type_of(param.def_id))
|
||||
});
|
||||
if param_type.is_suggestable(tcx) {
|
||||
if param_type.is_suggestable(tcx, false) {
|
||||
err.span_suggestion(
|
||||
tcx.def_span(src_def_id),
|
||||
"consider changing this type parameter to be a `const` generic",
|
||||
|
|
|
@ -2676,7 +2676,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
span,
|
||||
ty,
|
||||
opt_sugg: Some((span, Applicability::MachineApplicable))
|
||||
.filter(|_| ty.is_suggestable(tcx)),
|
||||
.filter(|_| ty.is_suggestable(tcx, false)),
|
||||
});
|
||||
|
||||
ty
|
||||
|
|
|
@ -1070,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let (_, expected_ty) = formal_and_expected_inputs[expected_idx];
|
||||
if expected_ty.is_unit() {
|
||||
"()".to_string()
|
||||
} else if expected_ty.is_suggestable(tcx) {
|
||||
} else if expected_ty.is_suggestable(tcx, false) {
|
||||
format!("/* {} */", expected_ty)
|
||||
} else {
|
||||
"/* value */".to_string()
|
||||
|
|
|
@ -507,7 +507,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(found));
|
||||
// Only suggest changing the return type for methods that
|
||||
// haven't set a return type at all (and aren't `fn main()` or an impl).
|
||||
match (&fn_decl.output, found.is_suggestable(self.tcx), can_suggest, expected.is_unit()) {
|
||||
match (
|
||||
&fn_decl.output,
|
||||
found.is_suggestable(self.tcx, false),
|
||||
can_suggest,
|
||||
expected.is_unit(),
|
||||
) {
|
||||
(&hir::FnRetTy::DefaultReturn(span), true, true, true) => {
|
||||
err.subdiagnostic(AddReturnTypeSuggestion::Add { span, found });
|
||||
true
|
||||
|
|
|
@ -1929,7 +1929,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
|||
visitor.visit_ty(ty);
|
||||
let mut diag = bad_placeholder(tcx, visitor.0, "return type");
|
||||
let ret_ty = fn_sig.skip_binder().output();
|
||||
if ret_ty.is_suggestable(tcx) {
|
||||
if ret_ty.is_suggestable(tcx, false) {
|
||||
diag.span_suggestion(
|
||||
ty.span,
|
||||
"replace with the correct return type",
|
||||
|
@ -1938,7 +1938,12 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
|||
);
|
||||
} else if matches!(ret_ty.kind(), ty::FnDef(..)) {
|
||||
let fn_sig = ret_ty.fn_sig(tcx);
|
||||
if fn_sig.skip_binder().inputs_and_output.iter().all(|t| t.is_suggestable(tcx)) {
|
||||
if fn_sig
|
||||
.skip_binder()
|
||||
.inputs_and_output
|
||||
.iter()
|
||||
.all(|t| t.is_suggestable(tcx, false))
|
||||
{
|
||||
diag.span_suggestion(
|
||||
ty.span,
|
||||
"replace with the correct return type",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue