1
Fork 0

Auto merge of #134294 - matthiaskrgr:rollup-anh6io8, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #134252 (Fix `Path::is_absolute` on Hermit)
 - #134254 (Fix building `std` for Hermit after `c_char` change)
 - #134255 (Update includes in `/library/core/src/error.rs`.)
 - #134261 (Document the symbol Visibility enum)
 - #134262 (Arbitrary self types v2: adjust diagnostic.)
 - #134265 (Rename `ty_def_id` so people will stop using it by accident)
 - #134271 (Arbitrary self types v2: better feature gate test)
 - #134274 (Add check-pass test for `&raw`)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-12-14 06:44:05 +00:00
commit ed14192604
28 changed files with 157 additions and 54 deletions

View file

@ -246,6 +246,12 @@ hir_analysis_invalid_receiver_ty = invalid `self` parameter type: `{$receiver_ty
hir_analysis_invalid_receiver_ty_help =
consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types =
consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
hir_analysis_invalid_receiver_ty_no_arbitrary_self_types = invalid `self` parameter type: `{$receiver_ty}`
.note = type of `self` must be `Self` or a type that dereferences to it
hir_analysis_invalid_union_field =
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
.note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`

View file

@ -1748,9 +1748,15 @@ fn check_method_receiver<'tcx>(
// Report error; would not have worked with `arbitrary_self_types[_pointers]`.
{
match receiver_validity_err {
ReceiverValidityError::DoesNotDeref => {
ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => {
tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty })
}
ReceiverValidityError::DoesNotDeref => {
tcx.dcx().emit_err(errors::InvalidReceiverTyNoArbitrarySelfTypes {
span,
receiver_ty,
})
}
ReceiverValidityError::MethodGenericParamUsed => {
tcx.dcx().emit_err(errors::InvalidGenericReceiverTy { span, receiver_ty })
}

View file

@ -1655,6 +1655,16 @@ pub(crate) struct NonConstRange {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_receiver_ty_no_arbitrary_self_types, code = E0307)]
#[note]
#[help(hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types)]
pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> {
#[primary_span]
pub span: Span,
pub receiver_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_receiver_ty, code = E0307)]
#[note]

View file

@ -9,7 +9,6 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_middle::bug;
use rustc_middle::query::Key;
use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};
use rustc_middle::ty::{
self, AdtDef, Binder, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeVisitableExt,
@ -1007,8 +1006,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
)),
..
}) = node
&& let Some(ty_def_id) = qself_ty.ty_def_id()
&& let [inherent_impl] = tcx.inherent_impls(ty_def_id)
&& let Some(adt_def) = qself_ty.ty_adt_def()
&& let [inherent_impl] = tcx.inherent_impls(adt_def.did())
&& let name = format!("{ident2}_{ident3}")
&& let Some(ty::AssocItem { kind: ty::AssocKind::Fn, .. }) = tcx
.associated_items(inherent_impl)

View file

@ -294,10 +294,22 @@ pub enum Linkage {
Common,
}
/// Specifies the symbol visibility with regards to dynamic linking.
///
/// Visibility doesn't have any effect when linkage is internal.
///
/// DSO means dynamic shared object, that is a dynamically linked executable or dylib.
#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
pub enum Visibility {
/// Export the symbol from the DSO and apply overrides of the symbol by outside DSOs to within
/// the DSO if the object file format supports this.
Default,
/// Hide the symbol outside of the defining DSO even when external linkage is used to export it
/// from the object file.
Hidden,
/// Export the symbol from the DSO, but don't apply overrides of the symbol by outside DSOs to
/// within the DSO. Equivalent to default visibility with object file formats that don't support
/// overriding exported symbols by another DSO.
Protected,
}

View file

@ -41,7 +41,8 @@ pub trait Key: Sized {
None
}
fn ty_def_id(&self) -> Option<DefId> {
/// Used to detect when ADT def ids are used as keys in a cycle for better error reporting.
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
None
}
}
@ -423,7 +424,7 @@ impl<'tcx> Key for Ty<'tcx> {
DUMMY_SP
}
fn ty_def_id(&self) -> Option<DefId> {
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
match *self.kind() {
ty::Adt(adt, _) => Some(adt.did()),
ty::Coroutine(def_id, ..) => Some(def_id),
@ -471,8 +472,8 @@ impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
self.value.default_span(tcx)
}
fn ty_def_id(&self) -> Option<DefId> {
self.value.ty_def_id()
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
self.value.def_id_for_ty_in_cycle()
}
}
@ -593,7 +594,7 @@ impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>
DUMMY_SP
}
fn ty_def_id(&self) -> Option<DefId> {
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
match self.1.value.kind() {
ty::Adt(adt, _) => Some(adt.did()),
_ => None,

View file

@ -100,7 +100,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
}
for info in &cycle_error.cycle {
if info.query.dep_kind == dep_kinds::representability_adt_ty
&& let Some(def_id) = info.query.ty_def_id
&& let Some(def_id) = info.query.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
{
@ -182,7 +182,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
&cycle_error.cycle,
|cycle| {
if cycle[0].query.dep_kind == dep_kinds::layout_of
&& let Some(def_id) = cycle[0].query.ty_def_id
&& let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle
&& let Some(def_id) = def_id.as_local()
&& let def_kind = tcx.def_kind(def_id)
&& matches!(def_kind, DefKind::Closure)
@ -209,7 +209,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
if frame.query.dep_kind != dep_kinds::layout_of {
continue;
}
let Some(frame_def_id) = frame.query.ty_def_id else {
let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else {
continue;
};
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {

View file

@ -349,9 +349,9 @@ pub(crate) fn create_query_frame<
hasher.finish::<Hash64>()
})
};
let ty_def_id = key.ty_def_id();
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();
QueryStackFrame::new(description, span, def_id, def_kind, kind, ty_def_id, hash)
QueryStackFrame::new(description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
}
pub(crate) fn encode_query_results<'a, 'tcx, Q>(

View file

@ -33,7 +33,7 @@ pub struct QueryStackFrame {
pub def_id: Option<DefId>,
pub def_kind: Option<DefKind>,
/// A def-id that is extracted from a `Ty` in a query key
pub ty_def_id: Option<DefId>,
pub def_id_for_ty_in_cycle: Option<DefId>,
pub dep_kind: DepKind,
/// This hash is used to deterministically pick
/// a query to remove cycles in the parallel compiler.
@ -48,10 +48,10 @@ impl QueryStackFrame {
def_id: Option<DefId>,
def_kind: Option<DefKind>,
dep_kind: DepKind,
ty_def_id: Option<DefId>,
def_id_for_ty_in_cycle: Option<DefId>,
hash: impl FnOnce() -> Hash64,
) -> Self {
Self { description, span, def_id, def_kind, ty_def_id, dep_kind, hash: hash() }
Self { description, span, def_id, def_kind, def_id_for_ty_in_cycle, dep_kind, hash: hash() }
}
// FIXME(eddyb) Get more valid `Span`s on queries.