diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index ba35a37c32ce1..79de9bbb351f2 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -330,8 +330,12 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { ty::Float(FloatTy::F128) => "C4f128", ty::Never => "z", - // Placeholders (should be demangled as `_`). - ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => "p", + // Should only be encountered with polymorphization, + // or within the identity-substituted impl header of an + // item nested within an impl item. + ty::Param(_) => "p", + + ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => bug!(), _ => "", }; @@ -416,12 +420,18 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { // Mangle all nominal types as paths. ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args) | ty::FnDef(def_id, args) - | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Closure(def_id, args) | ty::CoroutineClosure(def_id, args) | ty::Coroutine(def_id, args) => { self.print_def_path(def_id, args)?; } + + // We may still encounter projections here due to the printing + // logic sometimes passing identity-substituted impl headers. + ty::Alias(ty::Projection, ty::AliasTy { def_id, args, .. }) => { + self.print_def_path(def_id, args)?; + } + ty::Foreign(def_id) => { self.print_def_path(def_id, &[])?; } @@ -467,8 +477,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { r.print(self)?; } - ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"), - ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"), + ty::Alias(..) => bug!("symbol_names: unexpected alias"), ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"), } @@ -550,21 +559,26 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { let (ct_ty, valtree) = match ct.kind() { ty::ConstKind::Value(ty, val) => (ty, val), - // Placeholders (should be demangled as `_`). - // NOTE(eddyb) despite `Unevaluated` having a `DefId` (and therefore - // a path), even for it we still need to encode a placeholder, as - // the path could refer back to e.g. an `impl` using the constant. - ty::ConstKind::Unevaluated(_) - | ty::ConstKind::Expr(_) - | ty::ConstKind::Param(_) - | ty::ConstKind::Infer(_) - | ty::ConstKind::Bound(..) - | ty::ConstKind::Placeholder(_) - | ty::ConstKind::Error(_) => { + // Should only be encountered with polymorphization, + // or within the identity-substituted impl header of an + // item nested within an impl item. + ty::ConstKind::Param(_) => { // Never cached (single-character). self.push("p"); return Ok(()); } + + // We may still encounter unevaluated consts due to the printing + // logic sometimes passing identity-substituted impl headers. + ty::Unevaluated(ty::UnevaluatedConst { def, args, .. }) => { + return self.print_def_path(def, args); + } + + ty::ConstKind::Expr(_) + | ty::ConstKind::Infer(_) + | ty::ConstKind::Bound(..) + | ty::ConstKind::Placeholder(_) + | ty::ConstKind::Error(_) => bug!(), }; if let Some(&i) = self.consts.get(&ct) { diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 3755f4a33cba1..979671cfa9d31 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -1058,6 +1058,13 @@ tool_doc!( is_library = true, crates = ["run_make_support"] ); +tool_doc!( + Compiletest, + "src/tools/compiletest", + rustc_tool = false, + is_library = true, + crates = ["compiletest"] +); #[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)] pub struct ErrorIndex { diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 003b11ec7cff4..2124890b94f67 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -945,6 +945,7 @@ impl<'a> Builder<'a> { doc::Releases, doc::RunMakeSupport, doc::BuildHelper, + doc::Compiletest, ), Kind::Dist => describe!( dist::Docs, diff --git a/src/librustdoc/doctest/rust.rs b/src/librustdoc/doctest/rust.rs index 5c0898f28fcc0..71a0e3d72deeb 100644 --- a/src/librustdoc/doctest/rust.rs +++ b/src/librustdoc/doctest/rust.rs @@ -122,23 +122,14 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> { // anything else, this will combine them for us. let attrs = Attributes::from_ast(ast_attrs); if let Some(doc) = attrs.opt_doc_value() { - // Use the outermost invocation, so that doctest names come from where the docs were written. - let span = ast_attrs - .iter() - .find(|attr| attr.doc_str().is_some()) - .map(|attr| attr.span.ctxt().outer_expn().expansion_cause().unwrap_or(attr.span)) - .unwrap_or(DUMMY_SP); + let span = span_of_fragments(&attrs.doc_strings).unwrap_or(sp); self.collector.position = span; markdown::find_testable_code( &doc, &mut self.collector, self.codes, self.enable_per_target_ignores, - Some(&crate::html::markdown::ExtraInfo::new( - self.tcx, - def_id, - span_of_fragments(&attrs.doc_strings).unwrap_or(sp), - )), + Some(&crate::html::markdown::ExtraInfo::new(self.tcx, def_id, span)), ); } diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 933913eb47c34..93df6aa72550f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -125,7 +125,7 @@ pub struct TestProps { // Build documentation for all specified aux-builds as well pub build_aux_docs: bool, /// Build the documentation for each crate in a unique output directory. - /// Uses /docs//doc + /// Uses `/docs//doc`. pub unique_doc_out_dir: bool, // Flag to force a crate to be built with the host architecture pub force_host: bool, @@ -1304,12 +1304,12 @@ pub fn llvm_has_libzstd(config: &Config) -> bool { false } -/// Takes a directive of the form " [- ]", -/// returns the numeric representation of and as -/// tuple: ( as u32, as u32) +/// Takes a directive of the form `" [- ]"`, +/// returns the numeric representation of `` and `` as +/// tuple: `( as u32, as u32)`. /// -/// If the part is omitted, the second component of the tuple -/// is the same as . +/// If the `` part is omitted, the second component of the tuple +/// is the same as ``. fn extract_version_range(line: &str, parse: F) -> Option<(u32, u32)> where F: Fn(&str) -> Option, diff --git a/tests/rustdoc-ui/doctest/doctest-output-include-fail.md b/tests/rustdoc-ui/doctest/doctest-output-include-fail.md new file mode 100644 index 0000000000000..a8e61238f3115 --- /dev/null +++ b/tests/rustdoc-ui/doctest/doctest-output-include-fail.md @@ -0,0 +1,7 @@ +With a code sample, that has an error: + +```rust +fn main() { + let x = 234 // no semicolon here! oh no! +} +``` diff --git a/tests/rustdoc-ui/doctest/doctest-output-include-fail.rs b/tests/rustdoc-ui/doctest/doctest-output-include-fail.rs new file mode 100644 index 0000000000000..4fc0674a0c98b --- /dev/null +++ b/tests/rustdoc-ui/doctest/doctest-output-include-fail.rs @@ -0,0 +1,7 @@ +//@ compile-flags:--test --test-args=--test-threads=1 +//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR" +//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ failure-status: 101 + +// https://github.com/rust-lang/rust/issues/130470 +#![doc = include_str!("doctest-output-include-fail.md")] diff --git a/tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout b/tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout new file mode 100644 index 0000000000000..22d15f8743c68 --- /dev/null +++ b/tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout @@ -0,0 +1,24 @@ + +running 1 test +test $DIR/doctest-output-include-fail.md - (line 3) ... FAILED + +failures: + +---- $DIR/doctest-output-include-fail.md - (line 3) stdout ---- +error: expected `;`, found `}` + --> $DIR/doctest-output-include-fail.md:5:16 + | +LL | let x = 234 // no semicolon here! oh no! + | ^ help: add `;` here +LL | } + | - unexpected token + +error: aborting due to 1 previous error + +Couldn't compile the test. + +failures: + $DIR/doctest-output-include-fail.md - (line 3) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-ui/doctest/doctest-output.stdout b/tests/rustdoc-ui/doctest/doctest-output.stdout index 35b0e366fb5cc..c3b1570c43ec1 100644 --- a/tests/rustdoc-ui/doctest/doctest-output.stdout +++ b/tests/rustdoc-ui/doctest/doctest-output.stdout @@ -1,7 +1,7 @@ running 3 tests test $DIR/doctest-output.rs - (line 8) ... ok -test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok +test $DIR/doctest-output.rs - ExpandedStruct (line 25) ... ok test $DIR/doctest-output.rs - foo::bar (line 18) ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME