mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
Fix docs
This commit is contained in:
parent
93e0c7d77a
commit
e584bb8384
@ -98,8 +98,8 @@ impl TextRange {
|
||||
/// let range = TextRange::up_to(point);
|
||||
///
|
||||
/// assert_eq!(range.len(), point);
|
||||
/// assert_eq!(range, TextRange::new(TextSize::zero(), point));
|
||||
/// assert_eq!(range, TextRange::at(TextSize::zero(), point));
|
||||
/// assert_eq!(range, TextRange::new(0.into(), point));
|
||||
/// assert_eq!(range, TextRange::at(0.into(), point));
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn up_to(end: TextSize) -> TextRange {
|
||||
@ -254,7 +254,7 @@ impl TextRange {
|
||||
/// ```rust
|
||||
/// # use text_size::*;
|
||||
/// assert_eq!(
|
||||
/// TextRange::empty(TextSize::zero()).cover_offset(20.into()),
|
||||
/// TextRange::empty(0.into()).cover_offset(20.into()),
|
||||
/// TextRange::new(0.into(), 20.into()),
|
||||
/// )
|
||||
/// ```
|
||||
|
||||
@ -1,35 +1,24 @@
|
||||
use {
|
||||
std::{borrow::Cow, sync::Arc},
|
||||
text_size::*,
|
||||
};
|
||||
use text_size::TextSize;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct BadRope<'a>(&'a [&'a str]);
|
||||
|
||||
impl BadRope<'_> {
|
||||
fn text_len(self) -> TextSize {
|
||||
self.0.iter().map(TextSize::of).sum()
|
||||
self.0.iter().copied().map(TextSize::of).sum()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
macro_rules! test {
|
||||
($($expr:expr),+ $(,)?) => {
|
||||
$(let _ = TextSize::of($expr);)+
|
||||
};
|
||||
}
|
||||
let x: char = 'c';
|
||||
let _ = TextSize::of(x);
|
||||
|
||||
test! {
|
||||
"",
|
||||
&"",
|
||||
'a',
|
||||
&'a',
|
||||
&String::new(),
|
||||
&String::new().into_boxed_str(),
|
||||
&Arc::new(String::new()),
|
||||
&Cow::Borrowed(""),
|
||||
}
|
||||
let x: &str = "hello";
|
||||
let _ = TextSize::of(x);
|
||||
|
||||
let x: &String = &"hello".into();
|
||||
let _ = TextSize::of(x);
|
||||
|
||||
let _ = BadRope(&[""]).text_len();
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ fn checked_math() {
|
||||
assert_eq!(size(1).checked_add(size(1)), Some(size(2)));
|
||||
assert_eq!(size(1).checked_sub(size(1)), Some(size(0)));
|
||||
assert_eq!(size(1).checked_sub(size(2)), None);
|
||||
assert_eq!(TextSize::MAX.checked_add(size(1)), None);
|
||||
assert_eq!(size(!0).checked_add(size(1)), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user