From 28b699c86a73a20591a4e39b40943017c6a8aba5 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sun, 22 Oct 2023 00:27:30 +0200 Subject: [PATCH] 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. --- crates/aiken-lang/src/tipo/environment.rs | 31 +++++++---------------- crates/aiken-lang/src/tipo/error.rs | 4 +-- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/crates/aiken-lang/src/tipo/environment.rs b/crates/aiken-lang/src/tipo/environment.rs index 954ebfdc..afc7da76 100644 --- a/crates/aiken-lang/src/tipo/environment.rs +++ b/crates/aiken-lang/src/tipo/environment.rs @@ -355,33 +355,20 @@ impl<'a> Environment<'a> { fn handle_unused(&mut self, unused: HashMap) { for (name, (kind, location, _)) in unused.into_iter().filter(|(_, (_, _, used))| !used) { let warning = match kind { - EntityKind::ImportedType | EntityKind::ImportedTypeAndConstructor => { - Warning::UnusedType { - name, - imported: true, - location, - } + EntityKind::ImportedType + | EntityKind::ImportedTypeAndConstructor + | EntityKind::ImportedConstructor + | EntityKind::ImportedValue => { + Warning::UnusedImportedValueOrType { name, location } } - EntityKind::ImportedConstructor => Warning::UnusedConstructor { - name, - imported: true, - location, - }, EntityKind::PrivateConstant => { Warning::UnusedPrivateModuleConstant { name, location } } - EntityKind::PrivateTypeConstructor(_) => Warning::UnusedConstructor { - name, - imported: false, - location, - }, + EntityKind::PrivateTypeConstructor(_) => { + Warning::UnusedConstructor { name, location } + } EntityKind::PrivateFunction => Warning::UnusedPrivateFunction { name, location }, - EntityKind::PrivateType => Warning::UnusedType { - name, - imported: false, - location, - }, - EntityKind::ImportedValue => Warning::UnusedImportedValue { name, location }, + EntityKind::PrivateType => Warning::UnusedType { name, location }, EntityKind::Variable => Warning::UnusedVariable { name, location }, }; diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index 2ce8b768..7a2c9341 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -1437,7 +1437,6 @@ pub enum Warning { UnusedConstructor { #[label] location: Span, - imported: bool, 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." ))] #[diagnostic(code("unused:import::value"))] - UnusedImportedValue { + UnusedImportedValueOrType { #[label] location: Span, name: String, @@ -1509,7 +1508,6 @@ pub enum Warning { UnusedType { #[label] location: Span, - imported: bool, name: String, },