mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
Drop unused API
This commit is contained in:
parent
12a4ae2401
commit
5dcfeee68c
@ -80,7 +80,7 @@ impl TextRange {
|
||||
/// assert_eq!(range, TextRange::new(point, point));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub const fn empty(offset: TextSize) -> TextRange {
|
||||
pub fn empty(offset: TextSize) -> TextRange {
|
||||
TextRange {
|
||||
start: offset,
|
||||
end: offset,
|
||||
@ -102,9 +102,11 @@ impl TextRange {
|
||||
/// assert_eq!(range, TextRange::at(TextSize::zero(), point));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub const fn up_to(end: TextSize) -> TextRange {
|
||||
let start = TextSize::zero();
|
||||
TextRange { start, end }
|
||||
pub fn up_to(end: TextSize) -> TextRange {
|
||||
TextRange {
|
||||
start: 0.into(),
|
||||
end,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,25 +53,11 @@ impl TextSize {
|
||||
pub fn of<T: TextLen>(text: T) -> TextSize {
|
||||
text.text_len()
|
||||
}
|
||||
|
||||
/// A size of zero.
|
||||
///
|
||||
/// This is equivalent to `TextSize::default()` or [`TextSize::MIN`],
|
||||
/// but is more explicit on intent.
|
||||
#[inline]
|
||||
pub const fn zero() -> TextSize {
|
||||
TextSize { raw: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
/// Methods to act like a primitive integer type, where reasonably applicable.
|
||||
// Last updated for parity with Rust 1.42.0.
|
||||
impl TextSize {
|
||||
/// The smallest representable text size. (`u32::MIN`)
|
||||
pub const MIN: TextSize = TextSize { raw: u32::MIN };
|
||||
/// The largest representable text size. (`u32::MAX`)
|
||||
pub const MAX: TextSize = TextSize { raw: u32::MAX };
|
||||
|
||||
/// Checked addition. Returns `None` if overflow occurred.
|
||||
#[inline]
|
||||
pub fn checked_add(self, rhs: TextSize) -> Option<TextSize> {
|
||||
@ -172,6 +158,6 @@ where
|
||||
{
|
||||
#[inline]
|
||||
fn sum<I: Iterator<Item = A>>(iter: I) -> TextSize {
|
||||
iter.fold(TextSize::zero(), Add::add)
|
||||
iter.fold(0.into(), Add::add)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
use {
|
||||
crate::TextSize,
|
||||
std::{borrow::Cow, convert::TryInto, rc::Rc, sync::Arc},
|
||||
};
|
||||
use {crate::TextSize, std::convert::TryInto};
|
||||
|
||||
use priv_in_pub::Sealed;
|
||||
mod priv_in_pub {
|
||||
@ -22,6 +19,14 @@ impl TextLen for &'_ str {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sealed for &'_ String {}
|
||||
impl TextLen for &'_ String {
|
||||
#[inline]
|
||||
fn text_len(self) -> TextSize {
|
||||
self.as_str().text_len()
|
||||
}
|
||||
}
|
||||
|
||||
impl Sealed for char {}
|
||||
impl TextLen for char {
|
||||
#[inline]
|
||||
@ -29,40 +34,3 @@ impl TextLen for char {
|
||||
(self.len_utf8() as u32).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> Sealed for &'_ D where D: TextLen + Copy {}
|
||||
impl<D> TextLen for &'_ D
|
||||
where
|
||||
D: TextLen + Copy,
|
||||
{
|
||||
fn text_len(self) -> TextSize {
|
||||
D::text_len(*self)
|
||||
}
|
||||
}
|
||||
|
||||
// Because we could not find a smart blanket impl to do this automatically and
|
||||
// cleanly (rust-analyzer/text-size#36), just provide a bunch of manual impls.
|
||||
// If a standard type fits in this macro and you need it to impl TextLen, just
|
||||
// open a PR and we are likely to accept it. Or convince Rust to deref to &str.
|
||||
macro_rules! impl_textlen_for_string {
|
||||
($($ty:ty),+ $(,)?) => {$(
|
||||
impl Sealed for $ty {}
|
||||
impl TextLen for $ty {
|
||||
#[inline]
|
||||
fn text_len(self) -> TextSize {
|
||||
<&str>::text_len(self)
|
||||
}
|
||||
}
|
||||
)+};
|
||||
}
|
||||
|
||||
impl_textlen_for_string! {
|
||||
&Box<str>,
|
||||
&String,
|
||||
&Cow<'_, str>,
|
||||
&Cow<'_, String>,
|
||||
&Arc<str>,
|
||||
&Arc<String>,
|
||||
&Rc<str>,
|
||||
&Rc<String>,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user