Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
process::{self, Stdio},
};

use always_assert::always;
use ide::{
AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange,
HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SingleResolve,
Expand Down Expand Up @@ -265,10 +266,11 @@ pub(crate) fn handle_on_type_formatting(
// `text.char_at(position) == typed_char`.
position.offset -= TextSize::of('.');
let char_typed = params.ch.chars().next().unwrap_or('\0');
assert!({
let text = snap.analysis.file_text(position.file_id)?;
text[usize::from(position.offset)..].starts_with(char_typed)
});

let text = snap.analysis.file_text(position.file_id)?;
if !always!(text[usize::from(position.offset)..].starts_with(char_typed)) {
return Ok(None);
}

// We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
// but it requires precise cursor positioning to work, and one can't
Expand Down
4 changes: 3 additions & 1 deletion docs/dev/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ if idx >= len {
## Assertions

Assert liberally.
Prefer `stdx::never!` to standard `assert!`.
Prefer [`stdx::never!`](https://docs.rs/always-assert/0.1.2/always_assert/macro.never.html) to standard `assert!`.

**Rationale:** See [cross cutting concern: error handling](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/architecture.md#error-handling).

## Getters & Setters

Expand Down