Skip to content

Commit 816efae

Browse files
committed
fix: New clippy warnings
1 parent 88e4570 commit 816efae

File tree

10 files changed

+71
-91
lines changed

10 files changed

+71
-91
lines changed

vhdl_lang/src/analysis/concurrent.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,7 @@ impl<'a> AnalyzeContext<'a> {
185185
// @TODO architecture
186186
InstantiatedUnit::Entity(ref mut entity_name, ..) => {
187187
fn is_entity(kind: &NamedEntityKind) -> bool {
188-
if let NamedEntityKind::Entity(..) = kind {
189-
true
190-
} else {
191-
false
192-
}
188+
matches!(kind, NamedEntityKind::Entity(..))
193189
}
194190

195191
if let Err(err) =
@@ -200,11 +196,7 @@ impl<'a> AnalyzeContext<'a> {
200196
}
201197
InstantiatedUnit::Component(ref mut component_name) => {
202198
fn is_component(kind: &NamedEntityKind) -> bool {
203-
if let NamedEntityKind::Component = kind {
204-
true
205-
} else {
206-
false
207-
}
199+
matches!(kind, NamedEntityKind::Component)
208200
}
209201

210202
if let Err(err) =
@@ -215,11 +207,7 @@ impl<'a> AnalyzeContext<'a> {
215207
}
216208
InstantiatedUnit::Configuration(ref mut config_name) => {
217209
fn is_configuration(kind: &NamedEntityKind) -> bool {
218-
if let NamedEntityKind::Configuration(..) = kind {
219-
true
220-
} else {
221-
false
222-
}
210+
matches!(kind, NamedEntityKind::Configuration(..))
223211
}
224212

225213
if let Err(err) = self.resolve_non_overloaded(

vhdl_lang/src/analysis/named_entity.rs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,26 @@ impl NamedEntityKind {
5454
}
5555

5656
pub fn is_deferred_constant(&self) -> bool {
57-
if let NamedEntityKind::DeferredConstant = self {
58-
true
59-
} else {
60-
false
61-
}
57+
matches!(self, NamedEntityKind::DeferredConstant)
6258
}
6359

6460
pub fn is_non_deferred_constant(&self) -> bool {
65-
if let NamedEntityKind::Object(ObjectClass::Constant) = self {
66-
true
67-
} else {
68-
false
69-
}
61+
matches!(self, NamedEntityKind::Object(ObjectClass::Constant))
7062
}
7163

7264
pub fn is_protected_type(&self) -> bool {
73-
if let NamedEntityKind::ProtectedType(..) = self {
74-
true
75-
} else {
76-
false
77-
}
65+
matches!(self, NamedEntityKind::ProtectedType(..))
7866
}
7967

8068
pub fn is_type(&self) -> bool {
81-
match self {
69+
matches!(
70+
self,
8271
NamedEntityKind::IncompleteType
83-
| NamedEntityKind::ProtectedType(..)
84-
| NamedEntityKind::InterfaceType
85-
| NamedEntityKind::Subtype(..)
86-
| NamedEntityKind::TypeDeclaration(..) => true,
87-
_ => false,
88-
}
72+
| NamedEntityKind::ProtectedType(..)
73+
| NamedEntityKind::InterfaceType
74+
| NamedEntityKind::Subtype(..)
75+
| NamedEntityKind::TypeDeclaration(..)
76+
)
8977
}
9078

9179
pub fn implicit_declarations(&self) -> Vec<Arc<NamedEntity>> {
@@ -180,10 +168,10 @@ pub struct ParameterList {
180168

181169
impl ParameterList {
182170
pub fn add_param(&mut self, param: Arc<NamedEntity>) {
183-
debug_assert!(match param.kind() {
184-
NamedEntityKind::InterfaceObject(..) | NamedEntityKind::InterfaceFile(..) => true,
185-
_ => false,
186-
});
171+
debug_assert!(matches!(
172+
param.kind(),
173+
NamedEntityKind::InterfaceObject(..) | NamedEntityKind::InterfaceFile(..)
174+
));
187175

188176
self.params.push(param);
189177
}
@@ -364,19 +352,11 @@ impl NamedEntity {
364352
}
365353

366354
pub fn is_subprogram(&self) -> bool {
367-
if let NamedEntityKind::Subprogram(..) = self.kind {
368-
true
369-
} else {
370-
false
371-
}
355+
matches!(self.kind, NamedEntityKind::Subprogram(..))
372356
}
373357

374358
pub fn is_subprogram_decl(&self) -> bool {
375-
if let NamedEntityKind::SubprogramDecl(..) = self.kind {
376-
true
377-
} else {
378-
false
379-
}
359+
matches!(self.kind, NamedEntityKind::SubprogramDecl(..))
380360
}
381361

382362
pub fn is_explicit(&self) -> bool {

vhdl_lang/src/data/diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ impl Diagnostic {
103103
pub type DiagnosticResult<T> = Result<T, Diagnostic>;
104104

105105
pub trait DiagnosticHandler {
106-
fn push(self: &mut Self, diagnostic: Diagnostic);
107-
fn append(self: &mut Self, diagnostics: Vec<Diagnostic>) {
106+
fn push(&mut self, diagnostic: Diagnostic);
107+
fn append(&mut self, diagnostics: Vec<Diagnostic>) {
108108
for diagnostic in diagnostics.into_iter() {
109109
self.push(diagnostic);
110110
}
@@ -142,7 +142,7 @@ impl<'a> dyn DiagnosticHandler + 'a {
142142
}
143143

144144
impl DiagnosticHandler for Vec<Diagnostic> {
145-
fn push(self: &mut Self, diagnostic: Diagnostic) {
145+
fn push(&mut self, diagnostic: Diagnostic) {
146146
self.push(diagnostic)
147147
}
148148
}

vhdl_lang/src/data/latin_1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub fn char_to_latin1(chr: char) -> Option<u8> {
3333
Some(byte)
3434
} else if byte == 0xc2 {
3535
let next_byte = bytes[1];
36-
if 128 <= next_byte && next_byte < 192 {
36+
if (128..192).contains(&next_byte) {
3737
Some(next_byte)
3838
} else {
3939
None
4040
}
4141
} else if byte == 0xc3 {
4242
let next_byte = bytes[1];
43-
if 128 <= next_byte && next_byte < 192 {
43+
if (128..192).contains(&next_byte) {
4444
Some(next_byte + 64)
4545
} else {
4646
None
@@ -122,15 +122,15 @@ impl Latin1String {
122122
i += 1;
123123
} else if byte == 0xc2 {
124124
let next_byte = bytes[i + 1];
125-
if 128 <= next_byte && next_byte < 192 {
125+
if (128..192).contains(&next_byte) {
126126
latin1_bytes.push(next_byte);
127127
i += 2;
128128
} else {
129129
error = true;
130130
}
131131
} else if byte == 0xc3 {
132132
let next_byte = bytes[i + 1];
133-
if 128 <= next_byte && next_byte < 192 {
133+
if (128..192).contains(&next_byte) {
134134
latin1_bytes.push(next_byte + 64);
135135
i += 2;
136136
} else {

vhdl_lang/src/data/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl SrcPos {
388388
}
389389

390390
// Newline
391-
into.push_str("\n");
391+
into.push('\n');
392392
}
393393

394394
fn code_context_from_contents(

vhdl_lang/src/data/symbol_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ impl Symbol {
3838
}
3939

4040
/// Returns the name of the symbol.
41-
pub fn name(self: &Self) -> &Latin1String {
41+
pub fn name(&self) -> &Latin1String {
4242
self.name.as_ref()
4343
}
4444

4545
/// Returns the name of the symbol as a UTF-8 string.
46-
pub fn name_utf8(self: &Self) -> String {
46+
pub fn name_utf8(&self) -> String {
4747
self.name.to_string()
4848
}
4949
}
5050

5151
impl PartialEq for Symbol {
5252
/// Symbols are compared just based on the `id` field.
53-
fn eq(self: &Self, other: &Self) -> bool {
53+
fn eq(&self, other: &Self) -> bool {
5454
self.id == other.id
5555
}
5656
}

vhdl_lang/src/syntax/declarative_part.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,25 @@ pub fn parse_declarative_part_leave_end_token(
8282
let mut declarations: Vec<Declaration> = Vec::new();
8383

8484
fn is_recover_token(kind: Kind) -> bool {
85-
match kind {
86-
Type | Subtype | Component | Impure | Pure | Function | Procedure | Package | For
87-
| File | Shared | Constant | Signal | Variable | Attribute | Use | Alias => true,
88-
_ => false,
89-
}
85+
matches!(
86+
kind,
87+
Type | Subtype
88+
| Component
89+
| Impure
90+
| Pure
91+
| Function
92+
| Procedure
93+
| Package
94+
| For
95+
| File
96+
| Shared
97+
| Constant
98+
| Signal
99+
| Variable
100+
| Attribute
101+
| Use
102+
| Alias
103+
)
90104
};
91105

92106
while let Some(token) = stream.peek()? {

vhdl_lang/src/syntax/interface_declaration.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ enum InterfaceListType {
266266
}
267267

268268
fn is_sync_kind(list_type: InterfaceListType, kind: Kind) -> bool {
269-
match (list_type, kind) {
269+
matches!(
270+
(list_type, kind),
270271
(InterfaceListType::Generic, Constant)
271-
| (InterfaceListType::Port, Signal)
272-
| (InterfaceListType::Parameter, Constant)
273-
| (InterfaceListType::Parameter, Variable)
274-
| (InterfaceListType::Parameter, Signal) => true,
275-
_ => false,
276-
}
272+
| (InterfaceListType::Port, Signal)
273+
| (InterfaceListType::Parameter, Constant)
274+
| (InterfaceListType::Parameter, Variable)
275+
| (InterfaceListType::Parameter, Signal)
276+
)
277277
}
278278

279279
fn parse_interface_list(

vhdl_lang/src/syntax/tokens/tokenizer.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,7 @@ impl From<Utf8ToLatin1Error> for TokenError {
555555
/// char may not come after ], ), all, or identifier
556556
fn can_be_char(last_token_kind: Option<Kind>) -> bool {
557557
if let Some(kind) = last_token_kind {
558-
match kind {
559-
RightSquare | RightPar | All | Identifier => false,
560-
_ => true,
561-
}
558+
!matches!(kind, RightSquare | RightPar | All | Identifier)
562559
} else {
563560
true
564561
}
@@ -569,7 +566,7 @@ fn parse_integer(
569566
base: u64,
570567
stop_on_suffix: bool,
571568
) -> Result<u64, TokenError> {
572-
let mut result = Some(0 as u64);
569+
let mut result = Some(0_u64);
573570
let mut too_large_digit = None;
574571
let mut invalid_character = None;
575572

@@ -836,9 +833,7 @@ fn parse_real_literal(
836833
}
837834

838835
fn exponentiate(value: u64, exp: u32) -> Option<u64> {
839-
(10 as u64)
840-
.checked_pow(exp)
841-
.and_then(|x| x.checked_mul(value))
836+
(10_u64).checked_pow(exp).and_then(|x| x.checked_mul(value))
842837
}
843838

844839
/// LRM 15.5 Abstract literals
@@ -864,7 +859,7 @@ fn parse_abstract_literal(
864859
Ok((
865860
AbstractLiteral,
866861
Value::AbstractLiteral(ast::AbstractLiteral::Real(
867-
real * (10.0 as f64).powi(exp),
862+
real * (10.0_f64).powi(exp),
868863
)),
869864
))
870865
}
@@ -911,7 +906,7 @@ fn parse_abstract_literal(
911906
if let Some(b'#') = reader.peek()? {
912907
reader.skip();
913908
let integer = base_result?;
914-
if base >= 2 && base <= 16 {
909+
if (2..=16).contains(&base) {
915910
Ok((
916911
AbstractLiteral,
917912
Value::AbstractLiteral(ast::AbstractLiteral::Integer(integer)),

vhdl_ls/src/vhdl_server.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,16 @@ impl<T: RpcChannel + Clone> InitializedVHDLServer<T> {
242242
files_with_notifications: FnvHashMap::default(),
243243
};
244244

245-
let mut capabilities = ServerCapabilities::default();
246-
capabilities.text_document_sync = Some(TextDocumentSyncCapability::Kind(
247-
TextDocumentSyncKind::Incremental,
248-
));
249-
capabilities.declaration_provider = Some(true);
250-
capabilities.definition_provider = Some(true);
251-
capabilities.references_provider = Some(true);
245+
let capabilities = ServerCapabilities {
246+
text_document_sync: Some(TextDocumentSyncCapability::Kind(
247+
TextDocumentSyncKind::Incremental,
248+
)),
249+
declaration_provider: Some(true),
250+
definition_provider: Some(true),
251+
references_provider: Some(true),
252+
..Default::default()
253+
};
254+
252255
let result = InitializeResult {
253256
capabilities,
254257
server_info: None,

0 commit comments

Comments
 (0)