Skip to content
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

Rollup of 9 pull requests #54319

Merged
merged 25 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4ced4f3
Add doc for impl From for Addr
phungleson Aug 21, 2018
1a0e8f9
Remove namespace for keywords
GuillaumeGomez Sep 10, 2018
fab6b06
Add treat-err-as-bug flag in rustdoc
GuillaumeGomez Sep 13, 2018
818938f
Remove treat-err-as-bug test
GuillaumeGomez Sep 14, 2018
fc6e1ed
Regression test for rust-lang/rust#53675.
pnkfelix Sep 14, 2018
1984079
lint to change numeric literal instead of into
csmoe Sep 16, 2018
0ff0669
replace old literal in expr
csmoe Sep 16, 2018
17a28f7
add test for numeric literal cast
csmoe Sep 16, 2018
d31a2a0
trim type numeric literal suffix
csmoe Sep 16, 2018
9d6c4f0
merge into/literal suggestion for DRY
csmoe Sep 17, 2018
2fb6585
add test for float/integer
csmoe Sep 17, 2018
e4e4039
libsyntax: fix casing in error message
Sep 17, 2018
82e1750
Add -Z dont-buffer-diagnostics, a way to force NLL to immediately emi…
pnkfelix Sep 15, 2018
79da7a0
libsyntax: add optional help message for deprecated features
Sep 17, 2018
ff61794
Remove REAMDE with now-out-of-date docs about docs.
frewsxcv Sep 18, 2018
993d022
OsStr: Document that it's not NUL terminated
cgwalters Sep 18, 2018
3cdebfb
Rollup merge of #53522 - phungleson:fix-impl-from-for-addr, r=TimNN
GuillaumeGomez Sep 18, 2018
6aed133
Rollup merge of #54097 - GuillaumeGomez:remove-keyword-namespace, r=Q…
GuillaumeGomez Sep 18, 2018
108be3c
Rollup merge of #54205 - GuillaumeGomez:treat-err-as-bug, r=QuietMisd…
GuillaumeGomez Sep 18, 2018
cdd9034
Rollup merge of #54225 - pnkfelix:issue-53675-add-test-called-panic, …
GuillaumeGomez Sep 18, 2018
22d3812
Rollup merge of #54232 - pnkfelix:add-way-to-disable-diagnostic-buffe…
GuillaumeGomez Sep 18, 2018
5f1a123
Rollup merge of #54273 - csmoe:lint_ty_lit, r=estebank
GuillaumeGomez Sep 18, 2018
50b9694
Rollup merge of #54299 - snaedis:issue-54246, r=varkor
GuillaumeGomez Sep 18, 2018
6a4e7bb
Rollup merge of #54311 - frewsxcv:frewsxcv-readme, r=GuillaumeGomez
GuillaumeGomez Sep 18, 2018
85d214e
Rollup merge of #54313 - cgwalters:osstr-ref-cstr, r=joshtriplett
GuillaumeGomez Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/doc/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"disable user provided type assertion in NLL"),
nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED],
"in match codegen, do not include ReadForMatch statements (used by mir-borrowck)"),
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."),
polonius: bool = (false, parse_bool, [UNTRACKED],
"enable polonius-based borrow-checker"),
codegen_time_graph: bool = (false, parse_bool, [UNTRACKED],
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ pub fn build_session_with_source_map(
let can_emit_warnings = !(warnings_allow || cap_lints_allow);

let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;

let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
Expand Down Expand Up @@ -1059,6 +1060,7 @@ pub fn build_session_with_source_map(
can_emit_warnings,
treat_err_as_bug,
report_delayed_bugs,
dont_buffer_diagnostics,
external_macro_backtrace,
..Default::default()
},
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use std::thread::panicking;
use syntax_pos::{MultiSpan, Span};

/// Used for emitting structured error messages and other diagnostic information.
///
/// If there is some state in a downstream crate you would like to
/// access in the methods of `DiagnosticBuilder` here, consider
/// extending `HandlerFlags`, accessed via `self.handler.flags`.
#[must_use]
#[derive(Clone)]
pub struct DiagnosticBuilder<'a> {
Expand Down Expand Up @@ -89,8 +93,14 @@ impl<'a> DiagnosticBuilder<'a> {
self.cancel();
}

/// Buffers the diagnostic for later emission.
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
/// Buffers the diagnostic for later emission, unless handler
/// has disabled such buffering.
pub fn buffer(mut self, buffered_diagnostics: &mut Vec<Diagnostic>) {
if self.handler.flags.dont_buffer_diagnostics || self.handler.flags.treat_err_as_bug {
self.emit();
return;
}

// We need to use `ptr::read` because `DiagnosticBuilder`
// implements `Drop`.
let diagnostic;
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,20 @@ thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> =

#[derive(Default)]
pub struct HandlerFlags {
/// If false, warning-level lints are suppressed.
/// (rustc: see `--allow warnings` and `--cap-lints`)
pub can_emit_warnings: bool,
/// If true, error-level diagnostics are upgraded to bug-level.
/// (rustc: see `-Z treat-err-as-bug`)
pub treat_err_as_bug: bool,
/// If true, immediately emit diagnostics that would otherwise be buffered.
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
pub dont_buffer_diagnostics: bool,
/// If true, immediately print bugs registered with `delay_span_bug`.
/// (rustc: see `-Z report-delayed-bugs`)
pub report_delayed_bugs: bool,
/// show macro backtraces even for non-local macros.
/// (rustc: see `-Z external-macro-backtrace`)
pub external_macro_backtrace: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ impl EarlyLintPass for DeprecatedAttr {
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
for &&(n, _, ref g) in &self.depr_attrs {
if attr.name() == n {
if let &AttributeGate::Gated(Stability::Deprecated(link),
if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion),
ref name,
ref reason,
_) = g {
Expand All @@ -792,7 +792,7 @@ impl EarlyLintPass for DeprecatedAttr {
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
err.span_suggestion_short_with_applicability(
attr.span,
"remove this attribute",
suggestion.unwrap_or("remove this attribute"),
String::new(),
Applicability::MachineApplicable
);
Expand Down
81 changes: 60 additions & 21 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,55 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
src,
if needs_paren { ")" } else { "" },
expected_ty);
let into_suggestion = format!("{}{}{}.into()",
if needs_paren { "(" } else { "" },
src,
if needs_paren { ")" } else { "" });
let into_suggestion = format!(
"{}{}{}.into()",
if needs_paren { "(" } else { "" },
src,
if needs_paren { ")" } else { "" },
);
let literal_is_ty_suffixed = |expr: &hir::Expr| {
if let hir::ExprKind::Lit(lit) = &expr.node {
lit.node.is_suffixed()
} else {
false
}
};

let into_sugg = into_suggestion.clone();
let suggest_to_change_suffix_or_into = |err: &mut DiagnosticBuilder,
note: Option<&str>| {
let suggest_msg = if literal_is_ty_suffixed(expr) {
format!(
"change the type of the numeric literal from `{}` to `{}`",
checked_ty,
expected_ty,
)
} else {
match note {
Some(note) => format!("{}, which {}", msg, note),
_ => format!("{} in a lossless way", msg),
}
};

let suffix_suggestion = format!(
"{}{}{}{}",
if needs_paren { "(" } else { "" },
src.trim_right_matches(&checked_ty.to_string()),
expected_ty,
if needs_paren { ")" } else { "" },
);

err.span_suggestion_with_applicability(
expr.span,
&suggest_msg,
if literal_is_ty_suffixed(expr) {
suffix_suggestion
} else {
into_sugg
},
Applicability::MachineApplicable,
);
};

match (&expected_ty.sty, &checked_ty.sty) {
(&ty::Int(ref exp), &ty::Int(ref found)) => {
Expand All @@ -444,11 +489,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
_ => {
err.span_suggestion_with_applicability(
expr.span,
&format!("{}, which {}", msg, will_sign_extend),
into_suggestion,
Applicability::MachineApplicable
suggest_to_change_suffix_or_into(
err,
Some(will_sign_extend),
);
}
}
Expand Down Expand Up @@ -477,12 +520,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
_ => {
err.span_suggestion_with_applicability(
expr.span,
&format!("{}, which {}", msg, will_zero_extend),
into_suggestion,
Applicability::MachineApplicable
);
suggest_to_change_suffix_or_into(
err,
Some(will_zero_extend),
);
}
}
true
Expand Down Expand Up @@ -583,12 +624,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
(&ty::Float(ref exp), &ty::Float(ref found)) => {
if found.bit_width() < exp.bit_width() {
err.span_suggestion_with_applicability(
expr.span,
&format!("{} in a lossless way", msg),
into_suggestion,
Applicability::MachineApplicable
);
suggest_to_change_suffix_or_into(
err,
None,
);
} else if can_cast {
err.span_suggestion_with_applicability(
expr.span,
Expand Down
19 changes: 11 additions & 8 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ impl DocAccessLevels for AccessLevels<DefId> {
///
/// If the given `error_format` is `ErrorOutputType::Json` and no `SourceMap` is given, a new one
/// will be created for the handler.
pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_map::SourceMap>>)
-> errors::Handler
{
pub fn new_handler(error_format: ErrorOutputType,
source_map: Option<Lrc<source_map::SourceMap>>,
treat_err_as_bug: bool,
) -> errors::Handler {
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
// stick to the defaults
let sessopts = Options::default();
Expand Down Expand Up @@ -299,7 +300,7 @@ pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_
emitter,
errors::HandlerFlags {
can_emit_warnings: true,
treat_err_as_bug: false,
treat_err_as_bug,
report_delayed_bugs: false,
external_macro_backtrace: false,
..Default::default()
Expand All @@ -323,9 +324,9 @@ pub fn run_core(search_paths: SearchPaths,
lint_cap: Option<lint::Level>,
describe_lints: bool,
mut manual_passes: Vec<String>,
mut default_passes: passes::DefaultPassOption)
-> (clean::Crate, RenderInfo, Vec<String>)
{
mut default_passes: passes::DefaultPassOption,
treat_err_as_bug: bool,
) -> (clean::Crate, RenderInfo, Vec<String>) {
// Parse, resolve, and typecheck the given crate.

let cpath = match input {
Expand Down Expand Up @@ -388,7 +389,9 @@ pub fn run_core(search_paths: SearchPaths,
};
driver::spawn_thread_pool(sessopts, move |sessopts| {
let source_map = Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping()));
let diagnostic_handler = new_handler(error_format, Some(source_map.clone()));
let diagnostic_handler = new_handler(error_format,
Some(source_map.clone()),
treat_err_as_bug);

let mut sess = session::build_session_(
sessopts, cpath, diagnostic_handler, source_map,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ impl Context {
*slot.borrow_mut() = self.current.clone();
});

let mut title = if it.is_primitive() {
// No need to include the namespace for primitive types
let mut title = if it.is_primitive() || it.is_keyword() {
// No need to include the namespace for primitive types and keywords
String::new()
} else {
self.current.join("::")
Expand Down
13 changes: 10 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,11 @@ fn main_args(args: &[String]) -> isize {
`short` (instead was `{}`)", arg));
}
};
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
*x == "treat-err-as-bug"
});

let diag = core::new_handler(error_format, None);
let diag = core::new_handler(error_format, None, treat_err_as_bug);

// check for deprecated options
check_deprecated_options(&matches, &diag);
Expand Down Expand Up @@ -560,7 +563,7 @@ fn main_args(args: &[String]) -> isize {
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
move |out| {
let Output { krate, passes, renderinfo } = out;
let diag = core::new_handler(error_format, None);
let diag = core::new_handler(error_format, None, treat_err_as_bug);
info!("going to format");
match output_format.as_ref().map(|s| &**s) {
Some("html") | None => {
Expand Down Expand Up @@ -694,6 +697,9 @@ where R: 'static + Send,
let force_unstable_if_unmarked = matches.opt_strs("Z").iter().any(|x| {
*x == "force-unstable-if-unmarked"
});
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
*x == "treat-err-as-bug"
});

let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

Expand All @@ -706,7 +712,8 @@ where R: 'static + Send,
core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
display_warnings, crate_name.clone(),
force_unstable_if_unmarked, edition, cg, error_format,
lint_opts, lint_cap, describe_lints, manual_passes, default_passes);
lint_opts, lint_cap, describe_lints, manual_passes, default_passes,
treat_err_as_bug);

info!("finished with rustc");

Expand Down
5 changes: 4 additions & 1 deletion src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use sys_common::{AsInner, IntoInner, FromInner};
///
/// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust
/// and platform-native string values, and in particular allowing a Rust string
/// to be converted into an "OS" string with no cost if possible.
/// to be converted into an "OS" string with no cost if possible. A consequence
/// of this is that `OsString` instances are *not* `NUL` terminated; in order
/// to pass to e.g. Unix system call, you should create a [`CStr`].
///
/// `OsString` is to [`&OsStr`] as [`String`] is to [`&str`]: the former
/// in each pair are owned strings; the latter are borrowed
Expand Down Expand Up @@ -65,6 +67,7 @@ use sys_common::{AsInner, IntoInner, FromInner};
///
/// [`OsStr`]: struct.OsStr.html
/// [`&OsStr`]: struct.OsStr.html
/// [`CStr`]: struct.CStr.html
/// [`From`]: ../convert/trait.From.html
/// [`String`]: ../string/struct.String.html
/// [`&str`]: ../primitive.str.html
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,28 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {

#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV4> for SocketAddr {
/// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`].
fn from(sock4: SocketAddrV4) -> SocketAddr {
SocketAddr::V4(sock4)
}
}

#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV6> for SocketAddr {
/// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`].
fn from(sock6: SocketAddrV6) -> SocketAddr {
SocketAddr::V6(sock6)
}
}

#[stable(feature = "addr_from_into_ip", since = "1.17.0")]
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
/// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`].
///
/// This conversion creates a [`SocketAddr::V4`] for a [`IpAddr::V4`]
/// and creates a [`SocketAddr::V6`] for a [`IpAddr::V6`].
///
/// `u16` is treated as port of the newly created [`SocketAddr`].
fn from(pieces: (I, u16)) -> SocketAddr {
SocketAddr::new(pieces.0.into(), pieces.1)
}
Expand Down
Loading