Update to use multipart suggestion
Nice.
This commit is contained in:
parent
4b132eefb4
commit
8d9187597a
@ -2,7 +2,7 @@ use crate::astconv::{
|
|||||||
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
|
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
|
||||||
};
|
};
|
||||||
use rustc_ast::ast::ParamKindOrd;
|
use rustc_ast::ast::ParamKindOrd;
|
||||||
use rustc_errors::{pluralize, struct_span_err, DiagnosticId, ErrorReported};
|
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorReported};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{GenericArg, GenericArgs};
|
use rustc_hir::{GenericArg, GenericArgs};
|
||||||
@ -448,10 +448,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
let emit_correct =
|
let emit_correct =
|
||||||
|correct: Result<(), (_, Option<rustc_errors::DiagnosticBuilder<'_>>)>| match correct {
|
|correct: Result<(), (_, Option<rustc_errors::DiagnosticBuilder<'_>>)>| match correct {
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
Err((v, None)) => Err(v == 0),
|
Err((_, None)) => Err(()),
|
||||||
Err((v, Some(mut err))) => {
|
Err((_, Some(mut err))) => {
|
||||||
err.emit();
|
err.emit();
|
||||||
Err(v == 0)
|
Err(())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -500,16 +500,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit a help message if it's possible that a type could be surrounded in braces
|
// Emit a help message if it's possible that a type could be surrounded in braces
|
||||||
if let Err((c_mismatch, Some(ref mut _const_err))) = &mut const_count_correct {
|
if let Err((c_mismatch, Some(ref mut _const_err))) = const_count_correct {
|
||||||
if let Err((t_mismatch, Some(ref mut type_err))) = &mut type_count_correct {
|
if let Err((t_mismatch, Some(ref mut type_err))) = type_count_correct {
|
||||||
if *c_mismatch == -*t_mismatch && *t_mismatch < 0 {
|
if c_mismatch == -t_mismatch && t_mismatch < 0 {
|
||||||
for i in 0..*c_mismatch as usize {
|
for i in 0..c_mismatch as usize {
|
||||||
// let t_span = unexpected_type_spans[i].clone();
|
let arg = &args.args[arg_counts.lifetimes + i];
|
||||||
let ident = args.args[arg_counts.lifetimes + i].id();
|
match arg {
|
||||||
type_err.help(&format!(
|
GenericArg::Type(hir::Ty {
|
||||||
"For more complex types, surround with braces: `{{ {} }}`",
|
kind: hir::TyKind::Path { .. }, ..
|
||||||
ident,
|
}) => {}
|
||||||
));
|
_ => continue,
|
||||||
|
}
|
||||||
|
let suggestions = vec![
|
||||||
|
(arg.span().shrink_to_lo(), String::from("{ ")),
|
||||||
|
(arg.span().shrink_to_hi(), String::from(" }")),
|
||||||
|
];
|
||||||
|
type_err.multipart_suggestion(
|
||||||
|
"If this generic argument was intended as a const parameter, \
|
||||||
|
try surrounding it with braces:",
|
||||||
|
suggestions,
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,8 +532,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
|
|
||||||
GenericArgCountResult {
|
GenericArgCountResult {
|
||||||
explicit_late_bound,
|
explicit_late_bound,
|
||||||
correct: arg_count_correct.map_err(|reported_err| GenericArgCountMismatch {
|
correct: arg_count_correct.map_err(|()| GenericArgCountMismatch {
|
||||||
reported: if reported_err { Some(ErrorReported) } else { None },
|
reported: Some(ErrorReported),
|
||||||
invalid_args: unexpected_spans,
|
invalid_args: unexpected_spans,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,10 @@ error[E0107]: wrong number of type arguments: expected 0, found 1
|
|||||||
LL | test::<CompileFlag::A>();
|
LL | test::<CompileFlag::A>();
|
||||||
| ^^^^^^^^^^^^^^ unexpected type argument
|
| ^^^^^^^^^^^^^^ unexpected type argument
|
||||||
|
|
|
|
||||||
= help: For more complex types, surround with braces: `{ HirId { owner: DefId(0:5 ~ invalid_enum[317d]::main[0]), local_id: 1 } }`
|
help: If this generic argument was intended as a const parameter, try surrounding it with braces:
|
||||||
|
|
|
||||||
|
LL | test::<{ CompileFlag::A }>();
|
||||||
|
| ^ ^
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ error[E0107]: wrong number of type arguments: expected 0, found 1
|
|||||||
|
|
|
|
||||||
LL | foo::<_, {[1]}>();
|
LL | foo::<_, {[1]}>();
|
||||||
| ^ unexpected type argument
|
| ^ unexpected type argument
|
||||||
|
|
|
||||||
= help: For more complex types, surround with braces: `{ HirId { owner: DefId(0:7 ~ issue_62878[317d]::main[0]), local_id: 1 } }`
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/issue-62878.rs:7:15
|
--> $DIR/issue-62878.rs:7:15
|
||||||
|
Loading…
Reference in New Issue
Block a user