Skip to content

Commit d1c29c6

Browse files
committed
Revert def_id addition from clean::Function, add test for
scrape-examples options
1 parent 8f80d86 commit d1c29c6

12 files changed

+25
-20
lines changed

src/doc/rustdoc/src/unstable-features.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,13 @@ Calculating code examples follows these rules:
458458

459459
### `--with-examples`: include examples of uses of items as documentation
460460

461-
This option, combined with `--scrape-examples-target-crate` and `--scrape-examples-output-path`, is used to implement the functionality in [RFC #3123](https://github.com/rust-lang/rfcs/pull/3123). Uses of an item (currently functions / call-sites) are found in a crate and its reverse-dependencies, and then the uses are included as documentation for that item. This feature is intended to be used via `cargo doc --scrape-examples`, but the rustdoc-only workflow looks like:
461+
This option, combined with `--scrape-examples-target-crate` and
462+
`--scrape-examples-output-path`, is used to implement the functionality in [RFC
463+
#3123](https://github.com/rust-lang/rfcs/pull/3123). Uses of an item (currently
464+
functions / call-sites) are found in a crate and its reverse-dependencies, and
465+
then the uses are included as documentation for that item. This feature is
466+
intended to be used via `cargo doc --scrape-examples`, but the rustdoc-only
467+
workflow looks like:
462468

463469
```bash
464470
$ rustdoc examples/ex.rs -Z unstable-options \
@@ -468,4 +474,8 @@ $ rustdoc examples/ex.rs -Z unstable-options \
468474
$ rustdoc src/lib.rs -Z unstable-options --with-examples output.calls
469475
```
470476

471-
First, the library must be checked to generate an `rmeta`. Then a reverse-dependency like `examples/ex.rs` is given to rustdoc with the target crate being documented (`foobar`) and a path to output the calls (`output.calls`). Then, the generated calls file can be passed via `--with-examples` to the subsequent documentation of `foobar`.
477+
First, the library must be checked to generate an `rmeta`. Then a
478+
reverse-dependency like `examples/ex.rs` is given to rustdoc with the target
479+
crate being documented (`foobar`) and a path to output the calls
480+
(`output.calls`). Then, the generated calls file can be passed via
481+
`--with-examples` to the subsequent documentation of `foobar`.

src/librustdoc/clean/inline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ fn build_external_function(cx: &mut DocContext<'_>, did: DefId) -> clean::Functi
235235
decl,
236236
generics,
237237
header: hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness },
238-
def_id: did,
239238
}
240239
}
241240

src/librustdoc/clean/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::Bo
801801
fn clean(&self, cx: &mut DocContext<'_>) -> Function {
802802
let (generics, decl) =
803803
enter_impl_trait(cx, |cx| (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)));
804-
let def_id = self.2.hir_id.owner.to_def_id();
805-
Function { decl, generics, header: self.0.header, def_id }
804+
Function { decl, generics, header: self.0.header }
806805
}
807806
}
808807

@@ -934,8 +933,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
934933
let (generics, decl) = enter_impl_trait(cx, |cx| {
935934
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
936935
});
937-
let def_id = self.def_id.to_def_id();
938-
let mut t = Function { header: sig.header, decl, generics, def_id };
936+
let mut t = Function { header: sig.header, decl, generics };
939937
if t.header.constness == hir::Constness::Const
940938
&& is_unstable_const_fn(cx.tcx, local_did).is_some()
941939
{
@@ -1069,7 +1067,6 @@ impl Clean<Item> for ty::AssocItem {
10691067
constness,
10701068
asyncness,
10711069
},
1072-
def_id: self.def_id,
10731070
},
10741071
defaultness,
10751072
)
@@ -1083,7 +1080,6 @@ impl Clean<Item> for ty::AssocItem {
10831080
constness: hir::Constness::NotConst,
10841081
asyncness: hir::IsAsync::NotAsync,
10851082
},
1086-
def_id: self.def_id,
10871083
})
10881084
}
10891085
}
@@ -2103,7 +2099,6 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
21032099
constness: hir::Constness::NotConst,
21042100
asyncness: hir::IsAsync::NotAsync,
21052101
},
2106-
def_id,
21072102
})
21082103
}
21092104
hir::ForeignItemKind::Static(ref ty, mutability) => {

src/librustdoc/clean/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,6 @@ crate struct Function {
12541254
crate decl: FnDecl,
12551255
crate generics: Generics,
12561256
crate header: hir::FnHeader,
1257-
crate def_id: DefId,
12581257
}
12591258

12601259
#[derive(Clone, PartialEq, Eq, Debug, Hash)]

src/librustdoc/html/render/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,10 @@ fn document_full_inner(
597597
clean::ItemKind::StrippedItem(box kind) | kind => kind,
598598
};
599599

600-
match kind {
601-
clean::ItemKind::FunctionItem(f) | clean::ItemKind::MethodItem(f, _) => {
602-
render_call_locations(w, cx, f.def_id, item);
600+
if let clean::ItemKind::FunctionItem(..) | clean::ItemKind::MethodItem(..) = kind {
601+
if let Some(def_id) = item.def_id.as_def_id() {
602+
render_call_locations(w, cx, def_id, item);
603603
}
604-
_ => {}
605604
}
606605
}
607606

src/librustdoc/json/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet<Qualifiers> {
289289

290290
impl FromWithTcx<clean::Function> for Function {
291291
fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self {
292-
let clean::Function { decl, generics, header, def_id: _ } = function;
292+
let clean::Function { decl, generics, header } = function;
293293
Function {
294294
decl: decl.into_tcx(tcx),
295295
generics: generics.into_tcx(tcx),
@@ -530,7 +530,7 @@ crate fn from_function_method(
530530
has_body: bool,
531531
tcx: TyCtxt<'_>,
532532
) -> Method {
533-
let clean::Function { header, decl, generics, def_id: _ } = function;
533+
let clean::Function { header, decl, generics } = function;
534534
Method {
535535
decl: decl.into_tcx(tcx),
536536
generics: generics.into_tcx(tcx),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// compile-flags: -Z unstable-options --scrape-examples-target-crate foobar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// compile-flags: -Z unstable-options --scrape-examples-output-path ex.calls
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together
2+

src/test/rustdoc-ui/scrape-examples-wrong-options.rs

-1
This file was deleted.

src/test/rustdoc-ui/scrape-examples-wrong-options.stderr

-2
This file was deleted.

0 commit comments

Comments
 (0)