diff --git a/.rustfmt.toml b/.rustfmt.toml
index 422da2bea..536703e6b 100644
--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -9,7 +9,6 @@ format_code_in_doc_comments = false
comment_width = 80
normalize_comments = true # changed
normalize_doc_attributes = false
-license_template_path = "FILE_HEADER" # changed
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
@@ -57,8 +56,6 @@ skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
-report_todo = "Always"
-report_fixme = "Always"
ignore = []
# Below are `rustfmt` internal settings
diff --git a/ink_linting/.rustfmt.toml b/ink_linting/.rustfmt.toml
deleted file mode 100644
index 8ebf443f8..000000000
--- a/ink_linting/.rustfmt.toml
+++ /dev/null
@@ -1,3 +0,0 @@
-license_template_path = "../FILE_HEADER" # changed
-report_todo = "Always"
-report_fixme = "Always"
diff --git a/ink_linting/src/lib.rs b/ink_linting/src/lib.rs
index cc92523e0..97ec87e7f 100644
--- a/ink_linting/src/lib.rs
+++ b/ink_linting/src/lib.rs
@@ -30,7 +30,10 @@ mod mapping_initialized;
#[doc(hidden)]
#[no_mangle]
-pub fn register_lints(_sess: &rustc_session::Session, lint_store: &mut rustc_lint::LintStore) {
+pub fn register_lints(
+ _sess: &rustc_session::Session,
+ lint_store: &mut rustc_lint::LintStore,
+) {
lint_store.register_lints(&[mapping_initialized::MAPPING_INITIALIZED]);
lint_store.register_late_pass(|| Box::new(mapping_initialized::MappingInitialized));
}
diff --git a/ink_linting/src/mapping_initialized.rs b/ink_linting/src/mapping_initialized.rs
index dfcfbe164..92e9ceaf8 100644
--- a/ink_linting/src/mapping_initialized.rs
+++ b/ink_linting/src/mapping_initialized.rs
@@ -14,20 +14,44 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see .
-use clippy_utils::{diagnostics::span_lint_and_then, source::snippet_opt};
+use clippy_utils::{
+ diagnostics::span_lint_and_then,
+ source::snippet_opt,
+};
use if_chain::if_chain;
use regex::Regex;
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_hir::{
def_id::DefId,
- intravisit::{walk_fn, walk_item, walk_qpath, FnKind, Visitor},
- BodyId, FnDecl, HirId, Item, ItemKind, QPath, VariantData,
+ intravisit::{
+ walk_fn,
+ walk_item,
+ walk_qpath,
+ FnKind,
+ Visitor,
+ },
+ BodyId,
+ FnDecl,
+ HirId,
+ Item,
+ ItemKind,
+ QPath,
+ VariantData,
+};
+use rustc_lint::{
+ LateContext,
+ LateLintPass,
};
-use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
-use rustc_session::{declare_lint, declare_lint_pass};
-use rustc_span::{source_map::Span, symbol::sym};
+use rustc_session::{
+ declare_lint,
+ declare_lint_pass,
+};
+use rustc_span::{
+ source_map::Span,
+ symbol::sym,
+};
declare_lint! {
/// **What it does:** Checks for ink! contracts that use
@@ -122,12 +146,12 @@ impl<'tcx> LateLintPass<'tcx> for MappingInitialized {
let attrs = cx.tcx.hir().attrs(item.hir_id());
let ink_attrs = get_ink_attribute(attrs);
if ink_attrs.is_none() {
- return;
+ return
}
if let ItemKind::Struct(variant_data, _) = &item.kind {
if let VariantData::Unit(..) = variant_data {
- return;
+ return
}
check_struct(cx, item, variant_data);
}
@@ -155,14 +179,14 @@ fn check_struct<'a>(cx: &LateContext<'a>, item: &'a Item, data: &VariantData) {
.expect("failed creating regex");
if re.is_match(&format!("{:?}", field.ty.kind)) {
marker = Some(field);
- return true;
+ return true
}
false
});
if !storage_contains_mapping {
log::debug!("Found `#[ink(storage)]` struct without `Mapping`");
- return;
+ return
}
log::debug!("Found `#[ink(storage)]` struct with `Mapping`");
@@ -256,7 +280,7 @@ impl<'tcx> Visitor<'tcx> for InkAttributeVisitor<'_, 'tcx> {
// We can return immediately if an incorrect constructor was already found
if let Some(constructor) = &self.constructor_info {
if !constructor.uses_initialize_contract {
- return;
+ return
}
}
@@ -269,9 +293,11 @@ impl<'tcx> Visitor<'tcx> for InkAttributeVisitor<'_, 'tcx> {
self.ink_attribute = get_ink_attribute(&attrs);
if self.ink_attribute == Some(InkAttribute::Storage) {
- return;
+ return
} else if self.ink_attribute == Some(InkAttribute::Constructor) {
- log::debug!("Found constructor, starting to search for `initialize_contract`");
+ log::debug!(
+ "Found constructor, starting to search for `initialize_contract`"
+ );
let mut visitor = InitializeContractVisitor {
cx: self.cx,
uses_initialize_contract: false,
@@ -287,7 +313,7 @@ impl<'tcx> Visitor<'tcx> for InkAttributeVisitor<'_, 'tcx> {
span,
});
- return;
+ return
}
walk_fn(self, kind, decl, body_id, span, id);
@@ -317,17 +343,18 @@ impl<'tcx> Visitor<'tcx> for InitializeContractVisitor<'_, 'tcx> {
fn visit_qpath(&mut self, qpath: &'tcx QPath<'_>, id: HirId, span: Span) {
log::debug!("Visiting path {:?}", qpath);
if self.uses_initialize_contract {
- return;
+ return
}
if let QPath::Resolved(_, path) = qpath {
log::debug!("QPath: {:?}", path.res);
- let re =
- Regex::new(r"ink_lang\[.*\]::codegen::dispatch::execution::initialize_contract")
- .expect("failed creating regex");
+ let re = Regex::new(
+ r"ink_lang\[.*\]::codegen::dispatch::execution::initialize_contract",
+ )
+ .expect("failed creating regex");
if re.is_match(&format!("{:?}", path.res)) {
self.uses_initialize_contract = true;
- return;
+ return
}
}
diff --git a/ink_linting/ui/fail/mapping-nested-initialize-call.rs b/ink_linting/ui/fail/mapping-nested-initialize-call.rs
index a8064b724..b9086a65a 100644
--- a/ink_linting/ui/fail/mapping-nested-initialize-call.rs
+++ b/ink_linting/ui/fail/mapping-nested-initialize-call.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/fail/mapping-nested-initialize-call.stderr b/ink_linting/ui/fail/mapping-nested-initialize-call.stderr
index 2bce8d28d..fc9b47bb2 100644
--- a/ink_linting/ui/fail/mapping-nested-initialize-call.stderr
+++ b/ink_linting/ui/fail/mapping-nested-initialize-call.stderr
@@ -1,5 +1,5 @@
error: `#[ink(storage)]` on `MyContract` contains `ink_storage::Mapping` without initializing it in the contract constructor.
- --> $DIR/mapping-nested-initialize-call.rs:26:5
+ --> $DIR/mapping-nested-initialize-call.rs:29:5
|
LL | / #[derive(SpreadAllocate)]
LL | | pub struct MyContract {
@@ -9,7 +9,7 @@ LL | | }
|
= note: `#[deny(mapping_initialized)]` on by default
help: this field uses `ink_storage::Mapping`
- --> $DIR/mapping-nested-initialize-call.rs:28:9
+ --> $DIR/mapping-nested-initialize-call.rs:31:9
|
LL | balances: Mapping,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/ink_linting/ui/fail/mapping-one-constructor.rs b/ink_linting/ui/fail/mapping-one-constructor.rs
index 18fbe1b78..8c6081995 100644
--- a/ink_linting/ui/fail/mapping-one-constructor.rs
+++ b/ink_linting/ui/fail/mapping-one-constructor.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/fail/mapping-one-constructor.stderr b/ink_linting/ui/fail/mapping-one-constructor.stderr
index c8f71934a..b78ff9ffe 100644
--- a/ink_linting/ui/fail/mapping-one-constructor.stderr
+++ b/ink_linting/ui/fail/mapping-one-constructor.stderr
@@ -1,5 +1,5 @@
error: `#[ink(storage)]` on `MyContract` contains `ink_storage::Mapping` without initializing it in the contract constructor.
- --> $DIR/mapping-one-constructor.rs:26:5
+ --> $DIR/mapping-one-constructor.rs:29:5
|
LL | / #[derive(SpreadAllocate)]
LL | | pub struct MyContract {
@@ -9,7 +9,7 @@ LL | | }
|
= note: `#[deny(mapping_initialized)]` on by default
help: this field uses `ink_storage::Mapping`
- --> $DIR/mapping-one-constructor.rs:28:9
+ --> $DIR/mapping-one-constructor.rs:31:9
|
LL | balances: Mapping,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/ink_linting/ui/fail/mapping-two-constructors-01.rs b/ink_linting/ui/fail/mapping-two-constructors-01.rs
index 645ce9a50..4c2e426bf 100644
--- a/ink_linting/ui/fail/mapping-two-constructors-01.rs
+++ b/ink_linting/ui/fail/mapping-two-constructors-01.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/fail/mapping-two-constructors-01.stderr b/ink_linting/ui/fail/mapping-two-constructors-01.stderr
index 013f92b92..2c291635c 100644
--- a/ink_linting/ui/fail/mapping-two-constructors-01.stderr
+++ b/ink_linting/ui/fail/mapping-two-constructors-01.stderr
@@ -1,5 +1,5 @@
error: `#[ink(storage)]` on `MyContract` contains `ink_storage::Mapping` without initializing it in the contract constructor.
- --> $DIR/mapping-two-constructors-01.rs:26:5
+ --> $DIR/mapping-two-constructors-01.rs:29:5
|
LL | / #[derive(SpreadAllocate)]
LL | | pub struct MyContract {
@@ -9,7 +9,7 @@ LL | | }
|
= note: `#[deny(mapping_initialized)]` on by default
help: this field uses `ink_storage::Mapping`
- --> $DIR/mapping-two-constructors-01.rs:28:9
+ --> $DIR/mapping-two-constructors-01.rs:31:9
|
LL | balances: Mapping,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/ink_linting/ui/fail/mapping-two-constructors-02.rs b/ink_linting/ui/fail/mapping-two-constructors-02.rs
index 253ac1a5b..a92f4952b 100644
--- a/ink_linting/ui/fail/mapping-two-constructors-02.rs
+++ b/ink_linting/ui/fail/mapping-two-constructors-02.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/fail/mapping-two-constructors-02.stderr b/ink_linting/ui/fail/mapping-two-constructors-02.stderr
index 0f2d582e3..8d0916f98 100644
--- a/ink_linting/ui/fail/mapping-two-constructors-02.stderr
+++ b/ink_linting/ui/fail/mapping-two-constructors-02.stderr
@@ -1,5 +1,5 @@
error: `#[ink(storage)]` on `MyContract` contains `ink_storage::Mapping` without initializing it in the contract constructor.
- --> $DIR/mapping-two-constructors-02.rs:26:5
+ --> $DIR/mapping-two-constructors-02.rs:29:5
|
LL | / #[derive(SpreadAllocate)]
LL | | pub struct MyContract {
@@ -9,7 +9,7 @@ LL | | }
|
= note: `#[deny(mapping_initialized)]` on by default
help: this field uses `ink_storage::Mapping`
- --> $DIR/mapping-two-constructors-02.rs:28:9
+ --> $DIR/mapping-two-constructors-02.rs:31:9
|
LL | balances: Mapping,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/ink_linting/ui/pass/mapping-additional-logic-constructor.rs b/ink_linting/ui/pass/mapping-additional-logic-constructor.rs
index 964d8a91c..d57864527 100644
--- a/ink_linting/ui/pass/mapping-additional-logic-constructor.rs
+++ b/ink_linting/ui/pass/mapping-additional-logic-constructor.rs
@@ -22,7 +22,10 @@ use ink_lang as ink;
mod my_contract {
/// The `Mapping` must be recognized, even if it is imported
/// under a different name.
- use ink_storage::{traits::SpreadAllocate, Mapping as SomeOtherName};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping as SomeOtherName,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/pass/mapping-dont-use-fully-qualified-path.rs b/ink_linting/ui/pass/mapping-dont-use-fully-qualified-path.rs
index c56c189d2..c1245dc52 100644
--- a/ink_linting/ui/pass/mapping-dont-use-fully-qualified-path.rs
+++ b/ink_linting/ui/pass/mapping-dont-use-fully-qualified-path.rs
@@ -21,7 +21,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
use ink_lang::utils::initialize_contract as foo;
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/pass/mapping-one-constructor.rs b/ink_linting/ui/pass/mapping-one-constructor.rs
index 48544660d..382238b43 100644
--- a/ink_linting/ui/pass/mapping-one-constructor.rs
+++ b/ink_linting/ui/pass/mapping-one-constructor.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]
diff --git a/ink_linting/ui/pass/mapping-two-constructors.rs b/ink_linting/ui/pass/mapping-two-constructors.rs
index f16cddfa2..4ee1dbe40 100644
--- a/ink_linting/ui/pass/mapping-two-constructors.rs
+++ b/ink_linting/ui/pass/mapping-two-constructors.rs
@@ -20,7 +20,10 @@ use ink_lang as ink;
#[ink::contract]
mod my_contract {
- use ink_storage::{traits::SpreadAllocate, Mapping};
+ use ink_storage::{
+ traits::SpreadAllocate,
+ Mapping,
+ };
#[ink(storage)]
#[derive(SpreadAllocate)]