Add CONST_ITEM_MUTATION lint
Fixes #74053 Fixes #55721 This PR adds a new lint `CONST_ITEM_MUTATION`. Given an item `const FOO: SomeType = ..`, this lint fires on: * Attempting to write directly to a field (`FOO.field = some_val`) or array entry (`FOO.array_field[0] = val`) * Taking a mutable reference to the `const` item (`&mut FOO`), including through an autoderef `FOO.some_mut_self_method()` The lint message explains that since each use of a constant creates a new temporary, the original `const` item will not be modified.
This commit is contained in:
parent
d2454643e1
commit
f422ef141a
17 changed files with 403 additions and 68 deletions
|
@ -21,7 +21,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let Expr { ty, temp_lifetime: _, span, kind } = expr;
|
||||
match kind {
|
||||
ExprKind::Scope { region_scope: _, lint_level: _, value } => this.as_constant(value),
|
||||
ExprKind::Literal { literal, user_ty } => {
|
||||
ExprKind::Literal { literal, user_ty, const_id: _ } => {
|
||||
let user_ty = user_ty.map(|user_ty| {
|
||||
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
|
||||
span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue