Skip to content

Commit f004cae

Browse files
committed
Auto merge of #54319 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #53522 (Add doc for impl From for Addr) - #54097 (rustdoc: Remove namespace for keywords) - #54205 (Add treat-err-as-bug flag in rustdoc) - #54225 (Regression test for #53675.) - #54232 (add `-Z dont-buffer-diagnostics`) - #54273 (Suggest to change numeric literal instead of casting) - #54299 (Issue 54246) - #54311 (Remove README with now-out-of-date docs about docs.) - #54313 (OsStr: Document that it's not NUL terminated) Failed merges: r? @ghost
2 parents 36c0ee9 + 85d214e commit f004cae

21 files changed

+230
-84
lines changed

src/doc/README.md

-32
This file was deleted.

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13311331
"disable user provided type assertion in NLL"),
13321332
nll_dont_emit_read_for_match: bool = (false, parse_bool, [UNTRACKED],
13331333
"in match codegen, do not include ReadForMatch statements (used by mir-borrowck)"),
1334+
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
1335+
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting)."),
13341336
polonius: bool = (false, parse_bool, [UNTRACKED],
13351337
"enable polonius-based borrow-checker"),
13361338
codegen_time_graph: bool = (false, parse_bool, [UNTRACKED],

src/librustc/session/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ pub fn build_session_with_source_map(
10121012
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
10131013

10141014
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
1015+
let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
10151016
let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;
10161017

10171018
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
@@ -1059,6 +1060,7 @@ pub fn build_session_with_source_map(
10591060
can_emit_warnings,
10601061
treat_err_as_bug,
10611062
report_delayed_bugs,
1063+
dont_buffer_diagnostics,
10621064
external_macro_backtrace,
10631065
..Default::default()
10641066
},

src/librustc_errors/diagnostic_builder.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use std::thread::panicking;
2121
use syntax_pos::{MultiSpan, Span};
2222

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

92-
/// Buffers the diagnostic for later emission.
93-
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
96+
/// Buffers the diagnostic for later emission, unless handler
97+
/// has disabled such buffering.
98+
pub fn buffer(mut self, buffered_diagnostics: &mut Vec<Diagnostic>) {
99+
if self.handler.flags.dont_buffer_diagnostics || self.handler.flags.treat_err_as_bug {
100+
self.emit();
101+
return;
102+
}
103+
94104
// We need to use `ptr::read` because `DiagnosticBuilder`
95105
// implements `Drop`.
96106
let diagnostic;

src/librustc_errors/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,20 @@ thread_local!(pub static TRACK_DIAGNOSTICS: Cell<fn(&Diagnostic)> =
303303

304304
#[derive(Default)]
305305
pub struct HandlerFlags {
306+
/// If false, warning-level lints are suppressed.
307+
/// (rustc: see `--allow warnings` and `--cap-lints`)
306308
pub can_emit_warnings: bool,
309+
/// If true, error-level diagnostics are upgraded to bug-level.
310+
/// (rustc: see `-Z treat-err-as-bug`)
307311
pub treat_err_as_bug: bool,
312+
/// If true, immediately emit diagnostics that would otherwise be buffered.
313+
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
314+
pub dont_buffer_diagnostics: bool,
315+
/// If true, immediately print bugs registered with `delay_span_bug`.
316+
/// (rustc: see `-Z report-delayed-bugs`)
308317
pub report_delayed_bugs: bool,
318+
/// show macro backtraces even for non-local macros.
319+
/// (rustc: see `-Z external-macro-backtrace`)
309320
pub external_macro_backtrace: bool,
310321
}
311322

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl EarlyLintPass for DeprecatedAttr {
783783
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
784784
for &&(n, _, ref g) in &self.depr_attrs {
785785
if attr.name() == n {
786-
if let &AttributeGate::Gated(Stability::Deprecated(link),
786+
if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion),
787787
ref name,
788788
ref reason,
789789
_) = g {
@@ -792,7 +792,7 @@ impl EarlyLintPass for DeprecatedAttr {
792792
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
793793
err.span_suggestion_short_with_applicability(
794794
attr.span,
795-
"remove this attribute",
795+
suggestion.unwrap_or("remove this attribute"),
796796
String::new(),
797797
Applicability::MachineApplicable
798798
);

src/librustc_typeck/check/demand.rs

+60-21
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,55 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
415415
src,
416416
if needs_paren { ")" } else { "" },
417417
expected_ty);
418-
let into_suggestion = format!("{}{}{}.into()",
419-
if needs_paren { "(" } else { "" },
420-
src,
421-
if needs_paren { ")" } else { "" });
418+
let into_suggestion = format!(
419+
"{}{}{}.into()",
420+
if needs_paren { "(" } else { "" },
421+
src,
422+
if needs_paren { ")" } else { "" },
423+
);
424+
let literal_is_ty_suffixed = |expr: &hir::Expr| {
425+
if let hir::ExprKind::Lit(lit) = &expr.node {
426+
lit.node.is_suffixed()
427+
} else {
428+
false
429+
}
430+
};
431+
432+
let into_sugg = into_suggestion.clone();
433+
let suggest_to_change_suffix_or_into = |err: &mut DiagnosticBuilder,
434+
note: Option<&str>| {
435+
let suggest_msg = if literal_is_ty_suffixed(expr) {
436+
format!(
437+
"change the type of the numeric literal from `{}` to `{}`",
438+
checked_ty,
439+
expected_ty,
440+
)
441+
} else {
442+
match note {
443+
Some(note) => format!("{}, which {}", msg, note),
444+
_ => format!("{} in a lossless way", msg),
445+
}
446+
};
447+
448+
let suffix_suggestion = format!(
449+
"{}{}{}{}",
450+
if needs_paren { "(" } else { "" },
451+
src.trim_right_matches(&checked_ty.to_string()),
452+
expected_ty,
453+
if needs_paren { ")" } else { "" },
454+
);
455+
456+
err.span_suggestion_with_applicability(
457+
expr.span,
458+
&suggest_msg,
459+
if literal_is_ty_suffixed(expr) {
460+
suffix_suggestion
461+
} else {
462+
into_sugg
463+
},
464+
Applicability::MachineApplicable,
465+
);
466+
};
422467

423468
match (&expected_ty.sty, &checked_ty.sty) {
424469
(&ty::Int(ref exp), &ty::Int(ref found)) => {
@@ -444,11 +489,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
444489
}
445490
}
446491
_ => {
447-
err.span_suggestion_with_applicability(
448-
expr.span,
449-
&format!("{}, which {}", msg, will_sign_extend),
450-
into_suggestion,
451-
Applicability::MachineApplicable
492+
suggest_to_change_suffix_or_into(
493+
err,
494+
Some(will_sign_extend),
452495
);
453496
}
454497
}
@@ -477,12 +520,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
477520
}
478521
}
479522
_ => {
480-
err.span_suggestion_with_applicability(
481-
expr.span,
482-
&format!("{}, which {}", msg, will_zero_extend),
483-
into_suggestion,
484-
Applicability::MachineApplicable
485-
);
523+
suggest_to_change_suffix_or_into(
524+
err,
525+
Some(will_zero_extend),
526+
);
486527
}
487528
}
488529
true
@@ -583,12 +624,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
583624
}
584625
(&ty::Float(ref exp), &ty::Float(ref found)) => {
585626
if found.bit_width() < exp.bit_width() {
586-
err.span_suggestion_with_applicability(
587-
expr.span,
588-
&format!("{} in a lossless way", msg),
589-
into_suggestion,
590-
Applicability::MachineApplicable
591-
);
627+
suggest_to_change_suffix_or_into(
628+
err,
629+
None,
630+
);
592631
} else if can_cast {
593632
err.span_suggestion_with_applicability(
594633
expr.span,

src/librustdoc/core.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ impl DocAccessLevels for AccessLevels<DefId> {
260260
///
261261
/// If the given `error_format` is `ErrorOutputType::Json` and no `SourceMap` is given, a new one
262262
/// will be created for the handler.
263-
pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_map::SourceMap>>)
264-
-> errors::Handler
265-
{
263+
pub fn new_handler(error_format: ErrorOutputType,
264+
source_map: Option<Lrc<source_map::SourceMap>>,
265+
treat_err_as_bug: bool,
266+
) -> errors::Handler {
266267
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
267268
// stick to the defaults
268269
let sessopts = Options::default();
@@ -299,7 +300,7 @@ pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_
299300
emitter,
300301
errors::HandlerFlags {
301302
can_emit_warnings: true,
302-
treat_err_as_bug: false,
303+
treat_err_as_bug,
303304
report_delayed_bugs: false,
304305
external_macro_backtrace: false,
305306
..Default::default()
@@ -323,9 +324,9 @@ pub fn run_core(search_paths: SearchPaths,
323324
lint_cap: Option<lint::Level>,
324325
describe_lints: bool,
325326
mut manual_passes: Vec<String>,
326-
mut default_passes: passes::DefaultPassOption)
327-
-> (clean::Crate, RenderInfo, Vec<String>)
328-
{
327+
mut default_passes: passes::DefaultPassOption,
328+
treat_err_as_bug: bool,
329+
) -> (clean::Crate, RenderInfo, Vec<String>) {
329330
// Parse, resolve, and typecheck the given crate.
330331

331332
let cpath = match input {
@@ -388,7 +389,9 @@ pub fn run_core(search_paths: SearchPaths,
388389
};
389390
driver::spawn_thread_pool(sessopts, move |sessopts| {
390391
let source_map = Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping()));
391-
let diagnostic_handler = new_handler(error_format, Some(source_map.clone()));
392+
let diagnostic_handler = new_handler(error_format,
393+
Some(source_map.clone()),
394+
treat_err_as_bug);
392395

393396
let mut sess = session::build_session_(
394397
sessopts, cpath, diagnostic_handler, source_map,

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1830,8 +1830,8 @@ impl Context {
18301830
*slot.borrow_mut() = self.current.clone();
18311831
});
18321832

1833-
let mut title = if it.is_primitive() {
1834-
// No need to include the namespace for primitive types
1833+
let mut title = if it.is_primitive() || it.is_keyword() {
1834+
// No need to include the namespace for primitive types and keywords
18351835
String::new()
18361836
} else {
18371837
self.current.join("::")

src/librustdoc/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ fn main_args(args: &[String]) -> isize {
404404
`short` (instead was `{}`)", arg));
405405
}
406406
};
407+
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
408+
*x == "treat-err-as-bug"
409+
});
407410

408-
let diag = core::new_handler(error_format, None);
411+
let diag = core::new_handler(error_format, None, treat_err_as_bug);
409412

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

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

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

711718
info!("finished with rustc");
712719

src/libstd/ffi/os_str.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ use sys_common::{AsInner, IntoInner, FromInner};
3434
///
3535
/// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust
3636
/// and platform-native string values, and in particular allowing a Rust string
37-
/// to be converted into an "OS" string with no cost if possible.
37+
/// to be converted into an "OS" string with no cost if possible. A consequence
38+
/// of this is that `OsString` instances are *not* `NUL` terminated; in order
39+
/// to pass to e.g. Unix system call, you should create a [`CStr`].
3840
///
3941
/// `OsString` is to [`&OsStr`] as [`String`] is to [`&str`]: the former
4042
/// in each pair are owned strings; the latter are borrowed
@@ -65,6 +67,7 @@ use sys_common::{AsInner, IntoInner, FromInner};
6567
///
6668
/// [`OsStr`]: struct.OsStr.html
6769
/// [`&OsStr`]: struct.OsStr.html
70+
/// [`CStr`]: struct.CStr.html
6871
/// [`From`]: ../convert/trait.From.html
6972
/// [`String`]: ../string/struct.String.html
7073
/// [`&str`]: ../primitive.str.html

src/libstd/net/addr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -554,20 +554,28 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {
554554

555555
#[stable(feature = "ip_from_ip", since = "1.16.0")]
556556
impl From<SocketAddrV4> for SocketAddr {
557+
/// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`].
557558
fn from(sock4: SocketAddrV4) -> SocketAddr {
558559
SocketAddr::V4(sock4)
559560
}
560561
}
561562

562563
#[stable(feature = "ip_from_ip", since = "1.16.0")]
563564
impl From<SocketAddrV6> for SocketAddr {
565+
/// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`].
564566
fn from(sock6: SocketAddrV6) -> SocketAddr {
565567
SocketAddr::V6(sock6)
566568
}
567569
}
568570

569571
#[stable(feature = "addr_from_into_ip", since = "1.17.0")]
570572
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
573+
/// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`].
574+
///
575+
/// This conversion creates a [`SocketAddr::V4`] for a [`IpAddr::V4`]
576+
/// and creates a [`SocketAddr::V6`] for a [`IpAddr::V6`].
577+
///
578+
/// `u16` is treated as port of the newly created [`SocketAddr`].
571579
fn from(pieces: (I, u16)) -> SocketAddr {
572580
SocketAddr::new(pieces.0.into(), pieces.1)
573581
}

0 commit comments

Comments
 (0)