Merge unused imported constructors and unused imported type with unused imported value

This was somewhat weirdly done, with a boolean 'imported' set on the
  formers; but an explicit new warning for values. I don't see the point
  of distinguishing them so I just merged them all into a single
  warning.

  I have however preserved the 'UnusedType' and 'UnusedConstructor'
  warnings since they were ALSO used for unused private constructors or
  types.
This commit is contained in:
KtorZ 2023-10-22 00:27:30 +02:00
parent 5f8e256050
commit 28b699c86a
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 10 additions and 25 deletions

View File

@ -355,33 +355,20 @@ impl<'a> Environment<'a> {
fn handle_unused(&mut self, unused: HashMap<String, (EntityKind, Span, bool)>) { fn handle_unused(&mut self, unused: HashMap<String, (EntityKind, Span, bool)>) {
for (name, (kind, location, _)) in unused.into_iter().filter(|(_, (_, _, used))| !used) { for (name, (kind, location, _)) in unused.into_iter().filter(|(_, (_, _, used))| !used) {
let warning = match kind { let warning = match kind {
EntityKind::ImportedType | EntityKind::ImportedTypeAndConstructor => { EntityKind::ImportedType
Warning::UnusedType { | EntityKind::ImportedTypeAndConstructor
name, | EntityKind::ImportedConstructor
imported: true, | EntityKind::ImportedValue => {
location, Warning::UnusedImportedValueOrType { name, location }
} }
}
EntityKind::ImportedConstructor => Warning::UnusedConstructor {
name,
imported: true,
location,
},
EntityKind::PrivateConstant => { EntityKind::PrivateConstant => {
Warning::UnusedPrivateModuleConstant { name, location } Warning::UnusedPrivateModuleConstant { name, location }
} }
EntityKind::PrivateTypeConstructor(_) => Warning::UnusedConstructor { EntityKind::PrivateTypeConstructor(_) => {
name, Warning::UnusedConstructor { name, location }
imported: false, }
location,
},
EntityKind::PrivateFunction => Warning::UnusedPrivateFunction { name, location }, EntityKind::PrivateFunction => Warning::UnusedPrivateFunction { name, location },
EntityKind::PrivateType => Warning::UnusedType { EntityKind::PrivateType => Warning::UnusedType { name, location },
name,
imported: false,
location,
},
EntityKind::ImportedValue => Warning::UnusedImportedValue { name, location },
EntityKind::Variable => Warning::UnusedVariable { name, location }, EntityKind::Variable => Warning::UnusedVariable { name, location },
}; };

View File

@ -1437,7 +1437,6 @@ pub enum Warning {
UnusedConstructor { UnusedConstructor {
#[label] #[label]
location: Span, location: Span,
imported: bool,
name: String, name: String,
}, },
@ -1463,7 +1462,7 @@ pub enum Warning {
"No big deal, but you might want to remove it to get rid of that warning." "No big deal, but you might want to remove it to get rid of that warning."
))] ))]
#[diagnostic(code("unused:import::value"))] #[diagnostic(code("unused:import::value"))]
UnusedImportedValue { UnusedImportedValueOrType {
#[label] #[label]
location: Span, location: Span,
name: String, name: String,
@ -1509,7 +1508,6 @@ pub enum Warning {
UnusedType { UnusedType {
#[label] #[label]
location: Span, location: Span,
imported: bool,
name: String, name: String,
}, },