Skip to content

Rollup of 4 pull requests #42978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
60 changes: 20 additions & 40 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 42 additions & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ use std::cmp::max;
use std::cmp::Ordering::Equal;
use std::default::Default;
use std::env;
use std::ffi::OsString;
use std::io::{self, Read, Write};
use std::iter::repeat;
use std::path::PathBuf;
use std::process;
use std::process::{self, Command, Stdio};
use std::rc::Rc;
use std::str;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -356,27 +357,65 @@ fn handle_explain(code: &str,
match descriptions.find_description(&normalised) {
Some(ref description) => {
let mut is_in_code_block = false;
let mut text = String::new();

// Slice off the leading newline and print.
for line in description[1..].lines() {
let indent_level = line.find(|c: char| !c.is_whitespace())
.unwrap_or_else(|| line.len());
let dedented_line = &line[indent_level..];
if dedented_line.starts_with("```") {
is_in_code_block = !is_in_code_block;
println!("{}", &line[..(indent_level+3)]);
text.push_str(&line[..(indent_level+3)]);
} else if is_in_code_block && dedented_line.starts_with("# ") {
continue;
} else {
println!("{}", line);
text.push_str(line);
}
text.push('\n');
}

show_content_with_pager(&text);
}
None => {
early_error(output, &format!("no extended information for {}", code));
}
}
}

fn show_content_with_pager(content: &String) {
let pager_name = env::var_os("PAGER").unwrap_or_else(|| if cfg!(windows) {
OsString::from("more.com")
} else {
OsString::from("less")
});

let mut fallback_to_println = false;

match Command::new(pager_name).stdin(Stdio::piped()).spawn() {
Ok(mut pager) => {
if let Some(mut pipe) = pager.stdin.as_mut() {
if pipe.write_all(content.as_bytes()).is_err() {
fallback_to_println = true;
}
}

if pager.wait().is_err() {
fallback_to_println = true;
}
}
Err(_) => {
fallback_to_println = true;
}
}

// If pager fails for whatever reason, we should still print the content
// to standard output
if fallback_to_println {
print!("{}", content);
}
}

impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
fn early_callback(&mut self,
matches: &getopts::Matches,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
match it.node {
hir::ForeignItemFn(..) => {}
_ => {
struct_span_err!(tcx.sess, it.span, E0619,
struct_span_err!(tcx.sess, it.span, E0621,
"intrinsic must be a function")
.span_label(it.span, "expected a function")
.emit();
Expand Down
20 changes: 20 additions & 0 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4726,6 +4726,26 @@ let x = &[1_usize, 2] as &[usize]; // ok!
```
"##,

E0621: r##"
An intrinsic was declared without being a function.

Erroneous code example:

```compile_fail,E0621
#![feature(intrinsics)]
extern "rust-intrinsic" {
pub static breakpoint : unsafe extern "rust-intrinsic" fn();
// error: intrinsic must be a function
}

fn main() { unsafe { breakpoint(); } }
```

An intrinsic is a function available for use in a given programming language
whose implementation is handled specially by the compiler. In order to fix this
error, just declare a function.
"##,

}

register_diagnostics! {
Expand Down
39 changes: 30 additions & 9 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,29 @@ impl OpenOptions {
/// # Errors
///
/// This function will return an error under a number of different
/// circumstances, to include but not limited to:
///
/// * Opening a file that does not exist without setting `create` or
/// `create_new`.
/// * Attempting to open a file with access that the user lacks
/// permissions for
/// * Filesystem-level errors (full disk, etc)
/// * Invalid combinations of open options (truncate without write access,
/// no access mode set, etc)
/// circumstances. Some of these error conditions are listed here, together
/// with their [`ErrorKind`]. The mapping to [`ErrorKind`]s is not part of
/// the compatiblity contract of the function, especially the `Other` kind
/// might change to more specific kinds in the future.
///
/// * [`NotFound`]: The specified file does not exist and neither `create`
/// or `create_new` is set.
/// * [`NotFound`]: One of the directory components of the file path does
/// not exist.
/// * [`PermissionDenied`]: The user lacks permission to get the specified
/// access rights for the file.
/// * [`PermissionDenied`]: The user lacks permission to open one of the
/// directory components of the specified path.
/// * [`AlreadyExists`]: `create_new` was specified and the file already
/// exists.
/// * [`InvalidInput`]: Invalid combinations of open options (truncate
/// without write access, no access mode set, etc.).
/// * [`Other`]: One of the directory components of the specified file path
/// was not, in fact, a directory.
/// * [`Other`]: Filesystem-level errors: full disk, write permission
/// requested on a read-only file system, exceeded disk quota, too many
/// open files, too long filename, too many symbolic links in the
/// specified path (Unix-like systems only), etc.
///
/// # Examples
///
Expand All @@ -670,6 +684,13 @@ impl OpenOptions {
///
/// let file = OpenOptions::new().open("foo.txt");
/// ```
///
/// [`ErrorKind`]: ../io/enum.ErrorKind.html
/// [`AlreadyExists`]: ../io/enum.ErrorKind.html#variant.AlreadyExists
/// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput
/// [`NotFound`]: ../io/enum.ErrorKind.html#variant.NotFound
/// [`Other`]: ../io/enum.ErrorKind.html#variant.Other
/// [`PermissionDenied`]: ../io/enum.ErrorKind.html#variant.PermissionDenied
#[stable(feature = "rust1", since = "1.0.0")]
pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> {
self._open(path.as_ref())
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0619.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ fn main() {
_ => {}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#![feature(intrinsics)]
extern "rust-intrinsic" {
pub static breakpoint : unsafe extern "rust-intrinsic" fn();
//~^ ERROR intrinsic must be a function
//~^ ERROR intrinsic must be a function [E0621]
}
fn main() { unsafe { breakpoint(); } }
2 changes: 1 addition & 1 deletion src/tools/rls
Submodule rls updated from d26fd6 to 4c0a8b