Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New lint: uninformative_asserts #6258

Closed
wants to merge 3 commits into from

Conversation

HMPerson1
Copy link
Contributor

Fixes #6207

changelog: New lint: uninformative_asserts

@rust-highfive
Copy link

r? @llogiq

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 28, 2020
@llogiq
Copy link
Contributor

llogiq commented Oct 28, 2020

Test error appears to be unrelated, we may have to wait for a rustup & rebase. I'll have time to look at the code this evening.

@@ -352,6 +353,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {
store.register_pre_expansion_pass(|| box write::Write::default());
store.register_pre_expansion_pass(|| box attrs::EarlyAttributes);
store.register_pre_expansion_pass(|| box dbg_macro::DbgMacro);
store.register_pre_expansion_pass(|| box uninformative_asserts::UninformativeAsserts::default());
Copy link
Member

@ebroto ebroto Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just chiming in to say this because @llogiq may not be aware of it, but we try to avoid pre-expansion lints lately. If possible, this should target the expanded version.

See here and here for some background.

Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think this is a good PR, I only left a few nitpicky messages / suggestions. The big thing is obviously to rewrite this as a Post-Expansion pass as @ebroto mentioned.

Ping me if I can do anything to help.

}

fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) {
if item.attrs.iter().any(|attr| attr.has_name(sym!(test))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about #[cfg(test)]? I think we may want to check for that, too.

Perhaps that could be a fn is_test_related(&[Attribute]) -> bool helper function.

}

fn check_item_post(&mut self, _: &EarlyContext<'_>, item: &Item) {
if item.attrs.iter().any(|attr| attr.has_name(sym!(test))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this check is duplicated here, it should really be a helper.

"`assert!` called without custom panic message",
None,
"consider adding a custom panic message",
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may even want a suggestion like {macro}({args}, "<your panic message here>") (with suitable snippets for macro and args). This would help people if they haven't added a message before.

/// # let foo = 0u8;
/// # let a = 0u8;
/// # let b = 0u8;
/// assert!(some_condition(foo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should have a ///# #![allow(clippy::uninformative_assert)] line pretended. Otherwise clippy-checking the doctests would fail.

@bors
Copy link
Contributor

bors commented Oct 30, 2020

☔ The latest upstream changes (presumably #6197) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@Urcra
Copy link
Contributor

Urcra commented Nov 5, 2020

Just chiming in, but shouldn't this be a restriction lint instead of pedantic. Since it's pretty similar to unwrap_used. And most of the annoyances with uninformative assert messages should go away with RFC 2011

@llogiq
Copy link
Contributor

llogiq commented Nov 7, 2020

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@giraffate
Copy link
Contributor

ping from triage @llogiq. This seems to be still waiting for review. Could you have any update on this?

@HMPerson1
Copy link
Contributor Author

Been swamped with school work for the past few weeks, but I am still working on rewriting this.

@llogiq
Copy link
Contributor

llogiq commented Nov 27, 2020

@giraffate I already reviewed this. Waiting for changes to review again.

@giraffate
Copy link
Contributor

@llogiq oh, sorry for my wrong pinging.

@rustbot modify labels: -S-waiting-on-review +S-waiting-on-author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Nov 27, 2020
@giraffate
Copy link
Contributor

ping from triage @HMPerson1. Could you have any update on this?

@giraffate
Copy link
Contributor

ping from triage @HMPerson1. I'm closing this according to triage procedure, because this didn't have any update in 2 weeks from previous ping. If you have more time to continue working on this, feel free to reopen.

@giraffate giraffate closed this Jan 4, 2021
@giraffate giraffate added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jan 4, 2021
@blyxyas blyxyas removed the S-inactive-closed Status: Closed due to inactivity label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint assert! without message
9 participants