Skip to content

Commit

Permalink
Auto merge of rust-lang#128835 - matthiaskrgr:rollup-apzlbxy, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#128306 (Update NonNull::align_offset quarantees)
 - rust-lang#128612 (Make `validate_mir` ensure the final MIR for all bodies)
 - rust-lang#128648 (Add regression test)
 - rust-lang#128749 (Mark `{f32,f64}::{next_up,next_down,midpoint}` inline)
 - rust-lang#128795 (Update E0517 message to reflect RFC 2195.)
 - rust-lang#128825 (rm `declared_features` field in resolver)
 - rust-lang#128826 (Only suggest `#[allow]` for `--warn` and `--deny` lint level flags)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 8, 2024
2 parents 2048386 + 70dccc2 commit 3e9bd8b
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 29 deletions.
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
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
3 changes: 3 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ impl f32 {
/// [`INFINITY`]: Self::INFINITY
/// [`MIN`]: Self::MIN
/// [`MAX`]: Self::MAX
#[inline]
#[unstable(feature = "float_next_up_down", issue = "91399")]
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
pub const fn next_up(self) -> Self {
Expand Down Expand Up @@ -845,6 +846,7 @@ impl f32 {
/// [`INFINITY`]: Self::INFINITY
/// [`MIN`]: Self::MIN
/// [`MAX`]: Self::MAX
#[inline]
#[unstable(feature = "float_next_up_down", issue = "91399")]
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
pub const fn next_down(self) -> Self {
Expand Down Expand Up @@ -1042,6 +1044,7 @@ impl f32 {
/// assert_eq!(1f32.midpoint(4.0), 2.5);
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
/// ```
#[inline]
#[unstable(feature = "num_midpoint", issue = "110840")]
pub fn midpoint(self, other: f32) -> f32 {
cfg_if! {
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ impl f64 {
/// [`INFINITY`]: Self::INFINITY
/// [`MIN`]: Self::MIN
/// [`MAX`]: Self::MAX
#[inline]
#[unstable(feature = "float_next_up_down", issue = "91399")]
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
pub const fn next_up(self) -> Self {
Expand Down Expand Up @@ -853,6 +854,7 @@ impl f64 {
/// [`INFINITY`]: Self::INFINITY
/// [`MIN`]: Self::MIN
/// [`MAX`]: Self::MAX
#[inline]
#[unstable(feature = "float_next_up_down", issue = "91399")]
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
pub const fn next_down(self) -> Self {
Expand Down Expand Up @@ -1051,6 +1053,7 @@ impl f64 {
/// assert_eq!(1f64.midpoint(4.0), 2.5);
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
/// ```
#[inline]
#[unstable(feature = "num_midpoint", issue = "110840")]
pub fn midpoint(self, other: f64) -> f64 {
const LO: f64 = f64::MIN_POSITIVE * 2.;
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
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
1 change: 0 additions & 1 deletion tests/ui/lint/group-forbid-always-trumps-cli.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `-F unused-variables` implied by `-F unused`
= help: to override `-F unused` add `#[allow(unused_variables)]`

error: aborting due to 1 previous error

0 comments on commit 3e9bd8b

Please sign in to comment.