Auto merge of #128689 - matthiaskrgr:rollup-ukyn8wq, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #128385 (rustdoc-json: discard non-local inherent impls for primitives)
 - #128559 (Don't re-elaborated already elaborated caller bounds in method probe)
 - #128631 (handle crates when they are not specified for std docs)
 - #128664 (Add `Debug` impls to API types in `rustc_codegen_ssa`)
 - #128686 (fix the invalid argument type)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-08-05 17:03:58 +00:00
commit f7eefec4e0
10 changed files with 56 additions and 61 deletions

View File

@ -8,7 +8,7 @@ use rustc_span::Span;
use crate::traits::*; use crate::traits::*;
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum IntPredicate { pub enum IntPredicate {
IntEQ, IntEQ,
IntNE, IntNE,
@ -22,7 +22,7 @@ pub enum IntPredicate {
IntSLE, IntSLE,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum RealPredicate { pub enum RealPredicate {
RealPredicateFalse, RealPredicateFalse,
RealOEQ, RealOEQ,
@ -42,7 +42,7 @@ pub enum RealPredicate {
RealPredicateTrue, RealPredicateTrue,
} }
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq, Debug)]
pub enum AtomicRmwBinOp { pub enum AtomicRmwBinOp {
AtomicXchg, AtomicXchg,
AtomicAdd, AtomicAdd,
@ -57,7 +57,7 @@ pub enum AtomicRmwBinOp {
AtomicUMin, AtomicUMin,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum AtomicOrdering { pub enum AtomicOrdering {
Unordered, Unordered,
Relaxed, Relaxed,
@ -67,7 +67,7 @@ pub enum AtomicOrdering {
SequentiallyConsistent, SequentiallyConsistent,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum SynchronizationScope { pub enum SynchronizationScope {
SingleThread, SingleThread,
CrossThread, CrossThread,

View File

@ -23,7 +23,7 @@ use crate::mir::operand::{OperandRef, OperandValue};
use crate::mir::place::{PlaceRef, PlaceValue}; use crate::mir::place::{PlaceRef, PlaceValue};
use crate::MemFlags; use crate::MemFlags;
#[derive(Copy, Clone)] #[derive(Copy, Clone, Debug)]
pub enum OverflowOp { pub enum OverflowOp {
Add, Add,
Sub, Sub,

View File

@ -774,18 +774,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// instantiation that replaces `Self` with the object type itself. Hence, // instantiation that replaces `Self` with the object type itself. Hence,
// a `&self` method will wind up with an argument type like `&dyn Trait`. // a `&self` method will wind up with an argument type like `&dyn Trait`.
let trait_ref = principal.with_self_ty(self.tcx, self_ty); let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| { self.assemble_candidates_for_bounds(
this.push_candidate( traits::supertraits(self.tcx, trait_ref),
Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: smallvec![] }, |this, new_trait_ref, item| {
true, this.push_candidate(
); Candidate {
}); item,
kind: ObjectCandidate(new_trait_ref),
import_ids: smallvec![],
},
true,
);
},
);
} }
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) { fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
// FIXME: do we want to commit to this behavior for param bounds?
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| { let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
let bound_predicate = predicate.kind(); let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
@ -806,7 +811,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} }
}); });
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| { self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
this.push_candidate( this.push_candidate(
Candidate { Candidate {
item, item,
@ -820,15 +825,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// Do a search through a list of bounds, using a callback to actually // Do a search through a list of bounds, using a callback to actually
// create the candidates. // create the candidates.
fn elaborate_bounds<F>( fn assemble_candidates_for_bounds<F>(
&mut self, &mut self,
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>, bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
mut mk_cand: F, mut mk_cand: F,
) where ) where
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem), F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
{ {
let tcx = self.tcx; for bound_trait_ref in bounds {
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref); debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) { for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
if !self.has_applicable_self(&item) { if !self.has_applicable_self(&item) {

View File

@ -62,7 +62,7 @@ pub use self::specialize::{
}; };
pub use self::structural_normalize::StructurallyNormalizeExt; pub use self::structural_normalize::StructurallyNormalizeExt;
pub use self::util::{ pub use self::util::{
elaborate, expand_trait_aliases, impl_item_is_final, supertraits, transitive_bounds, elaborate, expand_trait_aliases, impl_item_is_final, supertraits,
transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars, transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars,
BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo, BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo,
}; };

View File

@ -264,15 +264,6 @@ pub fn supertraits<I: Interner>(
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits() elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
} }
pub fn transitive_bounds<I: Interner>(
cx: I,
trait_refs: impl Iterator<Item = ty::Binder<I, ty::TraitRef<I>>>,
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
elaborate(cx, trait_refs.map(|trait_ref| trait_ref.upcast(cx)))
.filter_only_self()
.filter_to_traits()
}
impl<I: Interner> Elaborator<I, I::Clause> { impl<I: Interner> Elaborator<I, I::Clause> {
fn filter_to_traits(self) -> FilterToTraits<I, Self> { fn filter_to_traits(self) -> FilterToTraits<I, Self> {
FilterToTraits { _cx: PhantomData, base_iterator: self } FilterToTraits { _cx: PhantomData, base_iterator: self }

View File

@ -599,6 +599,16 @@ impl Step for Std {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let stage = self.stage; let stage = self.stage;
let target = self.target; let target = self.target;
let crates = if self.crates.is_empty() {
builder
.in_tree_crates("sysroot", Some(target))
.iter()
.map(|c| c.name.to_string())
.collect()
} else {
self.crates
};
let out = match self.format { let out = match self.format {
DocumentationFormat::Html => builder.doc_out(target), DocumentationFormat::Html => builder.doc_out(target),
DocumentationFormat::Json => builder.json_doc_out(target), DocumentationFormat::Json => builder.json_doc_out(target),
@ -627,7 +637,7 @@ impl Step for Std {
extra_args.push("--disable-minification"); extra_args.push("--disable-minification");
} }
doc_std(builder, self.format, stage, target, &out, &extra_args, &self.crates); doc_std(builder, self.format, stage, target, &out, &extra_args, &crates);
// Don't open if the format is json // Don't open if the format is json
if let DocumentationFormat::Json = self.format { if let DocumentationFormat::Json = self.format {
@ -639,7 +649,7 @@ impl Step for Std {
let index = out.join("std").join("index.html"); let index = out.join("std").join("index.html");
builder.open_in_browser(index); builder.open_in_browser(index);
} else { } else {
for requested_crate in &*self.crates { for requested_crate in crates {
if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) { if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) {
let index = out.join(requested_crate).join("index.html"); let index = out.join(requested_crate).join("index.html");
builder.open_in_browser(index); builder.open_in_browser(index);

View File

@ -536,8 +536,7 @@ pub fn get_closest_merge_base_commit(
let merge_base = get_git_merge_base(config, source_dir).unwrap_or_else(|_| "HEAD".into()); let merge_base = get_git_merge_base(config, source_dir).unwrap_or_else(|_| "HEAD".into());
git.arg(Path::new("rev-list")); git.args(["rev-list", &format!("--author={author}"), "-n1", "--first-parent", &merge_base]);
git.args([&format!("--author={author}"), "-n1", "--first-parent", &merge_base]);
if !target_paths.is_empty() { if !target_paths.is_empty() {
git.arg("--").args(target_paths); git.arg("--").args(target_paths);

View File

@ -310,16 +310,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// `public_items` map, so we can skip inserting into the // `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're // paths map if there was already an entry present and we're
// not a public item. // not a public item.
if !self.cache.paths.contains_key(&item.item_id.expect_def_id()) let item_def_id = item.item_id.expect_def_id();
if !self.cache.paths.contains_key(&item_def_id)
|| self || self
.cache .cache
.effective_visibilities .effective_visibilities
.is_directly_public(self.tcx, item.item_id.expect_def_id()) .is_directly_public(self.tcx, item_def_id)
{ {
self.cache.paths.insert( self.cache
item.item_id.expect_def_id(), .paths
(self.cache.stack.clone(), item.type_()), .insert(item_def_id, (self.cache.stack.clone(), item.type_()));
);
} }
} }
} }
@ -381,9 +381,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
&& adt.is_fundamental() && adt.is_fundamental()
{ {
for ty in generics { for ty in generics {
if let Some(did) = ty.def_id(self.cache) { dids.extend(ty.def_id(self.cache));
dids.insert(did);
}
} }
} }
} }
@ -396,32 +394,26 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
.primitive_type() .primitive_type()
.and_then(|t| self.cache.primitive_locations.get(&t).cloned()); .and_then(|t| self.cache.primitive_locations.get(&t).cloned());
if let Some(did) = did { dids.extend(did);
dids.insert(did);
}
} }
} }
if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) { if let Some(generics) = i.trait_.as_ref().and_then(|t| t.generics()) {
for bound in generics { for bound in generics {
if let Some(did) = bound.def_id(self.cache) { dids.extend(bound.def_id(self.cache));
dids.insert(did);
}
} }
} }
let impl_item = Impl { impl_item: item }; let impl_item = Impl { impl_item: item };
if impl_item.trait_did().map_or(true, |d| self.cache.traits.contains_key(&d)) { let impl_did = impl_item.def_id();
let trait_did = impl_item.trait_did();
if trait_did.map_or(true, |d| self.cache.traits.contains_key(&d)) {
for did in dids { for did in dids {
if self.impl_ids.entry(did).or_default().insert(impl_item.def_id()) { if self.impl_ids.entry(did).or_default().insert(impl_did) {
self.cache self.cache.impls.entry(did).or_default().push(impl_item.clone());
.impls
.entry(did)
.or_insert_with(Vec::new)
.push(impl_item.clone());
} }
} }
} else { } else {
let trait_did = impl_item.trait_did().expect("no trait did"); let trait_did = trait_did.expect("no trait did");
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item)); self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
} }
None None

View File

@ -216,13 +216,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
fn after_krate(&mut self) -> Result<(), Error> { fn after_krate(&mut self) -> Result<(), Error> {
debug!("Done with crate"); debug!("Done with crate");
debug!("Adding Primitive impls");
for primitive in Rc::clone(&self.cache).primitive_locations.values() {
self.get_impls(*primitive);
}
let e = ExternalCrate { crate_num: LOCAL_CRATE }; let e = ExternalCrate { crate_num: LOCAL_CRATE };
let index = (*self.index).clone().into_inner(); let index = (*self.index).clone().into_inner();
debug!("Constructing Output"); debug!("Constructing Output");

View File

@ -0,0 +1,5 @@
// This test asserts that `index` is not polluted with unrelated items.
// See https://github.com/rust-lang/rust/issues/114039
//@ count "$.index[*]" 1
fn main() {}