diff --git a/Cargo.toml b/Cargo.toml index f8dd465890e0c2..5e44eda500b1d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] # Please update rustfmt.toml when bumping the Rust edition edition = "2024" -rust-version = "1.90" +rust-version = "1.91" homepage = "https://docs.astral.sh/ruff" documentation = "https://docs.astral.sh/ruff" repository = "https://github.com/astral-sh/ruff" diff --git a/crates/ruff_annotate_snippets/src/lib.rs b/crates/ruff_annotate_snippets/src/lib.rs index e623489f97ea8c..f8d0e1e5c6028b 100644 --- a/crates/ruff_annotate_snippets/src/lib.rs +++ b/crates/ruff_annotate_snippets/src/lib.rs @@ -1,5 +1,3 @@ -#![expect(clippy::needless_doctest_main)] - //! A library for formatting of text or programming code snippets. //! //! It's primary purpose is to build an ASCII-graphical representation of the snippet diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index c9013040554c99..f9bb731170faba 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -8,7 +8,6 @@ use ruff_text_size::{Ranged, TextRange, TextSize}; pub use self::render::{ DisplayDiagnostic, DisplayDiagnostics, DummyFileResolver, FileResolver, Input, - ceil_char_boundary, github::{DisplayGithubDiagnostics, GithubRenderer}, }; use crate::cancellation::CancellationToken; diff --git a/crates/ruff_db/src/diagnostic/render.rs b/crates/ruff_db/src/diagnostic/render.rs index 5cd82206943542..9ae7aa623e0774 100644 --- a/crates/ruff_db/src/diagnostic/render.rs +++ b/crates/ruff_db/src/diagnostic/render.rs @@ -1087,7 +1087,8 @@ impl<'r> EscapedSourceCode<'r> { continue; } let start = range.start(); - let end = ceil_char_boundary(&self.text, start + TextSize::from(1)); + let end = + TextSize::try_from(self.text.ceil_char_boundary(start.to_usize() + 1)).unwrap(); ann.range = TextRange::new(start, end); } @@ -1095,86 +1096,6 @@ impl<'r> EscapedSourceCode<'r> { } } -/// Finds the closest [`TextSize`] not less than the offset given for which -/// `is_char_boundary` is `true`. Unless the offset given is greater than -/// the length of the underlying contents, in which case, the length of the -/// contents is returned. -/// -/// Can be replaced with `str::ceil_char_boundary` once it's stable. -/// -/// # Examples -/// -/// From `std`: -/// -/// ``` -/// use ruff_db::diagnostic::ceil_char_boundary; -/// use ruff_text_size::{Ranged, TextLen, TextSize}; -/// -/// let source = "โค๏ธ๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ"; -/// assert_eq!(source.text_len(), TextSize::from(26)); -/// assert!(!source.is_char_boundary(13)); -/// -/// let closest = ceil_char_boundary(source, TextSize::from(13)); -/// assert_eq!(closest, TextSize::from(14)); -/// assert_eq!(&source[..closest.to_usize()], "โค๏ธ๐Ÿงก๐Ÿ’›"); -/// ``` -/// -/// Additional examples: -/// -/// ``` -/// use ruff_db::diagnostic::ceil_char_boundary; -/// use ruff_text_size::{Ranged, TextRange, TextSize}; -/// -/// let source = "Hello"; -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(0)), -/// TextSize::from(0) -/// ); -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(5)), -/// TextSize::from(5) -/// ); -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(6)), -/// TextSize::from(5) -/// ); -/// -/// let source = "ฮฑ"; -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(0)), -/// TextSize::from(0) -/// ); -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(1)), -/// TextSize::from(2) -/// ); -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(2)), -/// TextSize::from(2) -/// ); -/// -/// assert_eq!( -/// ceil_char_boundary(source, TextSize::from(3)), -/// TextSize::from(2) -/// ); -/// ``` -pub fn ceil_char_boundary(text: &str, offset: TextSize) -> TextSize { - let upper_bound = offset - .to_u32() - .saturating_add(4) - .min(text.text_len().to_u32()); - (offset.to_u32()..upper_bound) - .map(TextSize::from) - .find(|offset| text.is_char_boundary(offset.to_usize())) - .unwrap_or_else(|| TextSize::from(upper_bound)) -} - /// A stub implementation of [`FileResolver`] intended for testing. pub struct DummyFileResolver; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 50b3f5d4743ad1..79d20990183b65 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.92" +channel = "1.93"