diff options
| author | bors <bors@rust-lang.org> | 2018-01-30 11:10:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-30 11:10:06 +0000 |
| commit | def3269a71be2e737cad27418a3dad9f5bd6cd32 (patch) | |
| tree | 1b6a3bf9de28edffa1c9ac671aa066d1c079e35d /src/libstd | |
| parent | fe7e1a45f37f4265434cead827f587e75412f85c (diff) | |
| parent | 393a1994af93977fe1e35fb4ec308bc4e5d1a6dd (diff) | |
| download | rust-def3269a71be2e737cad27418a3dad9f5bd6cd32.tar.gz rust-def3269a71be2e737cad27418a3dad9f5bd6cd32.zip | |
Auto merge of #47870 - kennytm:rollup, r=kennytm
Rollup of 12 pull requests - Successful merges: #47515, #47603, #47718, #47732, #47760, #47780, #47822, #47826, #47836, #47839, #47853, #47855 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 9 | ||||
| -rw-r--r-- | src/libstd/process.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process/process_common.rs | 16 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index b01420f36a0..82a687ae5e4 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1384,9 +1384,14 @@ impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap<K, V, S> { type Output = V; + /// Returns a reference to the value corresponding to the supplied key. + /// + /// # Panics + /// + /// Panics if the key is not present in the `HashMap`. #[inline] - fn index(&self, index: &Q) -> &V { - self.get(index).expect("no entry found for key") + fn index(&self, key: &Q) -> &V { + self.get(key).expect("no entry found for key") } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 5c66ac6ddde..9b2f815b713 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1843,4 +1843,10 @@ mod tests { } assert!(events > 0); } + + #[test] + fn test_command_implements_send() { + fn take_send_type<T: Send>(_: T) {} + take_send_type(Command::new("")) + } } diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs index c53bcdbf8e3..7e057401fab 100644 --- a/src/libstd/sys/unix/process/process_common.rs +++ b/src/libstd/sys/unix/process/process_common.rs @@ -45,7 +45,7 @@ pub struct Command { // other keys. program: CString, args: Vec<CString>, - argv: Vec<*const c_char>, + argv: Argv, env: CommandEnv<DefaultEnvKey>, cwd: Option<CString>, @@ -58,6 +58,12 @@ pub struct Command { stderr: Option<Stdio>, } +// Create a new type for argv, so that we can make it `Send` +struct Argv(Vec<*const c_char>); + +// It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args` +unsafe impl Send for Argv {} + // passed back to std::process with the pipes connected to the child, if any // were requested pub struct StdioPipes { @@ -92,7 +98,7 @@ impl Command { let mut saw_nul = false; let program = os2c(program, &mut saw_nul); Command { - argv: vec![program.as_ptr(), ptr::null()], + argv: Argv(vec![program.as_ptr(), ptr::null()]), program, args: Vec::new(), env: Default::default(), @@ -111,8 +117,8 @@ impl Command { // Overwrite the trailing NULL pointer in `argv` and then add a new null // pointer. let arg = os2c(arg, &mut self.saw_nul); - self.argv[self.args.len() + 1] = arg.as_ptr(); - self.argv.push(ptr::null()); + self.argv.0[self.args.len() + 1] = arg.as_ptr(); + self.argv.0.push(ptr::null()); // Also make sure we keep track of the owned value to schedule a // destructor for this memory. @@ -133,7 +139,7 @@ impl Command { self.saw_nul } pub fn get_argv(&self) -> &Vec<*const c_char> { - &self.argv + &self.argv.0 } #[allow(dead_code)] |
