Skip to content

Commit

Permalink
Auto merge of rust-lang#91269 - matthiaskrgr:rollup-jh8i8eh, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#90611 (Fix another ICE in rustdoc scrape_examples)
 - rust-lang#91197 (rustdoc: Rename `Type::ResolvedPath` to `Type::Path` and don't re-export it)
 - rust-lang#91223 (Fix headings indent)
 - rust-lang#91240 (Saner formatting for UTF8_CHAR_WIDTH table)
 - rust-lang#91248 (Bump compiler-builtins to 0.1.53)
 - rust-lang#91252 (Fix bug where submodules wouldn't be updated when running x.py from a subdirectory)
 - rust-lang#91259 (Remove `--display-doctest-warnings`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 27, 2021
2 parents ccce985 + 092477d commit bbad745
Show file tree
Hide file tree
Showing 26 changed files with 200 additions and 148 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.52"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0"
checksum = "2467ff455350a4df7d02f1ed1449d0279605a763de5d586dcf6aa7d732508bcb"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
33 changes: 17 additions & 16 deletions library/core/src/str/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,23 @@ pub(super) const fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {

// https://tools.ietf.org/html/rfc3629
const UTF8_CHAR_WIDTH: &[u8; 256] = &[
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, // 0x1F
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E
4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F
];

/// Given a first byte, determines how many bytes are in this UTF-8 character.
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core" }
libc = { version = "0.2.106", default-features = false, features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "0.1.52" }
compiler_builtins = { version = "0.1.53" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl Build {

// NOTE: The check for the empty directory is here because when running x.py the first time,
// the submodule won't be checked out. Check it out now so we can build it.
if !channel::GitInfo::new(false, relative_path).is_git() && !dir_is_empty(&absolute_path) {
if !channel::GitInfo::new(false, &absolute_path).is_git() && !dir_is_empty(&absolute_path) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/doc/rustdoc/src/documentation-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ conversion, so type inference fails because the type is not unique. Please note
that you must write the `(())` in one sequence without intermediate whitespace
so that `rustdoc` understands you want an implicit `Result`-returning function.

## Showing warnings in doctests

You can show warnings in doctests by running `rustdoc --test --test-args=--show-output`
(or, if you're using cargo, `cargo test --doc -- --show-output`).
By default, this will still hide `unused` warnings, since so many examples use private functions;
you can add `#![warn(unused)]` to the top of your example if you want to see unused variables or dead code warnings.
You can also use [`#![doc(test(attr(warn(unused))))]`][test-attr] in the crate root to enable warnings globally.

[test-attr]: ./the-doc-attribute.md#testattr

## Documenting macros

Here’s an example of documenting a macro:
Expand Down
16 changes: 0 additions & 16 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,6 @@ all these files are linked from every page, changing where they are can be cumbe
specially cache them. This flag will rename all these files in the output to include the suffix in
the filename. For example, `light.css` would become `light-suf.css` with the above command.

### `--display-doctest-warnings`: display warnings when documenting or running documentation tests

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --display-doctest-warnings
$ rustdoc --test src/lib.rs -Z unstable-options --display-doctest-warnings
```

The intent behind this flag is to allow the user to see warnings that occur within their library or
their documentation tests, which are usually suppressed. However, [due to a
bug][issue-display-warnings], this flag doesn't 100% work as intended. See the linked issue for
details.

[issue-display-warnings]: https://github.com/rust-lang/rust/issues/41574

### `--extern-html-root-url`: control how rustdoc links to non-local crates

Using this flag looks like this:
Expand Down
12 changes: 3 additions & 9 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ use crate::visit_ast::Module as DocModule;

use utils::*;

crate use utils::{get_auto_trait_and_blanket_impls, krate, register_res};

crate use self::types::FnRetTy::*;
crate use self::types::ItemKind::*;
crate use self::types::SelfTy::*;
crate use self::types::Type::*;
crate use self::types::Visibility::{Inherited, Public};
crate use self::types::*;
crate use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res};

crate trait Clean<T> {
fn clean(&self, cx: &mut DocContext<'_>) -> T;
Expand Down Expand Up @@ -1411,12 +1405,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
};
inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, did, false, vec![], substs);
ResolvedPath { path }
Type::Path { path }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
ResolvedPath { path }
Type::Path { path }
}
ty::Dynamic(obj, ref reg) => {
// HACK: pick the first `did` as the `did` of the trait object. Someone
Expand Down
24 changes: 14 additions & 10 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use rustc_target::spec::abi::Abi;
use crate::clean::cfg::Cfg;
use crate::clean::external_path;
use crate::clean::inline::{self, print_inlined_const};
use crate::clean::types::Type::{QPath, ResolvedPath};
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
use crate::clean::Clean;
use crate::core::DocContext;
Expand All @@ -43,10 +42,14 @@ use crate::formats::item_type::ItemType;
use crate::html::render::cache::ExternalLocation;
use crate::html::render::Context;

use self::FnRetTy::*;
use self::ItemKind::*;
use self::SelfTy::*;
use self::Type::*;
crate use self::FnRetTy::*;
crate use self::ItemKind::*;
crate use self::SelfTy::*;
crate use self::Type::{
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
RawPointer, Slice, Tuple,
};
crate use self::Visibility::{Inherited, Public};

crate type ItemIdSet = FxHashSet<ItemId>;

Expand Down Expand Up @@ -1418,8 +1421,9 @@ crate struct PolyTrait {
crate enum Type {
/// A named type, which could be a trait.
///
/// This is mostly Rustdoc's version of [`hir::Path`]. It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
ResolvedPath { path: Path },
/// This is mostly Rustdoc's version of [`hir::Path`].
/// It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
Path { path: Path },
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
/// A type parameter.
Expand Down Expand Up @@ -1485,7 +1489,7 @@ impl Type {
/// Checks if this is a `T::Name` path for an associated type.
crate fn is_assoc_ty(&self) -> bool {
match self {
ResolvedPath { path, .. } => path.is_assoc_ty(),
Type::Path { path, .. } => path.is_assoc_ty(),
_ => false,
}
}
Expand All @@ -1499,7 +1503,7 @@ impl Type {

crate fn generics(&self) -> Option<Vec<&Type>> {
match self {
ResolvedPath { path, .. } => path.generics(),
Type::Path { path, .. } => path.generics(),
_ => None,
}
}
Expand All @@ -1522,7 +1526,7 @@ impl Type {

fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
let t: PrimitiveType = match *self {
ResolvedPath { ref path } => return Some(path.def_id()),
Type::Path { ref path } => return Some(path.def_id()),
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::clean::auto_trait::AutoTraitFinder;
use crate::clean::blanket_impl::BlanketImplFinder;
use crate::clean::{
inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item,
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type,
TypeBinding, Visibility,
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, Type, TypeBinding, Visibility,
};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;
Expand Down Expand Up @@ -187,7 +186,7 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
for &did in prim.impls(tcx).iter().filter(|did| !did.is_local()) {
inline::build_impl(cx, None, did, None, ret);
}
} else if let ResolvedPath { path } = target {
} else if let Type::Path { path } = target {
let did = path.def_id();
if !did.is_local() {
inline::build_impls(cx, None, did, None, ret);
Expand Down Expand Up @@ -362,7 +361,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
_ => {
let _ = register_res(cx, path.res);
ResolvedPath { path }
Type::Path { path }
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ crate struct Options {
///
/// Be aware: This option can come both from the CLI and from crate attributes!
crate manual_passes: Vec<String>,
/// Whether to display warnings during doc generation or while gathering doctests. By default,
/// all non-rustdoc-specific lints are allowed when generating docs.
crate display_doctest_warnings: bool,
/// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
/// with and without documentation.
crate show_coverage: bool,
Expand Down Expand Up @@ -197,7 +194,6 @@ impl fmt::Debug for Options {
.field("persist_doctests", &self.persist_doctests)
.field("default_passes", &self.default_passes)
.field("manual_passes", &self.manual_passes)
.field("display_doctest_warnings", &self.display_doctest_warnings)
.field("show_coverage", &self.show_coverage)
.field("crate_version", &self.crate_version)
.field("render_options", &self.render_options)
Expand Down Expand Up @@ -639,7 +635,6 @@ impl Options {
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
let playground_url = matches.opt_str("playground-url");
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
let display_doctest_warnings = matches.opt_present("display-doctest-warnings");
let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
let enable_minification = !matches.opt_present("disable-minification");
Expand Down Expand Up @@ -707,7 +702,6 @@ impl Options {
test_args,
default_passes,
manual_passes,
display_doctest_warnings,
show_coverage,
crate_version,
test_run_directory,
Expand Down
31 changes: 9 additions & 22 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ use crate::passes::span_of_attrs;
crate struct TestOptions {
/// Whether to disable the default `extern crate my_crate;` when creating doctests.
crate no_crate_inject: bool,
/// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
/// the default `#![allow(unused)]`.
crate display_doctest_warnings: bool,
/// Additional crate-level attributes to add to doctests.
crate attrs: Vec<String>,
}
Expand All @@ -65,14 +62,16 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
}
});

debug!(?lint_opts);

let crate_types =
if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };

let sessopts = config::Options {
maybe_sysroot: options.maybe_sysroot.clone(),
search_paths: options.libs.clone(),
crate_types,
lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] },
lint_opts,
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
cg: options.codegen_options.clone(),
externs: options.externs.clone(),
Expand Down Expand Up @@ -106,7 +105,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
};

let test_args = options.test_args.clone();
let display_doctest_warnings = options.display_doctest_warnings;
let nocapture = options.nocapture;
let externs = options.externs.clone();
let json_unused_externs = options.json_unused_externs;
Expand All @@ -118,8 +116,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
let collector = global_ctxt.enter(|tcx| {
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);

let mut opts = scrape_test_config(crate_attrs);
opts.display_doctest_warnings |= options.display_doctest_warnings;
let opts = scrape_test_config(crate_attrs);
let enable_per_target_ignores = options.enable_per_target_ignores;
let mut collector = Collector::new(
tcx.crate_name(LOCAL_CRATE),
Expand Down Expand Up @@ -165,7 +162,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
Err(ErrorReported) => return Err(ErrorReported),
};

run_tests(test_args, nocapture, display_doctest_warnings, tests);
run_tests(test_args, nocapture, tests);

// Collect and warn about unused externs, but only if we've gotten
// reports for each doctest
Expand Down Expand Up @@ -208,29 +205,19 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
Ok(())
}

crate fn run_tests(
mut test_args: Vec<String>,
nocapture: bool,
display_doctest_warnings: bool,
tests: Vec<test::TestDescAndFn>,
) {
crate fn run_tests(mut test_args: Vec<String>, nocapture: bool, tests: Vec<test::TestDescAndFn>) {
test_args.insert(0, "rustdoctest".to_string());
if nocapture {
test_args.push("--nocapture".to_string());
}
test::test_main(
&test_args,
tests,
Some(test::Options::new().display_output(display_doctest_warnings)),
);
test::test_main(&test_args, tests, None);
}

// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
use rustc_ast_pretty::pprust;

let mut opts =
TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() };
let mut opts = TestOptions { no_crate_inject: false, attrs: Vec::new() };

let test_attrs: Vec<_> = attrs
.iter()
Expand Down Expand Up @@ -510,7 +497,7 @@ crate fn make_test(
let mut prog = String::new();
let mut supports_color = false;

if opts.attrs.is_empty() && !opts.display_doctest_warnings {
if opts.attrs.is_empty() {
// If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
// lints that are commonly triggered in doctests. The crate-level test attributes are
// commonly used to make tests fail in case they trigger warnings, so having this there in
Expand Down
17 changes: 1 addition & 16 deletions src/librustdoc/doctest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ assert_eq!(2+2, 4);
fn make_test_no_crate_inject() {
// Even if you do use the crate within the test, setting `opts.no_crate_inject` will skip
// adding it anyway.
let opts =
TestOptions { no_crate_inject: true, display_doctest_warnings: false, attrs: vec![] };
let opts = TestOptions { no_crate_inject: true, attrs: vec![] };
let input = "use asdf::qwop;
assert_eq!(2+2, 4);";
let expected = "#![allow(unused)]
Expand Down Expand Up @@ -215,20 +214,6 @@ assert_eq!(2+2, 4);"
assert_eq!((output, len), (expected, 1));
}

#[test]
fn make_test_display_doctest_warnings() {
// If the user is asking to display doctest warnings, suppress the default `allow(unused)`.
let mut opts = TestOptions::default();
opts.display_doctest_warnings = true;
let input = "assert_eq!(2+2, 4);";
let expected = "fn main() {
assert_eq!(2+2, 4);
}"
.to_string();
let (output, len, _) = make_test(input, None, false, &opts, DEFAULT_EDITION, None);
assert_eq!((output, len), (expected, 1));
}

#[test]
fn make_test_issues_21299_33731() {
let opts = TestOptions::default();
Expand Down
Loading

0 comments on commit bbad745

Please sign in to comment.