Skip to content

Commit 79fc1af

Browse files
authored
Merge branch 'rust-lang:master' into mips-sig
2 parents 01fd2e5 + c7b0d4e commit 79fc1af

27 files changed

+160
-88
lines changed

compiler/rustc_error_codes/src/error_codes/E0517.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ impl Foo {
2525
These attributes do not work on typedefs, since typedefs are just aliases.
2626

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

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

3740
`#[repr(packed)]` reduces padding to make the struct size smaller. The
3841
representation of enums isn't strictly defined in Rust, and this attribute
@@ -42,3 +45,5 @@ won't work on enums.
4245
types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via
4346
SIMD. This doesn't make much sense for enums since they don't consist of a
4447
single list of data.
48+
49+
[rfc2195]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md

compiler/rustc_errors/src/emitter.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,9 +2595,7 @@ fn num_decimal_digits(num: usize) -> usize {
25952595

25962596
// We replace some characters so the CLI output is always consistent and underlines aligned.
25972597
// Keep the following list in sync with `rustc_span::char_width`.
2598-
// ATTENTION: keep lexicografically sorted so that the binary search will work
25992598
const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
2600-
// tidy-alphabetical-start
26012599
// In terminals without Unicode support the following will be garbled, but in *all* terminals
26022600
// the underlying codepoint will be as well. We could gate this replacement behind a "unicode
26032601
// support" gate.
@@ -2610,7 +2608,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
26102608
('\u{0006}', "␆"),
26112609
('\u{0007}', "␇"),
26122610
('\u{0008}', "␈"),
2613-
('\u{0009}', " "), // We do our own tab replacement
2611+
('\t', " "), // We do our own tab replacement
26142612
('\u{000b}', "␋"),
26152613
('\u{000c}', "␌"),
26162614
('\u{000d}', "␍"),
@@ -2643,13 +2641,23 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
26432641
('\u{2067}', "�"),
26442642
('\u{2068}', "�"),
26452643
('\u{2069}', "�"),
2646-
// tidy-alphabetical-end
26472644
];
26482645

26492646
fn normalize_whitespace(s: &str) -> String {
2650-
// Scan the input string for a character in the ordered table above. If it's present, replace
2651-
// it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
2652-
// char. At the end, allocate all chars into a string in one operation.
2647+
const {
2648+
let mut i = 1;
2649+
while i < OUTPUT_REPLACEMENTS.len() {
2650+
assert!(
2651+
OUTPUT_REPLACEMENTS[i - 1].0 < OUTPUT_REPLACEMENTS[i].0,
2652+
"The OUTPUT_REPLACEMENTS array must be sorted (for binary search to work) \
2653+
and must contain no duplicate entries"
2654+
);
2655+
i += 1;
2656+
}
2657+
}
2658+
// Scan the input string for a character in the ordered table above.
2659+
// If it's present, replace it with its alternative string (it can be more than 1 char!).
2660+
// Otherwise, retain the input char.
26532661
s.chars().fold(String::with_capacity(s.len()), |mut s, c| {
26542662
match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) {
26552663
Ok(i) => s.push_str(OUTPUT_REPLACEMENTS[i].1),

compiler/rustc_interface/src/passes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
818818
});
819819
sess.time("layout_testing", || layout_test::test_layout(tcx));
820820
sess.time("abi_testing", || abi_test::test_abi(tcx));
821+
if tcx.sess.opts.unstable_opts.validate_mir {
822+
sess.time("ensuring_optimized_MIR_is_computable", || {
823+
tcx.hir().par_body_owners(|def_id| {
824+
tcx.instance_mir(ty::InstanceKind::Item(def_id.into()));
825+
});
826+
});
827+
}
821828
}
822829

823830
/// Runs the type-checking, region checking and other miscellaneous analysis

compiler/rustc_middle/src/lint.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ pub fn explain_lint_level_source(
228228
err.note_once(format!(
229229
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
230230
));
231-
err.help_once(format!(
232-
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
233-
));
231+
if matches!(orig_level, Level::Warn | Level::Deny) {
232+
err.help_once(format!(
233+
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
234+
));
235+
}
234236
}
235237
}
236238
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,6 @@ pub struct Resolver<'a, 'tcx> {
11291129
/// Also includes of list of each fields visibility
11301130
struct_constructors: LocalDefIdMap<(Res, ty::Visibility<DefId>, Vec<ty::Visibility<DefId>>)>,
11311131

1132-
/// Features declared for this crate.
1133-
declared_features: FxHashSet<Symbol>,
1134-
11351132
lint_buffer: LintBuffer,
11361133

11371134
next_node_id: NodeId,
@@ -1402,7 +1399,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14021399

14031400
let registered_tools = tcx.registered_tools(());
14041401

1405-
let features = tcx.features();
14061402
let pub_vis = ty::Visibility::<DefId>::Public;
14071403
let edition = tcx.sess.edition();
14081404

@@ -1506,7 +1502,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15061502
multi_segment_macro_resolutions: Default::default(),
15071503
builtin_attrs: Default::default(),
15081504
containers_deriving_copy: Default::default(),
1509-
declared_features: features.declared_features.clone(),
15101505
lint_buffer: LintBuffer::default(),
15111506
next_node_id: CRATE_NODE_ID,
15121507
node_id_to_def_id,

compiler/rustc_resolve/src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10011001
let feature = stability.feature;
10021002

10031003
let is_allowed = |feature| {
1004-
self.declared_features.contains(&feature) || span.allows_unstable(feature)
1004+
self.tcx.features().declared_features.contains(&feature)
1005+
|| span.allows_unstable(feature)
10051006
};
10061007
let allowed_by_implication = implied_by.is_some_and(|feature| is_allowed(feature));
10071008
if !is_allowed(feature) && !allowed_by_implication {

library/core/src/num/f32.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ impl f32 {
797797
/// [`INFINITY`]: Self::INFINITY
798798
/// [`MIN`]: Self::MIN
799799
/// [`MAX`]: Self::MAX
800+
#[inline]
800801
#[unstable(feature = "float_next_up_down", issue = "91399")]
801802
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
802803
pub const fn next_up(self) -> Self {
@@ -845,6 +846,7 @@ impl f32 {
845846
/// [`INFINITY`]: Self::INFINITY
846847
/// [`MIN`]: Self::MIN
847848
/// [`MAX`]: Self::MAX
849+
#[inline]
848850
#[unstable(feature = "float_next_up_down", issue = "91399")]
849851
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
850852
pub const fn next_down(self) -> Self {
@@ -1042,6 +1044,7 @@ impl f32 {
10421044
/// assert_eq!(1f32.midpoint(4.0), 2.5);
10431045
/// assert_eq!((-5.5f32).midpoint(8.0), 1.25);
10441046
/// ```
1047+
#[inline]
10451048
#[unstable(feature = "num_midpoint", issue = "110840")]
10461049
pub fn midpoint(self, other: f32) -> f32 {
10471050
cfg_if! {

library/core/src/num/f64.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ impl f64 {
805805
/// [`INFINITY`]: Self::INFINITY
806806
/// [`MIN`]: Self::MIN
807807
/// [`MAX`]: Self::MAX
808+
#[inline]
808809
#[unstable(feature = "float_next_up_down", issue = "91399")]
809810
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
810811
pub const fn next_up(self) -> Self {
@@ -853,6 +854,7 @@ impl f64 {
853854
/// [`INFINITY`]: Self::INFINITY
854855
/// [`MIN`]: Self::MIN
855856
/// [`MAX`]: Self::MAX
857+
#[inline]
856858
#[unstable(feature = "float_next_up_down", issue = "91399")]
857859
#[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")]
858860
pub const fn next_down(self) -> Self {
@@ -1051,6 +1053,7 @@ impl f64 {
10511053
/// assert_eq!(1f64.midpoint(4.0), 2.5);
10521054
/// assert_eq!((-5.5f64).midpoint(8.0), 1.25);
10531055
/// ```
1056+
#[inline]
10541057
#[unstable(feature = "num_midpoint", issue = "110840")]
10551058
pub fn midpoint(self, other: f64) -> f64 {
10561059
const LO: f64 = f64::MIN_POSITIVE * 2.;

library/core/src/ptr/non_null.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,16 +1169,23 @@ impl<T: ?Sized> NonNull<T> {
11691169
/// `align`.
11701170
///
11711171
/// If it is not possible to align the pointer, the implementation returns
1172-
/// `usize::MAX`. It is permissible for the implementation to *always*
1173-
/// return `usize::MAX`. Only your algorithm's performance can depend
1174-
/// on getting a usable offset here, not its correctness.
1172+
/// `usize::MAX`.
11751173
///
11761174
/// The offset is expressed in number of `T` elements, and not bytes.
11771175
///
11781176
/// There are no guarantees whatsoever that offsetting the pointer will not overflow or go
11791177
/// beyond the allocation that the pointer points into. It is up to the caller to ensure that
11801178
/// the returned offset is correct in all terms other than alignment.
11811179
///
1180+
/// When this is called during compile-time evaluation (which is unstable), the implementation
1181+
/// may return `usize::MAX` in cases where that can never happen at runtime. This is because the
1182+
/// actual alignment of pointers is not known yet during compile-time, so an offset with
1183+
/// guaranteed alignment can sometimes not be computed. For example, a buffer declared as `[u8;
1184+
/// N]` might be allocated at an odd or an even address, but at compile-time this is not yet
1185+
/// known, so the execution has to be correct for either choice. It is therefore impossible to
1186+
/// find an offset that is guaranteed to be 2-aligned. (This behavior is subject to change, as usual
1187+
/// for unstable APIs.)
1188+
///
11821189
/// # Panics
11831190
///
11841191
/// The function panics if `align` is not a power-of-two.

0 commit comments

Comments
 (0)