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

Incorrect warning: type alias is never used #54234

Closed
nitingupta910 opened this issue Sep 14, 2018 · 4 comments
Closed

Incorrect warning: type alias is never used #54234

nitingupta910 opened this issue Sep 14, 2018 · 4 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@nitingupta910
Copy link

With the following code, I'm getting an incorrect warning:

cargo run

   Compiling hellors v0.1.0 (file:///home/ngupta/temp/hellors)                                                                                                                                                
warning: type alias is never used: `Result`
 --> src/main.rs:3:1
  |
3 | type Result<T> = ::std::result::Result<(T, usize), usize>;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.44s
     Running `target/debug/hellors`

Code

// On success, return what was parsed and where to start parsing from next.
// On failure, return where the parsing failed.
type Result<T> = ::std::result::Result<(T, usize), usize>;

fn parse_until(terminator: &'static str) -> impl Fn(&str, usize) -> Result<&str> {
    move |s, location| {
        let s = &s[location..];
        match s.find(terminator) {
            Some(pos) => {
                let head = &s[..pos];
                Ok((head, location + pos + terminator.len()))
            },
            None => {
                Err(location)
            }
        }
    }
}

fn main() {
    let input = "hello\nworld";
    assert_eq!(Ok(("hello", 6)), parse_until("\n")(input, 0));
    assert_eq!(Err(6), parse_until("\n")(input, 6));
}

Version

rustc --version
rustc 1.29.0 (aa3ca1994 2018-09-11)
@Centril
Copy link
Contributor

Centril commented Sep 14, 2018

minimized to:

type Alias = ();

fn fun() -> impl FnOnce() -> Alias {
    || ()
}

fn main() {
    fun()();
}

@Centril Centril added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. labels Sep 14, 2018
@RalfJung
Copy link
Member

Potentially related: #47131

@sanxiyn
Copy link
Member

sanxiyn commented Mar 12, 2019

I just confirmed that this is fixed by #59129. #47131 is unrelated as it is about impl header, not impl Trait.

@sanxiyn sanxiyn removed the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 12, 2019
@sanxiyn
Copy link
Member

sanxiyn commented Mar 13, 2019

Fixed by #59129.

@sanxiyn sanxiyn closed this as completed Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants