Skip to content

Commit caa187f

Browse files
committed
Auto merge of rust-lang#125744 - fmease:rollup-ky7d098, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#125653 (Migrate `run-make/const-prop-lint` to `rmake.rs`) - rust-lang#125662 (Rewrite `fpic`, `simple-dylib` and `issue-37893` `run-make` tests in `rmake.rs` or ui test format) - rust-lang#125699 (Streamline `x fmt` and improve its output) - rust-lang#125701 ([ACP 362] genericize `ptr::from_raw_parts`) - rust-lang#125723 (Migrate `run-make/crate-data-smoke` to `rmake.rs`) - rust-lang#125733 (Add lang items for `AsyncFn*`, `Future`, `AsyncFnKindHelper`'s associated types) - rust-lang#125734 (ast: Revert a breaking attribute visiting order change) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 23ea77b + fdfffc0 commit caa187f

File tree

56 files changed

+519
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+519
-297
lines changed

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
852852
ctxt: AssocCtxt,
853853
) -> V::Result {
854854
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
855-
walk_list!(visitor, visit_attribute, attrs);
856855
try_visit!(visitor.visit_vis(vis));
857856
try_visit!(visitor.visit_ident(ident));
858857
try_visit!(kind.walk(item, ctxt, visitor));
858+
walk_list!(visitor, visit_attribute, attrs);
859859
V::Result::output()
860860
}
861861

compiler/rustc_hir/src/lang_items.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,18 @@ language_item_table! {
228228
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
229229
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
230230
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
231-
AsyncFnKindHelper, sym::async_fn_kind_helper,async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
231+
AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1);
232+
CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1);
233+
CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2);
234+
AsyncFnKindHelper, sym::async_fn_kind_helper, async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
235+
AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy, GenericRequirement::Exact(5);
232236

233237
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
234238

235239
Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
236240
FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
237241
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
242+
FutureOutput, sym::future_output, future_output, Target::AssocTy, GenericRequirement::Exact(0);
238243
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
239244

240245
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ pub fn suggest_impl_trait<'tcx>(
14781478
),
14791479
(
14801480
infcx.tcx.lang_items().future_trait(),
1481-
infcx.tcx.get_diagnostic_item(sym::FutureOutput),
1481+
infcx.tcx.lang_items().future_output(),
14821482
format_as_assoc,
14831483
),
14841484
(

compiler/rustc_span/src/symbol.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ symbols! {
210210
FsPermissions,
211211
FusedIterator,
212212
Future,
213-
FutureOutput,
214213
GlobalAlloc,
215214
Hash,
216215
HashMap,
@@ -439,8 +438,10 @@ symbols! {
439438
async_fn,
440439
async_fn_in_trait,
441440
async_fn_kind_helper,
441+
async_fn_kind_upvars,
442442
async_fn_mut,
443443
async_fn_once,
444+
async_fn_once_output,
444445
async_fn_track_caller,
445446
async_fn_traits,
446447
async_for_loop,
@@ -498,6 +499,8 @@ symbols! {
498499
call,
499500
call_mut,
500501
call_once,
502+
call_once_future,
503+
call_ref_future,
501504
caller_location,
502505
capture_disjoint_fields,
503506
catch_unwind,
@@ -911,6 +914,7 @@ symbols! {
911914
fundamental,
912915
fused_iterator,
913916
future,
917+
future_output,
914918
future_trait,
915919
gdb_script_file,
916920
ge,

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_macros::{TypeFoldable, TypeVisitable};
99
use rustc_middle::bug;
1010
use rustc_middle::traits::solve::Goal;
1111
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast};
12-
use rustc_span::sym;
1312

1413
use crate::solve::EvalCtxt;
1514

@@ -454,12 +453,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc
454453
.rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()]))
455454
.upcast(tcx),
456455
];
457-
let future_output_def_id = tcx
458-
.associated_items(future_trait_def_id)
459-
.filter_by_name_unhygienic(sym::Output)
460-
.next()
461-
.unwrap()
462-
.def_id;
456+
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
463457
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
464458
Ok((
465459
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -510,12 +504,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc
510504
);
511505
}
512506

513-
let future_output_def_id = tcx
514-
.associated_items(future_trait_def_id)
515-
.filter_by_name_unhygienic(sym::Output)
516-
.next()
517-
.unwrap()
518-
.def_id;
507+
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
519508
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
520509
Ok((
521510
bound_sig.rebind(AsyncCallableRelevantTypes {
@@ -592,13 +581,7 @@ fn coroutine_closure_to_ambiguous_coroutine<'tcx>(
592581
args: ty::CoroutineClosureArgs<'tcx>,
593582
sig: ty::CoroutineClosureSignature<'tcx>,
594583
) -> Ty<'tcx> {
595-
let async_fn_kind_trait_def_id = tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
596-
let upvars_projection_def_id = tcx
597-
.associated_items(async_fn_kind_trait_def_id)
598-
.filter_by_name_unhygienic(sym::Upvars)
599-
.next()
600-
.unwrap()
601-
.def_id;
584+
let upvars_projection_def_id = tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
602585
let tupled_upvars_ty = Ty::new_projection(
603586
tcx,
604587
upvars_projection_def_id,

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

+14-8
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
407407
output_coroutine_ty,
408408
coroutine_return_ty,
409409
}| {
410-
let (projection_term, term) = match tcx.item_name(goal.predicate.def_id()) {
411-
sym::CallOnceFuture => (
410+
let lang_items = tcx.lang_items();
411+
let (projection_term, term) = if Some(goal.predicate.def_id())
412+
== lang_items.call_once_future()
413+
{
414+
(
412415
ty::AliasTerm::new(
413416
tcx,
414417
goal.predicate.def_id(),
415418
[goal.predicate.self_ty(), tupled_inputs_ty],
416419
),
417420
output_coroutine_ty.into(),
418-
),
419-
sym::CallRefFuture => (
421+
)
422+
} else if Some(goal.predicate.def_id()) == lang_items.call_ref_future() {
423+
(
420424
ty::AliasTerm::new(
421425
tcx,
422426
goal.predicate.def_id(),
@@ -427,8 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
427431
],
428432
),
429433
output_coroutine_ty.into(),
430-
),
431-
sym::Output => (
434+
)
435+
} else if Some(goal.predicate.def_id()) == lang_items.async_fn_once_output() {
436+
(
432437
ty::AliasTerm::new(
433438
tcx,
434439
goal.predicate.def_id(),
@@ -438,8 +443,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
438443
],
439444
),
440445
coroutine_return_ty.into(),
441-
),
442-
name => bug!("no such associated type: {name}"),
446+
)
447+
} else {
448+
bug!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
443449
};
444450
ty::ProjectionPredicate { projection_term, term }
445451
},

compiler/rustc_trait_selection/src/traits/project.rs

+6-30
Original file line numberDiff line numberDiff line change
@@ -1680,14 +1680,8 @@ fn confirm_closure_candidate<'cx, 'tcx>(
16801680
args.coroutine_captures_by_ref_ty(),
16811681
)
16821682
} else {
1683-
let async_fn_kind_trait_def_id =
1684-
tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
1685-
let upvars_projection_def_id = tcx
1686-
.associated_items(async_fn_kind_trait_def_id)
1687-
.filter_by_name_unhygienic(sym::Upvars)
1688-
.next()
1689-
.unwrap()
1690-
.def_id;
1683+
let upvars_projection_def_id =
1684+
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
16911685
let tupled_upvars_ty = Ty::new_projection(
16921686
tcx,
16931687
upvars_projection_def_id,
@@ -1816,14 +1810,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18161810
args.coroutine_captures_by_ref_ty(),
18171811
)
18181812
} else {
1819-
let async_fn_kind_trait_def_id =
1820-
tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
1821-
let upvars_projection_def_id = tcx
1822-
.associated_items(async_fn_kind_trait_def_id)
1823-
.filter_by_name_unhygienic(sym::Upvars)
1824-
.next()
1825-
.unwrap()
1826-
.def_id;
1813+
let upvars_projection_def_id =
1814+
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
18271815
// When we don't know the closure kind (and therefore also the closure's upvars,
18281816
// which are computed at the same time), we must delay the computation of the
18291817
// generator's upvars. We do this using the `AsyncFnKindHelper`, which as a trait
@@ -1880,13 +1868,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18801868
let term = match item_name {
18811869
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
18821870
sym::Output => {
1883-
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
1884-
let future_output_def_id = tcx
1885-
.associated_items(future_trait_def_id)
1886-
.filter_by_name_unhygienic(sym::Output)
1887-
.next()
1888-
.unwrap()
1889-
.def_id;
1871+
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
18901872
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
18911873
}
18921874
name => bug!("no such associated type: {name}"),
@@ -1919,13 +1901,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
19191901
let term = match item_name {
19201902
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
19211903
sym::Output => {
1922-
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
1923-
let future_output_def_id = tcx
1924-
.associated_items(future_trait_def_id)
1925-
.filter_by_name_unhygienic(sym::Output)
1926-
.next()
1927-
.unwrap()
1928-
.def_id;
1904+
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
19291905
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
19301906
}
19311907
name => bug!("no such associated type: {name}"),

library/core/src/future/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::task::{Context, Poll};
3535
pub trait Future {
3636
/// The type of value produced on completion.
3737
#[stable(feature = "futures_api", since = "1.36.0")]
38-
#[rustc_diagnostic_item = "FutureOutput"]
38+
#[cfg_attr(not(bootstrap), lang = "future_output")]
3939
type Output;
4040

4141
/// Attempt to resolve the future to a final value, registering

library/core/src/ops/async_function.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
2626
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
2727
/// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`].
2828
#[unstable(feature = "async_fn_traits", issue = "none")]
29+
#[cfg_attr(not(bootstrap), lang = "call_ref_future")]
2930
type CallRefFuture<'a>: Future<Output = Self::Output>
3031
where
3132
Self: 'a;
@@ -46,10 +47,12 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
4647
pub trait AsyncFnOnce<Args: Tuple> {
4748
/// Future returned by [`AsyncFnOnce::async_call_once`].
4849
#[unstable(feature = "async_fn_traits", issue = "none")]
50+
#[cfg_attr(not(bootstrap), lang = "call_once_future")]
4951
type CallOnceFuture: Future<Output = Self::Output>;
5052

5153
/// Output type of the called closure's future.
5254
#[unstable(feature = "async_fn_traits", issue = "none")]
55+
#[cfg_attr(not(bootstrap), lang = "async_fn_once_output")]
5356
type Output;
5457

5558
/// Call the [`AsyncFnOnce`], returning a future which may move out of the called closure.
@@ -143,6 +146,7 @@ mod internal_implementation_detail {
143146
// `for<'env> fn() -> (&'env T, ...)`. This allows us to represent the binder
144147
// of the closure's self-capture, and these upvar types will be instantiated with
145148
// the `'closure_env` region provided to the associated type.
149+
#[cfg_attr(not(bootstrap), lang = "async_fn_kind_upvars")]
146150
type Upvars<'closure_env, Inputs, Upvars, BorrowedUpvarsAsFnPtr>;
147151
}
148152
}

library/core/src/ptr/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
120120
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
121121
#[inline]
122122
pub const fn from_raw_parts<T: ?Sized>(
123-
data_pointer: *const (),
123+
data_pointer: *const impl Thin,
124124
metadata: <T as Pointee>::Metadata,
125125
) -> *const T {
126126
aggregate_raw_ptr(data_pointer, metadata)
@@ -134,7 +134,7 @@ pub const fn from_raw_parts<T: ?Sized>(
134134
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
135135
#[inline]
136136
pub const fn from_raw_parts_mut<T: ?Sized>(
137-
data_pointer: *mut (),
137+
data_pointer: *mut impl Thin,
138138
metadata: <T as Pointee>::Metadata,
139139
) -> *mut T {
140140
aggregate_raw_ptr(data_pointer, metadata)

library/core/src/ptr/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
565565
#[rustc_allow_const_fn_unstable(ptr_metadata)]
566566
#[rustc_diagnostic_item = "ptr_null"]
567567
pub const fn null<T: ?Sized + Thin>() -> *const T {
568-
from_raw_parts(without_provenance(0), ())
568+
from_raw_parts(without_provenance::<()>(0), ())
569569
}
570570

571571
/// Creates a null mutable raw pointer.
@@ -591,7 +591,7 @@ pub const fn null<T: ?Sized + Thin>() -> *const T {
591591
#[rustc_allow_const_fn_unstable(ptr_metadata)]
592592
#[rustc_diagnostic_item = "ptr_null_mut"]
593593
pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
594-
from_raw_parts_mut(without_provenance_mut(0), ())
594+
from_raw_parts_mut(without_provenance_mut::<()>(0), ())
595595
}
596596

597597
/// Creates a pointer with the given address and no provenance.
@@ -835,7 +835,7 @@ pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
835835
#[rustc_allow_const_fn_unstable(ptr_metadata)]
836836
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts"]
837837
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
838-
intrinsics::aggregate_raw_ptr(data, len)
838+
from_raw_parts(data, len)
839839
}
840840

841841
/// Forms a raw mutable slice from a pointer and a length.
@@ -881,7 +881,7 @@ pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
881881
#[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")]
882882
#[rustc_diagnostic_item = "ptr_slice_from_raw_parts_mut"]
883883
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
884-
intrinsics::aggregate_raw_ptr(data, len)
884+
from_raw_parts_mut(data, len)
885885
}
886886

887887
/// Swaps the values at two mutable locations of the same type, without

library/core/src/str/converts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
222222
#[rustc_const_unstable(feature = "str_from_raw_parts", issue = "119206")]
223223
pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
224224
// SAFETY: the caller must uphold the safety contract for `from_raw_parts`.
225-
unsafe { &*ptr::from_raw_parts(ptr.cast(), len) }
225+
unsafe { &*ptr::from_raw_parts(ptr, len) }
226226
}
227227

228228
/// Creates an `&mut str` from a pointer and a length.
@@ -241,5 +241,5 @@ pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
241241
#[rustc_const_unstable(feature = "const_str_from_raw_parts_mut", issue = "119206")]
242242
pub const unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut str {
243243
// SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`.
244-
unsafe { &mut *ptr::from_raw_parts_mut(ptr.cast(), len) }
244+
unsafe { &mut *ptr::from_raw_parts_mut(ptr, len) }
245245
}

library/core/tests/mem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ fn align_of_val_raw_packed() {
8383
f: [u32],
8484
}
8585
let storage = [0u8; 4];
86-
let b: *const B = ptr::from_raw_parts(storage.as_ptr().cast(), 1);
86+
let b: *const B = ptr::from_raw_parts(storage.as_ptr(), 1);
8787
assert_eq!(unsafe { align_of_val_raw(b) }, 1);
8888

8989
const ALIGN_OF_VAL_RAW: usize = {
9090
let storage = [0u8; 4];
91-
let b: *const B = ptr::from_raw_parts(storage.as_ptr().cast(), 1);
91+
let b: *const B = ptr::from_raw_parts(storage.as_ptr(), 1);
9292
unsafe { align_of_val_raw(b) }
9393
};
9494
assert_eq!(ALIGN_OF_VAL_RAW, 1);

library/core/tests/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,15 @@ fn thin_box() {
965965
fn value_ptr(&self) -> *const T {
966966
let (_, offset) = self.layout();
967967
let data_ptr = unsafe { self.ptr.cast::<u8>().as_ptr().add(offset) };
968-
ptr::from_raw_parts(data_ptr.cast(), self.meta())
968+
ptr::from_raw_parts(data_ptr, self.meta())
969969
}
970970

971971
fn value_mut_ptr(&mut self) -> *mut T {
972972
let (_, offset) = self.layout();
973973
// FIXME: can this line be shared with the same in `value_ptr()`
974974
// without upsetting Stacked Borrows?
975975
let data_ptr = unsafe { self.ptr.cast::<u8>().as_ptr().add(offset) };
976-
from_raw_parts_mut(data_ptr.cast(), self.meta())
976+
from_raw_parts_mut(data_ptr, self.meta())
977977
}
978978
}
979979

0 commit comments

Comments
 (0)