Rollup merge of #98305 - klensy:no-err-alloc, r=compiler-errors
prohibit_generics: don't alloc error string if no error emitted Noticed unreaded allocs in DHAT.
This commit is contained in:
commit
0ed2feca61
1 changed files with 33 additions and 32 deletions
|
@ -2111,14 +2111,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
|
extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let args = segments.clone().flat_map(|segment| segment.args().args);
|
let args = segments.clone().flat_map(|segment| segment.args().args);
|
||||||
let types_and_spans: Vec<_> = segments
|
|
||||||
.clone()
|
let (lt, ty, ct, inf) =
|
||||||
.flat_map(|segment| {
|
args.clone().fold((false, false, false, false), |(lt, ty, ct, inf), arg| match arg {
|
||||||
segment.res.and_then(|res| {
|
hir::GenericArg::Lifetime(_) => (true, ty, ct, inf),
|
||||||
if segment.args().args.is_empty() {
|
hir::GenericArg::Type(_) => (lt, true, ct, inf),
|
||||||
None
|
hir::GenericArg::Const(_) => (lt, ty, true, inf),
|
||||||
} else {
|
hir::GenericArg::Infer(_) => (lt, ty, ct, true),
|
||||||
Some((
|
});
|
||||||
|
let mut emitted = false;
|
||||||
|
if lt || ty || ct || inf {
|
||||||
|
let types_and_spans: Vec<_> = segments
|
||||||
|
.clone()
|
||||||
|
.flat_map(|segment| {
|
||||||
|
segment.res.and_then(|res| {
|
||||||
|
if segment.args().args.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some((
|
||||||
match res {
|
match res {
|
||||||
Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
|
Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
|
||||||
Res::Def(_, def_id)
|
Res::Def(_, def_id)
|
||||||
|
@ -2130,32 +2140,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
},
|
},
|
||||||
segment.ident.span,
|
segment.ident.span,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.collect();
|
||||||
.collect();
|
let this_type = match &types_and_spans[..] {
|
||||||
let this_type = match &types_and_spans[..] {
|
[.., _, (last, _)] => format!(
|
||||||
[.., _, (last, _)] => format!(
|
"{} and {last}",
|
||||||
"{} and {last}",
|
types_and_spans[..types_and_spans.len() - 1]
|
||||||
types_and_spans[..types_and_spans.len() - 1]
|
.iter()
|
||||||
.iter()
|
.map(|(x, _)| x.as_str())
|
||||||
.map(|(x, _)| x.as_str())
|
.intersperse(&", ")
|
||||||
.intersperse(&", ")
|
.collect::<String>()
|
||||||
.collect::<String>()
|
),
|
||||||
),
|
[(only, _)] => only.to_string(),
|
||||||
[(only, _)] => only.to_string(),
|
[] => "this type".to_string(),
|
||||||
[] => "this type".to_string(),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let (lt, ty, ct, inf) =
|
|
||||||
args.clone().fold((false, false, false, false), |(lt, ty, ct, inf), arg| match arg {
|
|
||||||
hir::GenericArg::Lifetime(_) => (true, ty, ct, inf),
|
|
||||||
hir::GenericArg::Type(_) => (lt, true, ct, inf),
|
|
||||||
hir::GenericArg::Const(_) => (lt, ty, true, inf),
|
|
||||||
hir::GenericArg::Infer(_) => (lt, ty, ct, true),
|
|
||||||
});
|
|
||||||
let mut emitted = false;
|
|
||||||
if lt || ty || ct || inf {
|
|
||||||
let arg_spans: Vec<Span> = args.map(|arg| arg.span()).collect();
|
let arg_spans: Vec<Span> = args.map(|arg| arg.span()).collect();
|
||||||
|
|
||||||
let mut kinds = Vec::with_capacity(4);
|
let mut kinds = Vec::with_capacity(4);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue