1
Fork 0

Fix #109152, fix the scenario that we may can not get span of func

This commit is contained in:
yukang 2023-03-15 09:09:01 +08:00
parent 669e751639
commit b3af5e2f8b
3 changed files with 39 additions and 2 deletions

View file

@ -56,6 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
return;
}
let arg_ty = cx.typeck_results().expr_ty(&args[0]);
let default_span = args[0].span;
if let ty::FnDef(id, _) = arg_ty.kind() {
let fn_ty = cx.tcx.fn_sig(id).skip_binder();
let ret_ty = fn_ty.output().skip_binder();
@ -64,7 +65,10 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
MAP_UNIT_FN,
span,
MappingToUnit {
function_label: cx.tcx.span_of_impl(*id).unwrap(),
function_label: cx
.tcx
.span_of_impl(*id)
.unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,
@ -80,7 +84,10 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
MAP_UNIT_FN,
span,
MappingToUnit {
function_label: cx.tcx.span_of_impl(*id).unwrap(),
function_label: cx
.tcx
.span_of_impl(*id)
.unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,