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

abs doesn't work on tuple with implicit i32 element #194

Open
RazerM opened this issue Jan 6, 2018 · 2 comments
Open

abs doesn't work on tuple with implicit i32 element #194

RazerM opened this issue Jan 6, 2018 · 2 comments
Labels
A-inference Area: type inference

Comments

@RazerM
Copy link

RazerM commented Jan 6, 2018

I asked a question on #rust-beginners and it was suggested to make a bug report.

fn main() {
    let implicit = (3, 4);
    let explicit: (i32, i32) = (3, 4);
    let _ = implicit.0.abs(); // fails
    let _ = explicit.0.abs(); // works
}

Playground

@Havvy
Copy link
Contributor

Havvy commented Jan 6, 2018

The reference currently states in tokens:

  • If an integer type can be uniquely determined from the surrounding program context, the unsuffixed integer literal has that type.
  • If the program context under-constrains the type, it defaults to the signed 32-bit integer i32.
  • If the program context over-constrains the type, it is considered a static type error.

Whereas this example shows that even though it must be i32 by default, the abs method cannot figure it out. This may also be a part of the method call operator — does it happen anywhere else?

@ehuss ehuss added the A-inference Area: type inference label Aug 3, 2020
@madsmtm
Copy link
Contributor

madsmtm commented Dec 2, 2023

This is not tied to tuples:

fn main() {
    let implicit = 3;
    let explicit: i32 = 3;
    let _ = implicit.abs(); // fails
    let _ = explicit.abs(); // works
}

And the error is considered a bug in rustc, see rust-lang/rust#24124, so I don't think the reference has to document anything here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: type inference
Projects
None yet
Development

No branches or pull requests

4 participants