about summary refs log tree commit diff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-01 19:06:39 +0000
committerbors <bors@rust-lang.org>2024-03-01 19:06:39 +0000
commit2dceda4f32b97f60b122f2b32491e0267ef5cc0c (patch)
tree4989e8c8638ecb5f15eb0f2435bc8fa4dc1d634c /compiler/rustc_middle
parent17edacef07e8afc3b580ed8feead6c5e90d24a56 (diff)
parentff22925e500e767ffcc5485d006174f7d74e21f0 (diff)
downloadrust-2dceda4f32b97f60b122f2b32491e0267ef5cc0c.tar.gz
rust-2dceda4f32b97f60b122f2b32491e0267ef5cc0c.zip
Auto merge of #121859 - matthiaskrgr:rollup-i724wpm, r=matthiaskrgr
Rollup of 12 pull requests

Successful merges:

 - #120646 (Fix incorrect suggestion for uninitialized binding in pattern)
 - #121416 (Improve error messages for generics with default parameters)
 - #121475 (Add tidy check for .stderr/.stdout files for non-existent test revisions)
 - #121580 (make unused_imports less assertive in test modules)
 - #121736 (Remove `Mutex::unlock` Function)
 - #121784 (Make the success arms of `if lhs || rhs` meet up in a separate block)
 - #121818 (CFI: Remove unused `typeid_for_fnsig`)
 - #121819 (Handle stashing of delayed bugs)
 - #121828 (Remove unused fluent messages)
 - #121831 (Fix typo in comment)
 - #121850 (Make `ZeroablePrimitive` trait unsafe.)
 - #121853 (normalizes-to: handle negative impls)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/ty/generics.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs
index c81d9dfbc7d..2630b96869b 100644
--- a/compiler/rustc_middle/src/ty/generics.rs
+++ b/compiler/rustc_middle/src/ty/generics.rs
@@ -360,6 +360,30 @@ impl<'tcx> Generics {
         let own = &args[self.parent_count..][..self.params.len()];
         if self.has_self && self.parent.is_none() { &own[1..] } else { own }
     }
+
+    /// Returns true if a concrete type is specified after a default type.
+    /// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
+    /// `T<usize, String>` will return true
+    /// `T<usize>` will return false
+    pub fn check_concrete_type_after_default(
+        &'tcx self,
+        tcx: TyCtxt<'tcx>,
+        args: &'tcx [ty::GenericArg<'tcx>],
+    ) -> bool {
+        let mut default_param_seen = false;
+        for param in self.params.iter() {
+            if let Some(inst) =
+                param.default_value(tcx).map(|default| default.instantiate(tcx, args))
+            {
+                if inst == args[param.index as usize] {
+                    default_param_seen = true;
+                } else if default_param_seen {
+                    return true;
+                }
+            }
+        }
+        false
+    }
 }
 
 /// Bounds on generics.