Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/lib.rs')
-rw-r--r--crates/hir-ty/src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index 3fb8632d6b..4433dd6425 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -689,6 +689,18 @@ impl From<ExprOrPatId> for Span {
}
}
+impl Span {
+ pub(crate) fn pick_best(a: Span, b: Span) -> Span {
+ // We prefer dummy spans to minimize the risk of false errors.
+ if b.is_dummy() { b } else { a }
+ }
+
+ #[inline]
+ pub fn is_dummy(&self) -> bool {
+ matches!(self, Self::Dummy)
+ }
+}
+
pub fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> {
use std::env;
use std::sync::LazyLock;