{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/52407","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/52407/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/52407/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/52407/events","html_url":"https://github.com/rust-lang/rust/issues/52407","id":341345462,"node_id":"MDU6SXNzdWUzNDEzNDU0NjI=","number":52407,"title":"Integers print inconsistently via the `println!` macro","user":{"login":"jay-tyler","id":7076233,"node_id":"MDQ6VXNlcjcwNzYyMzM=","avatar_url":"https://avatars1.githubusercontent.com/u/7076233?v=4","gravatar_id":"","url":"https://api.github.com/users/jay-tyler","html_url":"https://github.com/jay-tyler","followers_url":"https://api.github.com/users/jay-tyler/followers","following_url":"https://api.github.com/users/jay-tyler/following{/other_user}","gists_url":"https://api.github.com/users/jay-tyler/gists{/gist_id}","starred_url":"https://api.github.com/users/jay-tyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jay-tyler/subscriptions","organizations_url":"https://api.github.com/users/jay-tyler/orgs","repos_url":"https://api.github.com/users/jay-tyler/repos","events_url":"https://api.github.com/users/jay-tyler/events{/privacy}","received_events_url":"https://api.github.com/users/jay-tyler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-15T19:31:38Z","updated_at":"2018-07-15T22:16:46Z","closed_at":null,"author_association":"NONE","body":"I'm just starting to learn Rust, and have been creating some simple shell scripts.\r\n\r\nI have a function that looks like this, where reader is either a file or stdin.\r\n```\r\nfn count_lines<R>(reader: R) -> usize\r\n    where R: BufRead\r\n{\r\n    let lines = reader.lines();\r\n    let mut count = 0;\r\n    for _ in lines {\r\n        count = count + 1;\r\n        println!(\"{}\", count);\r\n    }\r\n    println!(\"{}\", count);\r\n    println!(\"{}\", count);\r\n    count\r\n}\r\n```\r\n\r\nAnd the output looks like this when the reader is constructed via `std::io::stdin()` with a subsequent `lock()`.\r\n```\r\n$ cargo run --bin count\r\n    Finished dev [unoptimized + debuginfo] target(s) in 0.03s\r\n     Running `/Users/jason/rust/shell_scripts/target/debug/count`\r\nfirst_line\r\n1\r\nsecond_line\r\n2\r\nthird_line\r\n3\r\n3D\r\n3\r\n```\r\nNotice the end count first prints as a `3D`, and then subsequently prints as `3`. I don't see any \"D\" suffixes when the reader is an open `File`.\r\n\r\nCurrently running\r\n```\r\n$ rustc --version\r\nrustc 1.27.0 (3eda71b00 2018-06-19)\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/405122646","html_url":"https://github.com/rust-lang/rust/issues/52407#issuecomment-405122646","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/52407","id":405122646,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTEyMjY0Ng==","user":{"login":"jay-tyler","id":7076233,"node_id":"MDQ6VXNlcjcwNzYyMzM=","avatar_url":"https://avatars1.githubusercontent.com/u/7076233?v=4","gravatar_id":"","url":"https://api.github.com/users/jay-tyler","html_url":"https://github.com/jay-tyler","followers_url":"https://api.github.com/users/jay-tyler/followers","following_url":"https://api.github.com/users/jay-tyler/following{/other_user}","gists_url":"https://api.github.com/users/jay-tyler/gists{/gist_id}","starred_url":"https://api.github.com/users/jay-tyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jay-tyler/subscriptions","organizations_url":"https://api.github.com/users/jay-tyler/orgs","repos_url":"https://api.github.com/users/jay-tyler/repos","events_url":"https://api.github.com/users/jay-tyler/events{/privacy}","received_events_url":"https://api.github.com/users/jay-tyler/received_events","type":"User","site_admin":false},"created_at":"2018-07-15T22:16:46Z","updated_at":"2018-07-15T22:16:46Z","author_association":"NONE","body":"@sfackler I'm using iTerm2/bash on a MacBook. Same behavior inside `tmux`. The results above suggest some kind of race condition against stdout, which isn't likely to reproduce consistently across all devices and terminals.\r\n\r\nDo you have a reference for the shell deciding to print `^D`? Genuinely curious, and have tried `^D` aka EOF with a bunch of different programs/shells, all with very different behavior.\r\n* `ipython`: handles EOF by printing `Do you really want to exit ([y]/n)?`\r\n* `python`: prints `^D` before returning to prompt\r\n* `cat`: prints nothing and returns to prompt\r\n* `wc -l`: displays a highlighted `^D` which disappears after a second `^D`. Returns to prompt.\r\n\r\nMost of the behavior I'm seeing above seems to be programmatically defined. I'd like to catch and handle the EOF in Rust if I can. Seems to be possible in most programming languages."}}
{"actor":{"display_login":"jay-tyler"}}