Skip to content

Commit 5d6e8fc

Browse files
committed
Auto merge of #31214 - Manishearth:rollup, r=Manishearth
- Successful merges: #31172, #31177, #31211 - Failed merges:
2 parents 43c1a17 + b6faae1 commit 5d6e8fc

File tree

7 files changed

+147
-10
lines changed

7 files changed

+147
-10
lines changed

src/libcore/iter.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4252,13 +4252,15 @@ impl<A: Step> RangeFrom<A> {
42524252
///
42534253
/// # Examples
42544254
///
4255-
/// ```ignore
4256-
/// for i in (0u8..).step_by(2) {
4255+
/// ```
4256+
/// # #![feature(step_by)]
4257+
///
4258+
/// for i in (0u8..).step_by(2).take(10) {
42574259
/// println!("{}", i);
42584260
/// }
42594261
/// ```
42604262
///
4261-
/// This prints all even `u8` values.
4263+
/// This prints the first ten even natural integers (0 to 18).
42624264
#[unstable(feature = "step_by", reason = "recent addition",
42634265
issue = "27741")]
42644266
pub fn step_by(self, by: A) -> StepBy<A, Self> {

src/libstd/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<W: io::Write> io::Write for Maybe<W> {
112112
impl<R: io::Read> io::Read for Maybe<R> {
113113
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
114114
match *self {
115-
Maybe::Real(ref mut r) => handle_ebadf(r.read(buf), buf.len()),
115+
Maybe::Real(ref mut r) => handle_ebadf(r.read(buf), 0),
116116
Maybe::Fake => Ok(0)
117117
}
118118
}

src/libstd/sys/windows/process.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,15 @@ fn make_dirp(d: Option<&OsString>) -> (*const u16, Vec<u16>) {
351351
impl Stdio {
352352
fn to_handle(&self, stdio_id: c::DWORD) -> io::Result<Handle> {
353353
match *self {
354+
// If no stdio handle is available, then inherit means that it
355+
// should still be unavailable so propagate the
356+
// INVALID_HANDLE_VALUE.
354357
Stdio::Inherit => {
355-
stdio::get(stdio_id).and_then(|io| {
356-
io.handle().duplicate(0, true, c::DUPLICATE_SAME_ACCESS)
357-
})
358+
match stdio::get(stdio_id) {
359+
Ok(io) => io.handle().duplicate(0, true,
360+
c::DUPLICATE_SAME_ACCESS),
361+
Err(..) => Ok(Handle::new(c::INVALID_HANDLE_VALUE)),
362+
}
358363
}
359364
Stdio::Raw(handle) => {
360365
RawHandle::new(handle).duplicate(0, true, c::DUPLICATE_SAME_ACCESS)

src/libsyntax/errors/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use self::Destination::*;
1212

13-
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
13+
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, DUMMY_SP, Pos, Span};
1414
use diagnostics;
1515

1616
use errors::{Level, RenderSpan, DiagnosticBuilder};
@@ -109,8 +109,8 @@ impl Emitter for EmitterWriter {
109109
lvl: Level) {
110110
let error = match sp {
111111
Some(COMMAND_LINE_SP) => self.emit_(FileLine(COMMAND_LINE_SP), msg, code, lvl),
112+
Some(DUMMY_SP) | None => print_diagnostic(&mut self.dst, "", lvl, msg, code),
112113
Some(sp) => self.emit_(FullSpan(sp), msg, code, lvl),
113-
None => print_diagnostic(&mut self.dst, "", lvl, msg, code),
114114
};
115115

116116
if let Err(e) = error {

src/libsyntax/parse/parser.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,12 @@ impl<'a> Parser<'a> {
22182218
ex = ExprBreak(None);
22192219
}
22202220
hi = self.last_span.hi;
2221+
} else if self.token.is_keyword(keywords::Let) {
2222+
// Catch this syntax error here, instead of in `check_strict_keywords`, so
2223+
// that we can explicitly mention that let is not to be used as an expression
2224+
let mut db = self.fatal("expected expression, found statement (`let`)");
2225+
db.note("variable declaration using `let` is a statement");
2226+
return Err(db);
22212227
} else if self.check(&token::ModSep) ||
22222228
self.token.is_ident() &&
22232229
!self.check_keyword(keywords::True) &&

src/test/run-fail-fulldeps/qquote.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-cross-compile
1212

13-
// error-pattern:expected identifier, found keyword `let`
13+
// error-pattern:expected expression, found statement (`let`)
1414

1515
#![feature(quote, rustc_private)]
1616

src/test/run-pass/no-stdio.rs

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(libc)]
12+
13+
extern crate libc;
14+
15+
use std::process::{Command, Stdio};
16+
use std::env;
17+
use std::io::{self, Read, Write};
18+
19+
#[cfg(unix)]
20+
unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
21+
let doit = |a| {
22+
let r = libc::dup(a);
23+
assert!(r >= 0);
24+
return r
25+
};
26+
let a = doit(0);
27+
let b = doit(1);
28+
let c = doit(2);
29+
30+
assert!(libc::close(0) >= 0);
31+
assert!(libc::close(1) >= 0);
32+
assert!(libc::close(2) >= 0);
33+
34+
let r = f();
35+
36+
assert!(libc::dup2(a, 0) >= 0);
37+
assert!(libc::dup2(b, 1) >= 0);
38+
assert!(libc::dup2(c, 2) >= 0);
39+
40+
return r
41+
}
42+
43+
#[cfg(windows)]
44+
unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
45+
type DWORD = u32;
46+
type HANDLE = *mut u8;
47+
type BOOL = i32;
48+
49+
const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
50+
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
51+
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
52+
const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
53+
54+
extern "system" {
55+
fn GetStdHandle(which: DWORD) -> HANDLE;
56+
fn SetStdHandle(which: DWORD, handle: HANDLE) -> BOOL;
57+
}
58+
59+
let doit = |id| {
60+
let handle = GetStdHandle(id);
61+
assert!(handle != INVALID_HANDLE_VALUE);
62+
assert!(SetStdHandle(id, INVALID_HANDLE_VALUE) != 0);
63+
return handle
64+
};
65+
66+
let a = doit(STD_INPUT_HANDLE);
67+
let b = doit(STD_OUTPUT_HANDLE);
68+
let c = doit(STD_ERROR_HANDLE);
69+
70+
let r = f();
71+
72+
let doit = |id, handle| {
73+
assert!(SetStdHandle(id, handle) != 0);
74+
};
75+
doit(STD_INPUT_HANDLE, a);
76+
doit(STD_OUTPUT_HANDLE, b);
77+
doit(STD_ERROR_HANDLE, c);
78+
79+
return r
80+
}
81+
82+
fn main() {
83+
if env::args().len() > 1 {
84+
println!("test");
85+
assert!(io::stdout().write(b"test\n").is_ok());
86+
assert!(io::stderr().write(b"test\n").is_ok());
87+
assert_eq!(io::stdin().read(&mut [0; 10]).unwrap(), 0);
88+
return
89+
}
90+
91+
// First, make sure reads/writes without stdio work if stdio itself is
92+
// missing.
93+
let (a, b, c) = unsafe {
94+
without_stdio(|| {
95+
let a = io::stdout().write(b"test\n");
96+
let b = io::stderr().write(b"test\n");
97+
let c = io::stdin().read(&mut [0; 10]);
98+
99+
(a, b, c)
100+
})
101+
};
102+
103+
assert_eq!(a.unwrap(), 5);
104+
assert_eq!(b.unwrap(), 5);
105+
assert_eq!(c.unwrap(), 0);
106+
107+
// Second, spawn a child and do some work with "null" descriptors to make
108+
// sure it's ok
109+
let me = env::current_exe().unwrap();
110+
let status = Command::new(&me)
111+
.arg("next")
112+
.stdin(Stdio::null())
113+
.stdout(Stdio::null())
114+
.stderr(Stdio::null())
115+
.status().unwrap();
116+
assert!(status.success(), "{:?} isn't a success", status);
117+
118+
// Finally, close everything then spawn a child to make sure everything is
119+
// *still* ok.
120+
let status = unsafe {
121+
without_stdio(|| Command::new(&me).arg("next").status())
122+
}.unwrap();
123+
assert!(status.success(), "{:?} isn't a success", status);
124+
}

0 commit comments

Comments
 (0)