Skip to content

Commit 0c8422c

Browse files
committed
Auto merge of rust-lang#134164 - jhpratt:rollup-s7z0vcc, r=jhpratt
Rollup of 8 pull requests Successful merges: - rust-lang#134079 (Add a note saying that `{u8,i8}::from_{be,le,ne}_bytes` is meaningless) - rust-lang#134105 (Validate self in host predicates correctly) - rust-lang#134136 (Exercise const trait interaction with default fields) - rust-lang#134139 ([AIX] keep profile-rt symbol alive) - rust-lang#134141 (Remove more traces of anonymous ADTs) - rust-lang#134142 (Rudimentary heuristic to insert parentheses when needed for RPIT overcaptures lint) - rust-lang#134158 (Rename `projection_def_id` to `item_def_id`) - rust-lang#134160 (Add vacation entry for myself in triagebot.toml) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5a6036a + c384b28 commit 0c8422c

File tree

29 files changed

+174
-72
lines changed

29 files changed

+174
-72
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,8 @@ impl<'a> Linker for AixLinker<'a> {
16941694

16951695
fn pgo_gen(&mut self) {
16961696
self.link_arg("-bdbg:namedsects:ss");
1697+
self.link_arg("-u");
1698+
self.link_arg("__llvm_profile_runtime");
16971699
}
16981700

16991701
fn control_flow_guard(&mut self) {}

compiler/rustc_hir/src/def.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
99
use rustc_span::Symbol;
1010
use rustc_span::def_id::{DefId, LocalDefId};
1111
use rustc_span::hygiene::MacroKind;
12-
use rustc_span::symbol::kw;
1312

1413
use crate::definitions::DefPathData;
1514
use crate::hir;
@@ -256,7 +255,6 @@ impl DefKind {
256255

257256
pub fn def_path_data(self, name: Symbol) -> DefPathData {
258257
match self {
259-
DefKind::Struct | DefKind::Union if name == kw::Empty => DefPathData::AnonAdt,
260258
DefKind::Mod
261259
| DefKind::Struct
262260
| DefKind::Union

compiler/rustc_hir/src/definitions.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ pub enum DefPathData {
289289
/// An existential `impl Trait` type node.
290290
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
291291
OpaqueTy,
292-
/// An anonymous struct or union type i.e. `struct { foo: Type }` or `union { bar: Type }`
293-
AnonAdt,
294292
}
295293

296294
impl Definitions {
@@ -415,7 +413,7 @@ impl DefPathData {
415413
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
416414

417415
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
418-
| OpaqueTy | AnonAdt => None,
416+
| OpaqueTy => None,
419417
}
420418
}
421419

@@ -438,7 +436,6 @@ impl DefPathData {
438436
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
439437
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
440438
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
441-
AnonAdt => DefPathDataName::Anon { namespace: sym::anon_adt },
442439
}
443440
}
444441
}

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2882,8 +2882,6 @@ pub enum TyKind<'hir> {
28822882
Never,
28832883
/// A tuple (`(A, B, C, D, ...)`).
28842884
Tup(&'hir [Ty<'hir>]),
2885-
/// An anonymous struct or union type i.e. `struct { foo: Type }` or `union { foo: Type }`
2886-
AnonAdt(ItemId),
28872885
/// A path to a type definition (`module::module::...::Type`), or an
28882886
/// associated type (e.g., `<Vec<T> as Trait>::Type` or `<T>::Target`).
28892887
///

compiler/rustc_hir/src/intravisit.rs

-3
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
904904
}
905905
TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)),
906906
TyKind::Infer | TyKind::InferDelegation(..) | TyKind::Err(_) => {}
907-
TyKind::AnonAdt(item_id) => {
908-
try_visit!(visitor.visit_nested_item(item_id));
909-
}
910907
TyKind::Pat(ty, pat) => {
911908
try_visit!(visitor.visit_ty(ty));
912909
try_visit!(visitor.visit_pattern_type_pattern(pat));

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,19 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
711711
`{filter:?}` implied bounds: {clause:?}"
712712
);
713713
}
714+
ty::ClauseKind::HostEffect(host_effect_predicate) => {
715+
assert_eq!(
716+
host_effect_predicate.self_ty(),
717+
ty,
718+
"expected `Self` predicate when computing \
719+
`{filter:?}` implied bounds: {clause:?}"
720+
);
721+
}
714722

715723
ty::ClauseKind::RegionOutlives(_)
716724
| ty::ClauseKind::ConstArgHasType(_, _)
717725
| ty::ClauseKind::WellFormed(_)
718-
| ty::ClauseKind::ConstEvaluatable(_)
719-
| ty::ClauseKind::HostEffect(..) => {
726+
| ty::ClauseKind::ConstEvaluatable(_) => {
720727
bug!(
721728
"unexpected non-`Self` predicate when computing \
722729
`{filter:?}` implied bounds: {clause:?}"

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
203203
// corresponding `Projection` clause
204204
for def_ids in associated_types.values_mut() {
205205
for (projection_bound, span) in &projection_bounds {
206-
let def_id = projection_bound.projection_def_id();
206+
let def_id = projection_bound.item_def_id();
207207
def_ids.swap_remove(&def_id);
208208
if tcx.generics_require_sized_self(def_id) {
209209
tcx.emit_node_span_lint(
@@ -413,7 +413,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
413413
late_bound_in_projection_term,
414414
late_bound_in_term,
415415
|br_name| {
416-
let item_name = tcx.item_name(pred.projection_def_id());
416+
let item_name = tcx.item_name(pred.item_def_id());
417417
struct_span_code_err!(
418418
self.dcx(),
419419
span,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use rustc_span::{DUMMY_SP, Span};
5050
use rustc_trait_selection::infer::InferCtxtExt;
5151
use rustc_trait_selection::traits::wf::object_region_bounds;
5252
use rustc_trait_selection::traits::{self, ObligationCtxt};
53-
use tracing::{debug, debug_span, instrument};
53+
use tracing::{debug, instrument};
5454

5555
use crate::bounds::Bounds;
5656
use crate::check::check_abi_fn_ptr;
@@ -2304,19 +2304,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23042304
hir::TyKind::Tup(fields) => {
23052305
Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t)))
23062306
}
2307-
hir::TyKind::AnonAdt(item_id) => {
2308-
let _guard = debug_span!("AnonAdt");
2309-
2310-
let did = item_id.owner_id.def_id;
2311-
let adt_def = tcx.adt_def(did);
2312-
2313-
let args = ty::GenericArgs::for_item(tcx, did.to_def_id(), |param, _| {
2314-
tcx.mk_param_from_def(param)
2315-
});
2316-
debug!(?args);
2317-
2318-
Ty::new_adt(tcx, adt_def, tcx.mk_args(args))
2319-
}
23202307
hir::TyKind::BareFn(bf) => {
23212308
require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, hir_ty.span);
23222309

compiler/rustc_hir_pretty/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ impl<'a> State<'a> {
330330
hir::TyKind::Infer | hir::TyKind::InferDelegation(..) => {
331331
self.word("_");
332332
}
333-
hir::TyKind::AnonAdt(..) => self.word("/* anonymous adt */"),
334333
hir::TyKind::Pat(ty, pat) => {
335334
self.print_type(ty);
336335
self.word(" is ");

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454454
closure_kind: hir::ClosureKind,
455455
projection: ty::PolyProjectionPredicate<'tcx>,
456456
) -> Option<ExpectedSig<'tcx>> {
457-
let def_id = projection.projection_def_id();
457+
let def_id = projection.item_def_id();
458458

459459
// For now, we only do signature deduction based off of the `Fn` and `AsyncFn` traits,
460460
// for closures and async closures, respectively.

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10201020

10211021
self.insert_trait_and_projection(
10221022
trait_ref,
1023-
Some((proj.projection_def_id(), proj.term())),
1023+
Some((proj.item_def_id(), proj.term())),
10241024
&mut traits,
10251025
&mut fn_traits,
10261026
);

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ where
144144
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResult<I>,
145145
) -> Result<Candidate<I>, NoSolution> {
146146
if let Some(projection_pred) = assumption.as_projection_clause() {
147-
if projection_pred.projection_def_id() == goal.predicate.def_id() {
147+
if projection_pred.item_def_id() == goal.predicate.def_id() {
148148
let cx = ecx.cx();
149149
if !DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
150150
goal.predicate.alias.args,

compiler/rustc_passes/src/input_stats.rs

-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
337337
BareFn,
338338
Never,
339339
Tup,
340-
AnonAdt,
341340
Path,
342341
OpaqueDef,
343342
TraitObject,

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
716716
| hir::definitions::DefPathData::Use
717717
| hir::definitions::DefPathData::GlobalAsm
718718
| hir::definitions::DefPathData::MacroNs(..)
719-
| hir::definitions::DefPathData::LifetimeNs(..)
720-
| hir::definitions::DefPathData::AnonAdt => {
719+
| hir::definitions::DefPathData::LifetimeNs(..) => {
721720
bug!("encode_ty_name: unexpected `{:?}`", disambiguated_data.data);
722721
}
723722
});

compiler/rustc_symbol_mangling/src/v0.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
772772
| DefPathData::GlobalAsm
773773
| DefPathData::Impl
774774
| DefPathData::MacroNs(_)
775-
| DefPathData::LifetimeNs(_)
776-
| DefPathData::AnonAdt => {
775+
| DefPathData::LifetimeNs(_) => {
777776
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
778777
}
779778
};

compiler/rustc_trait_selection/src/errors.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir as hir;
1010
use rustc_hir::def::DefKind;
1111
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_hir::intravisit::{Visitor, walk_ty};
13-
use rustc_hir::{FnRetTy, GenericParamKind};
13+
use rustc_hir::{FnRetTy, GenericParamKind, Node};
1414
use rustc_macros::{Diagnostic, Subdiagnostic};
1515
use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath};
1616
use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, PolyTraitRef, Region, Ty, TyCtxt};
@@ -1888,10 +1888,35 @@ pub fn impl_trait_overcapture_suggestion<'tcx>(
18881888
.collect::<Vec<_>>()
18891889
.join(", ");
18901890

1891-
suggs.push((
1892-
tcx.def_span(opaque_def_id).shrink_to_hi(),
1893-
format!(" + use<{concatenated_bounds}>"),
1894-
));
1891+
let opaque_hir_id = tcx.local_def_id_to_hir_id(opaque_def_id);
1892+
// FIXME: This is a bit too conservative, since it ignores parens already written in AST.
1893+
let (lparen, rparen) = match tcx
1894+
.hir()
1895+
.parent_iter(opaque_hir_id)
1896+
.nth(1)
1897+
.expect("expected ty to have a parent always")
1898+
.1
1899+
{
1900+
Node::PathSegment(segment)
1901+
if segment.args().paren_sugar_output().is_some_and(|ty| ty.hir_id == opaque_hir_id) =>
1902+
{
1903+
("(", ")")
1904+
}
1905+
Node::Ty(ty) => match ty.kind {
1906+
rustc_hir::TyKind::Ptr(_) | rustc_hir::TyKind::Ref(..) => ("(", ")"),
1907+
// FIXME: RPITs are not allowed to be nested in `impl Fn() -> ...`,
1908+
// but we eventually could support that, and that would necessitate
1909+
// making this more sophisticated.
1910+
_ => ("", ""),
1911+
},
1912+
_ => ("", ""),
1913+
};
1914+
1915+
let rpit_span = tcx.def_span(opaque_def_id);
1916+
if !lparen.is_empty() {
1917+
suggs.push((rpit_span.shrink_to_lo(), lparen.to_string()));
1918+
}
1919+
suggs.push((rpit_span.shrink_to_hi(), format!(" + use<{concatenated_bounds}>{rparen}")));
18951920

18961921
Some(AddPreciseCapturingForOvercapture { suggs, apit_spans })
18971922
}

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
744744
let Some(clause) = clause.as_projection_clause() else {
745745
return ControlFlow::Continue(());
746746
};
747-
if clause.projection_def_id() != obligation.predicate.def_id {
747+
if clause.item_def_id() != obligation.predicate.def_id {
748748
return ControlFlow::Continue(());
749749
}
750750

@@ -847,7 +847,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
847847
let bound_predicate = predicate.kind();
848848
if let ty::ClauseKind::Projection(data) = predicate.kind().skip_binder() {
849849
let data = bound_predicate.rebind(data);
850-
if data.projection_def_id() != obligation.predicate.def_id {
850+
if data.item_def_id() != obligation.predicate.def_id {
851851
continue;
852852
}
853853

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17371737
env_predicate: PolyProjectionPredicate<'tcx>,
17381738
potentially_unnormalized_candidates: bool,
17391739
) -> ProjectionMatchesProjection {
1740-
debug_assert_eq!(obligation.predicate.def_id, env_predicate.projection_def_id());
1740+
debug_assert_eq!(obligation.predicate.def_id, env_predicate.item_def_id());
17411741

17421742
let mut nested_obligations = PredicateObligations::new();
17431743
let infer_predicate = self.infcx.instantiate_binder_with_fresh_vars(

compiler/rustc_type_ir/src/predicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ impl<I: Interner> ty::Binder<I, ProjectionPredicate<I>> {
692692
///
693693
/// Note that this is not the `DefId` of the `TraitRef` containing this
694694
/// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
695-
pub fn projection_def_id(&self) -> I::DefId {
695+
pub fn item_def_id(&self) -> I::DefId {
696696
// Ok to skip binder since trait `DefId` does not care about regions.
697697
self.skip_binder().projection_term.def_id
698698
}

library/core/src/num/mod.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ pub use saturating::Saturating;
7777
#[stable(feature = "rust1", since = "1.0.0")]
7878
pub use wrapping::Wrapping;
7979

80+
macro_rules! u8_xe_bytes_doc {
81+
() => {
82+
"
83+
84+
**Note**: This function is meaningless on `u8`. Byte order does not exist as a
85+
concept for byte-sized integers. This function is only provided in symmetry
86+
with larger integer types.
87+
88+
"
89+
};
90+
}
91+
92+
macro_rules! i8_xe_bytes_doc {
93+
() => {
94+
"
95+
96+
**Note**: This function is meaningless on `i8`. Byte order does not exist as a
97+
concept for byte-sized integers. This function is only provided in symmetry
98+
with larger integer types. You can cast from and to `u8` using `as i8` and `as
99+
u8`.
100+
101+
"
102+
};
103+
}
104+
80105
macro_rules! usize_isize_to_xe_bytes_doc {
81106
() => {
82107
"
@@ -348,8 +373,8 @@ impl i8 {
348373
reversed = "0x48",
349374
le_bytes = "[0x12]",
350375
be_bytes = "[0x12]",
351-
to_xe_bytes_doc = "",
352-
from_xe_bytes_doc = "",
376+
to_xe_bytes_doc = i8_xe_bytes_doc!(),
377+
from_xe_bytes_doc = i8_xe_bytes_doc!(),
353378
bound_condition = "",
354379
}
355380
midpoint_impl! { i8, i16, signed }
@@ -547,8 +572,8 @@ impl u8 {
547572
reversed = "0x48",
548573
le_bytes = "[0x12]",
549574
be_bytes = "[0x12]",
550-
to_xe_bytes_doc = "",
551-
from_xe_bytes_doc = "",
575+
to_xe_bytes_doc = u8_xe_bytes_doc!(),
576+
from_xe_bytes_doc = u8_xe_bytes_doc!(),
552577
bound_condition = "",
553578
}
554579
widening_impl! { u8, u16, 8, unsigned }

src/librustdoc/clean/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1841,9 +1841,6 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18411841
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
18421842
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
18431843
TyKind::Infer | TyKind::Err(_) | TyKind::Typeof(..) | TyKind::InferDelegation(..) => Infer,
1844-
TyKind::AnonAdt(..) => {
1845-
unimplemented!("Anonymous structs or unions are not supported yet")
1846-
}
18471844
}
18481845
}
18491846

src/tools/clippy/clippy_lints/src/dereference.rs

-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ impl TyCoercionStability {
818818
| TyKind::Typeof(..)
819819
| TyKind::TraitObject(..)
820820
| TyKind::InferDelegation(..)
821-
| TyKind::AnonAdt(..)
822821
| TyKind::Err(_) => Self::Reborrow,
823822
};
824823
}

src/tools/clippy/clippy_utils/src/hir_utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ impl HirEqInterExpr<'_, '_, '_> {
596596
(TyKind::Path(l), TyKind::Path(r)) => self.eq_qpath(l, r),
597597
(&TyKind::Tup(l), &TyKind::Tup(r)) => over(l, r, |l, r| self.eq_ty(l, r)),
598598
(&TyKind::Infer, &TyKind::Infer) => true,
599-
(TyKind::AnonAdt(l_item_id), TyKind::AnonAdt(r_item_id)) => l_item_id == r_item_id,
600599
_ => false,
601600
}
602601
}
@@ -1246,8 +1245,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
12461245
| TyKind::Infer
12471246
| TyKind::Never
12481247
| TyKind::InferDelegation(..)
1249-
| TyKind::OpaqueDef(_)
1250-
| TyKind::AnonAdt(_) => {},
1248+
| TyKind::OpaqueDef(_) => {},
12511249
}
12521250
}
12531251

tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed

+4
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ async fn async_fn<'a>(x: &'a ()) -> impl Sized + use<> {}
4242
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
4343
//~| WARN this changes meaning in Rust 2024
4444

45+
pub fn parens(x: &i32) -> &(impl Clone + use<>) { x }
46+
//~^ ERROR `impl Clone` will capture more lifetimes than possibly intended in edition 2024
47+
//~| WARN this changes meaning in Rust 2024
48+
4549
fn main() {}

tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs

+4
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ async fn async_fn<'a>(x: &'a ()) -> impl Sized {}
4242
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
4343
//~| WARN this changes meaning in Rust 2024
4444

45+
pub fn parens(x: &i32) -> &impl Clone { x }
46+
//~^ ERROR `impl Clone` will capture more lifetimes than possibly intended in edition 2024
47+
//~| WARN this changes meaning in Rust 2024
48+
4549
fn main() {}

0 commit comments

Comments
 (0)