Skip to content

Commit 976487c

Browse files
committed
Auto merge of #130597 - matthiaskrgr:rollup-9ls4066, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #130485 (Do not expect infer/bound/placeholder/error in v0 symbol mangling) - #130567 (Register tool docs for compiletest) - #130582 (rustdoc: use the correct span for doctests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2e45ec3 + ee4afa3 commit 976487c

File tree

9 files changed

+85
-34
lines changed

9 files changed

+85
-34
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,12 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
330330
ty::Float(FloatTy::F128) => "C4f128",
331331
ty::Never => "z",
332332

333-
// Placeholders (should be demangled as `_`).
334-
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => "p",
333+
// Should only be encountered with polymorphization,
334+
// or within the identity-substituted impl header of an
335+
// item nested within an impl item.
336+
ty::Param(_) => "p",
337+
338+
ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => bug!(),
335339

336340
_ => "",
337341
};
@@ -416,12 +420,18 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
416420
// Mangle all nominal types as paths.
417421
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
418422
| ty::FnDef(def_id, args)
419-
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
420423
| ty::Closure(def_id, args)
421424
| ty::CoroutineClosure(def_id, args)
422425
| ty::Coroutine(def_id, args) => {
423426
self.print_def_path(def_id, args)?;
424427
}
428+
429+
// We may still encounter projections here due to the printing
430+
// logic sometimes passing identity-substituted impl headers.
431+
ty::Alias(ty::Projection, ty::AliasTy { def_id, args, .. }) => {
432+
self.print_def_path(def_id, args)?;
433+
}
434+
425435
ty::Foreign(def_id) => {
426436
self.print_def_path(def_id, &[])?;
427437
}
@@ -467,8 +477,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
467477
r.print(self)?;
468478
}
469479

470-
ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"),
471-
ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"),
480+
ty::Alias(..) => bug!("symbol_names: unexpected alias"),
472481
ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"),
473482
}
474483

@@ -550,21 +559,26 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
550559
let (ct_ty, valtree) = match ct.kind() {
551560
ty::ConstKind::Value(ty, val) => (ty, val),
552561

553-
// Placeholders (should be demangled as `_`).
554-
// NOTE(eddyb) despite `Unevaluated` having a `DefId` (and therefore
555-
// a path), even for it we still need to encode a placeholder, as
556-
// the path could refer back to e.g. an `impl` using the constant.
557-
ty::ConstKind::Unevaluated(_)
558-
| ty::ConstKind::Expr(_)
559-
| ty::ConstKind::Param(_)
560-
| ty::ConstKind::Infer(_)
561-
| ty::ConstKind::Bound(..)
562-
| ty::ConstKind::Placeholder(_)
563-
| ty::ConstKind::Error(_) => {
562+
// Should only be encountered with polymorphization,
563+
// or within the identity-substituted impl header of an
564+
// item nested within an impl item.
565+
ty::ConstKind::Param(_) => {
564566
// Never cached (single-character).
565567
self.push("p");
566568
return Ok(());
567569
}
570+
571+
// We may still encounter unevaluated consts due to the printing
572+
// logic sometimes passing identity-substituted impl headers.
573+
ty::Unevaluated(ty::UnevaluatedConst { def, args, .. }) => {
574+
return self.print_def_path(def, args);
575+
}
576+
577+
ty::ConstKind::Expr(_)
578+
| ty::ConstKind::Infer(_)
579+
| ty::ConstKind::Bound(..)
580+
| ty::ConstKind::Placeholder(_)
581+
| ty::ConstKind::Error(_) => bug!(),
568582
};
569583

570584
if let Some(&i) = self.consts.get(&ct) {

src/bootstrap/src/core/build_steps/doc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,13 @@ tool_doc!(
10581058
is_library = true,
10591059
crates = ["run_make_support"]
10601060
);
1061+
tool_doc!(
1062+
Compiletest,
1063+
"src/tools/compiletest",
1064+
rustc_tool = false,
1065+
is_library = true,
1066+
crates = ["compiletest"]
1067+
);
10611068

10621069
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
10631070
pub struct ErrorIndex {

src/bootstrap/src/core/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ impl<'a> Builder<'a> {
945945
doc::Releases,
946946
doc::RunMakeSupport,
947947
doc::BuildHelper,
948+
doc::Compiletest,
948949
),
949950
Kind::Dist => describe!(
950951
dist::Docs,

src/librustdoc/doctest/rust.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,14 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
122122
// anything else, this will combine them for us.
123123
let attrs = Attributes::from_ast(ast_attrs);
124124
if let Some(doc) = attrs.opt_doc_value() {
125-
// Use the outermost invocation, so that doctest names come from where the docs were written.
126-
let span = ast_attrs
127-
.iter()
128-
.find(|attr| attr.doc_str().is_some())
129-
.map(|attr| attr.span.ctxt().outer_expn().expansion_cause().unwrap_or(attr.span))
130-
.unwrap_or(DUMMY_SP);
125+
let span = span_of_fragments(&attrs.doc_strings).unwrap_or(sp);
131126
self.collector.position = span;
132127
markdown::find_testable_code(
133128
&doc,
134129
&mut self.collector,
135130
self.codes,
136131
self.enable_per_target_ignores,
137-
Some(&crate::html::markdown::ExtraInfo::new(
138-
self.tcx,
139-
def_id,
140-
span_of_fragments(&attrs.doc_strings).unwrap_or(sp),
141-
)),
132+
Some(&crate::html::markdown::ExtraInfo::new(self.tcx, def_id, span)),
142133
);
143134
}
144135

src/tools/compiletest/src/header.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub struct TestProps {
125125
// Build documentation for all specified aux-builds as well
126126
pub build_aux_docs: bool,
127127
/// Build the documentation for each crate in a unique output directory.
128-
/// Uses <root output directory>/docs/<test name>/doc
128+
/// Uses `<root output directory>/docs/<test name>/doc`.
129129
pub unique_doc_out_dir: bool,
130130
// Flag to force a crate to be built with the host architecture
131131
pub force_host: bool,
@@ -1304,12 +1304,12 @@ pub fn llvm_has_libzstd(config: &Config) -> bool {
13041304
false
13051305
}
13061306

1307-
/// Takes a directive of the form "<version1> [- <version2>]",
1308-
/// returns the numeric representation of <version1> and <version2> as
1309-
/// tuple: (<version1> as u32, <version2> as u32)
1307+
/// Takes a directive of the form `"<version1> [- <version2>]"`,
1308+
/// returns the numeric representation of `<version1>` and `<version2>` as
1309+
/// tuple: `(<version1> as u32, <version2> as u32)`.
13101310
///
1311-
/// If the <version2> part is omitted, the second component of the tuple
1312-
/// is the same as <version1>.
1311+
/// If the `<version2>` part is omitted, the second component of the tuple
1312+
/// is the same as `<version1>`.
13131313
fn extract_version_range<F>(line: &str, parse: F) -> Option<(u32, u32)>
13141314
where
13151315
F: Fn(&str) -> Option<u32>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
With a code sample, that has an error:
2+
3+
```rust
4+
fn main() {
5+
let x = 234 // no semicolon here! oh no!
6+
}
7+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ compile-flags:--test --test-args=--test-threads=1
2+
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
3+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
4+
//@ failure-status: 101
5+
6+
// https://github.com/rust-lang/rust/issues/130470
7+
#![doc = include_str!("doctest-output-include-fail.md")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
running 1 test
3+
test $DIR/doctest-output-include-fail.md - (line 3) ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/doctest-output-include-fail.md - (line 3) stdout ----
8+
error: expected `;`, found `}`
9+
--> $DIR/doctest-output-include-fail.md:5:16
10+
|
11+
LL | let x = 234 // no semicolon here! oh no!
12+
| ^ help: add `;` here
13+
LL | }
14+
| - unexpected token
15+
16+
error: aborting due to 1 previous error
17+
18+
Couldn't compile the test.
19+
20+
failures:
21+
$DIR/doctest-output-include-fail.md - (line 3)
22+
23+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
24+

tests/rustdoc-ui/doctest/doctest-output.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
running 3 tests
33
test $DIR/doctest-output.rs - (line 8) ... ok
4-
test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok
4+
test $DIR/doctest-output.rs - ExpandedStruct (line 25) ... ok
55
test $DIR/doctest-output.rs - foo::bar (line 18) ... ok
66

77
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

0 commit comments

Comments
 (0)