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

cstack lint ignores #[fixed_stack_segment] on default methods #8753

Closed
SiegeLord opened this issue Aug 26, 2013 · 0 comments
Closed

cstack lint ignores #[fixed_stack_segment] on default methods #8753

SiegeLord opened this issue Aug 26, 2013 · 0 comments

Comments

@SiegeLord
Copy link
Contributor

rustc version: rustc 0.8-pre (05f1bbb 2013-08-25 12:26:16 -0700)

Code:

extern "C"
{
    fn a();
}

trait A
{
    #[fixed_stack_segment]
    fn foo()
    {
        unsafe
        {
            a();
        }
    }
}

fn main()
{
}

Error:

test.rs:13:3: 13:4 error: invoking non-Rust fn in fn without #[fixed_stack_segment] [-D cstack (default)]
test.rs:13                      a();
                                ^
error: aborting due to previous error

Note that I'm not sure the attribute is being applied correctly, in which case the lint is correctly identifying the issue and the bug is elsewhere... I don't know how to verify this though.

@brson brson closed this as completed in 0c89183 Sep 13, 2013
Jarcho pushed a commit to Jarcho/rust that referenced this issue Aug 29, 2022
feat(fix): Do not lint if the target code is inside a loop

close rust-lang#8753

we consider the following code.

```rust
fn main() {
    let vec = vec![1];
    let w: Vec<usize> = vec.iter().map(|i| i * i).collect();  // <- once.

    for i in 0..2 {
        let _ = w.contains(&i);
    }
}
```

and the clippy will issue the following warning.

```rust
warning: avoid using `collect()` when not needed
 --> src/main.rs:3:51
  |
3 |     let w: Vec<usize> = vec.iter().map(|i| i * i).collect();
  |                                                   ^^^^^^^
...
6 |         let _ = w.contains(&i);
  |                 -------------- the iterator could be used here instead
  |
  = note: `#[warn(clippy::needless_collect)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
help: check if the original Iterator contains an element instead of collecting then checking
  |
3 ~
4 |
5 |     for i in 0..2 {
6 ~         let _ = vec.iter().map(|i| i * i).any(|x| x == i);
```

Rewrite the code as indicated.

```rust
fn main() {
    let vec = vec![1];

    for i in 0..2 {
        let _ = vec.iter().map(|i| i * i).any(|x| x == i);  // <- execute `map` every loop.
    }
}
```

this code is valid in the compiler, but, it is different from the code before the rewrite.
So, we should not lint, If `collect` is outside of a loop.

Thank you in advance.

---

changelog: Do not lint if the target code is inside a loop in `needless_collect`
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

No branches or pull requests

1 participant