Skip to content

Commit bbad745

Browse files
committed
Auto merge of #91269 - matthiaskrgr:rollup-jh8i8eh, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #90611 (Fix another ICE in rustdoc scrape_examples) - #91197 (rustdoc: Rename `Type::ResolvedPath` to `Type::Path` and don't re-export it) - #91223 (Fix headings indent) - #91240 (Saner formatting for UTF8_CHAR_WIDTH table) - #91248 (Bump compiler-builtins to 0.1.53) - #91252 (Fix bug where submodules wouldn't be updated when running x.py from a subdirectory) - #91259 (Remove `--display-doctest-warnings`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ccce985 + 092477d commit bbad745

26 files changed

+200
-148
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ dependencies = [
678678

679679
[[package]]
680680
name = "compiler_builtins"
681-
version = "0.1.52"
681+
version = "0.1.53"
682682
source = "registry+https://github.com/rust-lang/crates.io-index"
683-
checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0"
683+
checksum = "2467ff455350a4df7d02f1ed1449d0279605a763de5d586dcf6aa7d732508bcb"
684684
dependencies = [
685685
"cc",
686686
"rustc-std-workspace-core",

Diff for: library/core/src/str/validations.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,23 @@ pub(super) const fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
244244

245245
// https://tools.ietf.org/html/rfc3629
246246
const UTF8_CHAR_WIDTH: &[u8; 256] = &[
247-
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,
248-
1, // 0x1F
249-
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,
250-
1, // 0x3F
251-
1, 1,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1, 1, 1, 1, 1, 1, 1, 1, 1, // 6
255+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 7
256+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8
257+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9
258+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A
259+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // B
260+
0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C
261+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // D
262+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // E
263+
4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F
263264
];
264265

265266
/// Given a first byte, determines how many bytes are in this UTF-8 character.

Diff for: library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
1818
libc = { version = "0.2.106", default-features = false, features = ['rustc-dep-of-std'] }
19-
compiler_builtins = { version = "0.1.52" }
19+
compiler_builtins = { version = "0.1.53" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }

Diff for: src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl Build {
493493

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

Diff for: src/doc/rustdoc/src/documentation-tests.md

+10
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ conversion, so type inference fails because the type is not unique. Please note
261261
that you must write the `(())` in one sequence without intermediate whitespace
262262
so that `rustdoc` understands you want an implicit `Result`-returning function.
263263

264+
## Showing warnings in doctests
265+
266+
You can show warnings in doctests by running `rustdoc --test --test-args=--show-output`
267+
(or, if you're using cargo, `cargo test --doc -- --show-output`).
268+
By default, this will still hide `unused` warnings, since so many examples use private functions;
269+
you can add `#![warn(unused)]` to the top of your example if you want to see unused variables or dead code warnings.
270+
You can also use [`#![doc(test(attr(warn(unused))))]`][test-attr] in the crate root to enable warnings globally.
271+
272+
[test-attr]: ./the-doc-attribute.md#testattr
273+
264274
## Documenting macros
265275

266276
Here’s an example of documenting a macro:

Diff for: src/doc/rustdoc/src/unstable-features.md

-16
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,6 @@ all these files are linked from every page, changing where they are can be cumbe
257257
specially cache them. This flag will rename all these files in the output to include the suffix in
258258
the filename. For example, `light.css` would become `light-suf.css` with the above command.
259259

260-
### `--display-doctest-warnings`: display warnings when documenting or running documentation tests
261-
262-
Using this flag looks like this:
263-
264-
```bash
265-
$ rustdoc src/lib.rs -Z unstable-options --display-doctest-warnings
266-
$ rustdoc --test src/lib.rs -Z unstable-options --display-doctest-warnings
267-
```
268-
269-
The intent behind this flag is to allow the user to see warnings that occur within their library or
270-
their documentation tests, which are usually suppressed. However, [due to a
271-
bug][issue-display-warnings], this flag doesn't 100% work as intended. See the linked issue for
272-
details.
273-
274-
[issue-display-warnings]: https://github.com/rust-lang/rust/issues/41574
275-
276260
### `--extern-html-root-url`: control how rustdoc links to non-local crates
277261

278262
Using this flag looks like this:

Diff for: src/librustdoc/clean/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ use crate::visit_ast::Module as DocModule;
4141

4242
use utils::*;
4343

44-
crate use utils::{get_auto_trait_and_blanket_impls, krate, register_res};
45-
46-
crate use self::types::FnRetTy::*;
47-
crate use self::types::ItemKind::*;
48-
crate use self::types::SelfTy::*;
49-
crate use self::types::Type::*;
50-
crate use self::types::Visibility::{Inherited, Public};
5144
crate use self::types::*;
45+
crate use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res};
5246

5347
crate trait Clean<T> {
5448
fn clean(&self, cx: &mut DocContext<'_>) -> T;
@@ -1411,12 +1405,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14111405
};
14121406
inline::record_extern_fqn(cx, did, kind);
14131407
let path = external_path(cx, did, false, vec![], substs);
1414-
ResolvedPath { path }
1408+
Type::Path { path }
14151409
}
14161410
ty::Foreign(did) => {
14171411
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
14181412
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
1419-
ResolvedPath { path }
1413+
Type::Path { path }
14201414
}
14211415
ty::Dynamic(obj, ref reg) => {
14221416
// HACK: pick the first `did` as the `did` of the trait object. Someone

Diff for: src/librustdoc/clean/types.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_target::spec::abi::Abi;
3434
use crate::clean::cfg::Cfg;
3535
use crate::clean::external_path;
3636
use crate::clean::inline::{self, print_inlined_const};
37-
use crate::clean::types::Type::{QPath, ResolvedPath};
3837
use crate::clean::utils::{is_literal_expr, print_const_expr, print_evaluated_const};
3938
use crate::clean::Clean;
4039
use crate::core::DocContext;
@@ -43,10 +42,14 @@ use crate::formats::item_type::ItemType;
4342
use crate::html::render::cache::ExternalLocation;
4443
use crate::html::render::Context;
4544

46-
use self::FnRetTy::*;
47-
use self::ItemKind::*;
48-
use self::SelfTy::*;
49-
use self::Type::*;
45+
crate use self::FnRetTy::*;
46+
crate use self::ItemKind::*;
47+
crate use self::SelfTy::*;
48+
crate use self::Type::{
49+
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
50+
RawPointer, Slice, Tuple,
51+
};
52+
crate use self::Visibility::{Inherited, Public};
5053

5154
crate type ItemIdSet = FxHashSet<ItemId>;
5255

@@ -1418,8 +1421,9 @@ crate struct PolyTrait {
14181421
crate enum Type {
14191422
/// A named type, which could be a trait.
14201423
///
1421-
/// This is mostly Rustdoc's version of [`hir::Path`]. It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
1422-
ResolvedPath { path: Path },
1424+
/// This is mostly Rustdoc's version of [`hir::Path`].
1425+
/// It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
1426+
Path { path: Path },
14231427
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
14241428
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
14251429
/// A type parameter.
@@ -1485,7 +1489,7 @@ impl Type {
14851489
/// Checks if this is a `T::Name` path for an associated type.
14861490
crate fn is_assoc_ty(&self) -> bool {
14871491
match self {
1488-
ResolvedPath { path, .. } => path.is_assoc_ty(),
1492+
Type::Path { path, .. } => path.is_assoc_ty(),
14891493
_ => false,
14901494
}
14911495
}
@@ -1499,7 +1503,7 @@ impl Type {
14991503

15001504
crate fn generics(&self) -> Option<Vec<&Type>> {
15011505
match self {
1502-
ResolvedPath { path, .. } => path.generics(),
1506+
Type::Path { path, .. } => path.generics(),
15031507
_ => None,
15041508
}
15051509
}
@@ -1522,7 +1526,7 @@ impl Type {
15221526

15231527
fn inner_def_id(&self, cache: Option<&Cache>) -> Option<DefId> {
15241528
let t: PrimitiveType = match *self {
1525-
ResolvedPath { ref path } => return Some(path.def_id()),
1529+
Type::Path { ref path } => return Some(path.def_id()),
15261530
DynTrait(ref bounds, _) => return Some(bounds[0].trait_.def_id()),
15271531
Primitive(p) => return cache.and_then(|c| c.primitive_locations.get(&p).cloned()),
15281532
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,

Diff for: src/librustdoc/clean/utils.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
44
inline, Clean, Crate, ExternalCrate, Generic, GenericArg, GenericArgs, ImportSource, Item,
5-
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Type,
6-
TypeBinding, Visibility,
5+
ItemKind, Lifetime, Path, PathSegment, Primitive, PrimitiveType, Type, TypeBinding, Visibility,
76
};
87
use crate::core::DocContext;
98
use crate::formats::item_type::ItemType;
@@ -187,7 +186,7 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret:
187186
for &did in prim.impls(tcx).iter().filter(|did| !did.is_local()) {
188187
inline::build_impl(cx, None, did, None, ret);
189188
}
190-
} else if let ResolvedPath { path } = target {
189+
} else if let Type::Path { path } = target {
191190
let did = path.def_id();
192191
if !did.is_local() {
193192
inline::build_impls(cx, None, did, None, ret);
@@ -362,7 +361,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
362361
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
363362
_ => {
364363
let _ = register_res(cx, path.res);
365-
ResolvedPath { path }
364+
Type::Path { path }
366365
}
367366
}
368367
}

Diff for: src/librustdoc/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ crate struct Options {
136136
///
137137
/// Be aware: This option can come both from the CLI and from crate attributes!
138138
crate manual_passes: Vec<String>,
139-
/// Whether to display warnings during doc generation or while gathering doctests. By default,
140-
/// all non-rustdoc-specific lints are allowed when generating docs.
141-
crate display_doctest_warnings: bool,
142139
/// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items
143140
/// with and without documentation.
144141
crate show_coverage: bool,
@@ -197,7 +194,6 @@ impl fmt::Debug for Options {
197194
.field("persist_doctests", &self.persist_doctests)
198195
.field("default_passes", &self.default_passes)
199196
.field("manual_passes", &self.manual_passes)
200-
.field("display_doctest_warnings", &self.display_doctest_warnings)
201197
.field("show_coverage", &self.show_coverage)
202198
.field("crate_version", &self.crate_version)
203199
.field("render_options", &self.render_options)
@@ -639,7 +635,6 @@ impl Options {
639635
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
640636
let playground_url = matches.opt_str("playground-url");
641637
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
642-
let display_doctest_warnings = matches.opt_present("display-doctest-warnings");
643638
let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
644639
let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
645640
let enable_minification = !matches.opt_present("disable-minification");
@@ -707,7 +702,6 @@ impl Options {
707702
test_args,
708703
default_passes,
709704
manual_passes,
710-
display_doctest_warnings,
711705
show_coverage,
712706
crate_version,
713707
test_run_directory,

Diff for: src/librustdoc/doctest.rs

+9-22
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ use crate::passes::span_of_attrs;
3838
crate struct TestOptions {
3939
/// Whether to disable the default `extern crate my_crate;` when creating doctests.
4040
crate no_crate_inject: bool,
41-
/// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
42-
/// the default `#![allow(unused)]`.
43-
crate display_doctest_warnings: bool,
4441
/// Additional crate-level attributes to add to doctests.
4542
crate attrs: Vec<String>,
4643
}
@@ -65,14 +62,16 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
6562
}
6663
});
6764

65+
debug!(?lint_opts);
66+
6867
let crate_types =
6968
if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
7069

7170
let sessopts = config::Options {
7271
maybe_sysroot: options.maybe_sysroot.clone(),
7372
search_paths: options.libs.clone(),
7473
crate_types,
75-
lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] },
74+
lint_opts,
7675
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
7776
cg: options.codegen_options.clone(),
7877
externs: options.externs.clone(),
@@ -106,7 +105,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
106105
};
107106

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

121-
let mut opts = scrape_test_config(crate_attrs);
122-
opts.display_doctest_warnings |= options.display_doctest_warnings;
119+
let opts = scrape_test_config(crate_attrs);
123120
let enable_per_target_ignores = options.enable_per_target_ignores;
124121
let mut collector = Collector::new(
125122
tcx.crate_name(LOCAL_CRATE),
@@ -165,7 +162,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
165162
Err(ErrorReported) => return Err(ErrorReported),
166163
};
167164

168-
run_tests(test_args, nocapture, display_doctest_warnings, tests);
165+
run_tests(test_args, nocapture, tests);
169166

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

211-
crate fn run_tests(
212-
mut test_args: Vec<String>,
213-
nocapture: bool,
214-
display_doctest_warnings: bool,
215-
tests: Vec<test::TestDescAndFn>,
216-
) {
208+
crate fn run_tests(mut test_args: Vec<String>, nocapture: bool, tests: Vec<test::TestDescAndFn>) {
217209
test_args.insert(0, "rustdoctest".to_string());
218210
if nocapture {
219211
test_args.push("--nocapture".to_string());
220212
}
221-
test::test_main(
222-
&test_args,
223-
tests,
224-
Some(test::Options::new().display_output(display_doctest_warnings)),
225-
);
213+
test::test_main(&test_args, tests, None);
226214
}
227215

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

232-
let mut opts =
233-
TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() };
220+
let mut opts = TestOptions { no_crate_inject: false, attrs: Vec::new() };
234221

235222
let test_attrs: Vec<_> = attrs
236223
.iter()
@@ -510,7 +497,7 @@ crate fn make_test(
510497
let mut prog = String::new();
511498
let mut supports_color = false;
512499

513-
if opts.attrs.is_empty() && !opts.display_doctest_warnings {
500+
if opts.attrs.is_empty() {
514501
// If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
515502
// lints that are commonly triggered in doctests. The crate-level test attributes are
516503
// commonly used to make tests fail in case they trigger warnings, so having this there in

Diff for: src/librustdoc/doctest/tests.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ assert_eq!(2+2, 4);
5252
fn make_test_no_crate_inject() {
5353
// Even if you do use the crate within the test, setting `opts.no_crate_inject` will skip
5454
// adding it anyway.
55-
let opts =
56-
TestOptions { no_crate_inject: true, display_doctest_warnings: false, attrs: vec![] };
55+
let opts = TestOptions { no_crate_inject: true, attrs: vec![] };
5756
let input = "use asdf::qwop;
5857
assert_eq!(2+2, 4);";
5958
let expected = "#![allow(unused)]
@@ -215,20 +214,6 @@ assert_eq!(2+2, 4);"
215214
assert_eq!((output, len), (expected, 1));
216215
}
217216

218-
#[test]
219-
fn make_test_display_doctest_warnings() {
220-
// If the user is asking to display doctest warnings, suppress the default `allow(unused)`.
221-
let mut opts = TestOptions::default();
222-
opts.display_doctest_warnings = true;
223-
let input = "assert_eq!(2+2, 4);";
224-
let expected = "fn main() {
225-
assert_eq!(2+2, 4);
226-
}"
227-
.to_string();
228-
let (output, len, _) = make_test(input, None, false, &opts, DEFAULT_EDITION, None);
229-
assert_eq!((output, len), (expected, 1));
230-
}
231-
232217
#[test]
233218
fn make_test_issues_21299_33731() {
234219
let opts = TestOptions::default();

0 commit comments

Comments
 (0)