Some lifetimes in function return types are not bound to concrete
content and can be set arbitrarily. Clippy should not propose to replace
them by the default `'_` lifetime if such a lifetime cannot be
determined unambigously.
close#13781
The `slow_vector_initialization` lint currently only suggests using the
`vec!` macro with size, but it does not suggest removing the `resize`
method call.
changelog: [`slow_vector_initialization`]: improve
`slow_vector_initialization` suggestion
In this case, the lint can be triggered as well as `is_empty()` will be
found on the target type.
One such case was found in Clippy sources (first commit)
changelog: [`len_zero`]: trigger if deref target implements `is_empty()`
Close#13861
Using `lifetime.ident.name` in suggestions will not output the raw
modifier. For example, `'r#struct` will be rendered as `'struct` which
would be incorrect.
Fix#13899
changelog: [`needless_arbitrary_self_type`]: use the raw lifetime name
in suggestions
Using `lifetime.ident.name` in suggestions will not output the raw
modifier. For example, `'r#struct` will be rendered as `'struct` which
would be incorrect.
Also, simplify boolean shortcut expression, and ensure that
applicability is properly applied, as it was ignored and
`MachineApplicable` was always used.
changelog: [`borrow_as_ptr`]: do not remove required parentheses in
autofix suggestion
Close#13882
This PR just makes sure that we exit the function before getting an ICE
and adds a regression test. Related to #12979. We would need to keep
researching the issue, but as the ICEing code isn't that complicated,
getting a hotfix into nightly is urgent.
changelog:[`borrow_interior_mutable_const`] Fix ICE #12979
Fixes#13862
`missing_headers::check` is sometimes called from outside of a body
(specifically, from `check_attributes`, where the LateContext's ParamEnv
is not yet properly initialized for that item). Using that empty
ParamEnv for trait solving things from within the body can then lead to
various ICEs, like the linked issue where we have a const generic
parameter `DMA_INST` without a `ConstArgHasType` bound in the ParamEnv
so the const parameter has no type, which is normally not supposed to
happen.
We have the item's DefId so we can just get its ParamEnv/TypingEnv from
there, and using that one for trait solving should be safe.
changelog: none
Convert the ICE reported in #12979 into a false negative.
We prefer a false negative to a ICE (because the ICE could
still affect the user even when not activating the lint).
Fixes#11846.
This PR has three commits:
- The first commit adds an `initializer-suggestions` configuration to
control suggestion applicability when initializers are present. The
following are the options:
- "none": do not suggest
- "maybe-incorrect": suggest, but do not apply suggestions with `--fix`
- "machine-applicable": suggest and apply suggestions with `--fix`
- The second commit fixes suggestions to handle field attributes
(problem [noticed by
@samueltardieu](https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1859261645)).
- The third commit adds `initializer-suggestions = "machine-applicable"`
to Clippy's `clippy.toml` and applies the suggestions. (Nothing seems to
break.)
---
changelog: make `inconsistent_struct_constructor` "all fields are
shorthand" requirement configurable
fix#13843
The `manual_div_ceil` lint makes incorrect suggestion when type suffixes
need to be made explicit in the suggested code.
changelog: [`manual_div_ceil`]: suggested code now includes appropriate
type suffixes where necessary
fix#13411
The `if_not_else` lint can be fixed automatically, but the issue above
reports that there is no implementation to do so. Therefore, this PR
implements it.
----
changelog: [`if_not_else`]: make suggestions for modified code
This will address https://github.com/rust-lang/rust-clippy/issues/13099
for the unnecessary_iter_cloned test.
changelog: [unnecessary_iter_cloned]: unnecessary_iter_cloned
manual_assert to use multipart_suggestions where appropriate
fix#11524
In a `no_std` environment, we can use `core::cmp::Reverse` instead of
`std::cmp::Reverse`.
----
changelog: [`unnecessary_sort_by`]: correct suggestion in `no_std`
Fixes#13375
I've added the lint next to the other attribute-related ones. Not sure
if this is the correct place, since while we are looking after the
`packed`-attribute (there is nothing we can do about types defined
elsewhere), we are more concerned about the type's representation set by
the attribute (instead of "duplicate attributes" and such).
The lint simply looks at the attributes themselves without concern for
the item-kind, since items where `repr` is not allowed end up in a
compile-error anyway.
I'm somewhat concerned about the level of noise this lint would cause
if/when it goes into stable, although it does _not_ come up in
`lintcheck`.
```
changelog: [`repr_packed_without_abi`]: Initial implementation
```
fix#12320
When there're multiple attributes, clippy suggests leaving an extra
comma and it makes an error.
changelog: [`must_use_unit`]: No longer make incorrect suggestions when
multiple attributes present.
Remove support for specializing ToString outside the standard library
This is the only trait specializable outside of the standard library. Before stabilizing specialization we will probably want to remove support for this. It was originally made specializable to allow a more efficient ToString in libproc_macro back when this way the only way to get any data out of a TokenStream. We now support getting individual tokens, so proc macros no longer need to call it as often.
changelog:
```
changelog: [`needless_option_take`]: now lints for all temporary expressions of type Option<T>.
```
fixes#13671
In general, needless_option_take should report whenever take() is called
on a temporary value, not just when the temporary value is created by
as_ref().
Also, we stop emitting machine applicable fixes in these cases, since
sometimes the intention of the user is to actually clear the original
option, in cases such as `option.as_mut().take()`.
Tweak multispan rendering to reduce output length
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments. We do that check not only on the first 4 lines of the multispan, but now also on the previous to last line as well.