From 3a8e0afdbcc0a5c5f27b86d2a062a44410c15e0e Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Mon, 8 Oct 2018 21:39:44 +0900 Subject: [PATCH 01/33] Reattach all grandchildren when constructing specialization graph. This commit fixes the issue #50452. --- .../traits/specialize/specialization_graph.rs | 27 +++++++++++----- .../specialization/issue-50452.rs | 32 +++++++++++++++++++ .../run-pass/specialization/issue-50452.rs | 29 +++++++++++++++++ 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/test/compile-fail/specialization/issue-50452.rs create mode 100644 src/test/run-pass/specialization/issue-50452.rs diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index e237cab5ea135..24e8f8ef75080 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -73,8 +73,8 @@ enum Inserted { /// The impl was inserted as a new child in this group of children. BecameNewSibling(Option), - /// The impl should replace an existing impl X, because the impl specializes X. - ReplaceChild(DefId), + /// The impl should replace existing impls [X1, ..], because the impl specializes X1, X2, etc. + ReplaceChildren(Vec), /// The impl is a specialization of an existing child. ShouldRecurseOn(DefId), @@ -124,6 +124,7 @@ impl<'a, 'gcx, 'tcx> Children { -> Result { let mut last_lint = None; + let mut replace_children = Vec::new(); debug!( "insert(impl_def_id={:?}, simplified_self={:?})", @@ -194,7 +195,7 @@ impl<'a, 'gcx, 'tcx> Children { debug!("placing as parent of TraitRef {:?}", tcx.impl_trait_ref(possible_sibling).unwrap()); - return Ok(Inserted::ReplaceChild(possible_sibling)); + replace_children.push(possible_sibling); } else { if !tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) { traits::overlapping_impls( @@ -211,6 +212,10 @@ impl<'a, 'gcx, 'tcx> Children { } } + if !replace_children.is_empty() { + return Ok(Inserted::ReplaceChildren(replace_children)); + } + // no overlap with any potential siblings, so add as a new sibling debug!("placing as new sibling"); self.insert_blindly(tcx, impl_def_id); @@ -282,7 +287,7 @@ impl<'a, 'gcx, 'tcx> Graph { last_lint = opt_lint; break; } - ReplaceChild(grand_child_to_be) => { + ReplaceChildren(grand_children_to_be) => { // We currently have // // P @@ -302,17 +307,23 @@ impl<'a, 'gcx, 'tcx> Graph { let siblings = self.children .get_mut(&parent) .unwrap(); - siblings.remove_existing(tcx, grand_child_to_be); + for &grand_child_to_be in &grand_children_to_be { + siblings.remove_existing(tcx, grand_child_to_be); + } siblings.insert_blindly(tcx, impl_def_id); } // Set G's parent to N and N's parent to P - self.parent.insert(grand_child_to_be, impl_def_id); + for &grand_child_to_be in &grand_children_to_be { + self.parent.insert(grand_child_to_be, impl_def_id); + } self.parent.insert(impl_def_id, parent); // Add G as N's child. - self.children.entry(impl_def_id).or_default() - .insert_blindly(tcx, grand_child_to_be); + for &grand_child_to_be in &grand_children_to_be { + self.children.entry(impl_def_id).or_default() + .insert_blindly(tcx, grand_child_to_be); + } break; } ShouldRecurseOn(new_parent) => { diff --git a/src/test/compile-fail/specialization/issue-50452.rs b/src/test/compile-fail/specialization/issue-50452.rs new file mode 100644 index 0000000000000..4a8d01d0de2f5 --- /dev/null +++ b/src/test/compile-fail/specialization/issue-50452.rs @@ -0,0 +1,32 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-fail + +#![feature(specialization)] + +pub trait Foo { + fn foo(); +} + +impl Foo for i32 {} +impl Foo for i64 { + fn foo() {} + //~^ERROR `foo` specializes an item from a parent `impl` +} +impl Foo for T { + fn foo() {} +} + +fn main() { + i32::foo(); + i64::foo(); + u8::foo(); +} diff --git a/src/test/run-pass/specialization/issue-50452.rs b/src/test/run-pass/specialization/issue-50452.rs new file mode 100644 index 0000000000000..6dec03f77819b --- /dev/null +++ b/src/test/run-pass/specialization/issue-50452.rs @@ -0,0 +1,29 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-pass + +#![feature(specialization)] + +pub trait Foo { + fn foo(); +} + +impl Foo for i32 {} +impl Foo for i64 {} +impl Foo for T { + fn foo() {} +} + +fn main() { + i32::foo(); + i64::foo(); + u8::foo(); +} From 8d2af4a5458f19fbf028b5a4012d389482327ccc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 11 Aug 2018 16:45:18 -0600 Subject: [PATCH 02/33] Update to new system calls and enviromental variables --- .gitmodules | 2 +- src/libstd/sys/redox/mod.rs | 23 ++++++ src/libstd/sys/redox/os.rs | 101 +++++++++++++++++-------- src/libstd/sys/redox/process.rs | 41 ++++++---- src/libstd/sys/redox/syscall/call.rs | 13 +--- src/libstd/sys/redox/syscall/flag.rs | 44 ++++++++++- src/libstd/sys/redox/syscall/number.rs | 2 +- 7 files changed, 168 insertions(+), 58 deletions(-) diff --git a/.gitmodules b/.gitmodules index 038237aa179a9..b5f60e6b6770f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,7 @@ url = https://github.com/rust-lang/rust-installer.git [submodule "src/liblibc"] path = src/liblibc - url = https://github.com/rust-lang/libc.git + url = https://gitlab.redox-os.org/redox-os/liblibc.git [submodule "src/doc/nomicon"] path = src/doc/nomicon url = https://github.com/rust-lang-nursery/nomicon.git diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index f943257c68733..f899439c3f707 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -75,6 +75,29 @@ pub fn cvt(result: Result) -> io::Result { result.map_err(|err| io::Error::from_raw_os_error(err.errno)) } +#[doc(hidden)] +pub trait IsMinusOne { + fn is_minus_one(&self) -> bool; +} + +macro_rules! impl_is_minus_one { + ($($t:ident)*) => ($(impl IsMinusOne for $t { + fn is_minus_one(&self) -> bool { + *self == -1 + } + })*) +} + +impl_is_minus_one! { i8 i16 i32 i64 isize } + +pub fn cvt_libc(t: T) -> io::Result { + if t.is_minus_one() { + Err(io::Error::last_os_error()) + } else { + Ok(t) + } +} + /// On Redox, use an illegal instruction to abort pub unsafe fn abort_internal() -> ! { ::core::intrinsics::abort(); diff --git a/src/libstd/sys/redox/os.rs b/src/libstd/sys/redox/os.rs index 5822216779b6e..84eb56615b60d 100644 --- a/src/libstd/sys/redox/os.rs +++ b/src/libstd/sys/redox/os.rs @@ -12,10 +12,12 @@ #![allow(unused_imports)] // lots of cfg code here +use libc::{self, c_char}; + use os::unix::prelude::*; use error::Error as StdError; -use ffi::{OsString, OsStr}; +use ffi::{CStr, CString, OsStr, OsString}; use fmt; use io::{self, Read, Write}; use iter; @@ -27,7 +29,7 @@ use ptr; use slice; use str; use sys_common::mutex::Mutex; -use sys::{cvt, fd, syscall}; +use sys::{cvt, cvt_libc, fd, syscall}; use vec; extern { @@ -129,6 +131,8 @@ pub fn current_exe() -> io::Result { Ok(PathBuf::from(path)) } +pub static ENV_LOCK: Mutex = Mutex::new(); + pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, _dont_send_or_sync_me: PhantomData<*mut ()>, @@ -140,52 +144,83 @@ impl Iterator for Env { fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } +pub unsafe fn environ() -> *mut *const *const c_char { + extern { static mut environ: *const *const c_char; } + &mut environ +} + /// Returns a vector of (variable, value) byte-vector pairs for all the /// environment variables of the current process. pub fn env() -> Env { - let mut variables: Vec<(OsString, OsString)> = Vec::new(); - if let Ok(mut file) = ::fs::File::open("env:") { - let mut string = String::new(); - if file.read_to_string(&mut string).is_ok() { - for line in string.lines() { - let mut parts = line.splitn(2, '='); - if let Some(name) = parts.next() { - let value = parts.next().unwrap_or(""); - variables.push((OsString::from(name.to_string()), - OsString::from(value.to_string()))); - } + unsafe { + let _guard = ENV_LOCK.lock(); + let mut environ = *environ(); + if environ == ptr::null() { + panic!("os::env() failure getting env string from OS: {}", + io::Error::last_os_error()); + } + let mut result = Vec::new(); + while *environ != ptr::null() { + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); } + environ = environ.offset(1); + } + return Env { + iter: result.into_iter(), + _dont_send_or_sync_me: PhantomData, + } + } + + fn parse(input: &[u8]) -> Option<(OsString, OsString)> { + // Strategy (copied from glibc): Variable name and value are separated + // by an ASCII equals sign '='. Since a variable name must not be + // empty, allow variable names starting with an equals sign. Skip all + // malformed lines. + if input.is_empty() { + return None; } + let pos = memchr::memchr(b'=', &input[1..]).map(|p| p + 1); + pos.map(|p| ( + OsStringExt::from_vec(input[..p].to_vec()), + OsStringExt::from_vec(input[p+1..].to_vec()), + )) } - Env { iter: variables.into_iter(), _dont_send_or_sync_me: PhantomData } } -pub fn getenv(key: &OsStr) -> io::Result> { - if ! key.is_empty() { - if let Ok(mut file) = ::fs::File::open(&("env:".to_owned() + key.to_str().unwrap())) { - let mut string = String::new(); - file.read_to_string(&mut string)?; - Ok(Some(OsString::from(string))) +pub fn getenv(k: &OsStr) -> io::Result> { + // environment variables with a nul byte can't be set, so their value is + // always None as well + let k = CString::new(k.as_bytes())?; + unsafe { + let _guard = ENV_LOCK.lock(); + let s = libc::getenv(k.as_ptr()) as *const libc::c_char; + let ret = if s.is_null() { + None } else { - Ok(None) - } - } else { - Ok(None) + Some(OsStringExt::from_vec(CStr::from_ptr(s).to_bytes().to_vec())) + }; + Ok(ret) } } -pub fn setenv(key: &OsStr, value: &OsStr) -> io::Result<()> { - if ! key.is_empty() { - let mut file = ::fs::File::create(&("env:".to_owned() + key.to_str().unwrap()))?; - file.write_all(value.as_bytes())?; - file.set_len(value.len() as u64)?; +pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { + let k = CString::new(k.as_bytes())?; + let v = CString::new(v.as_bytes())?; + + unsafe { + let _guard = ENV_LOCK.lock(); + cvt_libc(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) } - Ok(()) } -pub fn unsetenv(key: &OsStr) -> io::Result<()> { - ::fs::remove_file(&("env:".to_owned() + key.to_str().unwrap()))?; - Ok(()) +pub fn unsetenv(n: &OsStr) -> io::Result<()> { + let nbuf = CString::new(n.as_bytes())?; + + unsafe { + let _guard = ENV_LOCK.lock(); + cvt_libc(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + } } pub fn page_size() -> usize { diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index 2037616e6ac7c..f85834dff5d05 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -9,15 +9,17 @@ // except according to those terms. use env::{split_paths}; -use ffi::OsStr; +use ffi::{CStr, OsStr}; use os::unix::ffi::OsStrExt; use fmt; use io::{self, Error, ErrorKind}; use iter; use libc::{EXIT_SUCCESS, EXIT_FAILURE}; use path::{Path, PathBuf}; +use ptr; use sys::fd::FileDesc; use sys::fs::{File, OpenOptions}; +use sys::os::{ENV_LOCK, environ}; use sys::pipe::{self, AnonPipe}; use sys::{cvt, syscall}; use sys_common::process::{CommandEnv, DefaultEnvKey}; @@ -297,12 +299,6 @@ impl Command { t!(callback()); } - let args: Vec<[usize; 2]> = iter::once( - [self.program.as_ptr() as usize, self.program.len()] - ).chain( - self.args.iter().map(|arg| [arg.as_ptr() as usize, arg.len()]) - ).collect(); - self.env.apply(); let program = if self.program.contains(':') || self.program.contains('/') { @@ -321,14 +317,33 @@ impl Command { None }; - if let Some(program) = program { - if let Err(err) = syscall::execve(program.as_os_str().as_bytes(), &args) { - io::Error::from_raw_os_error(err.errno as i32) - } else { - panic!("return from exec without err"); + let fd = if let Some(program) = program { + t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY))) + } else { + return io::Error::from_raw_os_error(syscall::ENOENT); + }; + + let mut args: Vec<[usize; 2]> = iter::once( + [self.program.as_ptr() as usize, self.program.len()] + ).chain( + self.args.iter().map(|arg| [arg.as_ptr() as usize, arg.len()]) + ).collect(); + + let mut vars: Vec<[usize; 2]> = Vec::new(); + unsafe { + let _guard = ENV_LOCK.lock(); + let mut environ = *environ(); + while *environ != ptr::null() { + let var = CStr::from_ptr(*environ).to_bytes(); + vars.push([var.as_ptr() as usize, var.len()]); + environ = environ.offset(1); } + } + + if let Err(err) = syscall::fexec(fd, &args, &vars) { + io::Error::from_raw_os_error(err.errno as i32) } else { - io::Error::from_raw_os_error(syscall::ENOENT) + panic!("return from exec without err"); } } diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs index f9a8bd61ac800..0188d684d3a2d 100644 --- a/src/libstd/sys/redox/syscall/call.rs +++ b/src/libstd/sys/redox/syscall/call.rs @@ -82,12 +82,6 @@ pub fn dup2(fd: usize, newfd: usize, buf: &[u8]) -> Result { unsafe { syscall4(SYS_DUP2, fd, newfd, buf.as_ptr() as usize, buf.len()) } } -/// Replace the current process with a new executable -pub fn execve>(path: T, args: &[[usize; 2]]) -> Result { - unsafe { syscall4(SYS_EXECVE, path.as_ref().as_ptr() as usize, - path.as_ref().len(), args.as_ptr() as usize, args.len()) } -} - /// Exit the current process pub fn exit(status: usize) -> Result { unsafe { syscall1(SYS_EXIT, status) } @@ -110,9 +104,10 @@ pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result { unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) } } -/// Register a file for event-based I/O -pub fn fevent(fd: usize, flags: usize) -> Result { - unsafe { syscall2(SYS_FEVENT, fd, flags) } +/// Replace the current process with a new executable +pub fn fexec>(fd: usize, args: &[[usize; 2]], vars: &[[usize; 2]]) -> Result { + unsafe { syscall5(SYS_FEXEC, fd, args.as_ptr() as usize, args.len(), + vars.as_ptr() as usize, vars.len()) } } /// Map a file into memory diff --git a/src/libstd/sys/redox/syscall/flag.rs b/src/libstd/sys/redox/syscall/flag.rs index 0f61b9fa77b52..0f1a2c2315973 100644 --- a/src/libstd/sys/redox/syscall/flag.rs +++ b/src/libstd/sys/redox/syscall/flag.rs @@ -113,4 +113,46 @@ pub const SA_RESTART: usize = 0x10000000; pub const SA_NODEFER: usize = 0x40000000; pub const SA_RESETHAND: usize = 0x80000000; -pub const WNOHANG: usize = 1; +pub const WNOHANG: usize = 0x01; +pub const WUNTRACED: usize = 0x02; +pub const WCONTINUED: usize = 0x08; + +/// True if status indicates the child is stopped. +pub fn wifstopped(status: usize) -> bool { + (status & 0xff) == 0x7f +} + +/// If wifstopped(status), the signal that stopped the child. +pub fn wstopsig(status: usize) -> usize { + (status >> 8) & 0xff +} + +/// True if status indicates the child continued after a stop. +pub fn wifcontinued(status: usize) -> bool { + status == 0xffff +} + +/// True if STATUS indicates termination by a signal. +pub fn wifsignaled(status: usize) -> bool { + ((status & 0x7f) + 1) as i8 >= 2 +} + +/// If wifsignaled(status), the terminating signal. +pub fn wtermsig(status: usize) -> usize { + status & 0x7f +} + +/// True if status indicates normal termination. +pub fn wifexited(status: usize) -> bool { + wtermsig(status) == 0 +} + +/// If wifexited(status), the exit status. +pub fn wexitstatus(status: usize) -> usize { + (status >> 8) & 0xff +} + +/// True if status indicates a core dump was created. +pub fn wcoredump(status: usize) -> bool { + (status & 0x80) != 0 +} diff --git a/src/libstd/sys/redox/syscall/number.rs b/src/libstd/sys/redox/syscall/number.rs index 45cb40e390840..1e187565a675c 100644 --- a/src/libstd/sys/redox/syscall/number.rs +++ b/src/libstd/sys/redox/syscall/number.rs @@ -36,6 +36,7 @@ pub const SYS_FCHMOD: usize = SYS_CLASS_FILE | 94; pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207; pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55; pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927; +pub const SYS_FEXEC: usize = SYS_CLASS_FILE | 11; pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90; pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91; pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928; @@ -50,7 +51,6 @@ pub const SYS_BRK: usize = 45; pub const SYS_CHDIR: usize = 12; pub const SYS_CLOCK_GETTIME: usize = 265; pub const SYS_CLONE: usize = 120; -pub const SYS_EXECVE: usize = 11; pub const SYS_EXIT: usize = 1; pub const SYS_FUTEX: usize = 240; pub const SYS_GETCWD: usize = 183; From b400005861ae54fda63e7bac48010f5782577dd1 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 11 Aug 2018 16:48:09 -0600 Subject: [PATCH 03/33] Remove unused type parameter --- src/libstd/sys/redox/syscall/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs index 0188d684d3a2d..61cd97d6d4385 100644 --- a/src/libstd/sys/redox/syscall/call.rs +++ b/src/libstd/sys/redox/syscall/call.rs @@ -105,7 +105,7 @@ pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result { } /// Replace the current process with a new executable -pub fn fexec>(fd: usize, args: &[[usize; 2]], vars: &[[usize; 2]]) -> Result { +pub fn fexec(fd: usize, args: &[[usize; 2]], vars: &[[usize; 2]]) -> Result { unsafe { syscall5(SYS_FEXEC, fd, args.as_ptr() as usize, args.len(), vars.as_ptr() as usize, vars.len()) } } From 8c277d843cbac4d89f5f2dbfdb773cb80f48977b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 16 Aug 2018 18:47:52 -0600 Subject: [PATCH 04/33] Don't forget to close executable file --- src/libstd/sys/redox/process.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index f85834dff5d05..566c3e72922e4 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -318,7 +318,7 @@ impl Command { }; let fd = if let Some(program) = program { - t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY))) + t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY | syscall::O_CLOEXEC))) } else { return io::Error::from_raw_os_error(syscall::ENOENT); }; @@ -341,6 +341,7 @@ impl Command { } if let Err(err) = syscall::fexec(fd, &args, &vars) { + let _ = syscall::close(fd); io::Error::from_raw_os_error(err.errno as i32) } else { panic!("return from exec without err"); From 9d42b1bf04a807c18da0671ecadb8f4fa2044077 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Mon, 15 Oct 2018 21:16:04 +0200 Subject: [PATCH 05/33] Interpret shebangs on redox This is no longer handled on the kernel side --- src/libstd/sys/redox/process.rs | 94 ++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index 566c3e72922e4..3b2cb7c5e1363 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -10,15 +10,22 @@ use env::{split_paths}; use ffi::{CStr, OsStr}; +use fs::File; use os::unix::ffi::OsStrExt; use fmt; +<<<<<<< HEAD use io::{self, Error, ErrorKind}; use iter; +======= +use io::{self, prelude::*, BufReader, Error, ErrorKind, SeekFrom}; +>>>>>>> b7b1d416a1... Interpret shebangs on redox use libc::{EXIT_SUCCESS, EXIT_FAILURE}; use path::{Path, PathBuf}; use ptr; +use sys::ext::fs::MetadataExt; +use sys::ext::io::AsRawFd; use sys::fd::FileDesc; -use sys::fs::{File, OpenOptions}; +use sys::fs::{File as SysFile, OpenOptions}; use sys::os::{ENV_LOCK, environ}; use sys::pipe::{self, AnonPipe}; use sys::{cvt, syscall}; @@ -317,20 +324,80 @@ impl Command { None }; - let fd = if let Some(program) = program { - t!(cvt(syscall::open(program.as_os_str().as_bytes(), syscall::O_RDONLY | syscall::O_CLOEXEC))) + let mut file = if let Some(program) = program { + t!(File::open(program.as_os_str())) } else { return io::Error::from_raw_os_error(syscall::ENOENT); }; - let mut args: Vec<[usize; 2]> = iter::once( - [self.program.as_ptr() as usize, self.program.len()] - ).chain( - self.args.iter().map(|arg| [arg.as_ptr() as usize, arg.len()]) - ).collect(); + // Push all the arguments + let mut args: Vec<[usize; 2]> = Vec::with_capacity(1 + self.args.len()); + let interpreter = { + let mut reader = BufReader::new(&file); + + let mut shebang = [0; 2]; + let mut read = 0; + loop { + match t!(reader.read(&mut shebang[read..])) { + 0 => break, + n => read += n, + } + } + + if &shebang == b"#!" { + // This is an interpreted script. + // First of all, since we'll be passing another file to + // fexec(), we need to manually check that we have permission + // to execute this file: + let uid = t!(cvt(syscall::getuid())); + let gid = t!(cvt(syscall::getgid())); + let meta = t!(file.metadata()); + + let mode = if uid == meta.uid() as usize { + meta.mode() >> 3*2 & 0o7 + } else if gid == meta.gid() as usize { + meta.mode() >> 3*1 & 0o7 + } else { + meta.mode() & 0o7 + }; + if mode & 1 == 0 { + return io::Error::from_raw_os_error(syscall::EPERM); + } + + // Second of all, we need to actually read which interpreter it wants + let mut interpreter = Vec::new(); + t!(reader.read_until(b'\n', &mut interpreter)); + // Pop one trailing newline, if any + if interpreter.ends_with(&[b'\n']) { + interpreter.pop().unwrap(); + } + + // TODO: Here we could just reassign `file` directly, if it + // wasn't for lexical lifetimes. Remove the whole `let + // interpreter = { ... };` hack once NLL lands. + // NOTE: Although DO REMEMBER to make sure the interpreter path + // still lives long enough to reach fexec. + Some(interpreter) + } else { + None + } + }; + if let Some(ref interpreter) = interpreter { + let path: &OsStr = OsStr::from_bytes(&interpreter); + file = t!(File::open(path)); + + args.push([interpreter.as_ptr() as usize, interpreter.len()]); + } else { + t!(file.seek(SeekFrom::Start(0))); + } + + args.push([self.program.as_ptr() as usize, self.program.len()]); + args.extend(self.args.iter().map(|arg| [arg.as_ptr() as usize, arg.len()])); + + // Push all the variables let mut vars: Vec<[usize; 2]> = Vec::new(); - unsafe { + { let _guard = ENV_LOCK.lock(); let mut environ = *environ(); while *environ != ptr::null() { @@ -340,8 +407,7 @@ impl Command { } } - if let Err(err) = syscall::fexec(fd, &args, &vars) { - let _ = syscall::close(fd); + if let Err(err) = syscall::fexec(file.as_raw_fd(), &args, &vars) { io::Error::from_raw_os_error(err.errno as i32) } else { panic!("return from exec without err"); @@ -408,7 +474,7 @@ impl Stdio { let mut opts = OpenOptions::new(); opts.read(readable); opts.write(!readable); - let fd = File::open(Path::new("null:"), &opts)?; + let fd = SysFile::open(Path::new("null:"), &opts)?; Ok((ChildStdio::Owned(fd.into_fd()), None)) } } @@ -421,8 +487,8 @@ impl From for Stdio { } } -impl From for Stdio { - fn from(file: File) -> Stdio { +impl From for Stdio { + fn from(file: SysFile) -> Stdio { Stdio::Fd(file.into_fd()) } } From 91c1b7a9291ca4ea91f928b1abfe8fc8fe9a0111 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Thu, 18 Oct 2018 16:53:26 +0200 Subject: [PATCH 06/33] Revert liblibc submodule url --- .gitmodules | 2 +- src/liblibc | 2 +- src/libstd/sys/redox/process.rs | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index b5f60e6b6770f..038237aa179a9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,7 @@ url = https://github.com/rust-lang/rust-installer.git [submodule "src/liblibc"] path = src/liblibc - url = https://gitlab.redox-os.org/redox-os/liblibc.git + url = https://github.com/rust-lang/libc.git [submodule "src/doc/nomicon"] path = src/doc/nomicon url = https://github.com/rust-lang-nursery/nomicon.git diff --git a/src/liblibc b/src/liblibc index 1844a772b6077..c75ca6465a139 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit 1844a772b60771d0124a157019f627d60fea4e73 +Subproject commit c75ca6465a139704e00295be355b1f067af2f535 diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index 3b2cb7c5e1363..e7a87e3ff8855 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -10,16 +10,11 @@ use env::{split_paths}; use ffi::{CStr, OsStr}; -use fs::File; -use os::unix::ffi::OsStrExt; use fmt; -<<<<<<< HEAD -use io::{self, Error, ErrorKind}; -use iter; -======= +use fs::File; use io::{self, prelude::*, BufReader, Error, ErrorKind, SeekFrom}; ->>>>>>> b7b1d416a1... Interpret shebangs on redox use libc::{EXIT_SUCCESS, EXIT_FAILURE}; +use os::unix::ffi::OsStrExt; use path::{Path, PathBuf}; use ptr; use sys::ext::fs::MetadataExt; From 51e2a63fafba5ab38f8ebfea803daaef2ec87d02 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Thu, 18 Oct 2018 16:58:09 +0200 Subject: [PATCH 07/33] Fix tidy checks --- src/libstd/sys/redox/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index e7a87e3ff8855..4370c1e05027b 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -368,7 +368,7 @@ impl Command { interpreter.pop().unwrap(); } - // TODO: Here we could just reassign `file` directly, if it + // FIXME: Here we could just reassign `file` directly, if it // wasn't for lexical lifetimes. Remove the whole `let // interpreter = { ... };` hack once NLL lands. // NOTE: Although DO REMEMBER to make sure the interpreter path From 52deb6b45484b595613dfe7199a81706706f3fb7 Mon Sep 17 00:00:00 2001 From: Florian Hartwig Date: Tue, 30 Oct 2018 16:13:42 +0100 Subject: [PATCH 08/33] Add link to std::mem::size_of to size_of intrinsic documentation --- src/libcore/intrinsics.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index cceae9249e456..fe2afc59be8f1 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -672,6 +672,10 @@ extern "rust-intrinsic" { /// /// More specifically, this is the offset in bytes between successive /// items of the same type, including alignment padding. + /// + /// The stabilized version of this intrinsic is + /// [`std::mem::size_of`](../../std/mem/fn.size_of.html). + pub fn size_of() -> usize; /// Moves a value to an uninitialized memory location. From 19aa10132cc727c8561730ab096b21d14507c81d Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 31 Oct 2018 10:22:22 +0100 Subject: [PATCH 09/33] Speed up String::from_utf16 --- src/liballoc/string.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index ff3587d5d8730..8690f9017c406 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -618,7 +618,15 @@ impl String { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_utf16(v: &[u16]) -> Result { - decode_utf16(v.iter().cloned()).collect::>().map_err(|_| FromUtf16Error(())) + let mut ret = String::with_capacity(v.len()); + for c in decode_utf16(v.iter().cloned()) { + if let Ok(c) = c { + ret.push(c); + } else { + return Err(FromUtf16Error(())); + } + } + Ok(ret) } /// Decode a UTF-16 encoded slice `v` into a `String`, replacing From 7eece4771b49c4a199b0643f355b1ec6b63d95aa Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Fri, 19 Oct 2018 15:09:08 -0400 Subject: [PATCH 10/33] Add BufWriter::buffer method --- src/libstd/io/buffered.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index e26e6d391f84d..5b19c0b81bdb2 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -525,6 +525,25 @@ impl BufWriter { #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + /// Returns a reference to the internally buffered data. + /// + /// # Examples + /// + /// ```no_run + /// # #![feature(bufreader_buffer)] + /// use std::io::BufWriter; + /// use std::net::TcpStream; + /// + /// let mut buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` + #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[..] + } + /// Unwraps this `BufWriter`, returning the underlying writer. /// /// The buffer is written out before returning the writer. From 07d966dbb8bee4ff193293555bd9ff2705cb1ece Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 27 Oct 2018 12:19:04 -0400 Subject: [PATCH 11/33] Add some tests --- src/libstd/io/buffered.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 5b19c0b81bdb2..f7b26e5888d0c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -541,7 +541,7 @@ impl BufWriter { /// ``` #[unstable(feature = "bufreader_buffer", issue = "45323")] pub fn buffer(&self) -> &[u8] { - &self.buf[..] + &self.buf } /// Unwraps this `BufWriter`, returning the underlying writer. @@ -984,31 +984,31 @@ mod tests { let mut buf = [0, 0, 0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 3); - let b: &[_] = &[5, 6, 7]; - assert_eq!(buf, b); + assert_eq!(buf, [5, 6, 7]); + assert_eq!(*reader.buffer(), []); let mut buf = [0, 0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 2); - let b: &[_] = &[0, 1]; - assert_eq!(buf, b); + assert_eq!(buf, [0, 1]); + assert_eq!(*reader.buffer(), []); let mut buf = [0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); - let b: &[_] = &[2]; - assert_eq!(buf, b); + assert_eq!(buf, [2]); + assert_eq!(*reader.buffer(), [3]); let mut buf = [0, 0, 0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); - let b: &[_] = &[3, 0, 0]; - assert_eq!(buf, b); + assert_eq!(buf, [3, 0, 0]); + assert_eq!(*reader.buffer(), []); let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); - let b: &[_] = &[4, 0, 0]; - assert_eq!(buf, b); + assert_eq!(buf, [4, 0, 0]); + assert_eq!(*reader.buffer(), []); assert_eq!(reader.read(&mut buf).unwrap(), 0); } @@ -1097,31 +1097,40 @@ mod tests { let mut writer = BufWriter::with_capacity(2, inner); writer.write(&[0, 1]).unwrap(); + assert_eq!(*writer.buffer(), []); assert_eq!(*writer.get_ref(), [0, 1]); writer.write(&[2]).unwrap(); + assert_eq!(*writer.buffer(), [2]); assert_eq!(*writer.get_ref(), [0, 1]); writer.write(&[3]).unwrap(); + assert_eq!(*writer.buffer(), [2, 3]); assert_eq!(*writer.get_ref(), [0, 1]); writer.flush().unwrap(); + assert_eq!(*writer.buffer(), []); assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); writer.write(&[4]).unwrap(); writer.write(&[5]).unwrap(); + assert_eq!(*writer.buffer(), [4, 5]); assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); writer.write(&[6]).unwrap(); + assert_eq!(*writer.buffer(), [6]); assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5]); writer.write(&[7, 8]).unwrap(); + assert_eq!(*writer.buffer(), []); assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]); writer.write(&[9, 10, 11]).unwrap(); + assert_eq!(*writer.buffer(), []); assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); writer.flush().unwrap(); + assert_eq!(*writer.buffer(), []); assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); } From 40e41440e46a56b5d5fd66473c23efff6d44be3f Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Thu, 1 Nov 2018 13:29:47 -0400 Subject: [PATCH 12/33] Suggested edits --- src/libstd/io/buffered.rs | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index f7b26e5888d0c..12d1afe606950 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -534,7 +534,7 @@ impl BufWriter { /// use std::io::BufWriter; /// use std::net::TcpStream; /// - /// let mut buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// let buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); /// /// // See how many bytes are currently buffered /// let bytes_buffered = buf_writer.buffer().len(); @@ -985,30 +985,30 @@ mod tests { let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 3); assert_eq!(buf, [5, 6, 7]); - assert_eq!(*reader.buffer(), []); + assert_eq!(reader.buffer(), []); let mut buf = [0, 0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 2); assert_eq!(buf, [0, 1]); - assert_eq!(*reader.buffer(), []); + assert_eq!(reader.buffer(), []); let mut buf = [0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); assert_eq!(buf, [2]); - assert_eq!(*reader.buffer(), [3]); + assert_eq!(reader.buffer(), [3]); let mut buf = [0, 0, 0]; let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); assert_eq!(buf, [3, 0, 0]); - assert_eq!(*reader.buffer(), []); + assert_eq!(reader.buffer(), []); let nread = reader.read(&mut buf); assert_eq!(nread.unwrap(), 1); assert_eq!(buf, [4, 0, 0]); - assert_eq!(*reader.buffer(), []); + assert_eq!(reader.buffer(), []); assert_eq!(reader.read(&mut buf).unwrap(), 0); } @@ -1097,41 +1097,41 @@ mod tests { let mut writer = BufWriter::with_capacity(2, inner); writer.write(&[0, 1]).unwrap(); - assert_eq!(*writer.buffer(), []); - assert_eq!(*writer.get_ref(), [0, 1]); + assert_eq!(writer.buffer(), []); + assert_eq!(writer.get_ref(), [0, 1]); writer.write(&[2]).unwrap(); - assert_eq!(*writer.buffer(), [2]); - assert_eq!(*writer.get_ref(), [0, 1]); + assert_eq!(writer.buffer(), [2]); + assert_eq!(writer.get_ref(), [0, 1]); writer.write(&[3]).unwrap(); - assert_eq!(*writer.buffer(), [2, 3]); - assert_eq!(*writer.get_ref(), [0, 1]); + assert_eq!(writer.buffer(), [2, 3]); + assert_eq!(writer.get_ref(), [0, 1]); writer.flush().unwrap(); - assert_eq!(*writer.buffer(), []); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); + assert_eq!(writer.buffer(), []); + assert_eq!(writer.get_ref(), [0, 1, 2, 3]); writer.write(&[4]).unwrap(); writer.write(&[5]).unwrap(); - assert_eq!(*writer.buffer(), [4, 5]); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); + assert_eq!(writer.buffer(), [4, 5]); + assert_eq!(writer.get_ref(), [0, 1, 2, 3]); writer.write(&[6]).unwrap(); - assert_eq!(*writer.buffer(), [6]); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5]); + assert_eq!(writer.buffer(), [6]); + assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5]); writer.write(&[7, 8]).unwrap(); - assert_eq!(*writer.buffer(), []); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]); + assert_eq!(writer.buffer(), []); + assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]); writer.write(&[9, 10, 11]).unwrap(); - assert_eq!(*writer.buffer(), []); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); + assert_eq!(writer.buffer(), []); + assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); writer.flush().unwrap(); - assert_eq!(*writer.buffer(), []); - assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); + assert_eq!(writer.buffer(), []); + assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); } #[test] From 59a030916b8f1173c99f874365533574fa6314a9 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Thu, 1 Nov 2018 16:06:41 -0400 Subject: [PATCH 13/33] Fix compile errors in test --- src/libstd/io/buffered.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 12d1afe606950..476ee3f71caf0 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1098,40 +1098,40 @@ mod tests { writer.write(&[0, 1]).unwrap(); assert_eq!(writer.buffer(), []); - assert_eq!(writer.get_ref(), [0, 1]); + assert_eq!(*writer.get_ref(), [0, 1]); writer.write(&[2]).unwrap(); assert_eq!(writer.buffer(), [2]); - assert_eq!(writer.get_ref(), [0, 1]); + assert_eq!(*writer.get_ref(), [0, 1]); writer.write(&[3]).unwrap(); assert_eq!(writer.buffer(), [2, 3]); - assert_eq!(writer.get_ref(), [0, 1]); + assert_eq!(*writer.get_ref(), [0, 1]); writer.flush().unwrap(); assert_eq!(writer.buffer(), []); - assert_eq!(writer.get_ref(), [0, 1, 2, 3]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); writer.write(&[4]).unwrap(); writer.write(&[5]).unwrap(); assert_eq!(writer.buffer(), [4, 5]); - assert_eq!(writer.get_ref(), [0, 1, 2, 3]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3]); writer.write(&[6]).unwrap(); assert_eq!(writer.buffer(), [6]); - assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5]); writer.write(&[7, 8]).unwrap(); assert_eq!(writer.buffer(), []); - assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8]); writer.write(&[9, 10, 11]).unwrap(); assert_eq!(writer.buffer(), []); - assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); writer.flush().unwrap(); assert_eq!(writer.buffer(), []); - assert_eq!(writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); + assert_eq!(*writer.get_ref(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); } #[test] From 2d368b5de8c503718296a37912558a81267b65c0 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Kollasch" Date: Tue, 25 Sep 2018 13:03:14 +0000 Subject: [PATCH 14/33] NetBSD: link libstd with librt in addition to libpthread --- src/libstd/build.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/build.rs b/src/libstd/build.rs index b3851d22841e8..9d6e8c4cafdcb 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -41,8 +41,11 @@ fn main() { } else if target.contains("freebsd") { println!("cargo:rustc-link-lib=execinfo"); println!("cargo:rustc-link-lib=pthread"); + } else if target.contains("netbsd") { + println!("cargo:rustc-link-lib=pthread"); + println!("cargo:rustc-link-lib=rt"); } else if target.contains("dragonfly") || target.contains("bitrig") || - target.contains("netbsd") || target.contains("openbsd") { + target.contains("openbsd") { println!("cargo:rustc-link-lib=pthread"); } else if target.contains("solaris") { println!("cargo:rustc-link-lib=socket"); From 0c085299344d9af4e9bfd892a15d746b116ebe00 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Nov 2018 15:30:04 +0100 Subject: [PATCH 15/33] A few tweaks to iterations/collecting --- src/librustc/cfg/graphviz.rs | 3 +-- src/librustc/hir/lowering.rs | 3 +-- src/librustc/ty/query/on_disk_cache.rs | 2 +- src/libserialize/hex.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 18 ++++++++---------- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index cc4f3f95d079a..650aa39114fad 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -106,8 +106,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG { type Node = Node<'a>; type Edge = Edge<'a>; fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> { - let mut v = Vec::new(); - self.graph.each_node(|i, nd| { v.push((i, nd)); true }); + let v: Vec<_> = self.graph.enumerated_nodes().collect(); v.into() } fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> { diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index dd5d4b8f6afff..4f94b427ec169 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1062,8 +1062,7 @@ impl<'a> LoweringContext<'a> { attrs .iter() .map(|a| self.lower_attr(a)) - .collect::>() - .into() + .collect() } fn lower_attr(&mut self, attr: &Attribute) -> Attribute { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 54550b8a2055f..7d3ae64f4fcd6 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -281,7 +281,7 @@ impl<'sess> OnDiskCache<'sess> { // otherwise, abort break; } - interpret_alloc_index.reserve(new_n); + interpret_alloc_index.reserve(new_n - n); for idx in n..new_n { let id = encoder.interpret_allocs_inverse[idx]; let pos = encoder.position() as u32; diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 7f3736e82caa6..5604729d2f8dc 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -146,7 +146,7 @@ impl FromHex for str { } match modulus { - 0 => Ok(b.into_iter().collect()), + 0 => Ok(b), _ => Err(InvalidHexLength), } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index dd90ef06c3929..bfdb53a9d9e18 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -1200,16 +1200,14 @@ impl<'a> MethodDef<'a> { let sp = trait_.span; let variants = &enum_def.variants; - let self_arg_names = self_args.iter() - .enumerate() - .map(|(arg_count, _self_arg)| { - if arg_count == 0 { - "__self".to_string() - } else { + let self_arg_names = iter::once("__self".to_string()).chain( + self_args.iter() + .enumerate() + .skip(1) + .map(|(arg_count, _self_arg)| format!("__arg_{}", arg_count) - } - }) - .collect::>(); + ) + ).collect::>(); let self_arg_idents = self_arg_names.iter() .map(|name| cx.ident_of(&name[..])) @@ -1218,7 +1216,7 @@ impl<'a> MethodDef<'a> { // The `vi_idents` will be bound, solely in the catch-all, to // a series of let statements mapping each self_arg to an int // value corresponding to its discriminant. - let vi_idents: Vec = self_arg_names.iter() + let vi_idents = self_arg_names.iter() .map(|name| { let vi_suffix = format!("{}_vi", &name[..]); cx.ident_of(&vi_suffix[..]).gensym() From 2f7b95d932f9bac550e076920b7fab1e1021bd16 Mon Sep 17 00:00:00 2001 From: cynecx Date: Tue, 13 Nov 2018 17:23:30 +0100 Subject: [PATCH 16/33] Change sidebar selector to fix compatibility with docs.rs --- src/librustdoc/html/static/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 1ae3b0b88c6dd..fb599c8518957 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -956,7 +956,7 @@ span.since { padding-top: 0px; } - body > .sidebar { + .rustdoc > .sidebar { height: 45px; min-height: 40px; margin: 0; From 58a2267c15d7214e8ef9548ce95f2aad4502fbd2 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 13 Nov 2018 15:50:31 +0100 Subject: [PATCH 17/33] hir: remove an unused hir_vec macro pattern --- src/librustc/hir/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index f57e3ff913b38..dda94bd26bed1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -58,7 +58,6 @@ macro_rules! hir_vec { ($($x:expr),*) => ( $crate::hir::HirVec::from(vec![$($x),*]) ); - ($($x:expr,)*) => (hir_vec![$($x),*]) } pub mod check_attr; From 5ea0e0d1aa47924ba60d21164b3612fb79716eb3 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 13 Nov 2018 16:15:16 +0100 Subject: [PATCH 18/33] hir: simplify fmt::Debug for hir::Path --- src/librustc/hir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index dda94bd26bed1..2dd2deee26165 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -330,7 +330,7 @@ impl Path { impl fmt::Debug for Path { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "path({})", print::to_string(print::NO_ANN, |s| s.print_path(self, false))) + write!(f, "path({})", self) } } From 3d919297b9febda29b649d1862d39a96a4448812 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 13 Nov 2018 16:24:14 +0100 Subject: [PATCH 19/33] hir: remove an unused type alias --- src/librustc/hir/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 2dd2deee26165..595655589639d 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -27,7 +27,7 @@ use syntax_pos::{Span, DUMMY_SP, symbol::InternedString}; use syntax::source_map::{self, Spanned}; use rustc_target::spec::abi::Abi; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect}; -use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem}; +use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy}; use syntax::attr::InlineAttr; use syntax::ext::hygiene::SyntaxContext; use syntax::ptr::P; @@ -697,8 +697,6 @@ pub struct WhereEqPredicate { pub rhs_ty: P, } -pub type CrateConfig = HirVec>; - /// The top-level data structure that stores the entire contents of /// the crate currently being compiled. /// From cf4f5c3b349d994bb2024c700956f043fc913fe6 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 13 Nov 2018 17:23:18 +0100 Subject: [PATCH 20/33] hir: simplify a match expression --- src/librustc/hir/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 595655589639d..af67f8cec8ca8 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1193,8 +1193,8 @@ impl StmtKind { pub fn id(&self) -> NodeId { match *self { - StmtKind::Decl(_, id) => id, - StmtKind::Expr(_, id) => id, + StmtKind::Decl(_, id) | + StmtKind::Expr(_, id) | StmtKind::Semi(_, id) => id, } } From 4e35cbb22eceac145a6f794cde869b3684e0b1d5 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Mon, 12 Nov 2018 13:05:20 -0500 Subject: [PATCH 21/33] fix various typos in doc comments --- src/liballoc/collections/btree/node.rs | 2 +- src/liballoc/raw_vec.rs | 2 +- src/libcore/num/f32.rs | 2 +- src/libcore/task/wake.rs | 2 +- src/libproc_macro/lib.rs | 12 ++++++------ src/librustc/dep_graph/cgu_reuse_tracker.rs | 2 +- src/librustc/hir/def.rs | 2 +- src/librustc/infer/canonical/canonicalizer.rs | 2 +- src/librustc/infer/canonical/query_response.rs | 2 +- src/librustc/infer/canonical/substitute.rs | 2 +- .../nice_region_error/outlives_closure.rs | 2 +- src/librustc/infer/higher_ranked/mod.rs | 2 +- src/librustc/infer/mod.rs | 6 +++--- src/librustc/infer/type_variable.rs | 2 +- src/librustc/lint/levels.rs | 2 +- src/librustc/session/config.rs | 12 ++++++------ src/librustc/traits/query/dropck_outlives.rs | 2 +- src/librustc/ty/fold.rs | 4 ++-- src/librustc/ty/layout.rs | 2 +- src/librustc/ty/mod.rs | 2 +- src/librustc_codegen_llvm/base.rs | 2 +- src/librustc_codegen_llvm/llvm_util.rs | 2 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_data_structures/graph/scc/mod.rs | 2 +- src/librustc_data_structures/owning_ref/mod.rs | 4 ++-- src/librustc_data_structures/sorted_map.rs | 2 +- src/librustc_driver/lib.rs | 4 ++-- src/librustc_incremental/persist/dirty_clean.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_mir/borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/borrow_check/places_conflict.rs | 2 +- src/librustc_mir/build/matches/test.rs | 2 +- src/librustc_mir/hair/mod.rs | 2 +- src/librustc_mir/hair/pattern/_match.rs | 6 +++--- src/librustc_mir/interpret/validity.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustdoc/config.rs | 2 +- src/libstd/alloc.rs | 2 +- src/libstd/collections/hash/map.rs | 2 +- src/libstd/keyword_docs.rs | 2 +- src/libstd/net/ip.rs | 2 +- src/libstd/process.rs | 4 ++-- src/libstd/sys/redox/fd.rs | 2 +- src/libstd/sys/redox/syscall/call.rs | 4 ++-- src/libstd/sys/unix/fd.rs | 2 +- src/libstd/thread/mod.rs | 2 +- src/libsyntax/tokenstream.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- 49 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index deca9591fbd5c..f9b455fe796d1 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -69,7 +69,7 @@ struct LeafNode { /// This node's index into the parent node's `edges` array. /// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`. - /// This is only guaranteed to be initialized when `parent` is nonnull. + /// This is only guaranteed to be initialized when `parent` is non-null. parent_idx: MaybeUninit, /// The number of keys and values this node stores. diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 837770feecef5..e87bf78561c61 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -44,7 +44,7 @@ use boxed::Box; /// This enables you to use capacity growing logic catch the overflows in your length /// that might occur with zero-sized types. /// -/// However this means that you need to be careful when roundtripping this type +/// However this means that you need to be careful when round-tripping this type /// with a `Box<[T]>`: `cap()` won't yield the len. However `with_capacity`, /// `shrink_to_fit`, and `from_box` will actually set RawVec's private capacity /// field. This allows zero-sized types to not be special-cased by consumers of diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 577c823f9a060..d6c3996971a58 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -445,7 +445,7 @@ impl f32 { /// signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa. /// /// Rather than trying to preserve signaling-ness cross-platform, this - /// implementation favours preserving the exact bits. This means that + /// implementation favors preserving the exact bits. This means that /// any payloads encoded in NaNs will be preserved even if the result of /// this method is sent over the network from an x86 machine to a MIPS one. /// diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index c9fb22e0080dd..c0ce7255d6287 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -108,7 +108,7 @@ impl Drop for Waker { /// is ready to be run. /// /// This is similar to the `Waker` type, but cannot be sent across threads. -/// Task executors can use this type to implement more optimized singlethreaded wakeup +/// Task executors can use this type to implement more optimized single-threaded wakeup /// behavior. #[repr(transparent)] #[derive(Clone)] diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 1a2b16a4fed06..60b6a8bac41d3 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -535,7 +535,7 @@ impl TokenTree { } } -/// Prints token treee in a form convenient for debugging. +/// Prints token tree in a form convenient for debugging. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl fmt::Debug for TokenTree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -730,7 +730,7 @@ impl fmt::Debug for Group { /// An `Punct` is an single punctuation character like `+`, `-` or `#`. /// -/// Multicharacter operators like `+=` are represented as two instances of `Punct` with different +/// Multi-character operators like `+=` are represented as two instances of `Punct` with different /// forms of `Spacing` returned. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] #[derive(Clone)] @@ -788,7 +788,7 @@ impl Punct { /// Returns the spacing of this punctuation character, indicating whether it's immediately /// followed by another `Punct` in the token stream, so they can potentially be combined into - /// a multicharacter operator (`Joint`), or it's followed by some other token or whitespace + /// a multi-character operator (`Joint`), or it's followed by some other token or whitespace /// (`Alone`) so the operator has certainly ended. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn spacing(&self) -> Spacing { @@ -947,7 +947,7 @@ macro_rules! suffixed_int_literals { /// This function will create an integer like `1u32` where the integer /// value specified is the first part of the token and the integral is /// also suffixed at the end. - /// Literals created from negative numbers may not survive rountrips through + /// Literals created from negative numbers may not survive round-trips through /// `TokenStream` or strings and may be broken into two tokens (`-` and positive literal). /// /// Literals created through this method have the `Span::call_site()` @@ -1047,7 +1047,7 @@ impl Literal { /// Creates a new suffixed floating-point literal. /// - /// This consturctor will create a literal like `1.0f32` where the value + /// This constructor will create a literal like `1.0f32` where the value /// specified is the preceding part of the token and `f32` is the suffix of /// the token. This token will always be inferred to be an `f32` in the /// compiler. @@ -1096,7 +1096,7 @@ impl Literal { /// Creates a new suffixed floating-point literal. /// - /// This consturctor will create a literal like `1.0f64` where the value + /// This constructor will create a literal like `1.0f64` where the value /// specified is the preceding part of the token and `f64` is the suffix of /// the token. This token will always be inferred to be an `f64` in the /// compiler. diff --git a/src/librustc/dep_graph/cgu_reuse_tracker.rs b/src/librustc/dep_graph/cgu_reuse_tracker.rs index 99fc020bbe44f..0392d32989697 100644 --- a/src/librustc/dep_graph/cgu_reuse_tracker.rs +++ b/src/librustc/dep_graph/cgu_reuse_tracker.rs @@ -9,7 +9,7 @@ // except according to those terms. //! Some facilities for tracking how codegen-units are reused during incremental -//! compilition. This is used for incremental compiliation tests and debug +//! compilation. This is used for incremental compilation tests and debug //! output. use session::Session; diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 5d9d4deb0abc9..e4c434b562ddc 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -36,7 +36,7 @@ pub enum NonMacroAttrKind { Tool, /// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`). DeriveHelper, - /// Single-segment custom attriubte registered by a legacy plugin (`register_attribute`). + /// Single-segment custom attribute registered by a legacy plugin (`register_attribute`). LegacyPluginHelper, /// Single-segment custom attribute not registered in any way (`#[my_attr]`). Custom, diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index 61a861a8a1cd8..a787eeae663fd 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -10,7 +10,7 @@ //! This module contains the "canonicalizer" itself. //! -//! For an overview of what canonicaliation is and how it fits into +//! For an overview of what canonicalization is and how it fits into //! rustc, check out the [chapter in the rustc guide][c]. //! //! [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index f4607f7a9092f..6f3d10268351a 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -556,7 +556,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { } /// Given two sets of values for the same set of canonical variables, unify them. - /// The second set is produced lazilly by supplying indices from the first set. + /// The second set is produced lazily by supplying indices from the first set. fn unify_canonical_vars( &self, cause: &ObligationCause<'tcx>, diff --git a/src/librustc/infer/canonical/substitute.rs b/src/librustc/infer/canonical/substitute.rs index b8c1ed236c0ba..0b4d863bf4d1a 100644 --- a/src/librustc/infer/canonical/substitute.rs +++ b/src/librustc/infer/canonical/substitute.rs @@ -11,7 +11,7 @@ //! This module contains code to substitute new values into a //! `Canonical<'tcx, T>`. //! -//! For an overview of what canonicaliation is and how it fits into +//! For an overview of what canonicalization is and how it fits into //! rustc, check out the [chapter in the rustc guide][c]. //! //! [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs index 009a823568131..7a92b3084ba9f 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -20,7 +20,7 @@ use util::common::ErrorReported; use infer::lexical_region_resolve::RegionResolutionError::SubSupConflict; impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { - /// Print the error message for lifetime errors when binding excapes a closure. + /// Print the error message for lifetime errors when binding escapes a closure. /// /// Consider a case where we have /// diff --git a/src/librustc/infer/higher_ranked/mod.rs b/src/librustc/infer/higher_ranked/mod.rs index 3e08a4e021aed..877ca0d067be7 100644 --- a/src/librustc/infer/higher_ranked/mod.rs +++ b/src/librustc/infer/higher_ranked/mod.rs @@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// /// This routine is only intended to be used when the leak-check has /// passed; currently, it's used in the trait matching code to create - /// a set of nested obligations frmo an impl that matches against + /// a set of nested obligations from an impl that matches against /// something higher-ranked. More details can be found in /// `librustc/middle/traits/README.md`. /// diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index f5513acecf9e7..0453615f1646a 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1160,10 +1160,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } /// Takes ownership of the list of variable regions. This implies - /// that all the region constriants have already been taken, and + /// that all the region constraints have already been taken, and /// hence that `resolve_regions_and_report_errors` can never be /// called. This is used only during NLL processing to "hand off" ownership - /// of the set of region vairables into the NLL region context. + /// of the set of region variables into the NLL region context. pub fn take_region_var_origins(&self) -> VarInfos { let (var_infos, data) = self.region_constraints .borrow_mut() @@ -1478,7 +1478,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } /// Clears the selection, evaluation, and projection caches. This is useful when - /// repeatedly attemping to select an Obligation while changing only + /// repeatedly attempting to select an Obligation while changing only /// its ParamEnv, since FulfillmentContext doesn't use 'probe' pub fn clear_caches(&self) { self.selection_cache.clear(); diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 39bf59a7a4ec5..bec19ba9099dc 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -320,7 +320,7 @@ impl<'tcx> TypeVariableTable<'tcx> { /// but which have only been unified since `s` started, and /// return the types with which they were unified. So if we had /// a type variable `V0`, then we started the snapshot, then we - /// created a type variable `V1`, unifed `V0` with `T0`, and + /// created a type variable `V1`, unified `V0` with `T0`, and /// unified `V1` with `T1`, this function would return `{T0}`. pub fn types_escaping_snapshot(&mut self, s: &Snapshot<'tcx>) -> Vec> { let mut new_elem_threshold = u32::MAX; diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 732b32cc35d68..cfb9f04c4c6d1 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -189,7 +189,7 @@ impl<'a> LintLevelsBuilder<'a> { /// This function will perform a number of tasks: /// /// * It'll validate all lint-related attributes in `attrs` - /// * It'll mark all lint-related attriutes as used + /// * It'll mark all lint-related attributes as used /// * Lint levels will be updated based on the attributes provided /// * Lint attributes are validated, e.g. a #[forbid] can't be switched to /// #[allow] diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 78aabf86e300d..ee6d970750adf 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -224,7 +224,7 @@ impl Default for ErrorOutputType { // Use tree-based collections to cheaply get a deterministic Hash implementation. // DO NOT switch BTreeMap out for an unsorted container type! That would break -// dependency tracking for commandline arguments. +// dependency tracking for command-line arguments. #[derive(Clone, Hash)] pub struct OutputTypes(BTreeMap>); @@ -273,7 +273,7 @@ impl OutputTypes { // Use tree-based collections to cheaply get a deterministic Hash implementation. // DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That -// would break dependency tracking for commandline arguments. +// would break dependency tracking for command-line arguments. #[derive(Clone, Hash)] pub struct Externs(BTreeMap>>); @@ -339,7 +339,7 @@ macro_rules! top_level_options { ); } -// The top-level commandline options struct +// The top-level command-line options struct // // For each option, one has to specify how it behaves with regard to the // dependency tracking system of incremental compilation. This is done via the @@ -2377,11 +2377,11 @@ impl fmt::Display for CrateType { } } -/// Commandline arguments passed to the compiler have to be incorporated with +/// Command-line arguments passed to the compiler have to be incorporated with /// the dependency tracking system for incremental compilation. This module /// provides some utilities to make this more convenient. /// -/// The values of all commandline arguments that are relevant for dependency +/// The values of all command-line arguments that are relevant for dependency /// tracking are hashed into a single value that determines whether the /// incremental compilation cache can be re-used or not. This hashing is done /// via the DepTrackingHash trait defined below, since the standard Hash @@ -2394,7 +2394,7 @@ impl fmt::Display for CrateType { /// impl_dep_tracking_hash_via_hash!() macro that allows to simply reuse the /// Hash implementation for DepTrackingHash. It's important though that /// we have an opt-in scheme here, so one is hopefully forced to think about -/// how the hash should be calculated when adding a new commandline argument. +/// how the hash should be calculated when adding a new command-line argument. mod dep_tracking { use lint; use middle::cstore; diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 62317f074764f..99dc099d57738 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -200,7 +200,7 @@ impl_stable_hash_for!(struct DtorckConstraint<'tcx> { /// trivial for dropck-outlives. /// /// Note also that `needs_drop` requires a "global" type (i.e., one -/// with erased regions), but this funtcion does not. +/// with erased regions), but this function does not. pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { match ty.sty { // None of these types have a destructor and hence they do not diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index ffa4380a5d63c..ad1bf63c1d5cf 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -783,7 +783,7 @@ pub fn shift_vars<'a, 'gcx, 'tcx, T>( /// /// Note that what I'm calling an "escaping var" is often just called a "free var". However, /// we already use the term "free var". It refers to the regions or types that we use to represent -/// bound regions or type params on a fn definition while we are typechecking its body. +/// bound regions or type params on a fn definition while we are type checking its body. /// /// To clarify, conceptually there is no particular difference between /// an "escaping" var and a "free" var. However, there is a big @@ -859,7 +859,7 @@ struct LateBoundRegionsCollector { /// If true, we only want regions that are known to be /// "constrained" when you equate this type with another type. In - /// partcular, if you have e.g. `&'a u32` and `&'b u32`, equating + /// particular, if you have e.g. `&'a u32` and `&'b u32`, equating /// them constraints `'a == 'b`. But if you have `<&'a u32 as /// Trait>::Foo` and `<&'b u32 as Trait>::Foo`, normalizing those /// types may mean that `'a` and `'b` don't appear in the results, diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 5aeba652f3228..fde208b3faf3f 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1279,7 +1279,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { /// Type size "skeleton", i.e. the only information determining a type's size. /// While this is conservative, (aside from constant sizes, only pointers, /// newtypes thereof and null pointer optimized enums are allowed), it is -/// enough to statically check common usecases of transmute. +/// enough to statically check common use cases of transmute. #[derive(Copy, Clone, Debug)] pub enum SizeSkeleton<'tcx> { /// Any statically computable Layout. diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 9a63bb374c66d..a6197150f25f6 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2394,7 +2394,7 @@ impl<'a, 'gcx, 'tcx> FieldDef { /// Represents the various closure traits in the Rust language. This /// will determine the type of the environment (`self`, in the -/// desuaring) argument that the closure expects. +/// desugaring) argument that the closure expects. /// /// You can get the environment type of a closure using /// `tcx.closure_env_ty()`. diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 806025937cb11..aedc14cd85c1a 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -941,7 +941,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// /// In the process of working on rust-lang/rust#55238 a mysterious segfault was /// stumbled upon. The segfault was never reproduced locally, but it was -/// suspected to be releated to the fact that codegen worker threads were +/// suspected to be related to the fact that codegen worker threads were /// sticking around by the time the main thread was exiting, causing issues. /// /// This structure is an attempt to fix that issue where the `codegen_aborted` diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index eaa599e0cd0fa..267d7e0d54b63 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -184,7 +184,7 @@ const WASM_WHITELIST: &[(&str, Option<&str>)] = &[ ]; /// When rustdoc is running, provide a list of all known features so that all their respective -/// primtives may be documented. +/// primitives may be documented. /// /// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this /// iterator! diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 0d95b0c7bbc0c..f8593363bb16a 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -79,7 +79,7 @@ //! - In order to be able to also use symbols from two versions of the same //! crate (which naturally also have the same name), a stronger measure is //! required: The compiler accepts an arbitrary "disambiguator" value via the -//! `-C metadata` commandline argument. This disambiguator is then fed into +//! `-C metadata` command-line argument. This disambiguator is then fed into //! the symbol hash of every exported item. Consequently, the symbols in two //! identical crates but with different disambiguators are not in conflict //! with each other. This facility is mainly intended to be used by build diff --git a/src/librustc_data_structures/graph/scc/mod.rs b/src/librustc_data_structures/graph/scc/mod.rs index a989a54010222..64de0c2f565a1 100644 --- a/src/librustc_data_structures/graph/scc/mod.rs +++ b/src/librustc_data_structures/graph/scc/mod.rs @@ -38,7 +38,7 @@ struct SccData { /// successors can be found. ranges: IndexVec>, - /// Contains the succcessors for all the Sccs, concatenated. The + /// Contains the successors for all the Sccs, concatenated. The /// range of indices corresponding to a given SCC is found in its /// SccData. all_successors: Vec, diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index 02640a71010e2..27c2f8b718ab8 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -452,7 +452,7 @@ impl OwningRef { /// use owning_ref::{OwningRef, Erased}; /// /// fn main() { - /// // NB: Using the concrete types here for explicitnes. + /// // NB: Using the concrete types here for explicitness. /// // For less verbose code type aliases like `BoxRef` are provided. /// /// let owning_ref_a: OwningRef, [i32; 4]> @@ -722,7 +722,7 @@ impl OwningRefMut { /// use owning_ref::{OwningRefMut, Erased}; /// /// fn main() { - /// // NB: Using the concrete types here for explicitnes. + /// // NB: Using the concrete types here for explicitness. /// // For less verbose code type aliases like `BoxRef` are provided. /// /// let owning_ref_mut_a: OwningRefMut, [i32; 4]> diff --git a/src/librustc_data_structures/sorted_map.rs b/src/librustc_data_structures/sorted_map.rs index 730b13a0584fc..29d99a6aef3f2 100644 --- a/src/librustc_data_structures/sorted_map.rs +++ b/src/librustc_data_structures/sorted_map.rs @@ -15,7 +15,7 @@ use std::mem; use std::ops::{RangeBounds, Bound, Index, IndexMut}; /// `SortedMap` is a data structure with similar characteristics as BTreeMap but -/// slightly different trade-offs: lookup, inseration, and removal are O(log(N)) +/// slightly different trade-offs: lookup, insertion, and removal are O(log(N)) /// and elements can be iterated in order cheaply. /// /// `SortedMap` can be faster than a `BTreeMap` for small sizes (<50) since it diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 6c7982242bfad..ec3cb95db88f8 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -643,8 +643,8 @@ impl Compilation { } } -/// A trait for customising the compilation process. Offers a number of hooks for -/// executing custom code or customising input. +/// A trait for customizing the compilation process. Offers a number of hooks for +/// executing custom code or customizing input. pub trait CompilerCalls<'a> { /// Hook for a callback early in the process of handling arguments. This will /// be called straight after options have been parsed but before anything diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index 58a799bb45f2d..f76086139ed7e 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -160,7 +160,7 @@ const LABELS_FN_IN_TRAIT: &[&[&str]] = &[ EXTRA_TRAIT, ]; -/// For generic cases like inline-assemply/mod/etc +/// For generic cases like inline-assembly/mod/etc const LABELS_HIR_ONLY: &[&[&str]] = &[ BASE_HIR, ]; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2a9b58200e5d6..a327efc512bac 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1486,7 +1486,7 @@ declare_lint! { "detects edition keywords being used as an identifier" } -/// Checks for uses of edtion keywords used as an identifier +/// Checks for uses of edition keywords used as an identifier #[derive(Clone)] pub struct KeywordIdents; diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index a057f2f45c010..b318e73e26fa1 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -111,7 +111,7 @@ mod relate_tys; /// - `liveness` -- results of a liveness computation on the MIR; used to create liveness /// constraints for the regions in the types of variables /// - `flow_inits` -- results of a maybe-init dataflow analysis -/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysiss +/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis pub(crate) fn type_check<'gcx, 'tcx>( infcx: &InferCtxt<'_, 'gcx, 'tcx>, param_env: ty::ParamEnv<'gcx>, diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index c0f059619a497..715d6e0c0d1b3 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -262,7 +262,7 @@ struct PlaceComponents<'p, 'tcx: 'p> { impl<'p, 'tcx> PlaceComponents<'p, 'tcx> { /// Converts a list of `Place` components into an iterator; this /// iterator yields up a never-ending stream of `Option<&Place>`. - /// These begin with the "innermst" place and then with each + /// These begin with the "innermost" place and then with each /// projection therefrom. So given a place like `a.b.c` it would /// yield up: /// diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 9e6f32909bdea..1f510a17df220 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -30,7 +30,7 @@ use std::cmp::Ordering; impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// Identifies what test is needed to decide if `match_pair` is applicable. /// - /// It is a bug to call this with a simplifyable pattern. + /// It is a bug to call this with a simplifiable pattern. pub fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> { match *match_pair.pattern.kind { PatternKind::Variant { ref adt_def, substs: _, variant_index: _, subpatterns: _ } => { diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 8a24851de8149..d768601a33acd 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -115,7 +115,7 @@ pub enum StmtKind<'tcx> { /// reference to an expression in this enum is an `ExprRef<'tcx>`, which /// may in turn be another instance of this enum (boxed), or else an /// unlowered `&'tcx H::Expr`. Note that instances of `Expr` are very -/// shortlived. They are created by `Hair::to_expr`, analyzed and +/// short-lived. They are created by `Hair::to_expr`, analyzed and /// converted into MIR, and then discarded. /// /// If you compare `Expr` to the full compiler AST, you will see it is diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 69ca21c56242f..bf2058dcd27aa 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -55,11 +55,11 @@ /// all the values it covers are already covered by row 2. /// /// To compute `U`, we must have two other concepts. -/// 1. `S(c, P)` is a "specialised matrix", where `c` is a constructor (like `Some` or +/// 1. `S(c, P)` is a "specialized matrix", where `c` is a constructor (like `Some` or /// `None`). You can think of it as filtering `P` to just the rows whose *first* pattern /// can cover `c` (and expanding OR-patterns into distinct patterns), and then expanding /// the constructor into all of its components. -/// The specialisation of a row vector is computed by `specialize`. +/// The specialization of a row vector is computed by `specialize`. /// /// It is computed as follows. For each row `p_i` of P, we have four cases: /// 1.1. `p_(i,1) = c(r_1, .., r_a)`. Then `S(c, P)` has a corresponding row: @@ -1453,7 +1453,7 @@ fn should_treat_range_exhaustively(tcx: TyCtxt<'_, 'tcx, 'tcx>, ctor: &Construct /// mean creating a separate constructor for every single value in the range, which is clearly /// impractical. However, observe that for some ranges of integers, the specialisation will be /// identical across all values in that range (i.e. there are equivalence classes of ranges of -/// constructors based on their `is_useful_specialised` outcome). These classes are grouped by +/// constructors based on their `is_useful_specialized` outcome). These classes are grouped by /// the patterns that apply to them (in the matrix `P`). We can split the range whenever the /// patterns that apply to that range (specifically: the patterns that *intersect* with that range) /// change. diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 84aa5b6756660..8f267af654b07 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -67,7 +67,7 @@ macro_rules! try_validation { }} } -/// We want to show a nice path to the invalid field for diagnotsics, +/// We want to show a nice path to the invalid field for diagnostics, /// but avoid string operations in the happy case where no error happens. /// So we track a `Vec` where `PathElem` contains all the data we /// need to later print something for the user. diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index ca58239df8eac..a90cccfa7a774 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -172,7 +172,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { /// While the `ExprUseVisitor` walks, we will identify which /// expressions are borrowed, and insert their ids into this /// table. Actually, we insert the "borrow-id", which is normally - /// the id of the expession being borrowed: but in the case of + /// the id of the expression being borrowed: but in the case of /// `ref mut` borrows, the `id` of the pattern is /// inserted. Therefore later we remove that entry from the table /// and transfer it over to the value being matched. This will diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 305efd0d75af6..2f9f29adcc1a3 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1437,7 +1437,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { /// /// 1. Because the numbers of the region variables would otherwise be fairly unique to this /// particular method call, it winds up creating fewer types overall, which helps for memory - /// usage. (Admittedly, this is a rather small effect, though measureable.) + /// usage. (Admittedly, this is a rather small effect, though measurable.) /// /// 2. It makes it easier to deal with higher-ranked trait bounds, because we can replace any /// late-bound regions with 'static. Otherwise, if we were going to replace late-bound diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 7dafe67485a6e..f4d05c6dbd65c 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -187,7 +187,7 @@ pub struct RenderOptions { /// Whether to generate a table of contents on the output file when reading a standalone /// Markdown file. pub markdown_no_toc: bool, - /// Additional CSS files to link in pages generated from standlone Markdown files. + /// Additional CSS files to link in pages generated from standalone Markdown files. pub markdown_css: Vec, /// If present, playground URL to use in the "Run" button added to code samples generated from /// standalone Markdown files. If not present, `playground_url` is used. diff --git a/src/libstd/alloc.rs b/src/libstd/alloc.rs index 485b2ffe1975e..100ec8535c841 100644 --- a/src/libstd/alloc.rs +++ b/src/libstd/alloc.rs @@ -85,7 +85,7 @@ pub use alloc_crate::alloc::*; /// This is based on `malloc` on Unix platforms and `HeapAlloc` on Windows, /// plus related functions. /// -/// This type implements the `GlobalAlloc` trait and Rust programs by deafult +/// This type implements the `GlobalAlloc` trait and Rust programs by default /// work as if they had this definition: /// /// ```rust diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8de415e8aed5c..bb2f152edc63d 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1569,7 +1569,7 @@ impl HashMap /// where the key should go, meaning the keys may become "lost" if their /// location does not reflect their state. For instance, if you change a key /// so that the map now contains keys which compare equal, search may start - /// acting eratically, with two keys randomly masking eachother. Implementations + /// acting erratically, with two keys randomly masking each other. Implementations /// are free to assume this doesn't happen (within the limits of memory-safety). #[unstable(feature = "hash_raw_entry", issue = "54043")] pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut { diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index 6c95854c66cbf..13cf3133dcd12 100644 --- a/src/libstd/keyword_docs.rs +++ b/src/libstd/keyword_docs.rs @@ -615,7 +615,7 @@ mod loop_keyword { } // /// The keyword used to define structs. /// -/// Structs in Rust come in three flavours: Structs with named fields, tuple structs, and unit +/// Structs in Rust come in three flavors: Structs with named fields, tuple structs, and unit /// structs. /// /// ```rust diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index d45a66ef66532..e5838b954ed49 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -852,7 +852,7 @@ impl From<[u8; 4]> for IpAddr { impl Ipv6Addr { /// Creates a new IPv6 address from eight 16-bit segments. /// - /// The result will represent the IP address a:b:c:d:e:f:g:h. + /// The result will represent the IP address `a:b:c:d:e:f:g:h`. /// /// # Examples /// diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a9219f75362db..437153b56e49b 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1119,7 +1119,7 @@ impl From for Stdio { /// let file = File::open("foo.txt").unwrap(); /// /// let reverse = Command::new("rev") - /// .stdin(file) // Implicit File convertion into a Stdio + /// .stdin(file) // Implicit File conversion into a Stdio /// .output() /// .expect("failed reverse command"); /// @@ -1337,7 +1337,7 @@ impl Child { /// Attempts to collect the exit status of the child if it has already /// exited. /// - /// This function will not block the calling thread and will only advisorily + /// This function will not block the calling thread and will only /// check to see if the child process has exited or not. If the child has /// exited then on Unix the process id is reaped. This function is /// guaranteed to repeatedly return a successful exit status so long as the diff --git a/src/libstd/sys/redox/fd.rs b/src/libstd/sys/redox/fd.rs index d61103a872f9e..d62b09134bbf1 100644 --- a/src/libstd/sys/redox/fd.rs +++ b/src/libstd/sys/redox/fd.rs @@ -26,7 +26,7 @@ impl FileDesc { pub fn raw(&self) -> usize { self.fd } - /// Extracts the actual filedescriptor without closing it. + /// Extracts the actual file descriptor without closing it. pub fn into_raw(self) -> usize { let fd = self.fd; mem::forget(self); diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs index f9a8bd61ac800..246a86c29ece4 100644 --- a/src/libstd/sys/redox/syscall/call.rs +++ b/src/libstd/sys/redox/syscall/call.rs @@ -45,7 +45,7 @@ pub unsafe fn brk(addr: usize) -> Result { /// # Errors /// /// * `EACCES` - permission is denied for one of the components of `path`, or `path` -/// * `EFAULT` - `path` does not point to the process's addressible memory +/// * `EFAULT` - `path` does not point to the process's addressable memory /// * `EIO` - an I/O error occurred /// * `ENOENT` - `path` does not exit /// * `ENOTDIR` - `path` is not a directory @@ -347,7 +347,7 @@ pub fn waitpid(pid: usize, status: &mut usize, options: usize) -> Result /// /// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block /// * `EBADF` - the file descriptor is not valid or is not open for writing -/// * `EFAULT` - `buf` does not point to the process's addressible memory +/// * `EFAULT` - `buf` does not point to the process's addressable memory /// * `EIO` - an I/O error occurred /// * `ENOSPC` - the device containing the file descriptor has no room for data /// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index af33d2636fb1f..5a81d6dfb672e 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -46,7 +46,7 @@ impl FileDesc { pub fn raw(&self) -> c_int { self.fd } - /// Extracts the actual filedescriptor without closing it. + /// Extracts the actual file descriptor without closing it. pub fn into_raw(self) -> c_int { let fd = self.fd; mem::forget(self); diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index a57b8dc723767..8a845efd41362 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -233,7 +233,7 @@ pub use self::local::{LocalKey, AccessError}; /// /// You may want to use [`spawn`] instead of [`thread::spawn`], when you want /// to recover from a failure to launch a thread, indeed the free function will -/// panick where the `Builder` method will return a [`io::Result`]. +/// panic where the `Builder` method will return a [`io::Result`]. /// /// # Examples /// diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 29bd63d28c5ec..cfdd4340a19fe 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -150,7 +150,7 @@ impl TokenTree { } } - /// Modify the `TokenTree`'s span inplace. + /// Modify the `TokenTree`'s span in-place. pub fn set_span(&mut self, span: Span) { match *self { TokenTree::Token(ref mut sp, _) => *sp = span, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index dd90ef06c3929..2f6b306e8f8ba 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -68,7 +68,7 @@ //! The `i32`s in `B` and `C0` don't have an identifier, so the //! `Option`s would be `None` for them. //! -//! In the static cases, the structure is summarised, either into the just +//! In the static cases, the structure is summarized, either into the just //! spans of the fields or a list of spans and the field idents (for tuple //! structs and record structs, respectively), or a list of these, for //! enums (one for each variant). For empty struct and empty enum From 98f61a3195663465bc2f65287fbcbe14761fe6a8 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 13 Nov 2018 18:03:06 +0100 Subject: [PATCH 22/33] core/benches: Add `char::to_digit()` benchmarks --- src/libcore/benches/char/methods.rs | 42 +++++++++++++++++++++++++++++ src/libcore/benches/char/mod.rs | 11 ++++++++ src/libcore/benches/lib.rs | 1 + 3 files changed, 54 insertions(+) create mode 100644 src/libcore/benches/char/methods.rs create mode 100644 src/libcore/benches/char/mod.rs diff --git a/src/libcore/benches/char/methods.rs b/src/libcore/benches/char/methods.rs new file mode 100644 index 0000000000000..faf820d871cfa --- /dev/null +++ b/src/libcore/benches/char/methods.rs @@ -0,0 +1,42 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use test::Bencher; + +const CHARS: [char; 9] = ['0', 'x', '2', '5', 'A', 'f', '7', '8', '9']; +const RADIX: [u32; 5] = [2, 8, 10, 16, 32]; + +#[bench] +fn bench_to_digit_radix_2(b: &mut Bencher) { + b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(2)).min()) +} + +#[bench] +fn bench_to_digit_radix_10(b: &mut Bencher) { + b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(10)).min()) +} + +#[bench] +fn bench_to_digit_radix_16(b: &mut Bencher) { + b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(16)).min()) +} + +#[bench] +fn bench_to_digit_radix_36(b: &mut Bencher) { + b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(36)).min()) +} + +#[bench] +fn bench_to_digit_radix_var(b: &mut Bencher) { + b.iter(|| CHARS.iter().cycle() + .zip(RADIX.iter().cycle()) + .take(10_000) + .map(|(c, radix)| c.to_digit(*radix)).min()) +} diff --git a/src/libcore/benches/char/mod.rs b/src/libcore/benches/char/mod.rs new file mode 100644 index 0000000000000..a656e82cb61e6 --- /dev/null +++ b/src/libcore/benches/char/mod.rs @@ -0,0 +1,11 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod methods; diff --git a/src/libcore/benches/lib.rs b/src/libcore/benches/lib.rs index ced77d779182a..d44f1577d56b0 100644 --- a/src/libcore/benches/lib.rs +++ b/src/libcore/benches/lib.rs @@ -15,6 +15,7 @@ extern crate core; extern crate test; mod any; +mod char; mod hash; mod iter; mod num; From 04aade83f2785d6ca43049ff89026ed930f792f1 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 13 Nov 2018 17:49:38 +0100 Subject: [PATCH 23/33] core/char: Replace condition + `panic!()` with `assert!()` --- src/libcore/char/methods.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 35181afea3da6..fc212aa4f2086 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -121,9 +121,7 @@ impl char { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_digit(self, radix: u32) -> Option { - if radix > 36 { - panic!("to_digit: radix is too high (maximum 36)"); - } + assert!(radix <= 36, "to_digit: radix is too high (maximum 36)"); let val = match self { '0' ..= '9' => self as u32 - '0' as u32, 'a' ..= 'z' => self as u32 - 'a' as u32 + 10, From 17f08fecfd81479e04fc5ea7590cecdb429c7ce3 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 13 Nov 2018 18:05:46 +0100 Subject: [PATCH 24/33] core/char: Speed up `to_digit()` for `radix <= 10` ### Before ``` # Run 1 test char::methods::bench_to_digit_radix_10 ... bench: 16,265 ns/iter (+/- 1,774) test char::methods::bench_to_digit_radix_16 ... bench: 13,938 ns/iter (+/- 2,479) test char::methods::bench_to_digit_radix_2 ... bench: 13,090 ns/iter (+/- 524) test char::methods::bench_to_digit_radix_36 ... bench: 14,236 ns/iter (+/- 1,949) # Run 2 test char::methods::bench_to_digit_radix_10 ... bench: 16,176 ns/iter (+/- 1,589) test char::methods::bench_to_digit_radix_16 ... bench: 13,896 ns/iter (+/- 3,140) test char::methods::bench_to_digit_radix_2 ... bench: 13,158 ns/iter (+/- 1,112) test char::methods::bench_to_digit_radix_36 ... bench: 14,206 ns/iter (+/- 1,312) # Run 3 test char::methods::bench_to_digit_radix_10 ... bench: 16,221 ns/iter (+/- 2,423) test char::methods::bench_to_digit_radix_16 ... bench: 14,361 ns/iter (+/- 3,926) test char::methods::bench_to_digit_radix_2 ... bench: 13,097 ns/iter (+/- 671) test char::methods::bench_to_digit_radix_36 ... bench: 14,388 ns/iter (+/- 1,068) ``` ### After ``` # Run 1 test char::methods::bench_to_digit_radix_10 ... bench: 11,521 ns/iter (+/- 552) test char::methods::bench_to_digit_radix_16 ... bench: 12,926 ns/iter (+/- 684) test char::methods::bench_to_digit_radix_2 ... bench: 11,266 ns/iter (+/- 1,085) test char::methods::bench_to_digit_radix_36 ... bench: 14,213 ns/iter (+/- 614) # Run 2 test char::methods::bench_to_digit_radix_10 ... bench: 11,424 ns/iter (+/- 1,042) test char::methods::bench_to_digit_radix_16 ... bench: 12,854 ns/iter (+/- 1,193) test char::methods::bench_to_digit_radix_2 ... bench: 11,193 ns/iter (+/- 716) test char::methods::bench_to_digit_radix_36 ... bench: 14,249 ns/iter (+/- 3,514) # Run 3 test char::methods::bench_to_digit_radix_10 ... bench: 11,469 ns/iter (+/- 685) test char::methods::bench_to_digit_radix_16 ... bench: 12,852 ns/iter (+/- 568) test char::methods::bench_to_digit_radix_2 ... bench: 11,275 ns/iter (+/- 1,356) test char::methods::bench_to_digit_radix_36 ... bench: 14,188 ns/iter (+/- 1,501) ``` --- src/libcore/char/methods.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index fc212aa4f2086..46b201f7bbf2c 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -122,12 +122,27 @@ impl char { #[inline] pub fn to_digit(self, radix: u32) -> Option { assert!(radix <= 36, "to_digit: radix is too high (maximum 36)"); - let val = match self { - '0' ..= '9' => self as u32 - '0' as u32, - 'a' ..= 'z' => self as u32 - 'a' as u32 + 10, - 'A' ..= 'Z' => self as u32 - 'A' as u32 + 10, - _ => return None, + if radix == 10 { + return match self { + '0' ..= '9' => Some(self as u32 - '0' as u32), + _ => None, + }; + } + + let val = if radix < 10 { + match self { + '0' ..= '9' => self as u32 - '0' as u32, + _ => return None, + } + } else { + match self { + '0'..='9' => self as u32 - '0' as u32, + 'a'..='z' => self as u32 - 'a' as u32 + 10, + 'A'..='Z' => self as u32 - 'A' as u32 + 10, + _ => return None, + } }; + if val < radix { Some(val) } else { None } } From 008e5dcbd55cd751717ffd35a51dd65cd40011d4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 13 Nov 2018 13:42:05 -0800 Subject: [PATCH 25/33] appveyor: Use VS2017 for all our images This was [recommended by AppVeyor][1] to see if it has any impact on our build times, hopefully on the beneficial side of things! This shouldn't affect our binary compatibility for generated compilers like it would normally do for Linux. [1]: https://help.appveyor.com/discussions/questions/29832-did-recent-changes-apply-to-possibly-slow-down-builds#comment_46484879 --- appveyor.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 743e615c3f3ca..8cbb9c4e40a14 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,8 @@ environment: - SCCACHE_DIGEST: f808afabb4a4eb1d7112bcb3fa6be03b61e93412890c88e177c667eb37f46353d7ec294e559b16f9f4b5e894f2185fe7670a0df15fd064889ecbd80f0c34166c + # This is required for at least an AArch64 compiler in one image, and is + # otherwise recommended by AppVeyor currently for seeing if it has any + # affect on our job times. + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 Preview # By default schannel checks revocation of certificates unlike some other SSL # backends, but we've historically had problems on CI where a revocation @@ -82,7 +85,6 @@ environment: DIST_REQUIRE_ALL_TOOLS: 1 DEPLOY: 1 CI_JOB_NAME: dist-x86_64-msvc - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 Preview - RUST_CONFIGURE_ARGS: > --build=i686-pc-windows-msvc --target=i586-pc-windows-msvc From 15e7df8b519d9420ada60822ae55c202b013f6a6 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 13 Nov 2018 21:34:44 -0500 Subject: [PATCH 26/33] Remove unneeded newline. --- src/libcore/intrinsics.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index fe2afc59be8f1..99a7beb58f5e4 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -675,7 +675,6 @@ extern "rust-intrinsic" { /// /// The stabilized version of this intrinsic is /// [`std::mem::size_of`](../../std/mem/fn.size_of.html). - pub fn size_of() -> usize; /// Moves a value to an uninitialized memory location. From 547ac5ef0a2c34fb62611bddb4c45f57049f8f64 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 14 Nov 2018 10:56:45 +1300 Subject: [PATCH 27/33] save-analysis: be even more aggressive about ignorning macro-generated defs --- src/librustc_save_analysis/dump_visitor.rs | 12 +++++++----- src/librustc_save_analysis/span_utils.rs | 6 +----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 9bc3fbe7c245a..c65cd6a5ba74d 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -658,11 +658,13 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { impl_items: &'l [ast::ImplItem], ) { if let Some(impl_data) = self.save_ctxt.get_item_data(item) { - if let super::Data::RelationData(rel, imp) = impl_data { - self.dumper.dump_relation(rel); - self.dumper.dump_impl(imp); - } else { - span_bug!(item.span, "unexpected data kind: {:?}", impl_data); + if !self.span.filter_generated(item.span) { + if let super::Data::RelationData(rel, imp) = impl_data { + self.dumper.dump_relation(rel); + self.dumper.dump_impl(imp); + } else { + span_bug!(item.span, "unexpected data kind: {:?}", impl_data); + } } } self.visit_ty(&typ); diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index 902353da13f76..06b4f33b5db3e 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -124,14 +124,10 @@ impl<'a> SpanUtils<'a> { /// Used to filter out spans of minimal value, /// such as references to macro internal variables. pub fn filter_generated(&self, span: Span) -> bool { - if span.is_dummy() { + if generated_code(span) { return true; } - if !generated_code(span) { - return false; - } - //If the span comes from a fake source_file, filter it. !self.sess .source_map() From 818257e70233fbafdb382b940893c9c1d615da22 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 1 Nov 2018 08:59:32 +1100 Subject: [PATCH 28/33] Use `Mmap` to open the rmeta file. Because those files are quite large, contribute significantly to peak memory usage, but only a small fraction of the data is ever read. --- src/Cargo.lock | 2 ++ src/librustc_metadata/Cargo.toml | 4 +++- src/librustc_metadata/lib.rs | 2 ++ src/librustc_metadata/locator.rs | 26 +++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 0c08e35c18df3..64e18899c9d05 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2278,12 +2278,14 @@ version = "0.0.0" dependencies = [ "flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc_macro 0.0.0", "rustc 0.0.0", "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_target 0.0.0", "serialize 0.0.0", + "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_ext 0.0.0", "syntax_pos 0.0.0", diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml index 338824d5efe4c..276e2a911e697 100644 --- a/src/librustc_metadata/Cargo.toml +++ b/src/librustc_metadata/Cargo.toml @@ -11,12 +11,14 @@ crate-type = ["dylib"] [dependencies] flate2 = "1.0" log = "0.4" +memmap = "0.6" proc_macro = { path = "../libproc_macro" } rustc = { path = "../librustc" } -rustc_target = { path = "../librustc_target" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } +rustc_target = { path = "../librustc_target" } serialize = { path = "../libserialize" } +stable_deref_trait = "1.0.0" syntax = { path = "../libsyntax" } syntax_ext = { path = "../libsyntax_ext" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index 0cc0707a3a51f..0322c888ad5c9 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -30,6 +30,8 @@ extern crate libc; #[macro_use] extern crate log; +extern crate memmap; +extern crate stable_deref_trait; #[macro_use] extern crate syntax; extern crate syntax_pos; diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index a732446d50481..528c96f240dba 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -243,12 +243,14 @@ use std::cmp; use std::fmt; use std::fs; use std::io::{self, Read}; +use std::ops::Deref; use std::path::{Path, PathBuf}; use std::time::Instant; use flate2::read::DeflateDecoder; use rustc_data_structures::owning_ref::OwningRef; + pub struct CrateMismatch { path: PathBuf, got: String, @@ -856,6 +858,19 @@ fn get_metadata_section(target: &Target, return ret; } +/// A trivial wrapper for `Mmap` that implements `StableDeref`. +struct StableDerefMmap(memmap::Mmap); + +impl Deref for StableDerefMmap { + type Target = [u8]; + + fn deref(&self) -> &[u8] { + self.0.deref() + } +} + +unsafe impl stable_deref_trait::StableDeref for StableDerefMmap {} + fn get_metadata_section_imp(target: &Target, flavor: CrateFlavor, filename: &Path, @@ -892,9 +907,14 @@ fn get_metadata_section_imp(target: &Target, } } CrateFlavor::Rmeta => { - let buf = fs::read(filename).map_err(|_| - format!("failed to read rmeta metadata: '{}'", filename.display()))?; - rustc_erase_owner!(OwningRef::new(buf).map_owner_box()) + // mmap the file, because only a small fraction of it is read. + let file = std::fs::File::open(filename).map_err(|_| + format!("failed to open rmeta metadata: '{}'", filename.display()))?; + let mmap = unsafe { memmap::Mmap::map(&file) }; + let mmap = mmap.map_err(|_| + format!("failed to mmap rmeta metadata: '{}'", filename.display()))?; + + rustc_erase_owner!(OwningRef::new(StableDerefMmap(mmap)).map_owner_box()) } }; let blob = MetadataBlob(raw_bytes); From 64a517265297cc1d4e9e116dcbb06561c063c3d4 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 14 Nov 2018 08:55:53 +0100 Subject: [PATCH 29/33] core/char: Drop `radix == 10` special case This seems to perform equally well --- src/libcore/char/methods.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 46b201f7bbf2c..4207b3c776c7e 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -122,14 +122,7 @@ impl char { #[inline] pub fn to_digit(self, radix: u32) -> Option { assert!(radix <= 36, "to_digit: radix is too high (maximum 36)"); - if radix == 10 { - return match self { - '0' ..= '9' => Some(self as u32 - '0' as u32), - _ => None, - }; - } - - let val = if radix < 10 { + let val = if radix <= 10 { match self { '0' ..= '9' => self as u32 - '0' as u32, _ => return None, From 7843e2792dce0f20d23b3c1cca51652013bef0ea Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 14 Nov 2018 11:26:00 +0100 Subject: [PATCH 30/33] core/char: Add comment to `to_digit()` --- src/libcore/char/methods.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 4207b3c776c7e..d6fcff644acf6 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -122,6 +122,9 @@ impl char { #[inline] pub fn to_digit(self, radix: u32) -> Option { assert!(radix <= 36, "to_digit: radix is too high (maximum 36)"); + + // the code is split up here to improve execution speed for cases where + // the `radix` is constant and 10 or smaller let val = if radix <= 10 { match self { '0' ..= '9' => self as u32 - '0' as u32, From f8516055b3ecf1beb5aebff957e3ec01e6d4f0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 14 Nov 2018 14:49:40 +0100 Subject: [PATCH 31/33] submodules: update clippy from d8b42690 to 7e0ddef4 Changes: ```` Fix "too" -> "foo" typo in format.rs Fix `use_self` violation Fix wrong suggestion for `redundant_closure_call` Fix `use_self` false positive on `use` statements Fix `use_self` false positive Remove `+` from `has_unary_equivalent` Fix dogfood Update println! formatting Fix false positive in check mode caused by `gen_deprecated` RIIR update lints: Add check mode (update_lints.py rewrite complete) changed into_iter to iter and fixed a lint check Fix `collapsible_if` error Fix `possible_missing_comma` false positives format code fix comment spacing change single char str to char add lint to lintarray macro Revert "small fix" small fix added float support for mistyped literal lints tmp progress ```` --- src/tools/clippy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy b/src/tools/clippy index d8b426901a75b..7e0ddef4e7e1c 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit d8b426901a75b1eb975f52b4537f2736f2b94436 +Subproject commit 7e0ddef4e7e1c1d891998c676ad7eda7cf0d9ea8 From 055e7b7258cafb9b14f53b9d20c3960c1dbcc9b4 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Wed, 14 Nov 2018 12:41:39 -0500 Subject: [PATCH 32/33] add test for issue #55587 --- src/test/ui/issues/issue-55587.rs | 5 +++++ src/test/ui/issues/issue-55587.stderr | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/ui/issues/issue-55587.rs create mode 100644 src/test/ui/issues/issue-55587.stderr diff --git a/src/test/ui/issues/issue-55587.rs b/src/test/ui/issues/issue-55587.rs new file mode 100644 index 0000000000000..8b78749f6529a --- /dev/null +++ b/src/test/ui/issues/issue-55587.rs @@ -0,0 +1,5 @@ +use std::path::Path; + +fn main() { + let Path::new(); //~ ERROR expected tuple struct/variant +} diff --git a/src/test/ui/issues/issue-55587.stderr b/src/test/ui/issues/issue-55587.stderr new file mode 100644 index 0000000000000..876fb4391b1bc --- /dev/null +++ b/src/test/ui/issues/issue-55587.stderr @@ -0,0 +1,9 @@ +error[E0164]: expected tuple struct/variant, found method `::new` + --> $DIR/issue-55587.rs:4:9 + | +LL | let Path::new(); //~ ERROR expected tuple struct/variant + | ^^^^^^^^^^^ not a tuple variant or struct + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0164`. From e2ef0f742cd6ff1cabea0cef8999d6615a815eeb Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Wed, 14 Nov 2018 12:54:32 -0500 Subject: [PATCH 33/33] add test for issue #54348 --- src/test/ui/issues/issue-54348.rs | 5 +++++ src/test/ui/issues/issue-54348.stderr | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/issues/issue-54348.rs create mode 100644 src/test/ui/issues/issue-54348.stderr diff --git a/src/test/ui/issues/issue-54348.rs b/src/test/ui/issues/issue-54348.rs new file mode 100644 index 0000000000000..b980290391d3a --- /dev/null +++ b/src/test/ui/issues/issue-54348.rs @@ -0,0 +1,5 @@ +fn main() { + [1][0u64 as usize]; + [1][1.5 as usize]; // ERROR index out of bounds + [1][1u64 as usize]; // ERROR index out of bounds +} diff --git a/src/test/ui/issues/issue-54348.stderr b/src/test/ui/issues/issue-54348.stderr new file mode 100644 index 0000000000000..a9f1b4942584d --- /dev/null +++ b/src/test/ui/issues/issue-54348.stderr @@ -0,0 +1,16 @@ +error: index out of bounds: the len is 1 but the index is 1 + --> $DIR/issue-54348.rs:3:5 + | +LL | [1][1.5 as usize]; // ERROR index out of bounds + | ^^^^^^^^^^^^^^^^^ + | + = note: #[deny(const_err)] on by default + +error: index out of bounds: the len is 1 but the index is 1 + --> $DIR/issue-54348.rs:4:5 + | +LL | [1][1u64 as usize]; // ERROR index out of bounds + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +