]> git.lizzy.rs Git - rust.git/commitdiff
Move ty::print methods to Drop-based scope guards
authorMark Rousskov <mark.simulacrum@gmail.com>
Wed, 16 Feb 2022 18:04:48 +0000 (13:04 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Wed, 16 Feb 2022 22:24:23 +0000 (17:24 -0500)
30 files changed:
compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
compiler/rustc_codegen_gcc/src/type_of.rs
compiler/rustc_codegen_llvm/src/type_of.rs
compiler/rustc_codegen_ssa/src/mir/block.rs
compiler/rustc_const_eval/src/const_eval/eval_queries.rs
compiler/rustc_const_eval/src/interpret/validity.rs
compiler/rustc_const_eval/src/transform/check_consts/ops.rs
compiler/rustc_lint/src/builtin.rs
compiler/rustc_lint/src/context.rs
compiler/rustc_macros/src/query.rs
compiler/rustc_middle/src/lib.rs
compiler/rustc_middle/src/middle/stability.rs
compiler/rustc_middle/src/mir/interpret/mod.rs
compiler/rustc_middle/src/mir/pretty.rs
compiler/rustc_middle/src/ty/print/pretty.rs
compiler/rustc_middle/src/ty/structural_impls.rs
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
compiler/rustc_monomorphize/src/collector.rs
compiler/rustc_monomorphize/src/partitioning/mod.rs
compiler/rustc_query_impl/src/plumbing.rs
compiler/rustc_save_analysis/src/lib.rs
compiler/rustc_symbol_mangling/src/test.rs
compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
compiler/rustc_trait_selection/src/traits/select/mod.rs
compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs
compiler/rustc_typeck/src/check/demand.rs
compiler/rustc_typeck/src/check/method/suggest.rs
compiler/rustc_typeck/src/collect/item_bounds.rs

index 55c9b4d9ba12d7ded09ce5c00410b529f37aef4f..42717ad0ae0e1e1f0d86e038ee45ad18db2fec02 100644 (file)
@@ -779,29 +779,35 @@ fn swap(bcx: &mut FunctionBuilder<'_>, v: Value) -> Value {
         assert_inhabited | assert_zero_valid | assert_uninit_valid, <T> () {
             let layout = fx.layout_of(T);
             if layout.abi.is_uninhabited() {
-                with_no_trimmed_paths(|| crate::base::codegen_panic(
-                    fx,
-                    &format!("attempted to instantiate uninhabited type `{}`", T),
-                    span,
-                ));
+                with_no_trimmed_paths!({
+                    crate::base::codegen_panic(
+                        fx,
+                        &format!("attempted to instantiate uninhabited type `{}`", T),
+                        span,
+                    )
+                });
                 return;
             }
 
             if intrinsic == sym::assert_zero_valid && !layout.might_permit_raw_init(fx, /*zero:*/ true) {
-                with_no_trimmed_paths(|| crate::base::codegen_panic(
-                    fx,
-                    &format!("attempted to zero-initialize type `{}`, which is invalid", T),
-                    span,
-                ));
+                with_no_trimmed_paths!({
+                    crate::base::codegen_panic(
+                        fx,
+                        &format!("attempted to zero-initialize type `{}`, which is invalid", T),
+                        span,
+                    );
+                });
                 return;
             }
 
             if intrinsic == sym::assert_uninit_valid && !layout.might_permit_raw_init(fx, /*zero:*/ false) {
-                with_no_trimmed_paths(|| crate::base::codegen_panic(
-                    fx,
-                    &format!("attempted to leave type `{}` uninitialized, which is invalid", T),
-                    span,
-                ));
+                with_no_trimmed_paths!({
+                    crate::base::codegen_panic(
+                        fx,
+                        &format!("attempted to leave type `{}` uninitialized, which is invalid", T),
+                        span,
+                    )
+                });
                 return;
             }
         };
index 281e49fa8a35ed4b6344c58688b792236b42fa3d..0ada20cad2c3be3c3931a58151832a6c0d79a75b 100644 (file)
@@ -52,7 +52,7 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa
         ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
             if !cx.sess().fewer_names() =>
         {
-            let mut name = with_no_trimmed_paths(|| layout.ty.to_string());
+            let mut name = with_no_trimmed_paths!(layout.ty.to_string());
             if let (&ty::Adt(def, _), &Variants::Single { index }) =
                 (layout.ty.kind(), &layout.variants)
             {
index 81d0603bc5200f16c10637bcf205d50d8286d29a..f0970a8bc1a4575786e9d2bb3b3dcd1b082ac9b2 100644 (file)
@@ -43,8 +43,7 @@ fn uncached_llvm_type<'a, 'tcx>(
         // in problematically distinct types due to HRTB and subtyping (see #47638).
         // ty::Dynamic(..) |
         ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => {
-            let mut name =
-                with_no_visible_paths(|| with_no_trimmed_paths(|| layout.ty.to_string()));
+            let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
             if let (&ty::Adt(def, _), &Variants::Single { index }) =
                 (layout.ty.kind(), &layout.variants)
             {
index 4c7a09ca1e94b2ede7ff45f957aaf240552c3a8e..32a212196cbcd0f89e0736611878b601015a92c1 100644 (file)
@@ -535,8 +535,8 @@ enum AssertIntrinsic {
                 UninitValid => !layout.might_permit_raw_init(bx, /*zero:*/ false),
             };
             if do_panic {
-                let msg_str = with_no_visible_paths(|| {
-                    with_no_trimmed_paths(|| {
+                let msg_str = with_no_visible_paths!({
+                    with_no_trimmed_paths!({
                         if layout.abi.is_uninhabited() {
                             // Use this error even for the other intrinsics as it is more precise.
                             format!("attempted to instantiate uninhabited type `{}`", ty)
index bfb9c40be57df0e6d09c34b2caee8b8d63bfdad7..11eda987b977490e69e49836e9a150c816773e6f 100644 (file)
@@ -53,7 +53,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
 
     trace!(
         "eval_body_using_ecx: pushing stack frame for global: {}{}",
-        with_no_trimmed_paths(|| ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()))),
+        with_no_trimmed_paths!(ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()))),
         cid.promoted.map_or_else(String::new, |p| format!("::promoted[{:?}]", p))
     );
 
@@ -274,7 +274,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
         // The next two lines concatenated contain some discussion:
         // https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
         // subject/anon_const_instance_printing/near/135980032
-        let instance = with_no_trimmed_paths(|| key.value.instance.to_string());
+        let instance = with_no_trimmed_paths!(key.value.instance.to_string());
         trace!("const eval: {:?} ({})", key, instance);
     }
 
@@ -317,7 +317,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
                     // the expression, leading to the const eval error.
                     let instance = &key.value.instance;
                     if !instance.substs.is_empty() {
-                        let instance = with_no_trimmed_paths(|| instance.to_string());
+                        let instance = with_no_trimmed_paths!(instance.to_string());
                         let msg = format!("evaluation of `{}` failed", instance);
                         Cow::from(msg)
                     } else {
index 4060bee7e056c1c61554069927610d644a52521e..e95e327618f0bf8fd9bcf7fad03fe08ec8deb7dc 100644 (file)
@@ -33,7 +33,7 @@ macro_rules! throw_validation_failure {
             msg.push_str(", but expected ");
             write!(&mut msg, $($expected_fmt),+).unwrap();
         )?
-        let path = rustc_middle::ty::print::with_no_trimmed_paths(|| {
+        let path = rustc_middle::ty::print::with_no_trimmed_paths!({
             let where_ = &$where;
             if !where_.is_empty() {
                 let mut path = String::new();
index 8c3f8e8816464d156eddd3235cd4f119fb365f36..888c4b997dc30acf39930a4e97db783ec7255c0d 100644 (file)
@@ -108,9 +108,10 @@ fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> DiagnosticBuilder<'tc
                         .as_ref()
                         .and_then(|node| node.generics())
                     {
-                        let constraint = with_no_trimmed_paths(|| {
-                            format!("~const {}", trait_ref.print_only_trait_path())
-                        });
+                        let constraint = with_no_trimmed_paths!(format!(
+                            "~const {}",
+                            trait_ref.print_only_trait_path()
+                        ));
                         suggest_constraining_type_param(
                             tcx,
                             generics,
index a397db7f32921d733a573af5d95d0ab2f85f9982..a9530cd1bbf397c8a5fb4b2e6952422b11009b1d 100644 (file)
@@ -2634,7 +2634,7 @@ fn ty_find_init_error<'tcx>(
             // We are extremely conservative with what we warn about.
             let conjured_ty = cx.typeck_results().expr_ty(expr);
             if let Some((msg, span)) =
-                with_no_trimmed_paths(|| ty_find_init_error(cx.tcx, conjured_ty, init))
+                with_no_trimmed_paths!(ty_find_init_error(cx.tcx, conjured_ty, init))
             {
                 cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
                     let mut err = lint.build(&format!(
index d2d853efda2d25db2c69b2d029118b65939c5c76..39a400afb9facceab6a67e9d7ebae7df58369e9e 100644 (file)
@@ -994,7 +994,7 @@ fn path_qualified(
                 }
 
                 // This shouldn't ever be needed, but just in case:
-                with_no_trimmed_paths(|| {
+                with_no_trimmed_paths!({
                     Ok(vec![match trait_ref {
                         Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)),
                         None => Symbol::intern(&format!("<{}>", self_ty)),
@@ -1013,15 +1013,15 @@ fn path_append_impl(
 
                 // This shouldn't ever be needed, but just in case:
                 path.push(match trait_ref {
-                    Some(trait_ref) => with_no_trimmed_paths(|| {
-                        Symbol::intern(&format!(
+                    Some(trait_ref) => {
+                        with_no_trimmed_paths!(Symbol::intern(&format!(
                             "<impl {} for {}>",
                             trait_ref.print_only_trait_path(),
                             self_ty
-                        ))
-                    }),
+                        )))
+                    }
                     None => {
-                        with_no_trimmed_paths(|| Symbol::intern(&format!("<impl {}>", self_ty)))
+                        with_no_trimmed_paths!(Symbol::intern(&format!("<impl {}>", self_ty)))
                     }
                 });
 
index 478159147acbd31cd64ce6e5933723eb42aafa32..a6912653368b522de305956bc9e99753f584cf7c 100644 (file)
@@ -434,7 +434,9 @@ fn cache_on_disk(_: TyCtxt<'tcx>, _: &Self::Key) -> bool {
         #[allow(unused_variables)]
         fn describe(tcx: QueryCtxt<$tcx>, key: Self::Key) -> String {
             let (#tcx, #key) = (*tcx, key);
-            ::rustc_middle::ty::print::with_no_trimmed_paths(|| format!(#desc).into())
+            ::rustc_middle::ty::print::with_no_trimmed_paths!(
+                format!(#desc)
+            )
         }
     };
 
index e85cb413deb2ae6060174ba282a9d2c9393d5c65..d3de54b4950f6a4e6707e0dedcbbb0cf6f5b4b0b 100644 (file)
@@ -55,6 +55,7 @@
 #![feature(try_reserve_kind)]
 #![feature(nonzero_ops)]
 #![feature(unwrap_infallible)]
+#![feature(decl_macro)]
 #![recursion_limit = "512"]
 #![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
 
index 03cca51dc0b5474b28fa75dcb1627480197616b0..4d1bc3f15d72c62a7ee84c4f9fe9a7db01623122 100644 (file)
@@ -367,7 +367,7 @@ pub fn eval_stability(
                     let is_in_effect = deprecation_in_effect(depr_attr);
                     let lint = deprecation_lint(is_in_effect);
                     if self.lint_level_at_node(lint, id).0 != Level::Allow {
-                        let def_path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
+                        let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
                         let def_kind = self.def_kind(def_id).descr(def_id);
 
                         late_report_deprecation(
@@ -377,7 +377,7 @@ pub fn eval_stability(
                                 depr_attr.since,
                                 depr_attr.note,
                                 def_kind,
-                                def_path,
+                                &def_path,
                             ),
                             depr_attr.suggestion,
                             lint,
index 66f2c6e78a2e85c6f61eb2e8206681171d081a7a..4eac0009f69e2e1893d6448942cb2bfa8d466442 100644 (file)
@@ -147,7 +147,7 @@ pub struct GlobalId<'tcx> {
 
 impl<'tcx> GlobalId<'tcx> {
     pub fn display(self, tcx: TyCtxt<'tcx>) -> String {
-        let instance_name = with_no_trimmed_paths(|| tcx.def_path_str(self.instance.def.def_id()));
+        let instance_name = with_no_trimmed_paths!(tcx.def_path_str(self.instance.def.def_id()));
         if let Some(promoted) = self.promoted {
             format!("{}::{:?}", instance_name, promoted)
         } else {
index 4f29ef7a6402c862693d19ed7939ccaeb8847a14..3d9ac90a36e15774bce77258f46c61ec79ea3ba9 100644 (file)
@@ -94,10 +94,8 @@ pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) ->
         None => return false,
         Some(ref filters) => filters,
     };
-    let node_path = ty::print::with_forced_impl_filename_line(|| {
-        // see notes on #41697 below
-        tcx.def_path_str(def_id)
-    });
+    // see notes on #41697 below
+    let node_path = ty::print::with_forced_impl_filename_line!(tcx.def_path_str(def_id));
     filters.split('|').any(|or_filter| {
         or_filter.split('&').all(|and_filter| {
             let and_filter_trimmed = and_filter.trim();
@@ -125,10 +123,9 @@ fn dump_matched_mir_node<'tcx, F>(
     let _: io::Result<()> = try {
         let mut file =
             create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, body.source)?;
-        let def_path = ty::print::with_forced_impl_filename_line(|| {
-            // see notes on #41697 above
-            tcx.def_path_str(body.source.def_id())
-        });
+        // see notes on #41697 above
+        let def_path =
+            ty::print::with_forced_impl_filename_line!(tcx.def_path_str(body.source.def_id()));
         write!(file, "// MIR for `{}", def_path)?;
         match body.source.promoted {
             None => write!(file, "`")?,
@@ -959,10 +956,10 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn Write) -> io::Res
         _ => bug!("Unexpected def kind {:?}", kind),
     }
 
-    ty::print::with_forced_impl_filename_line(|| {
+    ty::print::with_forced_impl_filename_line! {
         // see notes on #41697 elsewhere
-        write!(w, "{}", tcx.def_path_str(def_id))
-    })?;
+        write!(w, "{}", tcx.def_path_str(def_id))?
+    }
 
     if body.source.promoted.is_none() && is_function {
         write!(w, "(")?;
index 893df1a009cfc26efc48ba94f22f8b1ffb6d9b67..a741c4cb32e98745bd95276609384aa45e8606cd 100644 (file)
@@ -63,66 +63,59 @@ macro_rules! scoped_cx {
     static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
 }
 
-/// Avoids running any queries during any prints that occur
-/// during the closure. This may alter the appearance of some
-/// types (e.g. forcing verbose printing for opaque types).
-/// This method is used during some queries (e.g. `explicit_item_bounds`
-/// for opaque types), to ensure that any debug printing that
-/// occurs during the query computation does not end up recursively
-/// calling the same query.
-pub fn with_no_queries<F: FnOnce() -> R, R>(f: F) -> R {
-    NO_QUERIES.with(|no_queries| {
-        let old = no_queries.replace(true);
-        let result = f();
-        no_queries.set(old);
-        result
-    })
-}
-
-/// Force us to name impls with just the filename/line number. We
-/// normally try to use types. But at some points, notably while printing
-/// cycle errors, this can result in extra or suboptimal error output,
-/// so this variable disables that check.
-pub fn with_forced_impl_filename_line<F: FnOnce() -> R, R>(f: F) -> R {
-    FORCE_IMPL_FILENAME_LINE.with(|force| {
-        let old = force.replace(true);
-        let result = f();
-        force.set(old);
-        result
-    })
-}
+macro_rules! define_helper {
+    ($($(#[$a:meta])* fn $name:ident($helper:ident, $tl:ident);)+) => {
+        $(
+            #[must_use]
+            pub struct $helper(bool);
+
+            impl $helper {
+                pub fn new() -> $helper {
+                    $helper($tl.with(|c| c.replace(true)))
+                }
+            }
 
-/// Adds the `crate::` prefix to paths where appropriate.
-pub fn with_crate_prefix<F: FnOnce() -> R, R>(f: F) -> R {
-    SHOULD_PREFIX_WITH_CRATE.with(|flag| {
-        let old = flag.replace(true);
-        let result = f();
-        flag.set(old);
-        result
-    })
-}
+            $(#[$a])*
+            pub macro $name($e:expr) {
+                {
+                    let _guard = $helper::new();
+                    $e
+                }
+            }
 
-/// Prevent path trimming if it is turned on. Path trimming affects `Display` impl
-/// of various rustc types, for example `std::vec::Vec` would be trimmed to `Vec`,
-/// if no other `Vec` is found.
-pub fn with_no_trimmed_paths<F: FnOnce() -> R, R>(f: F) -> R {
-    NO_TRIMMED_PATH.with(|flag| {
-        let old = flag.replace(true);
-        let result = f();
-        flag.set(old);
-        result
-    })
+            impl Drop for $helper {
+                fn drop(&mut self) {
+                    $tl.with(|c| c.set(self.0))
+                }
+            }
+        )+
+    }
 }
 
-/// Prevent selection of visible paths. `Display` impl of DefId will prefer visible (public) reexports of types as paths.
-pub fn with_no_visible_paths<F: FnOnce() -> R, R>(f: F) -> R {
-    NO_VISIBLE_PATH.with(|flag| {
-        let old = flag.replace(true);
-        let result = f();
-        flag.set(old);
-        result
-    })
-}
+define_helper!(
+    /// Avoids running any queries during any prints that occur
+    /// during the closure. This may alter the appearance of some
+    /// types (e.g. forcing verbose printing for opaque types).
+    /// This method is used during some queries (e.g. `explicit_item_bounds`
+    /// for opaque types), to ensure that any debug printing that
+    /// occurs during the query computation does not end up recursively
+    /// calling the same query.
+    fn with_no_queries(NoQueriesGuard, NO_QUERIES);
+    /// Force us to name impls with just the filename/line number. We
+    /// normally try to use types. But at some points, notably while printing
+    /// cycle errors, this can result in extra or suboptimal error output,
+    /// so this variable disables that check.
+    fn with_forced_impl_filename_line(ForcedImplGuard, FORCE_IMPL_FILENAME_LINE);
+    /// Adds the `crate::` prefix to paths where appropriate.
+    fn with_crate_prefix(CratePrefixGuard, SHOULD_PREFIX_WITH_CRATE);
+    /// Prevent path trimming if it is turned on. Path trimming affects `Display` impl
+    /// of various rustc types, for example `std::vec::Vec` would be trimmed to `Vec`,
+    /// if no other `Vec` is found.
+    fn with_no_trimmed_paths(NoTrimmedGuard, NO_TRIMMED_PATH);
+    /// Prevent selection of visible paths. `Display` impl of DefId will prefer
+    /// visible (public) reexports of types as paths.
+    fn with_no_visible_paths(NoVisibleGuard, NO_VISIBLE_PATH);
+);
 
 /// The "region highlights" are used to control region printing during
 /// specific error messages. When a "region highlight" is enabled, it
@@ -379,7 +372,7 @@ fn try_print_visible_def_path_recur(
                         // in cases where the `extern crate foo` has non-trivial
                         // parents, e.g. it's nested in `impl foo::Trait for Bar`
                         // (see also issues #55779 and #87932).
-                        self = with_no_visible_paths(|| self.print_def_path(def_id, &[]))?;
+                        self = with_no_visible_paths!(self.print_def_path(def_id, &[])?);
 
                         return Ok((self, true));
                     }
@@ -655,7 +648,7 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
                     return Ok(self);
                 }
 
-                return with_no_queries(|| {
+                return with_no_queries!({
                     let def_key = self.tcx().def_key(def_id);
                     if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
                         p!(write("{}", name));
index c1d714ed8d65e8db7c6f536dcdc5223b8cd32040..6311f401b0492b3a9cdb8f6657c0809aa3750fb1 100644 (file)
@@ -21,9 +21,9 @@
 impl fmt::Debug for ty::TraitDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         ty::tls::with(|tcx| {
-            with_no_trimmed_paths(|| {
-                FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])
-            })?;
+            with_no_trimmed_paths!(
+                FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])?
+            );
             Ok(())
         })
     }
@@ -32,9 +32,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl fmt::Debug for ty::AdtDef {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         ty::tls::with(|tcx| {
-            with_no_trimmed_paths(|| {
-                FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])
-            })?;
+            with_no_trimmed_paths!(
+                FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])?
+            );
             Ok(())
         })
     }
@@ -49,7 +49,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl<'tcx> fmt::Debug for ty::ExistentialTraitRef<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
+        with_no_trimmed_paths!(fmt::Display::fmt(self, f))
     }
 }
 
@@ -125,13 +125,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
+        with_no_trimmed_paths!(fmt::Display::fmt(self, f))
     }
 }
 
 impl<'tcx> fmt::Debug for Ty<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
+        with_no_trimmed_paths!(fmt::Display::fmt(self, f))
     }
 }
 
index 7db71ed598d932ec73ca3c56ffa9dff1554269bd..b83cbb753df72ae88b76e48b4138c0ec46fe1a05 100644 (file)
@@ -121,7 +121,7 @@ fn adt_derive_msg(&self, adt_def: &AdtDef) -> String {
 
     fn search_for_structural_match_violation(&self, ty: Ty<'tcx>) -> Option<String> {
         traits::search_for_structural_match_violation(self.span, self.tcx(), ty).map(|non_sm_ty| {
-            with_no_trimmed_paths(|| match non_sm_ty {
+            with_no_trimmed_paths!(match non_sm_ty {
                 traits::NonStructuralMatchTy::Adt(adt) => self.adt_derive_msg(adt),
                 traits::NonStructuralMatchTy::Dynamic => {
                     "trait objects cannot be used in patterns".to_string()
index 8a1fe6e91cb16b53e8ae1344f7633eea4ba307ae..b93677d464e587add9b976c2732110625fd835de 100644 (file)
@@ -454,7 +454,7 @@ fn collect_items_rec<'tcx>(
         && starting_point.node.krate() != LOCAL_CRATE
         && starting_point.node.is_user_defined()
     {
-        let formatted_item = with_no_trimmed_paths(|| starting_point.node.to_string());
+        let formatted_item = with_no_trimmed_paths!(starting_point.node.to_string());
         tcx.sess.span_note_without_error(
             starting_point.span,
             &format!("the above error was encountered while instantiating `{}`", formatted_item),
index 67597a0d7b46b5dea8d40f9bce3480e6ebb68146..7c8dc1a0ecba81593559c9b1fbacd81267d4f7c8 100644 (file)
@@ -427,7 +427,7 @@ fn collect_and_partition_mono_items<'tcx>(
         let mut item_keys: Vec<_> = items
             .iter()
             .map(|i| {
-                let mut output = with_no_trimmed_paths(|| i.to_string());
+                let mut output = with_no_trimmed_paths!(i.to_string());
                 output.push_str(" @@");
                 let mut empty = Vec::new();
                 let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
index ff9d32a6776520fb1aae2bd69b1900477fb61946..683d56d5d0feb3fc5a85e59994a5790a0b7c6a1b 100644 (file)
@@ -272,11 +272,12 @@ pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryS
                 let name = stringify!($name);
                 // Disable visible paths printing for performance reasons.
                 // Showing visible path instead of any path is not that important in production.
-                let description = ty::print::with_no_visible_paths(
-                    || ty::print::with_forced_impl_filename_line(
+                let description = ty::print::with_no_visible_paths!(
                     // Force filename-line mode to avoid invoking `type_of` query.
-                    || queries::$name::describe(tcx, key)
-                ));
+                    ty::print::with_forced_impl_filename_line!(
+                        queries::$name::describe(tcx, key)
+                    )
+                );
                 let description = if tcx.sess.verbose() {
                     format!("{} [{}]", description, name)
                 } else {
index 8b0adba9fab15b0202765c791ce53aaffc743ac0..669e501bb21ae5a711ca23c43304f555cfd0858c 100644 (file)
@@ -982,7 +982,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
     config: Option<Config>,
     mut handler: H,
 ) {
-    with_no_trimmed_paths(|| {
+    with_no_trimmed_paths!({
         tcx.dep_graph.with_ignore(|| {
             info!("Dumping crate {}", cratename);
 
index 700765a351ce18f17e33b3f8d63de3d1da76d159..611943652a6a151abe17c7b6ca35960829735dab 100644 (file)
@@ -48,7 +48,7 @@ fn process_attrs(&mut self, def_id: LocalDefId) {
                     tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
                 }
             } else if attr.has_name(DEF_PATH) {
-                let path = with_no_trimmed_paths(|| tcx.def_path_str(def_id.to_def_id()));
+                let path = with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id()));
                 tcx.sess.span_err(attr.span, &format!("def-path({})", path));
             }
 
index 6c8a08c09e7778acd9549e4ebf59bc81d5636e3f..a277f74f7a43fbf8bb6a17c247390eeaedeb4e0b 100644 (file)
@@ -161,7 +161,7 @@ fn on_unimplemented_note(
         }
 
         // Add all types without trimmed paths.
-        ty::print::with_no_trimmed_paths(|| {
+        ty::print::with_no_trimmed_paths!({
             let generics = self.tcx.generics_of(def_id);
             let self_ty = trait_ref.self_ty();
             // This is also included through the generics list as `Self`,
index 40cb9647a355541b505577e5e181876bcba28a79..3eb7a3bc7fcd992a5d50924a8ef0841b54b8d6e7 100644 (file)
@@ -443,9 +443,9 @@ fn suggest_restricting_param_bound(
                 {
                     // Missing generic type parameter bound.
                     let param_name = self_ty.to_string();
-                    let constraint = with_no_trimmed_paths(|| {
+                    let constraint = with_no_trimmed_paths!(
                         trait_pred.print_modifiers_and_trait_path().to_string()
-                    });
+                    );
                     if suggest_constraining_type_param(
                         self.tcx,
                         generics,
index db86041f6180b5efdc49a71aebda28ba7a8d2020..d92f26288c14e8e94dcdd7af4c12f7f714e16713 100644 (file)
@@ -92,7 +92,7 @@ fn candidate_from_obligation_no_cache<'o>(
                     if !candidate_set.ambiguous && no_candidates_apply {
                         let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
                         let self_ty = trait_ref.self_ty();
-                        let (trait_desc, self_desc) = with_no_trimmed_paths(|| {
+                        let (trait_desc, self_desc) = with_no_trimmed_paths!({
                             let trait_desc = trait_ref.print_only_trait_path().to_string();
                             let self_desc = if self_ty.has_concrete_skeleton() {
                                 Some(self_ty.to_string())
index 64af875dd22bbb8a2024f88e824c79fd90e76dba..1ed17b7985dd75cd11fa19d1d36a75c5e13fe0f7 100644 (file)
@@ -922,7 +922,7 @@ fn evaluate_stack<'o>(
                         if !candidate_set.ambiguous && candidate_set.vec.is_empty() {
                             let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
                             let self_ty = trait_ref.self_ty();
-                            let cause = with_no_trimmed_paths(|| {
+                            let cause = with_no_trimmed_paths!({
                                 IntercrateAmbiguityCause::DownstreamCrate {
                                     trait_desc: trait_ref.print_only_trait_path().to_string(),
                                     self_desc: if self_ty.has_concrete_skeleton() {
index 497ac207bbe4f3a226d277165e722a61ed10e9ee..e31a9b200e873c5069a2c3981c03472b48ef5319 100644 (file)
@@ -106,7 +106,7 @@ fn insert(
                 let self_ty = trait_ref.self_ty();
 
                 // FIXME: should postpone string formatting until we decide to actually emit.
-                with_no_trimmed_paths(|| {
+                with_no_trimmed_paths!({
                     OverlapError {
                         with_impl: possible_sibling,
                         trait_desc: trait_ref.print_only_trait_path().to_string(),
index d0e96e7538cf046de0341566083cf4d57d90530e..cc85bca398d66fba953291bf8db55cad5d218f8b 100644 (file)
@@ -324,7 +324,7 @@ fn suggest_compatible_variants(
                     let sole_field_ty = sole_field.ty(self.tcx, substs);
                     if self.can_coerce(expr_ty, sole_field_ty) {
                         let variant_path =
-                            with_no_trimmed_paths(|| self.tcx.def_path_str(variant.def_id));
+                            with_no_trimmed_paths!(self.tcx.def_path_str(variant.def_id));
                         // FIXME #56861: DRYer prelude filtering
                         if let Some(path) = variant_path.strip_prefix("std::prelude::") {
                             if let Some((_, path)) = path.split_once("::") {
index 81e2b3bc1621f2b026091c52bedb3667b0076158..2faf40f7293ce3f5e4e1dd8fde8221e8b9fcec83 100644 (file)
@@ -1326,7 +1326,7 @@ fn suggest_use_candidates(
                 let additional_newline = if found_use { "" } else { "\n" };
                 format!(
                     "use {};\n{}",
-                    with_crate_prefix(|| self.tcx.def_path_str(*trait_did)),
+                    with_crate_prefix!(self.tcx.def_path_str(*trait_did)),
                     additional_newline
                 )
             });
@@ -1339,7 +1339,7 @@ fn suggest_use_candidates(
                 let additional_newline = if found_use { "" } else { "\n" };
                 format!(
                     "use {}::*; // trait {}\n{}",
-                    with_crate_prefix(|| self.tcx.def_path_str(*parent_did)),
+                    with_crate_prefix!(self.tcx.def_path_str(*parent_did)),
                     self.tcx.item_name(*trait_did),
                     additional_newline
                 )
@@ -1358,12 +1358,12 @@ fn suggest_use_candidates(
                     msg.push_str(&format!(
                         "\ncandidate #{}: `use {};`",
                         i + 1,
-                        with_crate_prefix(|| self.tcx.def_path_str(*trait_did))
+                        with_crate_prefix!(self.tcx.def_path_str(*trait_did))
                     ));
                 } else {
                     msg.push_str(&format!(
                         "\n`use {};`",
-                        with_crate_prefix(|| self.tcx.def_path_str(*trait_did))
+                        with_crate_prefix!(self.tcx.def_path_str(*trait_did))
                     ));
                 }
             }
@@ -1376,13 +1376,13 @@ fn suggest_use_candidates(
                     msg.push_str(&format!(
                         "\ncandidate #{}: `use {}::*; // trait {}`",
                         candidates.len() + i + 1,
-                        with_crate_prefix(|| self.tcx.def_path_str(*parent_did)),
+                        with_crate_prefix!(self.tcx.def_path_str(*parent_did)),
                         self.tcx.item_name(*trait_did),
                     ));
                 } else {
                     msg.push_str(&format!(
                         "\n`use {}::*; // trait {}`",
-                        with_crate_prefix(|| self.tcx.def_path_str(*parent_did)),
+                        with_crate_prefix!(self.tcx.def_path_str(*parent_did)),
                         self.tcx.item_name(*trait_did),
                     ));
                 }
@@ -1422,7 +1422,7 @@ fn suggest_valid_traits(
             if let Some(did) = edition_fix {
                 err.note(&format!(
                     "'{}' is included in the prelude starting in Edition 2021",
-                    with_crate_prefix(|| self.tcx.def_path_str(did))
+                    with_crate_prefix!(self.tcx.def_path_str(did))
                 ));
             }
 
index 87a67c4a4e060ed147802f1cacd9c298bdbfc667..8801d0260bffce02a0074f5dd49315a7d15da7c5 100644 (file)
@@ -59,7 +59,7 @@ fn opaque_type_bounds<'tcx>(
     ast_bounds: &'tcx [hir::GenericBound<'tcx>],
     span: Span,
 ) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
-    ty::print::with_no_queries(|| {
+    ty::print::with_no_queries!({
         let item_ty =
             tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id));