Skip to content

Rollup of 3 pull requests #130597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),

_ => "",
};
Expand Down Expand Up @@ -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, &[])?;
}
Expand Down Expand Up @@ -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`"),
}

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ impl<'a> Builder<'a> {
doc::Releases,
doc::RunMakeSupport,
doc::BuildHelper,
doc::Compiletest,
),
Kind::Dist => describe!(
dist::Docs,
Expand Down
13 changes: 2 additions & 11 deletions src/librustdoc/doctest/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <root output directory>/docs/<test name>/doc
/// Uses `<root output directory>/docs/<test name>/doc`.
pub unique_doc_out_dir: bool,
// Flag to force a crate to be built with the host architecture
pub force_host: bool,
Expand Down Expand Up @@ -1304,12 +1304,12 @@ pub fn llvm_has_libzstd(config: &Config) -> bool {
false
}

/// Takes a directive of the form "<version1> [- <version2>]",
/// returns the numeric representation of <version1> and <version2> as
/// tuple: (<version1> as u32, <version2> as u32)
/// Takes a directive of the form `"<version1> [- <version2>]"`,
/// returns the numeric representation of `<version1>` and `<version2>` as
/// tuple: `(<version1> as u32, <version2> as u32)`.
///
/// If the <version2> part is omitted, the second component of the tuple
/// is the same as <version1>.
/// If the `<version2>` part is omitted, the second component of the tuple
/// is the same as `<version1>`.
fn extract_version_range<F>(line: &str, parse: F) -> Option<(u32, u32)>
where
F: Fn(&str) -> Option<u32>,
Expand Down
7 changes: 7 additions & 0 deletions tests/rustdoc-ui/doctest/doctest-output-include-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
With a code sample, that has an error:

```rust
fn main() {
let x = 234 // no semicolon here! oh no!
}
```
7 changes: 7 additions & 0 deletions tests/rustdoc-ui/doctest/doctest-output-include-fail.rs
Original file line number Diff line number Diff line change
@@ -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")]
24 changes: 24 additions & 0 deletions tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/doctest-output.stdout
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading