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 #128829

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 12 additions & 7 deletions compiler/rustc_error_codes/src/error_codes/E0517.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ impl Foo {
These attributes do not work on typedefs, since typedefs are just aliases.

Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
discriminant size for enums with no data fields on any of the variants, e.g.
`enum Color {Red, Blue, Green}`, effectively setting the size of the enum to
the size of the provided type. Such an enum can be cast to a value of the same
type as well. In short, `#[repr(u8)]` makes the enum behave like an integer
with a constrained set of allowed values.
discriminant size for enums. For enums with no data fields on any of the
variants, e.g. `enum Color {Red, Blue, Green}`, this effectively sets the size
of the enum to the size of the provided type. Such an enum can be cast to a
value of the same type as well. In short, `#[repr(u8)]` makes a field-less enum
behave like an integer with a constrained set of allowed values.

Only field-less enums can be cast to numerical primitives, so this attribute
will not apply to structs.
For a description of how `#[repr(C)]` and representations like `#[repr(u8)]`
affect the layout of enums with data fields, see [RFC 2195][rfc2195].

Only field-less enums can be cast to numerical primitives. Representations like
`#[repr(u8)]` will not apply to structs.

`#[repr(packed)]` reduces padding to make the struct size smaller. The
representation of enums isn't strictly defined in Rust, and this attribute
Expand All @@ -42,3 +45,5 @@ won't work on enums.
types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via
SIMD. This doesn't make much sense for enums since they don't consist of a
single list of data.

[rfc2195]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md
7 changes: 7 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,13 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
});
sess.time("layout_testing", || layout_test::test_layout(tcx));
sess.time("abi_testing", || abi_test::test_abi(tcx));
if tcx.sess.opts.unstable_opts.validate_mir {
sess.time("ensuring_optimized_MIR_is_computable", || {
tcx.hir().par_body_owners(|def_id| {
tcx.instance_mir(ty::InstanceKind::Item(def_id.into()));
});
});
}
}

/// Runs the type-checking, region checking and other miscellaneous analysis
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ pub fn explain_lint_level_source(
err.note_once(format!(
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
));
if matches!(orig_level, Level::Warn | Level::Deny) {
err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
));
}
}
}
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,28 +458,23 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
))
}

ty::FnDef(..) | ty::FnPtr(..) => {
let bound_sig = self_ty.fn_sig(cx);
let sig = bound_sig.skip_binder();
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
// `FnDef` and `FnPtr` only implement `AsyncFn*` when their
// return type implements `Future`.
let nested = vec![
bound_sig
.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()]))
.upcast(cx),
];
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
nested,
))
ty::FnDef(def_id, _) => {
let sig = self_ty.fn_sig(cx);
if sig.skip_binder().is_fn_trait_compatible() && !cx.has_target_features(def_id) {
fn_item_to_async_callable(cx, sig)
} else {
Err(NoSolution)
}
}
ty::FnPtr(..) => {
let sig = self_ty.fn_sig(cx);
if sig.skip_binder().is_fn_trait_compatible() {
fn_item_to_async_callable(cx, sig)
} else {
Err(NoSolution)
}
}

ty::Closure(_, args) => {
let args = args.as_closure();
let bound_sig = args.sig();
Expand Down Expand Up @@ -563,6 +558,29 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
}
}

fn fn_item_to_async_callable<I: Interner>(
cx: I,
bound_sig: ty::Binder<I, ty::FnSig<I>>,
) -> Result<(ty::Binder<I, AsyncCallableRelevantTypes<I>>, Vec<I::Predicate>), NoSolution> {
let sig = bound_sig.skip_binder();
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
// `FnDef` and `FnPtr` only implement `AsyncFn*` when their
// return type implements `Future`.
let nested = vec![
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
];
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
nested,
))
}

/// Given a coroutine-closure, project to its returned coroutine when we are *certain*
/// that the closure's kind is compatible with the goal.
fn coroutine_closure_to_certain_coroutine<I: Interner>(
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,6 @@ pub struct Resolver<'a, 'tcx> {
/// Also includes of list of each fields visibility
struct_constructors: LocalDefIdMap<(Res, ty::Visibility<DefId>, Vec<ty::Visibility<DefId>>)>,

/// Features declared for this crate.
declared_features: FxHashSet<Symbol>,

lint_buffer: LintBuffer,

next_node_id: NodeId,
Expand Down Expand Up @@ -1402,7 +1399,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

let registered_tools = tcx.registered_tools(());

let features = tcx.features();
let pub_vis = ty::Visibility::<DefId>::Public;
let edition = tcx.sess.edition();

Expand Down Expand Up @@ -1506,7 +1502,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
multi_segment_macro_resolutions: Default::default(),
builtin_attrs: Default::default(),
containers_deriving_copy: Default::default(),
declared_features: features.declared_features.clone(),
lint_buffer: LintBuffer::default(),
next_node_id: CRATE_NODE_ID,
node_id_to_def_id,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let feature = stability.feature;

let is_allowed = |feature| {
self.declared_features.contains(&feature) || span.allows_unstable(feature)
self.tcx.features().declared_features.contains(&feature)
|| span.allows_unstable(feature)
};
let allowed_by_implication = implied_by.is_some_and(|feature| is_allowed(feature));
if !is_allowed(feature) && !allowed_by_implication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
candidates.vec.push(AsyncClosureCandidate);
}
ty::FnDef(..) | ty::FnPtr(..) => {
candidates.vec.push(AsyncClosureCandidate);
// Provide an impl, but only for suitable `fn` pointers.
ty::FnPtr(sig) => {
if sig.is_fn_trait_compatible() {
candidates.vec.push(AsyncClosureCandidate);
}
}
// Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
ty::FnDef(def_id, _) => {
let tcx = self.tcx();
if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
&& tcx.codegen_fn_attrs(def_id).target_features.is_empty()
{
candidates.vec.push(AsyncClosureCandidate);
}
}
_ => {}
}
Expand Down
13 changes: 10 additions & 3 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,16 +1169,23 @@ impl<T: ?Sized> NonNull<T> {
/// `align`.
///
/// If it is not possible to align the pointer, the implementation returns
/// `usize::MAX`. It is permissible for the implementation to *always*
/// return `usize::MAX`. Only your algorithm's performance can depend
/// on getting a usable offset here, not its correctness.
/// `usize::MAX`.
///
/// The offset is expressed in number of `T` elements, and not bytes.
///
/// There are no guarantees whatsoever that offsetting the pointer will not overflow or go
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that
/// the returned offset is correct in all terms other than alignment.
///
/// When this is called during compile-time evaluation (which is unstable), the implementation
/// may return `usize::MAX` in cases where that can never happen at runtime. This is because the
/// actual alignment of pointers is not known yet during compile-time, so an offset with
/// guaranteed alignment can sometimes not be computed. For example, a buffer declared as `[u8;
/// N]` might be allocated at an odd or an even address, but at compile-time this is not yet
/// known, so the execution has to be correct for either choice. It is therefore impossible to
/// find an offset that is guaranteed to be 2-aligned. (This behavior is subject to change, as usual
/// for unstable APIs.)
///
/// # Panics
///
/// The function panics if `align` is not a power-of-two.
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/121127.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #121127
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes -C debuginfo=2
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes -C debuginfo=2
// Note that as of PR#123949 this only crashes with debuginfo enabled

#![feature(specialization)]
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/122909.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes
//@ known-bug: #122909


Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/126896.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: rust-lang/rust#126896
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes

#![feature(type_alias_impl_trait)]
type Two<'a, 'b> = impl std::fmt::Debug;
Expand Down
27 changes: 27 additions & 0 deletions tests/ui/async-await/async-closures/fn-exception.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ edition: 2021

#![feature(async_closure, target_feature_11)]
// `target_feature_11` just to test safe functions w/ target features.

use std::pin::Pin;
use std::future::Future;

unsafe extern "Rust" {
pub unsafe fn unsafety() -> Pin<Box<dyn Future<Output = ()> + 'static>>;
}

unsafe extern "C" {
pub safe fn abi() -> Pin<Box<dyn Future<Output = ()> + 'static>>;
}


#[target_feature(enable = "sse2")]
fn target_feature() -> Pin<Box<dyn Future<Output = ()> + 'static>> { todo!() }

fn test(f: impl async Fn()) {}

fn main() {
test(unsafety); //~ ERROR the trait bound
test(abi); //~ ERROR the trait bound
test(target_feature); //~ ERROR the trait bound
}
45 changes: 45 additions & 0 deletions tests/ui/async-await/async-closures/fn-exception.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
error[E0277]: the trait bound `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {unsafety}: AsyncFn<()>` is not satisfied
--> $DIR/fn-exception.rs:24:10
|
LL | test(unsafety);
| ---- ^^^^^^^^ the trait `AsyncFn<()>` is not implemented for fn item `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {unsafety}`
| |
| required by a bound introduced by this call
|
note: required by a bound in `test`
--> $DIR/fn-exception.rs:21:17
|
LL | fn test(f: impl async Fn()) {}
| ^^^^^^^^^^ required by this bound in `test`

error[E0277]: the trait bound `extern "C" fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {abi}: AsyncFn<()>` is not satisfied
--> $DIR/fn-exception.rs:25:10
|
LL | test(abi);
| ---- ^^^ the trait `AsyncFn<()>` is not implemented for fn item `extern "C" fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {abi}`
| |
| required by a bound introduced by this call
|
note: required by a bound in `test`
--> $DIR/fn-exception.rs:21:17
|
LL | fn test(f: impl async Fn()) {}
| ^^^^^^^^^^ required by this bound in `test`

error[E0277]: the trait bound `fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}: AsyncFn<()>` is not satisfied
--> $DIR/fn-exception.rs:26:10
|
LL | test(target_feature);
| ---- ^^^^^^^^^^^^^^ the trait `AsyncFn<()>` is not implemented for fn item `fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}`
| |
| required by a bound introduced by this call
|
note: required by a bound in `test`
--> $DIR/fn-exception.rs:21:17
|
LL | fn test(f: impl async Fn()) {}
| ^^^^^^^^^^ required by this bound in `test`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
16 changes: 16 additions & 0 deletions tests/ui/inline-const/using-late-bound-from-closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test for ICE: cannot convert ReLateParam to a region vid
// https://github.com/rust-lang/rust/issues/125873

#![feature(closure_lifetime_binder)]
fn foo() {
let a = for<'a> |b: &'a ()| -> &'a () {
const {
let awd = ();
let _: &'a () = &awd;
//~^ `awd` does not live long enough
};
b
};
}

fn main() {}
19 changes: 19 additions & 0 deletions tests/ui/inline-const/using-late-bound-from-closure.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0597]: `awd` does not live long enough
--> $DIR/using-late-bound-from-closure.rs:9:29
|
LL | let a = for<'a> |b: &'a ()| -> &'a () {
| -- lifetime `'a` defined here
LL | const {
LL | let awd = ();
| --- binding `awd` declared here
LL | let _: &'a () = &awd;
| ------ ^^^^ borrowed value does not live long enough
| |
| type annotation requires that `awd` is borrowed for `'a`
LL |
LL | };
| - `awd` dropped here while still borrowed

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0597`.
1 change: 0 additions & 1 deletion tests/ui/lint/command-line-lint-group-forbid.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ LL | let _InappropriateCamelCasing = true;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-F non-snake-case` implied by `-F bad-style`
= help: to override `-F bad-style` add `#[allow(non_snake_case)]`

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL | 0...100 => true,
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility`
= help: to override `--force-warn rust-2021-compatibility` add `#[allow(ellipsis_inclusive_range_patterns)]`

warning: 1 warning emitted

1 change: 0 additions & 1 deletion tests/ui/lint/force-warn/lint-group-allow-warnings.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ LL | pub fn FUNCTION() {}
| ^^^^^^^^ help: convert the identifier to snake case: `function`
|
= note: `--force-warn non-snake-case` implied by `--force-warn nonstandard-style`
= help: to override `--force-warn nonstandard-style` add `#[allow(non_snake_case)]`

warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: if this is an object-safe trait, use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
Loading
Loading