Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c00652c
feat(linter): strict balance equality lint
jubnzv Sep 5, 2023
422eff5
feat(lint): Handle temporary values resulted after Rvalue::Use
jubnzv Sep 8, 2023
c0c2b80
fix(lint): spans to emit diagnostics
jubnzv Sep 11, 2023
4de5d35
feat(tests): more tests
jubnzv Sep 11, 2023
e679c6f
feat(lint): Manually traverse functions in user-defined code
jubnzv Sep 12, 2023
0d2953f
feat(lint): interprocedural analysis that finds tainted returns
jubnzv Sep 13, 2023
20c34c5
fix(lint): recursive calls in interprocedural analysis
jubnzv Sep 13, 2023
233ddfa
fix(lint): false negative on `CheckedBinaryOp`
jubnzv Sep 13, 2023
1cfe0e4
feat(lint): propagation through references
jubnzv Sep 14, 2023
6512927
feat(lint): Propagate tainted values through `&mut` arguments
jubnzv Sep 15, 2023
7725462
chore(lint): docstring, comments
jubnzv Sep 15, 2023
c8434d4
feat(lint): handle comparison of references in functions
jubnzv Sep 15, 2023
62a5a35
chore(tests): comments
jubnzv Sep 15, 2023
0f99906
feat(lint+tests): updated `pass` test, fixed binop conditions
jubnzv Sep 15, 2023
3e8bde3
feat(tests): test for lint suppressions
jubnzv Sep 15, 2023
0e7bfee
Merge remote-tracking branch 'origin/master' into 1811-balance-condition
jubnzv Sep 15, 2023
46238bb
chore(tests): fmt
jubnzv Sep 15, 2023
0be39dd
chore(tests): fmt
jubnzv Sep 15, 2023
e202891
chore: Add changelog entry
jubnzv Sep 17, 2023
fc4a143
Merge remote-tracking branch 'origin/master' into 1811-balance-condition
jubnzv Oct 5, 2023
96d84e0
chore(lint): Reuse utility functions introduced in #1932
jubnzv Oct 5, 2023
5b5054a
chore: Fix changelog
jubnzv Oct 5, 2023
09f8f9b
Merge remote-tracking branch 'origin/master' into 1811-balance-condition
jubnzv Oct 25, 2023
fd358b8
chore: Fix comments
jubnzv Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Linter: `storage_never_freed` lint - [#1932](https://github.com/paritytech/ink/pull/1932)
- Linter: `strict_balance_equality` lint - [#1914](https://github.com/paritytech/ink/pull/1914)

## Version 5.0.0-alpha

Expand Down
6 changes: 6 additions & 0 deletions linting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ path = "ui/pass/storage_never_freed.rs"
[[example]]
name = "storage_never_freed_fail"
path = "ui/fail/storage_never_freed.rs"
[[example]]
name = "strict_balance_equality_pass"
path = "ui/pass/strict_balance_equality.rs"
[[example]]
name = "strict_balance_equality_fail"
path = "ui/fail/strict_balance_equality.rs"

[package.metadata.rust-analyzer]
rustc_private = true
Expand Down
6 changes: 1 addition & 5 deletions linting/src/ink_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use clippy_utils::match_def_path;
use if_chain::if_chain;
use rustc_hir::{
Expand Down Expand Up @@ -51,7 +52,6 @@ pub(crate) fn find_storage_struct(
.copied()
}

// TODO: Extracted from #1914; reuse this in #1914 when it is merged
/// Returns `ItemId`s defined inside the code block of `const _: () = {}`.
///
/// The Rust code expanded after ink! code generation used these to define different
Expand All @@ -77,7 +77,6 @@ fn items_in_unnamed_const(cx: &LateContext<'_>, id: &ItemId) -> Vec<ItemId> {
}
}

// TODO: Extracted from #1914; reuse this in #1914 when it is merged
/// Collect all the `ItemId`s in nested `const _: () = {}`
pub(crate) fn expand_unnamed_consts(
cx: &LateContext<'_>,
Expand All @@ -90,7 +89,6 @@ pub(crate) fn expand_unnamed_consts(
})
}

// TODO: Extracted from #1914; reuse this in #1914 when it is merged
/// Finds type of the struct that implements a contract with user-defined code
fn find_contract_ty_hir<'tcx>(
cx: &LateContext<'tcx>,
Expand All @@ -114,7 +112,6 @@ fn find_contract_ty_hir<'tcx>(
.copied()
}

// TODO: Extracted from #1914; reuse this in #1914 when it is merged
/// Compares types of two user-defined structs
fn eq_hir_struct_tys(lhs: &Ty<'_>, rhs: &Ty<'_>) -> bool {
match (lhs.kind, rhs.kind) {
Expand All @@ -126,7 +123,6 @@ fn eq_hir_struct_tys(lhs: &Ty<'_>, rhs: &Ty<'_>) -> bool {
}
}

// TODO: Extracted from #1914; reuse this in #1914 when it is merged
/// Finds an ID of the implementation of the contract struct containing user-defined code
pub(crate) fn find_contract_impl_id(
cx: &LateContext<'_>,
Expand Down
7 changes: 7 additions & 0 deletions linting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
html_favicon_url = "https://use.ink/crate-docs/favicon.png"
)]
#![feature(rustc_private)]
#![feature(box_patterns)]

dylint_linting::dylint_library!();

extern crate rustc_ast;
extern crate rustc_errors;
extern crate rustc_hir;
extern crate rustc_index;
extern crate rustc_lint;
extern crate rustc_middle;
extern crate rustc_mir_dataflow;
extern crate rustc_session;
extern crate rustc_span;

mod ink_utils;
mod primitive_topic;
mod storage_never_freed;
mod strict_balance_equality;

#[doc(hidden)]
#[no_mangle]
Expand All @@ -41,9 +45,12 @@ pub fn register_lints(
lint_store.register_lints(&[
primitive_topic::PRIMITIVE_TOPIC,
storage_never_freed::STORAGE_NEVER_FREED,
strict_balance_equality::STRICT_BALANCE_EQUALITY,
]);
lint_store.register_late_pass(|_| Box::new(primitive_topic::PrimitiveTopic));
lint_store.register_late_pass(|_| Box::new(storage_never_freed::StorageNeverFreed));
lint_store
.register_late_pass(|_| Box::new(strict_balance_equality::StrictBalanceEquality));
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions linting/src/primitive_topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use clippy_utils::{
diagnostics::span_lint_and_then,
is_lint_allowed,
Expand Down
1 change: 1 addition & 0 deletions linting/src/storage_never_freed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::ink_utils::{
expand_unnamed_consts,
find_contract_impl_id,
Expand Down
Loading