Skip to content

Commit ed14192

Browse files
committed
Auto merge of rust-lang#134294 - matthiaskrgr:rollup-anh6io8, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#134252 (Fix `Path::is_absolute` on Hermit) - rust-lang#134254 (Fix building `std` for Hermit after `c_char` change) - rust-lang#134255 (Update includes in `/library/core/src/error.rs`.) - rust-lang#134261 (Document the symbol Visibility enum) - rust-lang#134262 (Arbitrary self types v2: adjust diagnostic.) - rust-lang#134265 (Rename `ty_def_id` so people will stop using it by accident) - rust-lang#134271 (Arbitrary self types v2: better feature gate test) - rust-lang#134274 (Add check-pass test for `&raw`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a1740a9 + 4efa98c commit ed14192

28 files changed

+157
-54
lines changed

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ hir_analysis_invalid_receiver_ty = invalid `self` parameter type: `{$receiver_ty
246246
hir_analysis_invalid_receiver_ty_help =
247247
consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
248248
249+
hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types =
250+
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`)
251+
252+
hir_analysis_invalid_receiver_ty_no_arbitrary_self_types = invalid `self` parameter type: `{$receiver_ty}`
253+
.note = type of `self` must be `Self` or a type that dereferences to it
254+
249255
hir_analysis_invalid_union_field =
250256
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
251257
.note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,9 +1748,15 @@ fn check_method_receiver<'tcx>(
17481748
// Report error; would not have worked with `arbitrary_self_types[_pointers]`.
17491749
{
17501750
match receiver_validity_err {
1751-
ReceiverValidityError::DoesNotDeref => {
1751+
ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => {
17521752
tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty })
17531753
}
1754+
ReceiverValidityError::DoesNotDeref => {
1755+
tcx.dcx().emit_err(errors::InvalidReceiverTyNoArbitrarySelfTypes {
1756+
span,
1757+
receiver_ty,
1758+
})
1759+
}
17541760
ReceiverValidityError::MethodGenericParamUsed => {
17551761
tcx.dcx().emit_err(errors::InvalidGenericReceiverTy { span, receiver_ty })
17561762
}

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,16 @@ pub(crate) struct NonConstRange {
16551655
pub span: Span,
16561656
}
16571657

1658+
#[derive(Diagnostic)]
1659+
#[diag(hir_analysis_invalid_receiver_ty_no_arbitrary_self_types, code = E0307)]
1660+
#[note]
1661+
#[help(hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types)]
1662+
pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> {
1663+
#[primary_span]
1664+
pub span: Span,
1665+
pub receiver_ty: Ty<'tcx>,
1666+
}
1667+
16581668
#[derive(Diagnostic)]
16591669
#[diag(hir_analysis_invalid_receiver_ty, code = E0307)]
16601670
#[note]

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::def_id::DefId;
1111
use rustc_middle::bug;
12-
use rustc_middle::query::Key;
1312
use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};
1413
use rustc_middle::ty::{
1514
self, AdtDef, Binder, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeVisitableExt,
@@ -1007,8 +1006,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10071006
)),
10081007
..
10091008
}) = node
1010-
&& let Some(ty_def_id) = qself_ty.ty_def_id()
1011-
&& let [inherent_impl] = tcx.inherent_impls(ty_def_id)
1009+
&& let Some(adt_def) = qself_ty.ty_adt_def()
1010+
&& let [inherent_impl] = tcx.inherent_impls(adt_def.did())
10121011
&& let name = format!("{ident2}_{ident3}")
10131012
&& let Some(ty::AssocItem { kind: ty::AssocKind::Fn, .. }) = tcx
10141013
.associated_items(inherent_impl)

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,22 @@ pub enum Linkage {
294294
Common,
295295
}
296296

297+
/// Specifies the symbol visibility with regards to dynamic linking.
298+
///
299+
/// Visibility doesn't have any effect when linkage is internal.
300+
///
301+
/// DSO means dynamic shared object, that is a dynamically linked executable or dylib.
297302
#[derive(Copy, Clone, PartialEq, Debug, HashStable)]
298303
pub enum Visibility {
304+
/// Export the symbol from the DSO and apply overrides of the symbol by outside DSOs to within
305+
/// the DSO if the object file format supports this.
299306
Default,
307+
/// Hide the symbol outside of the defining DSO even when external linkage is used to export it
308+
/// from the object file.
300309
Hidden,
310+
/// Export the symbol from the DSO, but don't apply overrides of the symbol by outside DSOs to
311+
/// within the DSO. Equivalent to default visibility with object file formats that don't support
312+
/// overriding exported symbols by another DSO.
301313
Protected,
302314
}
303315

compiler/rustc_middle/src/query/keys.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub trait Key: Sized {
4141
None
4242
}
4343

44-
fn ty_def_id(&self) -> Option<DefId> {
44+
/// Used to detect when ADT def ids are used as keys in a cycle for better error reporting.
45+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
4546
None
4647
}
4748
}
@@ -423,7 +424,7 @@ impl<'tcx> Key for Ty<'tcx> {
423424
DUMMY_SP
424425
}
425426

426-
fn ty_def_id(&self) -> Option<DefId> {
427+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
427428
match *self.kind() {
428429
ty::Adt(adt, _) => Some(adt.did()),
429430
ty::Coroutine(def_id, ..) => Some(def_id),
@@ -471,8 +472,8 @@ impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
471472
self.value.default_span(tcx)
472473
}
473474

474-
fn ty_def_id(&self) -> Option<DefId> {
475-
self.value.ty_def_id()
475+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
476+
self.value.def_id_for_ty_in_cycle()
476477
}
477478
}
478479

@@ -593,7 +594,7 @@ impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>
593594
DUMMY_SP
594595
}
595596

596-
fn ty_def_id(&self) -> Option<DefId> {
597+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
597598
match self.1.value.kind() {
598599
ty::Adt(adt, _) => Some(adt.did()),
599600
_ => None,

compiler/rustc_middle/src/values.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
100100
}
101101
for info in &cycle_error.cycle {
102102
if info.query.dep_kind == dep_kinds::representability_adt_ty
103-
&& let Some(def_id) = info.query.ty_def_id
103+
&& let Some(def_id) = info.query.def_id_for_ty_in_cycle
104104
&& let Some(def_id) = def_id.as_local()
105105
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
106106
{
@@ -182,7 +182,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
182182
&cycle_error.cycle,
183183
|cycle| {
184184
if cycle[0].query.dep_kind == dep_kinds::layout_of
185-
&& let Some(def_id) = cycle[0].query.ty_def_id
185+
&& let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle
186186
&& let Some(def_id) = def_id.as_local()
187187
&& let def_kind = tcx.def_kind(def_id)
188188
&& matches!(def_kind, DefKind::Closure)
@@ -209,7 +209,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
209209
if frame.query.dep_kind != dep_kinds::layout_of {
210210
continue;
211211
}
212-
let Some(frame_def_id) = frame.query.ty_def_id else {
212+
let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else {
213213
continue;
214214
};
215215
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ pub(crate) fn create_query_frame<
349349
hasher.finish::<Hash64>()
350350
})
351351
};
352-
let ty_def_id = key.ty_def_id();
352+
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();
353353

354-
QueryStackFrame::new(description, span, def_id, def_kind, kind, ty_def_id, hash)
354+
QueryStackFrame::new(description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
355355
}
356356

357357
pub(crate) fn encode_query_results<'a, 'tcx, Q>(

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct QueryStackFrame {
3333
pub def_id: Option<DefId>,
3434
pub def_kind: Option<DefKind>,
3535
/// A def-id that is extracted from a `Ty` in a query key
36-
pub ty_def_id: Option<DefId>,
36+
pub def_id_for_ty_in_cycle: Option<DefId>,
3737
pub dep_kind: DepKind,
3838
/// This hash is used to deterministically pick
3939
/// a query to remove cycles in the parallel compiler.
@@ -48,10 +48,10 @@ impl QueryStackFrame {
4848
def_id: Option<DefId>,
4949
def_kind: Option<DefKind>,
5050
dep_kind: DepKind,
51-
ty_def_id: Option<DefId>,
51+
def_id_for_ty_in_cycle: Option<DefId>,
5252
hash: impl FnOnce() -> Hash64,
5353
) -> Self {
54-
Self { description, span, def_id, def_kind, ty_def_id, dep_kind, hash: hash() }
54+
Self { description, span, def_id, def_kind, def_id_for_ty_in_cycle, dep_kind, hash: hash() }
5555
}
5656

5757
// FIXME(eddyb) Get more valid `Span`s on queries.

library/core/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![stable(feature = "error_in_core", since = "1.81.0")]
33

44
use crate::any::TypeId;
5-
use crate::fmt::{Debug, Display, Formatter, Result};
5+
use crate::fmt::{self, Debug, Display, Formatter};
66

77
/// `Error` is a trait representing the basic expectations for error values,
88
/// i.e., values of type `E` in [`Result<T, E>`].
@@ -857,7 +857,7 @@ impl<'a> Request<'a> {
857857

858858
#[unstable(feature = "error_generic_member_access", issue = "99301")]
859859
impl<'a> Debug for Request<'a> {
860-
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
860+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
861861
f.debug_struct("Request").finish_non_exhaustive()
862862
}
863863
}

0 commit comments

Comments
 (0)