about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-03 20:03:54 +0000
committerbors <bors@rust-lang.org>2022-05-03 20:03:54 +0000
commite1b71feb592ba64805689e2b15b9fa570182c442 (patch)
treebfd9b0a882376f64b21a6529fe6ccf036d425b5e /compiler/rustc_trait_selection/src/traits
parent086bf7a8ff3550ff1f4c8e78d8b3a7804fdbbb36 (diff)
parentd33140d2dc95c33bc8281b476048c923476c8b73 (diff)
Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
-rw-r--r--compiler/rustc_trait_selection/src/traits/on_unimplemented.rs121
1 files changed, 61 insertions, 60 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs
index ce0e0a21ff5..c266eec25aa 100644
--- a/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs
+++ b/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs
@@ -304,42 +304,40 @@ impl<'tcx> OnUnimplementedFormatString {
             match token {
                 Piece::String(_) => (), // Normal string, no need to check it
                 Piece::NextArgument(a) => match a.position {
-                    // `{Self}` is allowed
-                    Position::ArgumentNamed(s, _) if s == kw::SelfUpper => (),
-                    // `{ThisTraitsName}` is allowed
-                    Position::ArgumentNamed(s, _) if s == trait_name => (),
-                    // `{from_method}` is allowed
-                    Position::ArgumentNamed(s, _) if s == sym::from_method => (),
-                    // `{from_desugaring}` is allowed
-                    Position::ArgumentNamed(s, _) if s == sym::from_desugaring => (),
-                    // `{ItemContext}` is allowed
-                    Position::ArgumentNamed(s, _) if s == sym::ItemContext => (),
-                    // `{integral}` and `{integer}` and `{float}` are allowed
-                    Position::ArgumentNamed(s, _)
-                        if s == sym::integral || s == sym::integer_ || s == sym::float =>
-                    {
-                        ()
-                    }
-                    // So is `{A}` if A is a type parameter
                     Position::ArgumentNamed(s, _) => {
-                        match generics.params.iter().find(|param| param.name == s) {
-                            Some(_) => (),
-                            None => {
-                                let reported = struct_span_err!(
-                                    tcx.sess,
-                                    span,
-                                    E0230,
-                                    "there is no parameter `{}` on {}",
-                                    s,
-                                    if trait_def_id == item_def_id {
-                                        format!("trait `{}`", trait_name)
-                                    } else {
-                                        "impl".to_string()
-                                    }
-                                )
-                                .emit();
-                                result = Err(reported);
-                            }
+                        match Symbol::intern(s) {
+                            // `{Self}` is allowed
+                            kw::SelfUpper => (),
+                            // `{ThisTraitsName}` is allowed
+                            s if s == trait_name => (),
+                            // `{from_method}` is allowed
+                            sym::from_method => (),
+                            // `{from_desugaring}` is allowed
+                            sym::from_desugaring => (),
+                            // `{ItemContext}` is allowed
+                            sym::ItemContext => (),
+                            // `{integral}` and `{integer}` and `{float}` are allowed
+                            sym::integral | sym::integer_ | sym::float => (),
+                            // So is `{A}` if A is a type parameter
+                            s => match generics.params.iter().find(|param| param.name == s) {
+                                Some(_) => (),
+                                None => {
+                                    let reported = struct_span_err!(
+                                        tcx.sess,
+                                        span,
+                                        E0230,
+                                        "there is no parameter `{}` on {}",
+                                        s,
+                                        if trait_def_id == item_def_id {
+                                            format!("trait `{}`", trait_name)
+                                        } else {
+                                            "impl".to_string()
+                                        }
+                                    )
+                                    .emit();
+                                    result = Err(reported);
+                                }
+                            },
                         }
                     }
                     // `{:1}` and `{}` are not to be used
@@ -392,34 +390,37 @@ impl<'tcx> OnUnimplementedFormatString {
             .map(|p| match p {
                 Piece::String(s) => s,
                 Piece::NextArgument(a) => match a.position {
-                    Position::ArgumentNamed(s, _) => match generic_map.get(&s) {
-                        Some(val) => val,
-                        None if s == name => &trait_str,
-                        None => {
-                            if let Some(val) = options.get(&s) {
-                                val
-                            } else if s == sym::from_desugaring || s == sym::from_method {
-                                // don't break messages using these two arguments incorrectly
-                                &empty_string
-                            } else if s == sym::ItemContext {
-                                &item_context
-                            } else if s == sym::integral {
-                                "{integral}"
-                            } else if s == sym::integer_ {
-                                "{integer}"
-                            } else if s == sym::float {
-                                "{float}"
-                            } else {
-                                bug!(
-                                    "broken on_unimplemented {:?} for {:?}: \
+                    Position::ArgumentNamed(s, _) => {
+                        let s = Symbol::intern(s);
+                        match generic_map.get(&s) {
+                            Some(val) => val,
+                            None if s == name => &trait_str,
+                            None => {
+                                if let Some(val) = options.get(&s) {
+                                    val
+                                } else if s == sym::from_desugaring || s == sym::from_method {
+                                    // don't break messages using these two arguments incorrectly
+                                    &empty_string
+                                } else if s == sym::ItemContext {
+                                    &item_context
+                                } else if s == sym::integral {
+                                    "{integral}"
+                                } else if s == sym::integer_ {
+                                    "{integer}"
+                                } else if s == sym::float {
+                                    "{float}"
+                                } else {
+                                    bug!(
+                                        "broken on_unimplemented {:?} for {:?}: \
                                       no argument matching {:?}",
-                                    self.0,
-                                    trait_ref,
-                                    s
-                                )
+                                        self.0,
+                                        trait_ref,
+                                        s
+                                    )
+                                }
                             }
                         }
-                    },
+                    }
                     _ => bug!("broken on_unimplemented {:?} - bad format arg", self.0),
                 },
             })