Skip to content
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

Rollup of 3 pull requests #112462

Closed
8 changes: 5 additions & 3 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ pub fn pre_configure_attrs(sess: &Session, attrs: &[Attribute]) -> ast::AttrVec
config_tokens: false,
lint_node_id: ast::CRATE_NODE_ID,
};
let attrs: ast::AttrVec =
attrs.iter().flat_map(|attr| strip_unconfigured.process_cfg_attr(attr)).collect();
if strip_unconfigured.in_cfg(&attrs) { attrs } else { ast::AttrVec::new() }
attrs
.iter()
.flat_map(|attr| strip_unconfigured.process_cfg_attr(attr))
.take_while(|attr| !is_cfg(attr) || strip_unconfigured.cfg_true(attr))
.collect()
}

#[macro_export]
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
) -> Result<Self::OutputTy, Self> {
Ok(noop_flat_map(node, collector))
}
fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, span: Span) {
fn expand_cfg_false(
&mut self,
collector: &mut InvocationCollector<'_, '_>,
_pos: usize,
span: Span,
) {
collector.cx.emit_err(RemoveNodeNotSupported { span, descr: Self::descr() });
}

Expand Down Expand Up @@ -1409,8 +1414,15 @@ impl InvocationCollectorNode for ast::Crate {
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
noop_visit_crate(self, visitor)
}
fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, _span: Span) {
self.attrs.clear();
fn expand_cfg_false(
&mut self,
collector: &mut InvocationCollector<'_, '_>,
pos: usize,
_span: Span,
) {
// Attributes above `cfg(FALSE)` are left in place, because we may want to configure
// some global crate properties even on fully unconfigured crates.
self.attrs.truncate(pos);
// Standard prelude imports are left in the crate for backward compatibility.
self.items.truncate(collector.cx.num_standard_library_imports);
}
Expand Down Expand Up @@ -1804,7 +1816,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
continue;
}

node.expand_cfg_false(self, span);
node.expand_cfg_false(self, pos, span);
continue;
}
sym::cfg_attr => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use super::{CanonicalInput, Certainty, EvalCtxt, Goal};
use crate::solve::canonicalize::{CanonicalizeMode, Canonicalizer};
use crate::solve::{CanonicalResponse, QueryResult, Response};
use rustc_data_structures::fx::FxHashSet;
use rustc_index::IndexVec;
use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
use rustc_infer::infer::canonical::CanonicalVarValues;
Expand Down Expand Up @@ -147,7 +148,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
// Cannot use `take_registered_region_obligations` as we may compute the response
// inside of a `probe` whenever we have multiple choices inside of the solver.
let region_obligations = self.infcx.inner.borrow().region_obligations().to_owned();
let region_constraints = self.infcx.with_region_constraints(|region_constraints| {
let mut region_constraints = self.infcx.with_region_constraints(|region_constraints| {
make_query_region_constraints(
self.tcx(),
region_obligations
Expand All @@ -157,6 +158,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
)
});

let mut seen = FxHashSet::default();
region_constraints.outlives.retain(|outlives| seen.insert(*outlives));

let mut opaque_types = self.infcx.clone_opaque_types_for_query_response();
// Only return opaque type keys for newly-defined opaques
opaque_types.retain(|(a, _)| {
Expand Down
18 changes: 9 additions & 9 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<T: ?Sized> *mut T {
/// with [`cast_mut`] on `*const T` and may have documentation value if used instead of implicit
/// coercion.
///
/// [`cast_mut`]: #method.cast_mut
/// [`cast_mut`]: pointer::cast_mut
#[stable(feature = "ptr_const_cast", since = "1.65.0")]
#[rustc_const_stable(feature = "ptr_const_cast", since = "1.65.0")]
#[inline(always)]
Expand All @@ -117,7 +117,7 @@ impl<T: ?Sized> *mut T {
/// Casts a pointer to its raw bits.
///
/// This is equivalent to `as usize`, but is more specific to enhance readability.
/// The inverse method is [`from_bits`](#method.from_bits-1).
/// The inverse method is [`from_bits`](pointer#method.from_bits-1).
///
/// In particular, `*p as usize` and `p as usize` will both compile for
/// pointers to numeric types but do very different things, so using this
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<T: ?Sized> *mut T {
/// Creates a pointer from its raw bits.
///
/// This is equivalent to `as *mut T`, but is more specific to enhance readability.
/// The inverse method is [`to_bits`](#method.to_bits-1).
/// The inverse method is [`to_bits`](pointer#method.to_bits-1).
///
/// # Examples
///
Expand Down Expand Up @@ -303,7 +303,7 @@ impl<T: ?Sized> *mut T {
///
/// For the mutable counterpart see [`as_mut`].
///
/// [`as_uninit_ref`]: #method.as_uninit_ref-1
/// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
/// [`as_mut`]: #method.as_mut
///
/// # Safety
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<T: ?Sized> *mut T {
///
/// For the mutable counterpart see [`as_uninit_mut`].
///
/// [`as_ref`]: #method.as_ref-1
/// [`as_ref`]: pointer#method.as_ref-1
/// [`as_uninit_mut`]: #method.as_uninit_mut
///
/// # Safety
Expand Down Expand Up @@ -624,7 +624,7 @@ impl<T: ?Sized> *mut T {
/// For the shared counterpart see [`as_ref`].
///
/// [`as_uninit_mut`]: #method.as_uninit_mut
/// [`as_ref`]: #method.as_ref-1
/// [`as_ref`]: pointer#method.as_ref-1
///
/// # Safety
///
Expand Down Expand Up @@ -689,7 +689,7 @@ impl<T: ?Sized> *mut T {
/// For the shared counterpart see [`as_uninit_ref`].
///
/// [`as_mut`]: #method.as_mut
/// [`as_uninit_ref`]: #method.as_uninit_ref-1
/// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
///
/// # Safety
///
Expand Down Expand Up @@ -779,7 +779,7 @@ impl<T: ?Sized> *mut T {
///
/// This function is the inverse of [`offset`].
///
/// [`offset`]: #method.offset-1
/// [`offset`]: pointer#method.offset-1
///
/// # Safety
///
Expand Down Expand Up @@ -2051,7 +2051,7 @@ impl<T> *mut [T] {
///
/// For the mutable counterpart see [`as_uninit_slice_mut`].
///
/// [`as_ref`]: #method.as_ref-1
/// [`as_ref`]: pointer#method.as_ref-1
/// [`as_uninit_slice_mut`]: #method.as_uninit_slice_mut
///
/// # Safety
Expand Down
90 changes: 78 additions & 12 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_hir::Mutability;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{Obligation, ObligationCause};
use rustc_middle::middle::stability;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{ParamEnv, TyCtxt};
use rustc_span::{
symbol::{sym, Symbol},
BytePos, FileName, RealFileName,
};
use rustc_trait_selection::traits::ObligationCtxt;
use serde::ser::{SerializeMap, SerializeSeq};
use serde::{Serialize, Serializer};

Expand Down Expand Up @@ -1112,28 +1115,76 @@ fn render_assoc_items<'a, 'cx: 'a>(
containing_item: &'a clean::Item,
it: DefId,
what: AssocItemRender<'a>,
aliased_type: Option<DefId>,
) -> impl fmt::Display + 'a + Captures<'cx> {
let mut derefs = DefIdSet::default();
derefs.insert(it);
display_fn(move |f| {
render_assoc_items_inner(f, cx, containing_item, it, what, &mut derefs);
render_assoc_items_inner(f, cx, containing_item, it, what, &mut derefs, aliased_type);
Ok(())
})
}

/// Check whether `impl_def_id` may apply to *some instantiation* of `item_def_id`.
fn is_valid_impl_for(tcx: TyCtxt<'_>, item_def_id: DefId, impl_def_id: DefId) -> bool {
let infcx = tcx.infer_ctxt().intercrate(true).build();
let ocx = ObligationCtxt::new(&infcx);
let param_env = ParamEnv::empty();

let alias_substs = infcx.fresh_substs_for_item(rustc_span::DUMMY_SP, item_def_id);
let alias_ty = tcx.type_of(item_def_id).subst(tcx, alias_substs);
let alias_bounds = tcx.predicates_of(item_def_id).instantiate(tcx, alias_substs);

let impl_substs = infcx.fresh_substs_for_item(rustc_span::DUMMY_SP, impl_def_id);
let impl_self_ty = tcx.type_of(impl_def_id).subst(tcx, impl_substs);
let impl_bounds = tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs);

if ocx.eq(&ObligationCause::dummy(), param_env, impl_self_ty, alias_ty).is_err() {
return false;
}
ocx.register_obligations(
alias_bounds
.iter()
.chain(impl_bounds)
.map(|(p, _)| Obligation::new(tcx, ObligationCause::dummy(), param_env, p)),
);

let errors = ocx.select_where_possible();
errors.is_empty()
}

// If `aliased_type` is `Some`, it means `it` is a type alias and `aliased_type` is the "actual"
// type aliased behind `it`. It is used to check whether or not the implementation of the aliased
// type can be displayed on the alias doc page.
fn render_assoc_items_inner(
mut w: &mut dyn fmt::Write,
cx: &mut Context<'_>,
containing_item: &clean::Item,
it: DefId,
what: AssocItemRender<'_>,
derefs: &mut DefIdSet,
aliased_type: Option<DefId>,
) {
info!("Documenting associated items of {:?}", containing_item.name);
let shared = Rc::clone(&cx.shared);
let cache = &shared.cache;
let Some(v) = cache.impls.get(&it) else { return };
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
let empty = Vec::new();
let v = match cache.impls.get(&it) {
Some(v) => v,
None => &empty,
};
let v2 = match aliased_type {
Some(aliased_type) => cache.impls.get(&aliased_type).unwrap_or(&empty),
None => &empty,
};
if v.is_empty() && v2.is_empty() {
return;
}
let mut saw_impls = FxHashSet::default();
let (non_trait, traits): (Vec<_>, _) =
v.iter().chain(v2).partition(|i| i.inner_impl().trait_.is_none());
let tcx = cx.tcx();
let is_alias = aliased_type.is_some();
if !non_trait.is_empty() {
let mut tmp_buf = Buffer::html();
let (render_mode, id, class_html) = match what {
Expand Down Expand Up @@ -1165,6 +1216,12 @@ fn render_assoc_items_inner(
};
let mut impls_buf = Buffer::html();
for i in &non_trait {
if !saw_impls.insert(i.def_id()) {
continue;
}
if is_alias && !is_valid_impl_for(tcx, it, i.def_id()) {
continue;
}
render_impl(
&mut impls_buf,
cx,
Expand Down Expand Up @@ -1193,9 +1250,14 @@ fn render_assoc_items_inner(
if !traits.is_empty() {
let deref_impl =
traits.iter().find(|t| t.trait_did() == cx.tcx().lang_items().deref_trait());
if let Some(impl_) = deref_impl {
if let Some(impl_) = deref_impl &&
(!is_alias || is_valid_impl_for(tcx, it, impl_.def_id()))
{
let has_deref_mut =
traits.iter().any(|t| t.trait_did() == cx.tcx().lang_items().deref_mut_trait());
traits.iter().any(|t| {
t.trait_did() == cx.tcx().lang_items().deref_mut_trait() &&
(!is_alias || is_valid_impl_for(tcx, it, t.def_id()))
});
render_deref_methods(&mut w, cx, impl_, containing_item, has_deref_mut, derefs);
}

Expand All @@ -1205,10 +1267,14 @@ fn render_assoc_items_inner(
return;
}

let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) =
traits.into_iter().partition(|t| t.inner_impl().kind.is_auto());
let (blanket_impl, concrete): (Vec<&Impl>, _) =
concrete.into_iter().partition(|t| t.inner_impl().kind.is_blanket());
let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) = traits
.into_iter()
.filter(|t| saw_impls.insert(t.def_id()))
.partition(|t| t.inner_impl().kind.is_auto());
let (blanket_impl, concrete): (Vec<&Impl>, _) = concrete
.into_iter()
.filter(|t| !is_alias || is_valid_impl_for(tcx, it, t.def_id()))
.partition(|t| t.inner_impl().kind.is_blanket());

render_all_impls(w, cx, containing_item, &concrete, &synthetic, &blanket_impl);
}
Expand Down Expand Up @@ -1247,10 +1313,10 @@ fn render_deref_methods(
return;
}
}
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs);
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs, None);
} else if let Some(prim) = target.primitive_type() {
if let Some(&did) = cache.primitive_locations.get(&prim) {
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs);
render_assoc_items_inner(&mut w, cx, container_item, did, what, derefs, None);
}
}
}
Expand Down
Loading