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 7 pull requests #125744

Merged
merged 24 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5cf198d
Remove path choice from `x fmt` and add `--all` option.
nnethercote May 28, 2024
e98740a
Clarify `x fmt` messages.
nnethercote May 29, 2024
3d5d6d2
Adjust `x fmt` printed output.
nnethercote May 29, 2024
a22cfcc
Rename `fmt_override`.
nnethercote May 29, 2024
4dec0a0
Clarify the closure in `rustfmt`.
nnethercote May 29, 2024
5b0e6cb
Migrate `run-make/const-prop-lint` to `rmake.rs`
GuillaumeGomez May 28, 2024
de1d0e0
Migrate `run-make/crate-data-smoke` to `rmake.rs`
GuillaumeGomez May 29, 2024
22953b3
convert simple-dylib to ui test
Oneirical May 28, 2024
0697884
convert fpic to ui test
Oneirical May 28, 2024
8c8d0db
rewrite and rename issue-37893 to rmake
Oneirical May 28, 2024
301d722
Add `run-make-support::rust_lib_name`
GuillaumeGomez May 29, 2024
0d63e6b
[ACP 362] genericize `ptr::from_raw_parts`
scottmcm May 29, 2024
7f11d6f
Add lang items for AsyncFn's associated types
compiler-errors May 29, 2024
3c4066d
Add a test for resolving `macro_rules` calls inside attributes
petrochenkov May 29, 2024
a9c7e02
Add lang item for Future::Output
compiler-errors May 29, 2024
a03ba7f
Add lang item for AsyncFnKindHelper::Upvars
compiler-errors May 29, 2024
6e67eaa
ast: Revert a breaking attribute visiting order change
petrochenkov May 29, 2024
3b6a3eb
Rollup merge of #125653 - GuillaumeGomez:migrate-const-prop-lint, r=j…
fmease May 29, 2024
c2c8e90
Rollup merge of #125662 - Oneirical:more-tests-again, r=jieyouxu
fmease May 29, 2024
c62fa82
Rollup merge of #125699 - nnethercote:streamline-rustfmt, r=Guillaume…
fmease May 29, 2024
849ccc8
Rollup merge of #125701 - scottmcm:generic-from-raw-parts, r=WaffleLa…
fmease May 29, 2024
a34d0f1
Rollup merge of #125723 - GuillaumeGomez:migrate-run-make-crate-data-…
fmease May 29, 2024
1ae1388
Rollup merge of #125733 - compiler-errors:async-fn-assoc-item, r=fmease
fmease May 29, 2024
fdfffc0
Rollup merge of #125734 - petrochenkov:macinattr, r=wesleywiser
fmease May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
ctxt: AssocCtxt,
) -> V::Result {
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_vis(vis));
try_visit!(visitor.visit_ident(ident));
try_visit!(kind.walk(item, ctxt, visitor));
walk_list!(visitor, visit_attribute, attrs);
V::Result::output()
}

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,18 @@ language_item_table! {
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnKindHelper, sym::async_fn_kind_helper,async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1);
CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1);
CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2);
AsyncFnKindHelper, sym::async_fn_kind_helper, async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy, GenericRequirement::Exact(5);

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

Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
FutureOutput, sym::future_output, future_output, Target::AssocTy, GenericRequirement::Exact(0);
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);

CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ pub fn suggest_impl_trait<'tcx>(
),
(
infcx.tcx.lang_items().future_trait(),
infcx.tcx.get_diagnostic_item(sym::FutureOutput),
infcx.tcx.lang_items().future_output(),
format_as_assoc,
),
(
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ symbols! {
FsPermissions,
FusedIterator,
Future,
FutureOutput,
GlobalAlloc,
Hash,
HashMap,
Expand Down Expand Up @@ -439,8 +438,10 @@ symbols! {
async_fn,
async_fn_in_trait,
async_fn_kind_helper,
async_fn_kind_upvars,
async_fn_mut,
async_fn_once,
async_fn_once_output,
async_fn_track_caller,
async_fn_traits,
async_for_loop,
Expand Down Expand Up @@ -498,6 +499,8 @@ symbols! {
call,
call_mut,
call_once,
call_once_future,
call_ref_future,
caller_location,
capture_disjoint_fields,
catch_unwind,
Expand Down Expand Up @@ -911,6 +914,7 @@ symbols! {
fundamental,
fused_iterator,
future,
future_output,
future_trait,
gdb_script_file,
ge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_macros::{TypeFoldable, TypeVisitable};
use rustc_middle::bug;
use rustc_middle::traits::solve::Goal;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast};
use rustc_span::sym;

use crate::solve::EvalCtxt;

Expand Down Expand Up @@ -454,12 +453,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc
.rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()]))
.upcast(tcx),
];
let future_output_def_id = tcx
.associated_items(future_trait_def_id)
.filter_by_name_unhygienic(sym::Output)
.next()
.unwrap()
.def_id;
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -510,12 +504,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc
);
}

let future_output_def_id = tcx
.associated_items(future_trait_def_id)
.filter_by_name_unhygienic(sym::Output)
.next()
.unwrap()
.def_id;
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -592,13 +581,7 @@ fn coroutine_closure_to_ambiguous_coroutine<'tcx>(
args: ty::CoroutineClosureArgs<'tcx>,
sig: ty::CoroutineClosureSignature<'tcx>,
) -> Ty<'tcx> {
let async_fn_kind_trait_def_id = tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
let upvars_projection_def_id = tcx
.associated_items(async_fn_kind_trait_def_id)
.filter_by_name_unhygienic(sym::Upvars)
.next()
.unwrap()
.def_id;
let upvars_projection_def_id = tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
let tupled_upvars_ty = Ty::new_projection(
tcx,
upvars_projection_def_id,
Expand Down
22 changes: 14 additions & 8 deletions compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
output_coroutine_ty,
coroutine_return_ty,
}| {
let (projection_term, term) = match tcx.item_name(goal.predicate.def_id()) {
sym::CallOnceFuture => (
let lang_items = tcx.lang_items();
let (projection_term, term) = if Some(goal.predicate.def_id())
== lang_items.call_once_future()
{
(
ty::AliasTerm::new(
tcx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
output_coroutine_ty.into(),
),
sym::CallRefFuture => (
)
} else if Some(goal.predicate.def_id()) == lang_items.call_ref_future() {
(
ty::AliasTerm::new(
tcx,
goal.predicate.def_id(),
Expand All @@ -427,8 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
],
),
output_coroutine_ty.into(),
),
sym::Output => (
)
} else if Some(goal.predicate.def_id()) == lang_items.async_fn_once_output() {
(
ty::AliasTerm::new(
tcx,
goal.predicate.def_id(),
Expand All @@ -438,8 +443,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
],
),
coroutine_return_ty.into(),
),
name => bug!("no such associated type: {name}"),
)
} else {
bug!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
};
ty::ProjectionPredicate { projection_term, term }
},
Expand Down
36 changes: 6 additions & 30 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1680,14 +1680,8 @@ fn confirm_closure_candidate<'cx, 'tcx>(
args.coroutine_captures_by_ref_ty(),
)
} else {
let async_fn_kind_trait_def_id =
tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
let upvars_projection_def_id = tcx
.associated_items(async_fn_kind_trait_def_id)
.filter_by_name_unhygienic(sym::Upvars)
.next()
.unwrap()
.def_id;
let upvars_projection_def_id =
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
let tupled_upvars_ty = Ty::new_projection(
tcx,
upvars_projection_def_id,
Expand Down Expand Up @@ -1816,14 +1810,8 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
args.coroutine_captures_by_ref_ty(),
)
} else {
let async_fn_kind_trait_def_id =
tcx.require_lang_item(LangItem::AsyncFnKindHelper, None);
let upvars_projection_def_id = tcx
.associated_items(async_fn_kind_trait_def_id)
.filter_by_name_unhygienic(sym::Upvars)
.next()
.unwrap()
.def_id;
let upvars_projection_def_id =
tcx.require_lang_item(LangItem::AsyncFnKindUpvars, None);
// When we don't know the closure kind (and therefore also the closure's upvars,
// which are computed at the same time), we must delay the computation of the
// generator's upvars. We do this using the `AsyncFnKindHelper`, which as a trait
Expand Down Expand Up @@ -1880,13 +1868,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
let term = match item_name {
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
sym::Output => {
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
let future_output_def_id = tcx
.associated_items(future_trait_def_id)
.filter_by_name_unhygienic(sym::Output)
.next()
.unwrap()
.def_id;
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
}
name => bug!("no such associated type: {name}"),
Expand Down Expand Up @@ -1919,13 +1901,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
let term = match item_name {
sym::CallOnceFuture | sym::CallRefFuture => sig.output(),
sym::Output => {
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
let future_output_def_id = tcx
.associated_items(future_trait_def_id)
.filter_by_name_unhygienic(sym::Output)
.next()
.unwrap()
.def_id;
let future_output_def_id = tcx.require_lang_item(LangItem::FutureOutput, None);
Ty::new_projection(tcx, future_output_def_id, [sig.output()])
}
name => bug!("no such associated type: {name}"),
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/future/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::task::{Context, Poll};
pub trait Future {
/// The type of value produced on completion.
#[stable(feature = "futures_api", since = "1.36.0")]
#[rustc_diagnostic_item = "FutureOutput"]
#[cfg_attr(not(bootstrap), lang = "future_output")]
type Output;

/// Attempt to resolve the future to a final value, registering
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ops/async_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
/// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`].
#[unstable(feature = "async_fn_traits", issue = "none")]
#[cfg_attr(not(bootstrap), lang = "call_ref_future")]
type CallRefFuture<'a>: Future<Output = Self::Output>
where
Self: 'a;
Expand All @@ -46,10 +47,12 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
pub trait AsyncFnOnce<Args: Tuple> {
/// Future returned by [`AsyncFnOnce::async_call_once`].
#[unstable(feature = "async_fn_traits", issue = "none")]
#[cfg_attr(not(bootstrap), lang = "call_once_future")]
type CallOnceFuture: Future<Output = Self::Output>;

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

/// Call the [`AsyncFnOnce`], returning a future which may move out of the called closure.
Expand Down Expand Up @@ -143,6 +146,7 @@ mod internal_implementation_detail {
// `for<'env> fn() -> (&'env T, ...)`. This allows us to represent the binder
// of the closure's self-capture, and these upvar types will be instantiated with
// the `'closure_env` region provided to the associated type.
#[cfg_attr(not(bootstrap), lang = "async_fn_kind_upvars")]
type Upvars<'closure_env, Inputs, Upvars, BorrowedUpvarsAsFnPtr>;
}
}
4 changes: 2 additions & 2 deletions library/core/src/ptr/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
#[inline]
pub const fn from_raw_parts<T: ?Sized>(
data_pointer: *const (),
data_pointer: *const impl Thin,
metadata: <T as Pointee>::Metadata,
) -> *const T {
aggregate_raw_ptr(data_pointer, metadata)
Expand All @@ -134,7 +134,7 @@ pub const fn from_raw_parts<T: ?Sized>(
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
#[inline]
pub const fn from_raw_parts_mut<T: ?Sized>(
data_pointer: *mut (),
data_pointer: *mut impl Thin,
metadata: <T as Pointee>::Metadata,
) -> *mut T {
aggregate_raw_ptr(data_pointer, metadata)
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
#[rustc_allow_const_fn_unstable(ptr_metadata)]
#[rustc_diagnostic_item = "ptr_null"]
pub const fn null<T: ?Sized + Thin>() -> *const T {
from_raw_parts(without_provenance(0), ())
from_raw_parts(without_provenance::<()>(0), ())
}

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

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

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

/// Swaps the values at two mutable locations of the same type, without
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/str/converts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
#[rustc_const_unstable(feature = "str_from_raw_parts", issue = "119206")]
pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
// SAFETY: the caller must uphold the safety contract for `from_raw_parts`.
unsafe { &*ptr::from_raw_parts(ptr.cast(), len) }
unsafe { &*ptr::from_raw_parts(ptr, len) }
}

/// Creates an `&mut str` from a pointer and a length.
Expand All @@ -241,5 +241,5 @@ pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
#[rustc_const_unstable(feature = "const_str_from_raw_parts_mut", issue = "119206")]
pub const unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut str {
// SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`.
unsafe { &mut *ptr::from_raw_parts_mut(ptr.cast(), len) }
unsafe { &mut *ptr::from_raw_parts_mut(ptr, len) }
}
4 changes: 2 additions & 2 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ fn align_of_val_raw_packed() {
f: [u32],
}
let storage = [0u8; 4];
let b: *const B = ptr::from_raw_parts(storage.as_ptr().cast(), 1);
let b: *const B = ptr::from_raw_parts(storage.as_ptr(), 1);
assert_eq!(unsafe { align_of_val_raw(b) }, 1);

const ALIGN_OF_VAL_RAW: usize = {
let storage = [0u8; 4];
let b: *const B = ptr::from_raw_parts(storage.as_ptr().cast(), 1);
let b: *const B = ptr::from_raw_parts(storage.as_ptr(), 1);
unsafe { align_of_val_raw(b) }
};
assert_eq!(ALIGN_OF_VAL_RAW, 1);
Expand Down
4 changes: 2 additions & 2 deletions library/core/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,15 @@ fn thin_box() {
fn value_ptr(&self) -> *const T {
let (_, offset) = self.layout();
let data_ptr = unsafe { self.ptr.cast::<u8>().as_ptr().add(offset) };
ptr::from_raw_parts(data_ptr.cast(), self.meta())
ptr::from_raw_parts(data_ptr, self.meta())
}

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

Expand Down
Loading
Loading