提交 f004cae5 编写于 作者: B bors

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 rust-lang/rust#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
# Rust documentations
## Building
To generate all the docs, follow the "Building Documentation" instructions in
the README in the root of the repository. This will convert the distributed
Markdown docs to HTML and generate HTML doc for the books, 'std' and 'extra'
libraries.
To generate HTML documentation from one source file/crate, do something like:
~~~~text
rustdoc --output html-doc/ --output-format html ../src/libstd/path.rs
~~~~
(This, of course, requires a working build of the `rustdoc` tool.)
## Additional notes
To generate an HTML version of a doc from Markdown manually, you can do
something like:
~~~~text
rustdoc reference.md
~~~~
(`reference.md` being the Rust Reference Manual.)
An overview of how to use the `rustdoc` command is available [in the docs][1].
Further details are available from the command line by with `rustdoc --help`.
[1]: https://github.com/rust-lang/rust/blob/master/src/doc/rustdoc/src/what-is-rustdoc.md
......@@ -1331,6 +1331,8 @@ fn parse_cross_lang_lto(slot: &mut CrossLangLto, v: Option<&str>) -> bool {
"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],
......
......@@ -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;
......@@ -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()
},
......
......@@ -21,6 +21,10 @@
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> {
......@@ -89,8 +93,14 @@ pub fn emit(&mut self) {
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;
......
......@@ -303,9 +303,20 @@ fn default_track_diagnostic(_: &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,
}
......
......@@ -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 {
......@@ -792,7 +792,7 @@ fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
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
);
......
......@@ -415,10 +415,55 @@ pub fn check_for_cast(&self,
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)) => {
......@@ -444,11 +489,9 @@ pub fn check_for_cast(&self,
}
}
_ => {
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),
);
}
}
......@@ -477,12 +520,10 @@ pub fn check_for_cast(&self,
}
}
_ => {
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
......@@ -583,12 +624,10 @@ pub fn check_for_cast(&self,
}
(&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,
......
......@@ -260,9 +260,10 @@ fn is_doc_reachable(&self, did: DefId) -> bool {
///
/// 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();
......@@ -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()
......@@ -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 {
......@@ -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,
......
......@@ -1830,8 +1830,8 @@ fn render_item(&self,
*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("::")
......
......@@ -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);
......@@ -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 => {
......@@ -694,6 +697,9 @@ fn rust_input<R, F>(cratefile: PathBuf,
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);
......@@ -706,7 +712,8 @@ fn rust_input<R, F>(cratefile: PathBuf,
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");
......
......@@ -34,7 +34,9 @@
///
/// `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
......@@ -65,6 +67,7 @@
///
/// [`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
......
......@@ -554,6 +554,7 @@ fn from_inner(addr: c::sockaddr_in6) -> 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)
}
......@@ -561,6 +562,7 @@ fn from(sock4: SocketAddrV4) -> SocketAddr {
#[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)
}
......@@ -568,6 +570,12 @@ fn from(sock6: SocketAddrV6) -> SocketAddr {
#[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)
}
......
......@@ -711,7 +711,7 @@ pub enum AttributeGate {
impl AttributeGate {
fn is_deprecated(&self) -> bool {
match *self {
Gated(Stability::Deprecated(_), ..) => true,
Gated(Stability::Deprecated(_, _), ..) => true,
_ => false,
}
}
......@@ -720,8 +720,9 @@ fn is_deprecated(&self) -> bool {
#[derive(Copy, Clone, Debug)]
pub enum Stability {
Unstable,
// Argument is tracking issue link.
Deprecated(&'static str),
// First argument is tracking issue link; second argument is an optional
// help message, which defaults to "remove this attribute"
Deprecated(&'static str, Option<&'static str>),
}
// fn() is not Debug
......@@ -1048,7 +1049,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
("no_builtins", Whitelisted, Ungated),
("no_mangle", Whitelisted, Ungated),
("no_debug", Whitelisted, Gated(
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721"),
Stability::Deprecated("https://github.com/rust-lang/rust/issues/29721", None),
"no_debug",
"the `#[no_debug]` attribute was an experimental feature that has been \
deprecated due to lack of demand",
......@@ -1061,7 +1062,8 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
cfg_fn!(omit_gdb_pretty_printer_section))),
("unsafe_destructor_blind_to_params",
Normal,
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"),
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761",
Some("replace this attribute with `#[may_dangle]`")),
"dropck_parametricity",
"unsafe_destructor_blind_to_params has been replaced by \
may_dangle and will be removed in the future",
......@@ -1140,9 +1142,10 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
("panic_implementation",
Normal,
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\
#issuecomment-415140224"),
#issuecomment-415140224",
Some("replace this attribute with `#[panic_handler]`")),
"panic_implementation",
"This attribute was renamed to `panic_handler`",
"this attribute was renamed to `panic_handler`",
cfg_fn!(panic_implementation))),
// RFC 2070
......
......@@ -15,6 +15,7 @@
// @has foo/index.html '//h2[@id="keywords"]' 'Keywords'
// @has foo/index.html '//a[@href="keyword.match.html"]' 'match'
// @has foo/keyword.match.html '//a[@class="keyword"]' 'match'
// @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match'
// @has foo/keyword.match.html '//section[@id="main"]//div[@class="docblock"]//p' 'this is a test!'
// @!has foo/index.html '//a/@href' 'foo/index.html'
// @!has foo/foo/index.html
......
......@@ -2,7 +2,7 @@ error: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_bli
--> $DIR/feature-gate-dropck-ugeh-2.rs:17:5
|
LL | #[unsafe_destructor_blind_to_params]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]`
|
note: lint level defined here
--> $DIR/feature-gate-dropck-ugeh-2.rs:11:9
......
......@@ -15,7 +15,7 @@
use core::panic::PanicInfo;
#[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
#[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489)
fn panic(info: &PanicInfo) -> ! {
loop {}
}
error[E0658]: This attribute was renamed to `panic_handler` (see issue #44489)
error[E0658]: this attribute was renamed to `panic_handler` (see issue #44489)
--> $DIR/feature-gate-panic-implementation.rs:18:1
|
LL | #[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
LL | #[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489)
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(panic_implementation)] to the crate attributes to enable
......
// rust-lang/rust#53675: At one point the compiler errored when a test
// named `panic` used the `assert!` macro in expression position.
// compile-pass
// compile-flags: --test
mod in_expression_position {
#[test]
fn panic() {
assert!(true)
}
}
mod in_statement_position {
#[test]
fn panic() {
assert!(true);
}
}
mod what_if_we_use_panic_directly_in_expr {
#[test]
#[should_panic]
fn panic() {
panic!("in expr")
}
}
mod what_if_we_use_panic_directly_in_stmt {
#[test]
#[should_panic]
fn panic() {
panic!("in stmt");
}
}
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(_: u16) {}
fn foo1(_: f64) {}
fn foo2(_: i32) {}
fn main() {
foo(1u8);
foo1(2f32);
foo2(3i16);
}
error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:16:9
|
LL | foo(1u8);
| ^^^ expected u16, found u8
help: change the type of the numeric literal from `u8` to `u16`
|
LL | foo(1u16);
| ^^^^
error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:17:10
|
LL | foo1(2f32);
| ^^^^ expected f64, found f32
help: change the type of the numeric literal from `f32` to `f64`
|
LL | foo1(2f64);
| ^^^^
error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:18:10
|
LL | foo2(3i16);
| ^^^^ expected i32, found i16
help: change the type of the numeric literal from `i16` to `i32`
|
LL | foo2(3i32);
| ^^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
error: use of deprecated attribute `panic_implementation`: This attribute was renamed to `panic_handler`. See https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224
error: use of deprecated attribute `panic_implementation`: this attribute was renamed to `panic_handler`. See https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224
--> $DIR/panic-implementation-deprecated.rs:19:1
|
LL | #[panic_implementation]
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[panic_handler]`
|
note: lint level defined here
--> $DIR/panic-implementation-deprecated.rs:13:9
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册