about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-06-23 14:39:09 -0700
committerGitHub <noreply@github.com>2022-06-23 14:39:09 -0700
commit0ed2feca617de0d99f23f96859b372be2e2baab3 (patch)
tree2ac1d10148b74162a300658463f34f6fa98890db
parent41cb5e9439d0e14d1eaa5bee29f7d7faa0e116fb (diff)
parentf00179521d10357d099b419a73a22f50295220f1 (diff)
downloadrust-0ed2feca617de0d99f23f96859b372be2e2baab3.tar.gz
rust-0ed2feca617de0d99f23f96859b372be2e2baab3.zip
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.
-rw-r--r--compiler/rustc_typeck/src/astconv/mod.rs65
1 files changed, 33 insertions, 32 deletions
diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs
index 84e3180b491..eec3b24aec2 100644
--- a/compiler/rustc_typeck/src/astconv/mod.rs
+++ b/compiler/rustc_typeck/src/astconv/mod.rs
@@ -2111,14 +2111,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
         extend: impl Fn(&mut DiagnosticBuilder<'tcx, ErrorGuaranteed>),
     ) -> bool {
         let args = segments.clone().flat_map(|segment| segment.args().args);
-        let types_and_spans: Vec<_> = segments
-            .clone()
-            .flat_map(|segment| {
-                segment.res.and_then(|res| {
-                    if segment.args().args.is_empty() {
-                        None
-                    } else {
-                        Some((
+
+        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 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 {
                                 Res::PrimTy(ty) => format!("{} `{}`", res.descr(), ty.name()),
                                 Res::Def(_, def_id)
@@ -2130,32 +2140,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                             },
                             segment.ident.span,
                         ))
-                    }
+                        }
+                    })
                 })
-            })
-            .collect();
-        let this_type = match &types_and_spans[..] {
-            [.., _, (last, _)] => format!(
-                "{} and {last}",
-                types_and_spans[..types_and_spans.len() - 1]
-                    .iter()
-                    .map(|(x, _)| x.as_str())
-                    .intersperse(&", ")
-                    .collect::<String>()
-            ),
-            [(only, _)] => only.to_string(),
-            [] => "this type".to_string(),
-        };
+                .collect();
+            let this_type = match &types_and_spans[..] {
+                [.., _, (last, _)] => format!(
+                    "{} and {last}",
+                    types_and_spans[..types_and_spans.len() - 1]
+                        .iter()
+                        .map(|(x, _)| x.as_str())
+                        .intersperse(&", ")
+                        .collect::<String>()
+                ),
+                [(only, _)] => only.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 mut kinds = Vec::with_capacity(4);