File tree Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -563,6 +563,17 @@ impl Module {
563
563
for diag in db. trait_data_with_diagnostics ( t. id ) . 1 . iter ( ) {
564
564
emit_def_diagnostic ( db, acc, diag) ;
565
565
}
566
+
567
+ for item in t. items ( db) {
568
+ let def: DefWithBody = match item {
569
+ AssocItem :: Function ( it) => it. into ( ) ,
570
+ AssocItem :: Const ( it) => it. into ( ) ,
571
+ AssocItem :: TypeAlias ( _) => continue ,
572
+ } ;
573
+
574
+ def. diagnostics ( db, acc) ;
575
+ }
576
+
566
577
acc. extend ( def. diagnostics ( db) )
567
578
}
568
579
ModuleDef :: Adt ( adt) => {
Original file line number Diff line number Diff line change @@ -388,22 +388,23 @@ mod F {
388
388
389
389
#[ test]
390
390
fn complex_ignore ( ) {
391
- // FIXME: this should trigger errors for the second case.
392
391
check_diagnostics (
393
392
r#"
394
393
trait T { fn a(); }
395
394
struct U {}
396
395
impl T for U {
397
396
fn a() {
398
- #[allow(non_snake_case)]
397
+ #[allow(non_snake_case, non_upper_case_globals )]
399
398
trait __BitFlagsOk {
400
399
const HiImAlsoBad: u8 = 2;
401
400
fn Dirty(&self) -> bool { false }
402
401
}
403
402
404
403
trait __BitFlagsBad {
405
404
const HiImAlsoBad: u8 = 2;
405
+ // ^^^^^^^^^^^ 💡 warn: Constant `HiImAlsoBad` should have UPPER_SNAKE_CASE name, e.g. `HI_IM_ALSO_BAD`
406
406
fn Dirty(&self) -> bool { false }
407
+ // ^^^^^💡 warn: Function `Dirty` should have snake_case name, e.g. `dirty`
407
408
}
408
409
}
409
410
}
@@ -463,14 +464,16 @@ extern {
463
464
464
465
#[ test]
465
466
fn incorrect_trait_and_assoc_item_names ( ) {
466
- // FIXME: Traits and functions in traits aren't currently checked by
467
- // r-a, even though rustc will complain about them.
468
467
check_diagnostics (
469
468
r#"
470
469
trait BAD_TRAIT {
471
470
// ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait`
471
+ const bad_const: u8;
472
+ // ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST`
472
473
fn BAD_FUNCTION();
474
+ // ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
473
475
fn BadFunction();
476
+ // ^^^^^^^^^^^ 💡 warn: Function `BadFunction` should have snake_case name, e.g. `bad_function`
474
477
}
475
478
"# ,
476
479
) ;
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ fn invalid_args_range(
103
103
104
104
#[ cfg( test) ]
105
105
mod tests {
106
- use crate :: tests:: check_diagnostics;
106
+ use crate :: tests:: { check_diagnostics, check_diagnostics_with_disabled } ;
107
107
108
108
#[ test]
109
109
fn simple_free_fn_zero ( ) {
@@ -197,7 +197,7 @@ fn f() {
197
197
fn method_unknown_receiver ( ) {
198
198
// note: this is incorrect code, so there might be errors on this in the
199
199
// future, but we shouldn't emit an argument count diagnostic here
200
- check_diagnostics (
200
+ check_diagnostics_with_disabled (
201
201
r#"
202
202
trait Foo { fn method(&self, arg: usize) {} }
203
203
@@ -206,6 +206,7 @@ fn f() {
206
206
x.method();
207
207
}
208
208
"# ,
209
+ std:: iter:: once ( "unused_variables" . to_string ( ) ) ,
209
210
) ;
210
211
}
211
212
Original file line number Diff line number Diff line change @@ -89,6 +89,16 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
89
89
check_diagnostics_with_config ( config, ra_fixture)
90
90
}
91
91
92
+ #[ track_caller]
93
+ pub ( crate ) fn check_diagnostics_with_disabled (
94
+ ra_fixture : & str ,
95
+ disabled : impl Iterator < Item = String > ,
96
+ ) {
97
+ let mut config = DiagnosticsConfig :: test_sample ( ) ;
98
+ config. disabled . extend ( disabled) ;
99
+ check_diagnostics_with_config ( config, ra_fixture)
100
+ }
101
+
92
102
#[ track_caller]
93
103
pub ( crate ) fn check_diagnostics_with_config ( config : DiagnosticsConfig , ra_fixture : & str ) {
94
104
let ( db, files) = RootDatabase :: with_many_files ( ra_fixture) ;
@@ -175,6 +185,7 @@ fn minicore_smoke_test() {
175
185
let mut config = DiagnosticsConfig :: test_sample ( ) ;
176
186
// This should be ignored since we conditionally remove code which creates single item use with braces
177
187
config. disabled . insert ( "unused_braces" . to_string ( ) ) ;
188
+ config. disabled . insert ( "unused_variables" . to_string ( ) ) ;
178
189
check_diagnostics_with_config ( config, & source) ;
179
190
}
180
191
You can’t perform that action at this time.
0 commit comments