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

'times' Iterating incorrect number of times #3398

Closed
doublec opened this issue Sep 5, 2012 · 3 comments
Closed

'times' Iterating incorrect number of times #3398

doublec opened this issue Sep 5, 2012 · 3 comments

Comments

@doublec
Copy link
Contributor

doublec commented Sep 5, 2012

The following code using 'times' only prints 44 lines, whereas I'd expect it to print 300 lines.

use std;

fn main() {
        for 300.times {
            io::println("Here's some Rust!");
        }
}

Replacing '300' with 300u prints 300 lines:

use std;

fn main() {
        for 300u.times {
            io::println("Here's some Rust!");
        }
}

Tested with rust incoming branch:

$ rustc test.rs
$ ./test |wc -l
44
@brson
Copy link
Contributor

brson commented Sep 5, 2012

I wonder if the 300 is getting inferred to an i8.

@brson
Copy link
Contributor

brson commented Sep 5, 2012

Here's a self-contained test case:

trait Times2 {
    pure fn times2(it: fn() -> bool);
}


impl i8: Times2 {
    pure fn times2(it: fn() -> bool) {
        let mut i = self;
        while i > 0 {
            if !it() { break }
            i -= 1;
        }
    }
}

impl int: Times2 {
    pure fn times2(it: fn() -> bool) {
        let mut i = self;
        while i > 0 {
            if !it() { break }
            i -= 1;
        }
    }
}

fn main() {
    let mut i = 0;
    for 300.times2 {
        i += 1;
    }

    assert i == 300;
}

If you change the order of impl declarations it works.

@nikomatsakis
Copy link
Contributor

I believe this is a dup of (or, rather, a consequence of) #3211

RalfJung pushed a commit to RalfJung/rust that referenced this issue Mar 25, 2024
Add libc direct test for shims and update CONTRIBUTING.md

Add more ``libc`` direct test for shims as mentioned in rust-lang#3179.

Changes:
- Added ``libc`` direct tests for ``rename`` and ``ftruncate64``
- Added the command for running ``pass-dep`` test in ``CONTRIBUTING.md``
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

3 participants