10010: internal: use idiomatic form of assertions r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-08-24 11:10:09 +00:00 committed by GitHub
commit ea5314d59c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -7,6 +7,7 @@ use std::{
process::{self, Stdio}, process::{self, Stdio},
}; };
use always_assert::always;
use ide::{ use ide::{
AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange, AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange,
HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SingleResolve, HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SingleResolve,
@ -265,10 +266,11 @@ pub(crate) fn handle_on_type_formatting(
// `text.char_at(position) == typed_char`. // `text.char_at(position) == typed_char`.
position.offset -= TextSize::of('.'); position.offset -= TextSize::of('.');
let char_typed = params.ch.chars().next().unwrap_or('\0'); let char_typed = params.ch.chars().next().unwrap_or('\0');
assert!({
let text = snap.analysis.file_text(position.file_id)?; let text = snap.analysis.file_text(position.file_id)?;
text[usize::from(position.offset)..].starts_with(char_typed) 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() ->{`, // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
// but it requires precise cursor positioning to work, and one can't // but it requires precise cursor positioning to work, and one can't

View file

@ -260,7 +260,9 @@ if idx >= len {
## Assertions ## Assertions
Assert liberally. 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 ## Getters & Setters