profile
viewpoint
Jarred Allen JarredAllen Claremont, CA https://jarredallen.github.io/ Computer Science major at Harvey Mudd College

JarredAllen/AP-Computer-Science-A-Project 1

This is the project that I made for the AP CS A with some help from group members.

AaronShah2/SGDA_Game_Jam_Proj 0

Project for the 2020 SGDA Game Jam.

JarredAllen/AutomatedGradesChecker 0

A program that will automatically check aeries for you and notify you when your grades are changed. Made as part of a group project for IB Computer Science SL.

JarredAllen/Calculator-Web-Server 0

A small project for summer 2017 internship

JarredAllen/chess-website 0

A simple webpage for playing chess

JarredAllen/crafting-interpreters-mycode 0

Backups of my code from following Crafting Interpreters https://craftinginterpreters.com

JarredAllen/ctf-writeups 0

A repository of write-ups I've written to CTF competitions.

JarredAllen/ctf_crypto_utils 0

A collection of utilities for solving cryptography problems in CTF competitions

push eventJarredAllen/multiagent

JarredAllen

commit sha beaf8fcdc1d2c69b07741fbdd000924dcf27a994

Minor fix so it actually works

view details

JarredAllen

commit sha e8ba39bda05c20e8b10b70c0ab8ea180e7f11a89

Change tic-tac-toe example to use the new expectimax function

view details

push time in 12 days

push eventJarredAllen/multiagent

JarredAllen

commit sha 43891230bb869965e529c8ba5a5a12d8d80602a7

Add expectimax algorithm

view details

push time in 12 days

issue commentrust-lang/rust-clippy

Suggest Option::ok_or{,_else}

There are some lints which have been deprecated and whose deprecation notices say that they were replaced by a new lint (into_iter_on_array, invalid_ref, and unused_label). All of those were deprecated because their functionality got moved into rustc lints, but I see no reason why we couldn't do the same thing but mention a different lint within clippy, instead. It would cause a bit of work for people who allowed one of the original lints being replaced (they'd have to change the allow statement manually), but I think that should be minimal because there's not really any reason to allow those lints in the first place.

That's a good point that we might want to extend it beyond just the specifics that standard_library_reimplementation captures. Perhaps it could be better to just take the original name and flip it to the antonym, for something like verbose_alternative (or maybe a different antonym to concise than that one. I'm not 100% on the word "verbose", but vocabulary isn't my forte).

JarredAllen

comment created time in 14 days

push eventJarredAllen/multiagent

JarredAllen

commit sha bca08f43228c9180ff151b33b6f4ce74875dcacb

Format existing code

view details

JarredAllen

commit sha 3cf0baa061ad66ad278f248d0c42da508af1f442

Add tic-tac-toe example

view details

push time in 15 days

push eventJarredAllen/multiagent

JarredAllen

commit sha 382057dfa0c6d350b23fa18d75a56bd71516510c

I think I finished minimax

view details

push time in 15 days

push eventJarredAllen/multiagent

JarredAllen

commit sha 9a6a23191c48da313c8d77c452a975acf38edfb0

Layout structure

view details

push time in 16 days

create barnchJarredAllen/multiagent

branch : master

created branch time in 16 days

created repositoryJarredAllen/multiagent

Implement multiagent algorithms in Rust

created time in 16 days

issue commentrust-lang/rust-clippy

Suggest Option::ok_or{,_else}

I think it might make more sense to make a lint to capture cases where a method that exists in the standard library is being reimplemented, and then call it standard_library_reimplementation or something like that, since all of the proposed cases to lint are the programmer writing out some function which already exists.

It is also worth pointing out that there already are several lints that handle cases of this (including map_unwrap_or, match_as_ref, ok_expect, filter_map) currently in clippy, which could be made a part of this lint if we do generalize it to be more broad.

JarredAllen

comment created time in a month

push eventjennyyyyzhen/in-class-2

JarredAllen

commit sha 893f2c647e43e5da8fd002b86e2f76dd9ea43a96

Add comment

view details

JarredAllen

commit sha 174b78cdb240c63af86ca3e60959c75d8105648f

Merge branch 'lab1' into lab2

view details

push time in a month

push eventjennyyyyzhen/in-class-2

JarredAllen

commit sha 33984a31f9481b4f086b06b08528ee5a12ea7f7e

New change

view details

JarredAllen

commit sha 893f2c647e43e5da8fd002b86e2f76dd9ea43a96

Add comment

view details

Jarred Allen

commit sha ed719b6df5d059efd4e923fb31ad37221418c744

Merge pull request #1 from jennyyyyzhen/lab1 New change

view details

push time in a month

PR merged jennyyyyzhen/in-class-2

New change
+2 -1

0 comment

1 changed file

JarredAllen

pr closed time in a month

push eventjennyyyyzhen/in-class-2

JarredAllen

commit sha 893f2c647e43e5da8fd002b86e2f76dd9ea43a96

Add comment

view details

push time in a month

create barnchjennyyyyzhen/in-class-2

branch : lab2

created branch time in a month

PR opened jennyyyyzhen/in-class-2

Reviewers
New change
+1 -1

0 comment

1 changed file

pr created time in a month

create barnchjennyyyyzhen/in-class-2

branch : lab1

created branch time in a month

PublicEvent

push eventJarredAllen/crafting-interpreters-mycode

Jarred Allen

commit sha 3f01499f481f7b60bc86d16dbd6c68729f13025d

Create README.md

view details

push time in a month

issue openedrust-lang/rust-clippy

Suggest Option::ok_or{,_else}

What it does

This lint should suggest calling Option::ok_or or Option::ok_or_else when this functionality is reimplemented using the Option::map_or or Option::map_or_else functions, respectively.

Categories (optional)

  • Kind: clippy::complexity

Makes it clearer that this is converting from an Option to a Result, and produces shorter code.

Drawbacks

None.

Example

optional.map_or(
    Err(0),
    |x| Ok(x),
)

Could be written as:

optional.ok_or(0)

created time in a month

Pull request review commentrust-itertools/itertools

Create counts method and tests for it

 fn tree_fold1() {         assert_eq!(actual, expected);     } }++#[test]+fn counts() {+    let a: [usize; 0] = [];+    assert_eq!(0, a.iter().counts().len());+    let b = [1, 1, 1, 2, 2, 3];+    let b_counts = b.iter().counts();+    assert_eq!(3, b_counts.len());+    assert_eq!(Some(&3), b_counts.get(&1));+    assert_eq!(Some(&2), b_counts.get(&2));+    assert_eq!(Some(&1), b_counts.get(&3));+    assert_eq!(None, b_counts.get(&4));+}

Yes, it would, and I've now included that. Thanks for the suggestion.

JarredAllen

comment created time in a month

push eventJarredAllen/itertools

JarredAllen

commit sha 1d05c2bb00d2bd118850baa227022ccb95d26f1b

Change test to quickcheck

view details

push time in a month

push eventJarredAllen/grq-map

Jarred Allen

commit sha fce4ebebab05fe7d8404b7be84099dbd22528205

Add Apache-2.0 license to repo

view details

push time in a month

push eventJarredAllen/grq-map

Jarred Allen

commit sha fc285e803e436ddf0311c93d3d244ea22b0a104d

Add MIT license to repo

view details

push time in a month

create barnchJarredAllen/grq-map

branch : master

created branch time in a month

created repositoryJarredAllen/grq-map

A rust data structure to map ranges on generic types to arbitrary values

created time in a month

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 4e28d99f413572087a74e1a70b17f051a08d3821

Replace panics with early returns

view details

push time in a month

PR opened rust-lang/rust-clippy

Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T>

Changelog: Fixes #5722

+15 -4

0 comment

3 changed files

pr created time in a month

push eventJarredAllen/rust-clippy

Philippe Nadon

commit sha 2d1515a2c532b0cceec4a14da6f21e48fdca2da5

Miri: Renamed "undef" to "uninit" Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - src/librustc_codegen_llvm/consts.rs - src/librustc_middle/mir/interpret/ - src/librustc_middle/ty/print/pretty.rs - src/librustc_mir/ - src/tools/clippy/clippy_lints/src/consts.rs Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193

view details

Ryan Wiedemann

commit sha 3e3e50bf0fa6282c7265e34589170033c2301edd

Add example of false positive to PTR_ARG docs. Fixes #214

view details

Ryan Wiedemann

commit sha fbf637d12c95528846bfa65ce67bd652f2affb43

formatting

view details

Yuki Okushi

commit sha 91aa55d891e029831e2eceb662184afc8d2e0415

Rollup merge of #75226 - pnadon:miri-undef-uninit, r=RalfJung Miri: Renamed "undef" to "uninit" Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - `src/librustc_codegen_llvm/consts.rs` - `src/librustc_middle/mir/interpret/` - `src/librustc_middle/ty/print/pretty.rs` - `src/librustc_mir/` - `src/tools/clippy/clippy_lints/src/consts.rs` Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193

view details

Matthias Krüger

commit sha c0a9d64818d7076b72fd6c3a9e6172eca659034b

stable-sort-primitive: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha ac194cafc124276d4614bf023ca7ea6e9be9c6ed

map_clone: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 04867e004ebc0f2edf66d0a457e785848451f13a

mutex-atomic: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 6af297f80e59050c87078f1ba6f05c97d6f90fd7

iter-next-slice: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha f171f89aed11043e459c3baab305e7f859debb94

int_plus_one: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha bdf4dc3abd9a49f699d9de209a1f4d55ce770191

implicit-saturating-sub: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 1f17c3b02bce95c7c95a320e9e6e8e88b216d235

multiple_inherent_impl: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 423615693ba27f77f2e01a82948bbe592f48f6d0

pub-enum-variant-names: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 2de290d5c5e1d2f0c0f112a51f0cba2e0cb91636

duration-subsec: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha db390f5e6a2e68a0f9e0d235f2b734e907cafef9

enum-clike-unportable-variant: tweak message a bit (Clike -> C-like)

view details

Matthias Krüger

commit sha 89591a78b83df30830bcc8f6fe57f6fe1fbf918e

enum-variant-names: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha 605e027fda4420669784864940abcbabef5b0efe

if_let_some_result: make lint adhere to lint message convention

view details

Matthias Krüger

commit sha be3e695b60b07e911a88f6cb660c5617836c5365

if_not_else: make lint adhere to lint message convention

view details

flip1995

commit sha 027780ca2cd54dc9619058e9082c62f268f5c362

Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup

view details

bors

commit sha fdc2f879f14a5dc59d63e9683ed48c608b3ebac0

Auto merge of #75405 - flip1995:clippyup, r=Manishearth Update Clippy Biweekly Clippy update (2 days late, since I wanted to wait for https://github.com/rust-lang/rust/pull/75098) r? @Manishearth

view details

Ryan Wiedemann

commit sha 7d2e42daec1a56ad8f70a2b146bd842e98e0430d

fix typo pointed out in review comment Co-authored-by: Philipp Krones <hello@philkrones.com>

view details

push time in a month

PR opened rust-itertools/itertools

Create counts method and tests for it

Creates the function described in #467 (I went with the name counts).

It currently uses for_each and makes a HashMap manually because the PR for the into_grouping_map function is still being worked on, but this function could easily be changed to call it once that PR is merged, if desired.

+37 -0

0 comment

2 changed files

pr created time in 2 months

create barnchJarredAllen/itertools

branch : counts

created branch time in 2 months

fork JarredAllen/itertools

Extra iterator adaptors, iterator methods, free functions, and macros.

https://docs.rs/itertools/

fork in 2 months

create barnchJarredAllen/rust-clippy

branch : rc-box-suggestion

created branch time in 2 months

issue commentrust-lang/rust-clippy

Clippy suggest `Rc<Box<T>>` -> `Box<T>`

I can implement this.

mahkoh

comment created time in 2 months

issue commentrust-lang/rust-clippy

Prefer unstable sort on primitives

I believe this can be closed since my PR was merged (not sure why github didn't do this automatically).

camsteffen

comment created time in 2 months

issue commentrust-itertools/itertools

New function: Count number of occurences of each item in an iterator

That other idea would be similar in complexity, so long as the documentation makes it clear that this method can be used (I'm not sure if I'd personally be able to figure out from the documentation in the PR that those methods are what I want to use to count distinct things in an iterator, if it had been already merged and I was staring at the documentation).

Although, I'm not sure that approach would be any better for people's uses. I can't think of any use cases where you'd want into_grouping_map_by(|x| x) (or whatever name we end up giving it) except for immediately calling count on it. Assuming the item type implements Eq in such a way that distinct items compare as unequal, anything you pass into the accumulate function would be equivalent to calling count and then mapping the resulting counts in some way (and I can't think of such a way to map it that makes sense).

JarredAllen

comment created time in 2 months

issue commentrust-itertools/itertools

New function: Count number of occurences of each item in an iterator

I'd say that your inability to figure out how to use the GroupingMap to implement this functionality is evidence that a method should exist to just do this in the Itertools trait. If you, a contributor to this project, can't figure out how to correctly implement the solution (or even which method to call), then I fail to see how regular users of the API could be expected to figure it out for themselves.

It would be easy enough to write this count_each function to be a thin wrapper around the functionality implemented in the GroupingMap, so that it reuses the other one and there's no code duplication.

JarredAllen

comment created time in 2 months

issue commentrust-itertools/itertools

New function: Count number of occurences of each item in an iterator

I fail to see how into_grouping_map is applicable here. I want something like the following behavior:

let values = [0, 0, 0, 1, 1, 2];
let counts = values.into_iter().count_each();
assert_eq!(3, counts[0]);
assert_eq!(2, counts[1]);
assert_eq!(1, counts[2]);

The into_grouping_map function can't be called here, because the items of the iterator aren't (K, V) tuples.

JarredAllen

comment created time in 2 months

issue openedrust-itertools/itertools

New function: Count number of occurences of each item in an iterator

It'd be nice if there could be a function in the Itertools trait which counts the number of times each element appears in the iterator and returns a HashMap of that information (maybe named count_each? I'm not too sure on the name).

I recently had to do this in code that I was writing and was surprised that I couldn't find this functionality in here. I could add this myself pretty easily, if this is wanted (not sure how that process works as I'm new to this project), as I've just written it in my own code.

created time in 2 months

push eventJarredAllen/jarredallen.github.io

dependabot[bot]

commit sha 62107e3cdb29c1f4a881c92f5013164ce2f7e60d

Bump kramdown from 2.2.1 to 2.3.0 Bumps [kramdown](https://github.com/gettalong/kramdown) from 2.2.1 to 2.3.0. - [Release notes](https://github.com/gettalong/kramdown/releases) - [Changelog](https://github.com/gettalong/kramdown/blob/master/doc/news.page) - [Commits](https://github.com/gettalong/kramdown/commits) Signed-off-by: dependabot[bot] <support@github.com>

view details

push time in 2 months

PR merged JarredAllen/jarredallen.github.io

Bump kramdown from 2.2.1 to 2.3.0 dependencies

Bumps kramdown from 2.2.1 to 2.3.0. <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/gettalong/kramdown/commits">compare view</a></li> </ul> </details> <br />

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the Security Alerts page.

</details>

+1 -1

0 comment

1 changed file

dependabot[bot]

pr closed time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 542740c2eceff2369b2ac44e891a37313dd1785c

Run cargo dev fmt

view details

push time in 2 months

pull request commentrust-lang/rust-clippy

Stable sort primitive

@flip1995 The only changed caused by running cargo dev fmt is replacing some multiple-line \\ comments with multiple-line /* comments, which it was explicitly suggested that I do the opposite of. Should I go back to the way cargo dev fmt suggests?

JarredAllen

comment created time in 2 months

Pull request review commentrust-lang/rust-clippy

Stable sort primitive

+use crate::utils::{span_lint_and_sugg, sugg::Sugg};++use if_chain::if_chain;++use rustc_errors::Applicability;+use rustc_hir::{Expr, ExprKind};+use rustc_lint::{LateContext, LateLintPass};+use rustc_middle::ty::{self, Ty};+use rustc_session::{declare_lint_pass, declare_tool_lint};++declare_clippy_lint! {+    /// **What it does:**+    /// When sorting primitive values (integers, bools, chars, as well+    /// as arrays, slices, and tuples of such items), it is better to+    /// use an unstable sort than a stable sort.+    ///+    /// **Why is this bad?**+    /// Using a stable sort consumes more memory and cpu cycles. Because+    /// values which compare equal are identical, preserving their+    /// relative order (the guarantee that a stable sort provides) means+    /// nothing, while the extra costs still apply.+    ///+    /// **Known problems:**+    /// None+    ///+    /// **Example:**+    ///+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort();+    /// ```+    /// Use instead:+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort_unstable();+    /// ```+    pub STABLE_SORT_PRIMITIVE,+    perf,+    "use of sort() when sort_unstable() is equivalent"+}++declare_lint_pass!(StableSortPrimitive => [STABLE_SORT_PRIMITIVE]);++/// The three "kinds" of sorts+enum SortingKind {+    Vanilla,+    /* The other kinds of lint are currently commented out because they

For some reason, cargo dev fmt seems to insist on changing those comments to be multiline ones.

JarredAllen

comment created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 25abd7ae76e2a708dda5487119c20af3be64edb7

Create stable_sort_primitive lint

view details

push time in 2 months

pull request commentrust-lang/rust-clippy

needless_collect: catch x: Vec<_> = iter.collect(); x.into_iter() ...

@phansch I think I've added those suggestions.

JarredAllen

comment created time in 2 months

push eventJarredAllen/rust-clippy

ThibsG

commit sha 442c8ae23b90874485468b3becfc011f8c9d40bb

Fix FP for `suspicious_arithmetic_impl` from `suspicious_trait_impl` lint

view details

Yuki Okushi

commit sha 142a273441d1cf2039bd2857ee57cfa402e2a3f7

Use `(std::)f64::EPSILON` in the examples as suggested in the lints

view details

flip1995

commit sha 51f2a6f8b6eea9ebefddff39e87a1ca16c59827c

Add documentation for basic Clippy hacking

view details

Philipp Krones

commit sha bdc01c882e5f212c9a8a0384aef1b670122a4337

Update Usage section of README.md

view details

bors

commit sha b4e4fa51ea328adf5b182d3820dca9286d5ef3bf

Auto merge of #5832 - rust-lang:update_usage_instr, r=Manishearth Update Usage section of README.md Fixes #5826 changelog: none

view details

bors

commit sha 79f948ec0a507f8dc663508ce013104847fcc9f3

Auto merge of #5829 - JohnTitor:epsilon, r=flip1995 Use `(std::)f64::EPSILON` in the examples as suggested in the lints `float_cmp(_const)` suggests using `{f32|f64}::EPSILON` and it'd be great if the docs mentioned it. changelog: none

view details

flip1995

commit sha 17903f6d7107c6d31ee15f4c46af29d1f4aa363f

Mention lint naming guidelines earlier

view details

flip1995

commit sha 3a4cc9f7f085e73fbfe57e8c896b90a5fe61c4f4

Address review comments

view details

Dmitry Murzin

commit sha b375f1dd20bf07175ec06d13e1e9dc8b20287cd3

Add suggestion for `iter_skip_next` lint

view details

Takayuki Nakata

commit sha c81bbd05b95ae03da9af4e7e25e3784edd039465

Fix FP `useless_conversion` Fix #5833.

view details

bors

commit sha da5a6fb1b65ec6581a67e942a3850f6bc15a552c

Auto merge of #5845 - giraffate:fix_fp_useless_conversion, r=yaahc Fix FP `useless_conversion` Fix #5833. changelog: none

view details

flip1995

commit sha d164ab65f706540f0132268c8ad2237d2e53e08a

Merge commit 'da5a6fb1b65ec6581a67e942a3850f6bc15a552c' into clippyup

view details

bors

commit sha f5d429cd762423901f946abd800dc2cd91366ccf

Auto merge of #5820 - ThibsG:FixSuspiciousArithmeticImpl, r=flip1995 Fix FP for `suspicious_arithmetic_impl` from `suspicious_trait_impl` … As discussed in #3215, the `suspicious_trait_impl` lint causes too many false positives, as it is complex to find out if binary operations are suspicious or not. This PR restricts the number of binary operations to at most one, otherwise we don't lint. This can be seen as very conservative, but at least FP can be reduced to bare minimum. Fixes: #3215 changelog: limit the `suspicious_arithmetic_impl` lint to one binop, to avoid many FPs

view details

Takayuki Nakata

commit sha 3a9ccffed8c5329e3fda67c2e310086ba261e15f

`chmod` 644 `clippy_lints/src/utils/ast_utils.rs`

view details

bors

commit sha d3e9db71c940e6a4575555a2b600ccb8a540facb

Auto merge of #5850 - giraffate:chmod_utils_ats_utils, r=flip1995 Small fix: `chmod` 644 `clippy_lints/src/utils/ast_utils.rs` changelog: none It looks like `clippy_lints/src/utils/ast_utils.rs` doesn't have to be an executable file.

view details

Bastian Kauschke

commit sha dfa1af20598da8eaeab979e3f38ad2c2cd80f719

clippy

view details

Bastian Kauschke

commit sha 88787083f43edc49cfa9c9e6191372fbad323791

this might be unqualified, but at least it's now quantified

view details

Bastian Kauschke

commit sha 6ce37fab95ddd9ac8716ae96dc2f86251a8c4a61

introduce PredicateAtom

view details

Bastian Kauschke

commit sha 133e1d677333fe683a75fac6d6344e7073fb96af

clippy

view details

flip1995

commit sha 04f44717614cdd5afd4cb0d47fe694a8f0ae1e2b

Merge remote-tracking branch 'upstream/master' into rustup

view details

push time in 2 months

Pull request review commentrust-lang/rust-clippy

Stable sort primitive

+// run-rustfix+#![warn(clippy::stable_sort_primitive)]++fn main() {+    // positive examples+    let mut vec = vec![1, 3, 2];+    vec.sort_unstable();+    let mut vec = vec![false, false, true];

@krishna-veerareddy I added test cases for a list of tuples and also for one of arrays.

JarredAllen

comment created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 1892a57be625225c0dd7377249b53775837459ca

Add test for sorting slices/tuples of primitives

view details

push time in 2 months

push eventJarredAllen/rust-clippy

Nicholas Nethercote

commit sha 62db617e401487f7b4b5d2d19591b16c7339d131

Avoid storing `SymbolStr` in a struct. It's intended only for very temporary use.

view details

JarredAllen

commit sha 70a41a92815a79c88dd9a2e8aa02503a3b95eae8

Enable detecting multiple-argument panics

view details

JarredAllen

commit sha 07867fde592babd74ee9934726c4c7010dee149b

Clean up dogfood fallout

view details

Matthias Krüger

commit sha 3618b97f59d9696c3e5ef83948269d0d7abfdc5b

fix typos (found by codespell)

view details

bors

commit sha 82c8f25efa57269160e29e4e1582312b2c8fe8df

Auto merge of #5810 - matthiaskrgr:typos_2, r=Manishearth fix typos (found by codespell) changelog: none

view details

bors

commit sha 57678c8315e339308fb0d1b205aaa413cd120e15

Auto merge of #5811 - JarredAllen:panic_multiple_args, r=phansch Panic multiple args changelog: Fixes bug with `panic` lint reported in #5767. I also did the same changes to the lints for `todo`, `unimplemented` and `unreachable`, so those lints should now also detect calls to those macros with a message.

view details

Valentin Lazureanu

commit sha 5a20489c5ca0951827cbb1b4d72ddfdfd393713a

Rename TypeckTables to TypeckResults.

view details

Takayuki Nakata

commit sha e5105e82d31b254a81f38fbf38a8043ba41bee3a

Fix typo

view details

bors

commit sha 1367f25fbf3e152aac66c88616258500b69b030f

Auto merge of #5814 - giraffate:fix_typo, r=flip1995 Fix typo changelog: none

view details

JarredAllen

commit sha 7c5d4a41459abeb40eea734efaf08657602815cb

Add test for correct behavior

view details

JarredAllen

commit sha e85b590936863e88da4ccd73af9f5da0787b9609

Fix bug in lint

view details

flip1995

commit sha 3d3a13d8719893972e2146cde86672151e7d5476

Fix sync fallout (fmt)

view details

bors

commit sha 9a945c741375740d89c3c2029f3a46adeb7e510f

Auto merge of #5817 - flip1995:rustup, r=flip1995 Rustup r? @ghost Preparation for emergency Clippyup to fix an ICE #5816 changelog: none

view details

flip1995

commit sha 0f501ac1db5152fac4712e0357fc498aed6f7313

Merge remote-tracking branch 'upstream/master' into rustup

view details

bors

commit sha 799eef691969c2f6ecf33359f0b1e1691a060648

Auto merge of #5818 - flip1995:rustup, r=flip1995 Rename TypeckTables to TypeckResults. r? @ghost changelog: none

view details

bors

commit sha 8cf4219c1673533eb5caf304237bffaa8e847067

Auto merge of #5815 - JarredAllen:redundant_pattern_bugfix, r=flip1995 Redundant pattern bugfix changelog: Fixes the bug reported #5766

view details

ThibsG

commit sha 442c8ae23b90874485468b3becfc011f8c9d40bb

Fix FP for `suspicious_arithmetic_impl` from `suspicious_trait_impl` lint

view details

Tim Nielens

commit sha c720d823e1e633cccfd24e1df76cc04a628e83b0

redundant_closure_call - don't lint when used more than once

view details

Tim Nielens

commit sha 0fecaf1abcbe8d4ba1a9c532b69aab6fab3097c8

redundant_closure_call - extract lint from misc_early.rs, adapt to LatePass

view details

Tim Nielens

commit sha 9603d9652b9d172842c77f566121437768bc962f

redundant_closure_call - add support for shadowed closures

view details

push time in 2 months

Pull request review commentrust-lang/rust-clippy

Stable sort primitive

+// run-rustfix+#![warn(clippy::stable_sort_primitive)]++fn main() {+    // positive examples+    let mut vec = vec![1, 3, 2];+    vec.sort_unstable();+    let mut vec = vec![false, false, true];

I believe Vec derefs to a slice, so I think the tests already have that last bit covered, unless I don't understand what you're getting at.

JarredAllen

comment created time in 2 months

issue commentrust-lang/rust-clippy

.min(x).max(y) with x < y

The two options are equivalent, behavior-wise, except when working with floats if NaN is passed in (calling either function on NaN returns the argument, so the first parameter will be the result in that case). It might be better to keep the arguments and swap the functions, in case the code was written with which value NaN becomes in mind, though I don't know if that's a common enough occurrence to worry about. I've never written or seen code which clamps a float which might be NaN and cares about what value it becomes, but I wouldn't be surprised if it exists.

JarredAllen

comment created time in 2 months

push eventJarredAllen/stipulate.rs

JarredAllen

commit sha 81cdac6da65868d9fb7d88b2c1e723d1ce8cc465

Match cargo fmt

view details

push time in 2 months

push eventJarredAllen/stipulate.rs

JarredAllen

commit sha e45d94cb749d9a11118320243799b88d0138eb25

Enable csv output to file

view details

push time in 2 months

push eventJarredAllen/stipulate.rs

JarredAllen

commit sha 32c7e3fdce13273f2b37a1db6900814db62bc6ce

Misc. changes (sorry for bad commit message)

view details

push time in 2 months

issue openedrust-lang/rust-clippy

.min(x).max(y) with x < y

What it does

Lints against people using min and max methods (on the float types or on Ord) to constrain a value to a range, but getting the arguments to min and max backwards (such that the argument to min is less than the argument to max). In that case, instead of clamping the value to be between the two arguments (likely what was intended), it will always return the argument of the second function called.

Categories (optional)

  • Kind: correctness

Drawbacks

None. If someone wanted the result of the expression this lint triggers on (which is unlikely), they could just include the returned value directly.

Example

Given a floating-point variable x:

x.min(-1.0).max(1.0)

will always give the value 1.0, whereas

x.max(-1.0).min(1.0)

will give the value of x, clamped between -1.0 and 1.0, with 1.0 for NaN.

created time in 2 months

issue openedrust-lang/rust-clippy

while_let_on_iterator causes compile error

<!-- Thank you for filing a bug report! 🐛 Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. -->

With this code:

let nums = vec![1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
let mut iter = nums.iter().peekable();
while iter.peek().is_some() {
    while let Some(&next_elem) = iter.next() {
        if next_elem == 2 {
            break;
        }
    }
}

I expected to see this happen: No suggestion or a suggestion which doesn't cause a compile error

Instead, this happened: Clippy makes this suggestion which causes a compile error:

let nums = vec![1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
let mut iter = nums.iter().peekable();
while iter.peek().is_some() {
    for &next_elem in iter {
        if next_elem == 2 {
            break;
        }
    }
}

which leads to the following compilation error

error[E0382]: borrow of moved value: `iter`
  --> src/main.rs:16:11
   |
15 |     let mut iter = nums.iter().peekable();
   |         -------- move occurs because `iter` has type `std::iter::Peekable<std::slice::Iter<'_, i32>>`, which does not implement the `Copy` trait
16 |     while iter.peek().is_some() {
   |           ^^^^ value borrowed here after move
17 |         for &next_elem in iter {
   |                           ----
   |                           |
   |                           value moved here, in previous iteration of loop
   |                           help: consider borrowing to avoid moving into the for loop: `&iter`

error: aborting due to previous err

Following that suggestion by borrowing there doesn't fix the issue, as it then suggests you remove the borrow due to &iter not being an iterable.

However, borrowing mutably (adding &mut) results in code which compiles and passes clippy. It would be nice if clippy could have this &mut in the original suggestion (though I don't know enough about the borrow checker to know how easy that would be to implement).

Here it is on the playground

Meta

  • cargo clippy -V: clippy 0.0.212 (5c1f21c 2020-07-13)
  • rustc -Vv:

rustc 1.45.0 (5c1f21c3b 2020-07-13) binary: rustc commit-hash: 5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2 commit-date: 2020-07-13 host: x86_64-unknown-linux-gnu release: 1.45.0 LLVM version: 10.0

created time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha bfb07777e94e28505358d4dd839323e85dd3d822

Add documentation to code

view details

push time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha 8455c10327d997febd42e5aa5ca186b128b5d5fe

Change consensus plots to use the closed form for the tail

view details

push time in 2 months

PR opened rust-lang/rust-clippy

WIP needless_collect: catch x: Vec<_> = iter.collect(); x.into_iter() ...

changelog: Expand the needless_collect lint as suggested in #5627 (WIP).

This PR is WIP because I can't figure out how to make the multi-part suggestion include its changes in the source code (the fixed is identical to the source, despite the lint making suggestions). Aside from that one issue, I think this should be good.

+261 -6

0 comment

4 changed files

pr created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha f6a1603d577cab9e1d15980b5b95a2f5a550c285

Fix a bug causing it to be too trigger-happy

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 3760de70effdaa94e01c8f600c64b60d0d7d1024

Fix formatting and dogfood fallout

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha af221cabebbf3a61864f3f1bfd9afc2ceb2c6285

Check for other things which can be used indirectly

view details

JarredAllen

commit sha de7766f17b29162e0f77c56431f74853bff4d051

Split indirect collects into their own test case

view details

push time in 2 months

pull request commentrust-lang/rust-clippy

Stable sort primitive

@phansch Is the review still coming?

JarredAllen

comment created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 4c33d06874cfe5721528815174a18bcd5a1b74ee

Write the lint and write tests

view details

push time in 2 months

push eventJarredAllen/rust-clippy

David Wood

commit sha b7c8b96e668a1e3c84cf559de1426c6eebd7d1c1

trait_sel: only test predicates w/ no substs This commit modifies the `substitute_normalize_and_test_predicates` query, renaming it to `impossible_predicates` and only checking predicates which do not require substs. By making this change, polymorphization doesn't have to explicitly support vtables. Signed-off-by: David Wood <david@davidtw.co>

view details

bors

commit sha 8c83d5f484950d86630f467d32efcd585de2d775

Auto merge of #5830 - flip1995:rustup, r=flip1995 trait_sel: only test predicates w/ no substs r? @ghost changelog: none

view details

JarredAllen

commit sha b6d5c727dbc3f06ff13f399bcc6369f89f55a598

Create test for wanted behavior

view details

push time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha d42c6b0ac4e9f7fcc51ef5f5f774fe01650ffed3

Last round of paper revisions

view details

push time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha 5ae032df8828fca4722c9dd83ee750aa389a6294

Next revisions for paper

view details

push time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha 536fbb357ed771260ef07a5e82a14fdf537e3212

Changes for newest revision of the paper

view details

push time in 2 months

issue commentrust-lang/rust-clippy

clippy redundant pattern matching suggestion not compiling

I believe this issue can be closed, as it has been fixed.

BenjaminRi

comment created time in 2 months

push eventJarredAllen/rust-clippy

Nicholas Nethercote

commit sha 62db617e401487f7b4b5d2d19591b16c7339d131

Avoid storing `SymbolStr` in a struct. It's intended only for very temporary use.

view details

Valentin Lazureanu

commit sha 5a20489c5ca0951827cbb1b4d72ddfdfd393713a

Rename TypeckTables to TypeckResults.

view details

JarredAllen

commit sha 7c5d4a41459abeb40eea734efaf08657602815cb

Add test for correct behavior

view details

JarredAllen

commit sha e85b590936863e88da4ccd73af9f5da0787b9609

Fix bug in lint

view details

flip1995

commit sha 3d3a13d8719893972e2146cde86672151e7d5476

Fix sync fallout (fmt)

view details

bors

commit sha 9a945c741375740d89c3c2029f3a46adeb7e510f

Auto merge of #5817 - flip1995:rustup, r=flip1995 Rustup r? @ghost Preparation for emergency Clippyup to fix an ICE #5816 changelog: none

view details

flip1995

commit sha 0f501ac1db5152fac4712e0357fc498aed6f7313

Merge remote-tracking branch 'upstream/master' into rustup

view details

bors

commit sha 799eef691969c2f6ecf33359f0b1e1691a060648

Auto merge of #5818 - flip1995:rustup, r=flip1995 Rename TypeckTables to TypeckResults. r? @ghost changelog: none

view details

bors

commit sha 8cf4219c1673533eb5caf304237bffaa8e847067

Auto merge of #5815 - JarredAllen:redundant_pattern_bugfix, r=flip1995 Redundant pattern bugfix changelog: Fixes the bug reported #5766

view details

Tim Nielens

commit sha c720d823e1e633cccfd24e1df76cc04a628e83b0

redundant_closure_call - don't lint when used more than once

view details

Tim Nielens

commit sha 0fecaf1abcbe8d4ba1a9c532b69aab6fab3097c8

redundant_closure_call - extract lint from misc_early.rs, adapt to LatePass

view details

Tim Nielens

commit sha 9603d9652b9d172842c77f566121437768bc962f

redundant_closure_call - add support for shadowed closures

view details

Tim Nielens

commit sha 1ac8b85c9fd38ff0a14061cae0b4d31e9bfafd56

redundant_closure_call - pr review

view details

bors

commit sha 942e0e6facd0944843441a4b8e004902487b6cb7

Auto merge of #5800 - montrivo:bugfix/redundant_closure, r=matthiaskrgr redundant_closure_call - don't lint when used more than once Fixes #3354. changelog: fix redundant_closure_call false positive when closure called more than once

view details

Tomasz Miąsko

commit sha a5cdd4aeb11fad6b0bf73d342398700a27c4484b

Ignore not really redundant clones of ManuallyDrop "Redundant" clones of `ManuallyDrop` are sometimes used for the side effect of invoking the clone, without running the drop implementation of the inner type. In other words, they aren't really redundant. For example, futures-rs crate: ```rust #[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. unsafe fn increase_refcount<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); // Now increase refcount, but don't drop new refcount either let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); } ``` Ignore redundant clone lint for ManuallyDrop.

view details

bors

commit sha 61e3d8a55c760a543659d270940c25c8180dc637

Auto merge of #5824 - tmiasko:manually-drop-clone, r=Manishearth Ignore not really redundant clones of ManuallyDrop "Redundant" clones of `ManuallyDrop` are sometimes used for the side effect of invoking the clone, without running the drop implementation of the inner type. In other words, they aren't really redundant. For example, futures-rs crate: ```rust #[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. unsafe fn increase_refcount<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); // Now increase refcount, but don't drop new refcount either let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); } ``` changelog: Ignore redundant clone lint for ManuallyDrop.

view details

JarredAllen

commit sha 8c8992116a31cd06505d0662cadea175847846ff

Begin progress on lint

view details

push time in 2 months

push eventJarredAllen/rust-clippy

Nicholas Nethercote

commit sha 62db617e401487f7b4b5d2d19591b16c7339d131

Avoid storing `SymbolStr` in a struct. It's intended only for very temporary use.

view details

flip1995

commit sha 3d3a13d8719893972e2146cde86672151e7d5476

Fix sync fallout (fmt)

view details

bors

commit sha 9a945c741375740d89c3c2029f3a46adeb7e510f

Auto merge of #5817 - flip1995:rustup, r=flip1995 Rustup r? @ghost Preparation for emergency Clippyup to fix an ICE #5816 changelog: none

view details

push time in 2 months

push eventJarredAllen/rust-clippy

push time in 2 months

create barnchJarredAllen/rust-clippy

branch : needless_collect

created branch time in 2 months

push eventJarredAllen/rust-clippy

Jane Lusby

commit sha 7c479fd8a7af670b8ff55f6d1d5c0d5178e6c196

Start work on clippy-fix as subcommand

view details

Jane Lusby

commit sha df2d3c82df7ed70de7aa0d8db642b4f454228c4d

check for unstable options

view details

Jane Lusby

commit sha 399e0231cd599e20b43ccb62c4ab2c55a730ded3

boycott manish

view details

Jane Lusby

commit sha e190cc5590c0ed6d4691cd83550de744734a8137

fix rustfmt issue

view details

Jane Lusby

commit sha 680cc2f25848721eca3a2332c48b13c02e027dbc

dogfood tasted bad

view details

ThibsG

commit sha 380f7218b3876225e726617531d9f02d42da0e38

Add lint on large const arrays

view details

ThibsG

commit sha 629cc4ada3666865eb90f8425d7ea657710cdc74

Update doc generation script

view details

Michael Sproul

commit sha 23df4a0183e0d954d47db98824295411d50f742e

Disallow bit-shifting in `integer_arithmetic` lint With this change, the lint checks all operations that are defined as being capable of overflow in the Rust Reference.

view details

Philipp Hansch

commit sha 69c3e9c90f9a7731dcfe129b10e55e440ee6f484

large_enum_variant: Report sizes of variants This reports the sizes of the largest and second-largest variants.

view details

Marcin Serwin

commit sha d3ebd06ec93cbc5a9cf47f7ced6e69704758db5e

Make the single char threshold strict inequality

view details

Marcin Serwin

commit sha 512f23fff1c8261ce537578b519f0c313f0ba174

Add test for zero single char names

view details

Tom Milligan

commit sha b2d986850d795f8aa3bdea1d2c840b080c9df81c

Working basic dereference clip

view details

ThibsG

commit sha 6b4ab827469529f4eda5f1e9492abcb9ad9d209a

Global rework + fix imports

view details

ThibsG

commit sha c1132434a7cf580a09d08a274bbfd2e776b324f8

Report using stmts and expr + tests

view details

ThibsG

commit sha b6d43305502f15d3c3e1a49f488eedc5ce330b4f

Check for Deref trait impl + add fixed version

view details

ThibsG

commit sha 72b9ae2a10b13a209f09c5ace0a7b9763b740e62

Use only check_expr with parent expr and precedence

view details

ThibsG

commit sha 3c2bbcf00e3b97ab1fb03665b4afc7b7df0cd25e

Better precedence case management + more tests

view details

Jane Lusby

commit sha 0441525690640ff374313fa5651a97829b0ea85a

Merge remote-tracking branch 'upstream/master' into clippy-fix

view details

Marcin Serwin

commit sha ce372c17cd705c9537e07662d5b2ccdbc41741b3

Change default many single char names threshold

view details

Jane Lusby

commit sha 216371d42412192ebee5bb94106b40d5ad77fc70

split it up for testing but the merge broke tests

view details

push time in 2 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha 501b5dde392cdf0370f1979a4dd4c948bf994885

Use proper LaTeX for theta in Figure 1

view details

push time in 2 months

PR opened rust-lang/rust-clippy

Redundant pattern bugfix

changelog: Fixes the bug reported #5766

+54 -34

0 comment

4 changed files

pr created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha e85b590936863e88da4ccd73af9f5da0787b9609

Fix bug in lint

view details

push time in 2 months

create barnchJarredAllen/rust-clippy

branch : redundant_pattern_bugfix

created branch time in 2 months

issue commentrust-lang/rust-clippy

Panic lint doesn't catch panics with formatting

I believe this can be closed, as my PR resolved it.

paulkernfeld

comment created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 408e26c9fb1cef6c5a5b49a952ea29cb9f7c8161

Run cargo fmt

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha cb03fffccaf17fbb23db37fe2c12f64b8ed48f10

Change lint to detect anything which coerces to a slice

view details

push time in 2 months

Pull request review commentrust-lang/rust-clippy

Stable sort primitive

+use crate::utils::{self, span_lint_and_sugg, sugg::Sugg};++use if_chain::if_chain;++use rustc_errors::Applicability;+use rustc_hir::{Expr, ExprKind};+use rustc_lint::{LateContext, LateLintPass};+use rustc_middle::ty::{self, Ty};+use rustc_session::{declare_lint_pass, declare_tool_lint};++declare_clippy_lint! {+    /// **What it does:**+    /// When sorting primitive values (integers, bools, chars, as well+    /// as arrays, slices, and tuples of such items), it is better to+    /// use an unstable sort than a stable sort.+    ///+    /// **Why is this bad?**+    /// Using a stable sort consumes more memory and cpu cycles. Because+    /// values which compare equal are identical, preserving their+    /// relative order (the guarantee that a stable sort provides) means+    /// nothing, while the extra costs still apply.+    ///+    /// **Known problems:**+    /// This lint only activates if the item being sorted is a `Vec`,+    /// and array, or a slice of primitive values. There may be other+    /// types which implemenet Deref to a slice of primitives, and calls+    /// to a sorting function on such types will not be detected.+    ///+    /// **Example:**+    ///+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort();+    /// ```+    /// Use instead:+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort_unstable();+    /// ```+    pub STABLE_SORT_PRIMITIVE,+    perf,+    "use of sort() when sort_unstable() is equivalent"+}++declare_lint_pass!(StableSortPrimitive => [STABLE_SORT_PRIMITIVE]);++/// The three "kinds" of sorts+enum SortingKind {+    Vanilla,+    /* The other kinds of lint are currently commented out because they+     * can map distinct values to equal ones. If the key function is+     * provably one-to-one, or if the Cmp function conserves equality,+     * then they could be linted on, but I don't know if we can check+     * for that. */++    /* ByKey,+     * ByCmp, */+}+impl SortingKind {+    /// The name of the stable version of this kind of sort+    fn stable_name(&self) -> &str {+        match self {+            SortingKind::Vanilla => "sort",+            /* SortingKind::ByKey => "sort_by_key",+             * SortingKind::ByCmp => "sort_by", */+        }+    }+    /// The name of the unstable version of this kind of sort+    fn unstable_name(&self) -> &str {+        match self {+            SortingKind::Vanilla => "sort_unstable",+            /* SortingKind::ByKey => "sort_unstable_by_key",+             * SortingKind::ByCmp => "sort_unstable_by", */+        }+    }+    /// Takes the name of a function call and returns the kind of sort+    /// that corresponds to that function name (or None if it isn't)+    fn from_stable_name(name: &str) -> Option<SortingKind> {+        match name {+            "sort" => Some(SortingKind::Vanilla),+            // "sort_by" => Some(SortingKind::ByCmp),+            // "sort_by_key" => Some(SortingKind::ByKey),+            _ => None,+        }+    }+}++/// A detected instance of this lint+struct LintDetection {+    slice_name: String,+    method: SortingKind,+    method_args: String,+}++/// Returns true iff the given type is a primitive which we should lint+/// on.+fn is_primitive_type(ty: Ty<'_>) -> bool {+    match ty.kind {+        ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => true,+        ty::Array(inner_type, _) | ty::Slice(inner_type) => is_primitive_type(inner_type),+        ty::Tuple(inner_types) => inner_types.types().all(is_primitive_type),+        _ => false,+    }+}++/// Returns true iff the given expression is a slice of primitives or if+/// it is of some type that implements deref to such a slice+fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {+    let expr_type = cx.tables().expr_ty(expr);

Thanks for the suggestion. I tried to handle it that way, but I wasn't able to figure out how to do it.

JarredAllen

comment created time in 2 months

Pull request review commentrust-lang/rust-clippy

Stable sort primitive

+use crate::utils::{self, span_lint_and_sugg, sugg::Sugg};++use if_chain::if_chain;++use rustc_errors::Applicability;+use rustc_hir::{Expr, ExprKind};+use rustc_lint::{LateContext, LateLintPass};+use rustc_middle::ty::{self, Ty};+use rustc_session::{declare_lint_pass, declare_tool_lint};++declare_clippy_lint! {+    /// **What it does:**+    /// When sorting primitive values (integers, bools, chars, as well+    /// as arrays, slices, and tuples of such items), it is better to+    /// use an unstable sort than a stable sort.+    ///+    /// **Why is this bad?**+    /// Using a stable sort consumes more memory and cpu cycles. Because+    /// values which compare equal are identical, preserving their+    /// relative order (the guarantee that a stable sort provides) means+    /// nothing, while the extra costs still apply.+    ///+    /// **Known problems:**+    /// This lint only activates if the item being sorted is a `Vec`,+    /// and array, or a slice of primitive values. There may be other+    /// types which implemenet Deref to a slice of primitives, and calls+    /// to a sorting function on such types will not be detected.+    ///+    /// **Example:**+    ///+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort();+    /// ```+    /// Use instead:+    /// ```rust+    /// let mut vec = vec![2, 1, 3];+    /// vec.sort_unstable();+    /// ```+    pub STABLE_SORT_PRIMITIVE,+    perf,+    "use of sort() when sort_unstable() is equivalent"+}++declare_lint_pass!(StableSortPrimitive => [STABLE_SORT_PRIMITIVE]);++/// The three "kinds" of sorts+enum SortingKind {+    Vanilla,+    /* The other kinds of lint are currently commented out because they+     * can map distinct values to equal ones. If the key function is+     * provably one-to-one, or if the Cmp function conserves equality,+     * then they could be linted on, but I don't know if we can check+     * for that. */++    /* ByKey,+     * ByCmp, */+}+impl SortingKind {+    /// The name of the stable version of this kind of sort+    fn stable_name(&self) -> &str {+        match self {+            SortingKind::Vanilla => "sort",+            /* SortingKind::ByKey => "sort_by_key",+             * SortingKind::ByCmp => "sort_by", */+        }+    }+    /// The name of the unstable version of this kind of sort+    fn unstable_name(&self) -> &str {+        match self {+            SortingKind::Vanilla => "sort_unstable",+            /* SortingKind::ByKey => "sort_unstable_by_key",+             * SortingKind::ByCmp => "sort_unstable_by", */+        }+    }+    /// Takes the name of a function call and returns the kind of sort+    /// that corresponds to that function name (or None if it isn't)+    fn from_stable_name(name: &str) -> Option<SortingKind> {+        match name {+            "sort" => Some(SortingKind::Vanilla),+            // "sort_by" => Some(SortingKind::ByCmp),+            // "sort_by_key" => Some(SortingKind::ByKey),+            _ => None,+        }+    }+}++/// A detected instance of this lint+struct LintDetection {+    slice_name: String,+    method: SortingKind,+    method_args: String,+}++/// Returns true iff the given type is a primitive which we should lint+/// on.+fn is_primitive_type(ty: Ty<'_>) -> bool {+    match ty.kind {+        ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => true,+        ty::Array(inner_type, _) | ty::Slice(inner_type) => is_primitive_type(inner_type),+        ty::Tuple(inner_types) => inner_types.types().all(is_primitive_type),+        _ => false,+    }+}++/// Returns true iff the given expression is a slice of primitives or if+/// it is of some type that implements deref to such a slice+fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {+    let expr_type = cx.tables().expr_ty(expr);+    match expr_type.kind {+        ty::Slice(element_type) | ty::Array(element_type, _) => is_primitive_type(element_type),+        ty::Adt(_, substs_ref) => {+            if utils::match_type(cx, expr_type, &utils::paths::VEC) {+                // We could potentially check for other types which have the same sorting methods+                is_primitive_type(substs_ref.types().next().unwrap())+            } else {+                println!("is not a Vec");

Oops. That was for debugging and I forgot to remove it.

JarredAllen

comment created time in 2 months

issue commentrust-lang/rust-clippy

clippy redundant pattern matching suggestion not compiling

I can fix this.

BenjaminRi

comment created time in 2 months

PR opened rust-lang/rust-clippy

Panic multiple args

changelog: Fixes bug with panic lint reported in #5767. I also did the same changes to the lints for todo, unimplemented and unreachable, so those lints should now also detect calls to those macros with a message.

+69 -10

0 comment

3 changed files

pr created time in 2 months

create barnchJarredAllen/rust-clippy

branch : panic_multiple_args

created branch time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 71ab11ae011d3a10f47b5dec40b48e0daa27f32f

Re-run cargo dev update_lints

view details

push time in 2 months

issue commentrust-lang/rust-clippy

Panic lint doesn't catch panics with formatting

I should be able to fix this.

paulkernfeld

comment created time in 2 months

PR opened rust-lang/rust-clippy

Stable sort primitive

changelog: Implements #5762

+237 -16

0 comment

10 changed files

pr created time in 2 months

push eventJarredAllen/rust-clippy

flip1995

commit sha ef896faa0153d0d96b6d6eafe7dd53b178525a25

Fix deploy script for beta deployment Since the beta/ directory already exists, we can't copy the complete master dir

view details

flip1995

commit sha c65eb4d66314d22d85cf2e58ff20ec1ca7404751

Track tag files, before checking for the diff

view details

flip1995

commit sha cf383cf48aa1bc09c50ae7d3599254c82b7dc0bf

Update changelog to beta-1.46

view details

flip1995

commit sha aba0d244d419261f94b3d942953412e35c3e857e

Typo: Change Log -> Changelog

view details

bors

commit sha d9bf9f01fe796698d412b69a279c104fbc8852d7

Auto merge of #5806 - flip1995:deploy_beta_fix, r=phansch Fix deploy script for beta deployment Since the `beta/` directory already exists, we can't copy the complete `master` dir changelog: none

view details

bors

commit sha c2cb565a3e80732233298c1e910883728bdd9174

Auto merge of #5807 - flip1995:changelog, r=yaahc Changelog [Rendered](https://github.com/flip1995/rust-clippy/blob/changelog/CHANGELOG.md) changelog: none

view details

JarredAllen

commit sha 5a2a9e05304494263661c9d328ea8753da65fcee

Created new lint

view details

JarredAllen

commit sha e9ee068b45d8c66dc6a90490384c8b202d1ee921

Create initial lint code

view details

JarredAllen

commit sha b172574b0f58f75e264caea0bbb1d5d05da9612b

Create a few tests

view details

JarredAllen

commit sha e9577fa32370903c762feb7ffd535fa2b185c368

Ensure tests pass

view details

JarredAllen

commit sha e774387b1701bb33cebd6f43b4d3e67565743f7a

Automatically work for only slices of primitives

view details

JarredAllen

commit sha 9476bd41c6b5dfbc77717b8d0fd61bf4ccad111a

Finish detecting types in the lint

view details

JarredAllen

commit sha df0d24d7b479c9d77dce98161a789f237b072eaa

Fix fallout on unnecessary_sort_by test

view details

JarredAllen

commit sha c546c773fb27830ae2a3a02b92bfcf2b44f60a0b

Fix typo in doc test

view details

push time in 2 months

push eventJarredAllen/rust-clippy

flip1995

commit sha f7acea2683c6124854bfe20e7127e4dfba344d3e

Register redundant_field_names and non_expressive_names as early passes

view details

flip1995

commit sha 485229c4a3d6a2fbe40f5a6976a33144a27497c6

Fix fallout in redundant_field_names

view details

flip1995

commit sha efd3dcff97f67f376e354c047133ce9044c52991

Fix fallout in similar_names

view details

Eduardo Broto

commit sha bb37a0f948b02e6434dbe3ea615960052d37f784

Avoid triggering similar names on code from expansion

view details

Thiago Arrais

commit sha a6f1af75d71fcf8e029b78142370e7563798c503

Lint for x.powi(2) => x * x

view details

Thiago Arrais

commit sha f62798454c8a7f9f2c3e87e0a913b3bd79b6d2ed

Lint (x * x + y * y).sqrt() => x.hypot(y)

view details

robojumper

commit sha 2e8a1be444afc6a9b5137d3e7e4fdcfcb1f89e0d

new lint: match_like_matches_macro

view details

Thiago Arrais

commit sha 0c8afa39ce8b2e7f0f9be7fc33fe3993d9bc3c53

Lint x.log(b) / y.log(b) => x.log(y)

view details

robojumper

commit sha 1740dda76386aff7205b2a709a32c95e8cbc0d57

fix match_like_matches_macro in clippy

view details

Thiago Arrais

commit sha 076ec872ce122403f3c75f20c773c64b194a5891

Lint for to_radians and to_degrees

view details

Thiago Arrais

commit sha f5596826fa59035e6c57d8968df0d61f69c2537b

Better copy for lint message Since x.log(y) is actually implemented as x.ln() / y.ln()

view details

Thiago Arrais

commit sha db7bc6b3bd0e58c8fbf7507713a4214299f39c36

Place radian lints under suboptimal_flops

view details

Thiago Arrais

commit sha 6dc066fdb9103122cd918b1b38e26fa6edbc7e2e

Includes TODO comment for hypot lint

view details

Thiago Arrais

commit sha 6be9491eace540d341f3b8dbf775a10e25f6431a

Reclassify powi(2) lint under suboptimal_flops

view details

Thiago Arrais

commit sha 3065201eb3a0c4976de7ef5b5b924afde1b18325

Includes TODO for constants equivalent to π/180

view details

Takayuki Nakata

commit sha 5307cb5614e7498f069bb634ab293e176e63c67f

Add a lint for `.repeat(1)` fix #3028.

view details

robojumper

commit sha 37d75da266443dd4253ceedebd692ba77dd72e03

make match_like_matches_macro only apply to matches with a wildcard

view details

Eduardo Broto

commit sha db1c946aaa02e1192d271dbcfe4598d726806108

unnecessary_sort_by: avoid linting if key borrows

view details

Tim Nielens

commit sha dac19e3afccc63ff976bcf0a5ee385bdd0e075d5

single_match_else - single expr/stmt else block corner case

view details

bors

commit sha 45eea9a822a9e684b8a8a16c3f56d0212a4fcfcb

Auto merge of #5771 - montrivo:bugfix/single-match-else, r=matthiaskrgr single_match_else - single expr/stmt else block corner case One approach to fix #3489. See discussion in the issue. changelog: single_match_else - single expr/stmt else block corner case fix

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha fe1837b2c40b1a4e7e06100d4ecd5695e1a45e6c

Fix fallout on unnecessary_sort_by test

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha e8690b35b6b757d963acfe472eb36bc5491d19ff

Finish detecting types in the lint

view details

push time in 2 months

issue commentrust-lang/rust-clippy

Prefer unstable sort on primitives

So I've looked at it more, and I don't think that sort_by or sort_by_key can be included. It's possible for different values to become equal when using one of those functions, so the unstable sort could give different results than the stable sort (for example, given a vec of integer values, vec.sort_by_key(|a| a/2) vs. the unstable equivalent).

Also, floating-point values can't be sorted because they don't implement Ord (because NaN compares weirdly), so they have to be dropped from the list of primitive types to detect. Also, even if you get around that, positive and negative zero compare as equal but are distinct, so the stable and unstable sorts are different.

camsteffen

comment created time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 2cb2bcfade6d4138d627644ec9e0f8fe20ec1391

Automatically work for only slices of primitives

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 4a8ccdcc159f183799cdadbbefc225c220534a37

Ensure tests pass

view details

push time in 2 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 72d99711b8b56315300750ea1d1196a3a644173c

Create initial lint code

view details

JarredAllen

commit sha 03d46e89ecde87d138c06b6cc08cfce761d146bb

Create a few tests

view details

push time in 3 months

push eventJarredAllen/amistad-su20-scratch-code

JarredAllen

commit sha f665b907db922c2f6d9a14ebdd6e252b4de4af8b

A few tweaks to making plots

view details

push time in 3 months

push eventJarredAllen/rust-clippy

JarredAllen

commit sha 400c8662f556a8a18d39e5ccc2e43f14719e8e3f

Created new lint

view details

push time in 3 months

more