diff options
| author | bors <bors@rust-lang.org> | 2022-06-04 23:14:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-04 23:14:09 +0000 |
| commit | 43874a2ee749c2dd9f052172341f2f87fa36cd79 (patch) | |
| tree | d4d0186c548df3f4fe7e6330e25bcf5b95d434e5 /src | |
| parent | 4e725bad73747a4c93a3ac53106e4b4006edc665 (diff) | |
| parent | 1794309e0aa451e63d74511d4af595a5bcd0f685 (diff) | |
| download | rust-43874a2ee749c2dd9f052172341f2f87fa36cd79.tar.gz rust-43874a2ee749c2dd9f052172341f2f87fa36cd79.zip | |
Auto merge of #97742 - matthiaskrgr:rollup-fr3j0t8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #97609 (Iterate over `maybe_unused_trait_imports` when checking dead trait imports) - #97688 (test const_copy to make sure bytewise pointer copies are working) - #97707 (Improve soundness of rustc_data_structures) - #97731 (Add regresion test for #87142) - #97735 (Don't generate "Impls on Foreign Types" for std) - #97737 (Fix pretty printing named bound regions under -Zverbose) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/formats/mod.rs | 17 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/generator/issue-87142.rs | 32 |
4 files changed, 50 insertions, 6 deletions
diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs index 9f26ccc74d1..b236bd7be4f 100644 --- a/src/librustdoc/formats/mod.rs +++ b/src/librustdoc/formats/mod.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId; pub(crate) use renderer::{run_format, FormatRenderer}; use crate::clean::{self, ItemId}; -use cache::Cache; +use crate::html::render::Context; /// Specifies whether rendering directly implemented trait items or ones from a certain Deref /// impl. @@ -65,7 +65,8 @@ impl Impl { // Returns true if this is an implementation on a "local" type, meaning: // the type is in the current crate, or the type and the trait are both // re-exported by the current crate. - pub(crate) fn is_on_local_type(&self, cache: &Cache) -> bool { + pub(crate) fn is_on_local_type(&self, cx: &Context<'_>) -> bool { + let cache = cx.cache(); let for_type = &self.inner_impl().for_; if let Some(for_type_did) = for_type.def_id(cache) { // The "for" type is local if it's in the paths for the current crate. @@ -80,6 +81,18 @@ impl Impl { if for_type_did.krate == trait_did.krate { return true; } + // Hack: many traits and types in std are re-exported from + // core or alloc. In general, rustdoc is capable of recognizing + // these implementations as being on local types. However, in at + // least one case (https://github.com/rust-lang/rust/issues/97610), + // rustdoc gets confused and labels an implementation as being on + // a foreign type. To make sure that confusion doesn't pass on to + // the reader, consider all implementations in std, core, and alloc + // to be on local types. + let crate_name = cx.tcx().crate_name(trait_did.krate); + if matches!(crate_name.as_str(), "std" | "core" | "alloc") { + return true; + } } return false; }; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 0b801a20995..23ce634cf28 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2281,11 +2281,10 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean |sym| format!("<a href=\"#{1}.{0}\">{0}</a>", sym, ItemType::Method), ); - let cache = cx.cache(); - if let Some(implementors) = cache.implementors.get(&it.item_id.expect_def_id()) { + if let Some(implementors) = cx.cache().implementors.get(&it.item_id.expect_def_id()) { let mut res = implementors .iter() - .filter(|i| !i.is_on_local_type(cache)) + .filter(|i| !i.is_on_local_type(cx)) .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .collect::<Vec<_>>(); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 8683e6dfcd9..d115185562c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -823,7 +823,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: } let (local, foreign) = - implementors.iter().partition::<Vec<_>, _>(|i| i.is_on_local_type(cache)); + implementors.iter().partition::<Vec<_>, _>(|i| i.is_on_local_type(cx)); let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter().partition(|i| i.inner_impl().kind.is_auto()); diff --git a/src/test/ui/generator/issue-87142.rs b/src/test/ui/generator/issue-87142.rs new file mode 100644 index 00000000000..fc10d04d46c --- /dev/null +++ b/src/test/ui/generator/issue-87142.rs @@ -0,0 +1,32 @@ +// compile-flags: -Cdebuginfo=2 +// build-pass + +// Regression test for #87142 +// This test needs the above flags and the "lib" crate type. + +#![feature(type_alias_impl_trait, generator_trait, generators)] +#![crate_type = "lib"] + +use std::ops::Generator; + +pub trait GeneratorProviderAlt: Sized { + type Gen: Generator<(), Return = (), Yield = ()>; + + fn start(ctx: Context<Self>) -> Self::Gen; +} + +pub struct Context<G: 'static + GeneratorProviderAlt> { + pub link: Box<G::Gen>, +} + +impl GeneratorProviderAlt for () { + type Gen = impl Generator<(), Return = (), Yield = ()>; + fn start(ctx: Context<Self>) -> Self::Gen { + move || { + match ctx { + _ => (), + } + yield (); + } + } +} |
