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

Unused assignment warning should trigger for structs #16789

Open
crumblingstatue opened this issue Aug 27, 2014 · 3 comments
Open

Unused assignment warning should trigger for structs #16789

crumblingstatue opened this issue Aug 27, 2014 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crumblingstatue
Copy link
Contributor

crumblingstatue commented Aug 27, 2014

This code should ideally trigger warnings about unused assignments, but it doesn't.

struct Pos {
    x: i32
}

fn foo() -> Pos{
    Pos{x: 2}
}

fn main() {
    foo().x += 1; // Unused assignment
    let mut f = Pos { x: 2 };
    f.x = 2; // Unused assignment
}

It could be useful in situations like this:

struct Property {
    x: i32
}

struct Foo {
    prop: Property
}

impl Foo {
    fn prop(&self) -> Property {
        self.prop
    }
    fn mut_prop(&mut self) -> &mut Property {
        &mut self.prop
    }
}

fn main() {
    let mut foo = Foo{prop: Property{x: 2}};
    foo.prop().x += 2; // Oops, accidentally called prop() instead of mut_prop()
    foo.mut_prop().x += 2;
}
@crumblingstatue crumblingstatue changed the title Unused assignment warning should trigger for struct fields Unused assignment warning should trigger for structs Aug 27, 2014
@sanxiyn sanxiyn added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 27, 2015
@steveklabnik
Copy link
Member

Triage: no change.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 21, 2017
@steveklabnik
Copy link
Member

Triage: no change

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 12, 2020
@LeSeulArtichaut
Copy link
Contributor

I’ll try to take a look at this!
@rustbot claim

@LeSeulArtichaut LeSeulArtichaut removed their assignment Sep 5, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 17, 2024
cfg Attribute Stripping for Proc Macro Expansion

This will attempt to process cfg attributes and cfg_attr attributes for proc macro expansion.
![image](https://github.com/rust-lang/rust-analyzer/assets/11785959/b85ef203-14a5-44c9-9b67-59a65a5f2d96)

Closes rust-lang#8434 , rust-lang#11657, and rust-lang#13904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants