Skip to content

Commit d45bef9

Browse files
committed
Auto merge of #57568 - Centril:rollup, r=Centril
Rollup of 16 pull requests Successful merges: - #57351 (Don't actually create a full MIR stack frame when not needed) - #57353 (Optimise floating point `is_finite` (2x) and `is_infinite` (1.6x).) - #57412 (Improve the wording) - #57436 (save-analysis: use a fallback when access levels couldn't be computed) - #57453 (lldb_batchmode.py: try `import _thread` for Python 3) - #57454 (Some cleanups for core::fmt) - #57461 (Change `String` to `&'static str` in `ParseResult::Failure`.) - #57473 (std: Render large exit codes as hex on Windows) - #57474 (save-analysis: Get path def from parent in case there's no def for the path itself.) - #57494 (Speed up item_bodies for large match statements involving regions) - #57496 (re-do docs for core::cmp) - #57508 (rustdoc: Allow inlining of reexported crates and crate items) - #57547 (Use `ptr::eq` where applicable) - #57557 (resolve: Mark extern crate items as used in more cases) - #57560 (hygiene: Do not treat `Self` ctor as a local variable) - #57564 (Update the const fn tracking issue to the new metabug) Failed merges: r? @ghost
2 parents 5012d7f + 3e2dcf9 commit d45bef9

File tree

59 files changed

+353
-186
lines changed

Some content is hidden

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

59 files changed

+353
-186
lines changed

src/doc/unstable-book/src/language-features/const-fn.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# `const_fn`
22

3-
The tracking issue for this feature is: [#24111]
3+
The tracking issue for this feature is: [#57563]
44

5-
[#24111]: https://github.com/rust-lang/rust/issues/24111
5+
[#57563]: https://github.com/rust-lang/rust/issues/57563
66

77
------------------------
88

src/etc/lldb_batchmode.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
import os
1919
import sys
2020
import threading
21-
import thread
2221
import re
2322
import time
2423

24+
try:
25+
import thread
26+
except ModuleNotFoundError:
27+
# The `thread` module was renamed to `_thread` in Python 3.
28+
import _thread as thread
29+
2530
# Set this to True for additional output
2631
DEBUG_OUTPUT = False
2732

src/libcore/cmp.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
//! Functionality for ordering and comparison.
22
//!
3-
//! This module defines both [`PartialOrd`] and [`PartialEq`] traits which are used
4-
//! by the compiler to implement comparison operators. Rust programs may
5-
//! implement [`PartialOrd`] to overload the `<`, `<=`, `>`, and `>=` operators,
6-
//! and may implement [`PartialEq`] to overload the `==` and `!=` operators.
3+
//! This module contains various tools for ordering and comparing values. In
4+
//! summary:
75
//!
8-
//! [`PartialOrd`]: trait.PartialOrd.html
9-
//! [`PartialEq`]: trait.PartialEq.html
6+
//! * [`Eq`] and [`PartialEq`] are traits that allow you to define total and
7+
//! partial equality between values, respectively. Implementing them overloads
8+
//! the `==` and `!=` operators.
9+
//! * [`Ord`] and [`PartialOrd`] are traits that allow you to define total and
10+
//! partial orderings between values, respectively. Implementing them overloads
11+
//! the `<`, `<=`, `>`, and `>=` operators.
12+
//! * [`Ordering`][cmp::Ordering] is an enum returned by the
13+
//! main functions of [`Ord`] and [`PartialOrd`], and describes an ordering.
14+
//! * [`Reverse`][cmp::Reverse] is a struct that allows you to easily reverse
15+
//! an ordering.
16+
//! * [`max`][cmp::max] and [`min`][cmp::min] are functions that build off of
17+
//! [`Ord`] and allow you to find the maximum or minimum of two values.
1018
//!
11-
//! # Examples
12-
//!
13-
//! ```
14-
//! let x: u32 = 0;
15-
//! let y: u32 = 1;
16-
//!
17-
//! // these two lines are equivalent
18-
//! assert_eq!(x < y, true);
19-
//! assert_eq!(x.lt(&y), true);
20-
//!
21-
//! // these two lines are also equivalent
22-
//! assert_eq!(x == y, false);
23-
//! assert_eq!(x.eq(&y), false);
24-
//! ```
19+
//! For more details, see the respective documentation of each item in the list.
2520
2621
#![stable(feature = "rust1", since = "1.0.0")]
2722

src/libcore/fmt/mod.rs

+9-38
Original file line numberDiff line numberDiff line change
@@ -191,29 +191,8 @@ pub trait Write {
191191
/// assert_eq!(&buf, "world");
192192
/// ```
193193
#[stable(feature = "rust1", since = "1.0.0")]
194-
fn write_fmt(&mut self, args: Arguments) -> Result {
195-
// This Adapter is needed to allow `self` (of type `&mut
196-
// Self`) to be cast to a Write (below) without
197-
// requiring a `Sized` bound.
198-
struct Adapter<'a,T: ?Sized +'a>(&'a mut T);
199-
200-
impl<T: ?Sized> Write for Adapter<'_, T>
201-
where T: Write
202-
{
203-
fn write_str(&mut self, s: &str) -> Result {
204-
self.0.write_str(s)
205-
}
206-
207-
fn write_char(&mut self, c: char) -> Result {
208-
self.0.write_char(c)
209-
}
210-
211-
fn write_fmt(&mut self, args: Arguments) -> Result {
212-
self.0.write_fmt(args)
213-
}
214-
}
215-
216-
write(&mut Adapter(self), args)
194+
fn write_fmt(mut self: &mut Self, args: Arguments) -> Result {
195+
write(&mut self, args)
217196
}
218197
}
219198

@@ -268,7 +247,7 @@ struct Void {
268247
/// family of functions. It contains a function to format the given value. At
269248
/// compile time it is ensured that the function and the value have the correct
270249
/// types, and then this struct is used to canonicalize arguments to one type.
271-
#[derive(Copy)]
250+
#[derive(Copy, Clone)]
272251
#[allow(missing_debug_implementations)]
273252
#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
274253
issue = "0")]
@@ -278,14 +257,6 @@ pub struct ArgumentV1<'a> {
278257
formatter: fn(&Void, &mut Formatter) -> Result,
279258
}
280259

281-
#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
282-
issue = "0")]
283-
impl Clone for ArgumentV1<'_> {
284-
fn clone(&self) -> Self {
285-
*self
286-
}
287-
}
288-
289260
impl<'a> ArgumentV1<'a> {
290261
#[inline(never)]
291262
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
@@ -1105,7 +1076,7 @@ impl<'a> Formatter<'a> {
11051076
self.args[i].as_usize()
11061077
}
11071078
rt::v1::Count::NextParam => {
1108-
self.curarg.next().and_then(|arg| arg.as_usize())
1079+
self.curarg.next()?.as_usize()
11091080
}
11101081
}
11111082
}
@@ -1171,15 +1142,15 @@ impl<'a> Formatter<'a> {
11711142
sign = Some('+'); width += 1;
11721143
}
11731144

1174-
let mut prefixed = false;
1175-
if self.alternate() {
1176-
prefixed = true; width += prefix.chars().count();
1145+
let prefixed = self.alternate();
1146+
if prefixed {
1147+
width += prefix.chars().count();
11771148
}
11781149

11791150
// Writes the sign if it exists, and then the prefix if it was requested
11801151
let write_prefix = |f: &mut Formatter| {
11811152
if let Some(c) = sign {
1182-
f.buf.write_str(c.encode_utf8(&mut [0; 4]))?;
1153+
f.buf.write_char(c)?;
11831154
}
11841155
if prefixed { f.buf.write_str(prefix) }
11851156
else { Ok(()) }
@@ -1341,7 +1312,7 @@ impl<'a> Formatter<'a> {
13411312

13421313
// remove the sign from the formatted parts
13431314
formatted.sign = b"";
1344-
width = if width < sign.len() { 0 } else { width - sign.len() };
1315+
width = width.saturating_sub(sign.len());
13451316
align = rt::v1::Alignment::Right;
13461317
self.fill = '0';
13471318
self.align = rt::v1::Alignment::Right;

src/libcore/num/f32.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ impl f32 {
161161
self != self
162162
}
163163

164+
// FIXME(#50145): `abs` is publicly unavailable in libcore due to
165+
// concerns about portability, so this implementation is for
166+
// private use internally.
167+
#[inline]
168+
fn abs_private(self) -> f32 {
169+
f32::from_bits(self.to_bits() & 0x7fff_ffff)
170+
}
171+
164172
/// Returns `true` if this value is positive infinity or negative infinity and
165173
/// false otherwise.
166174
///
@@ -181,7 +189,7 @@ impl f32 {
181189
#[stable(feature = "rust1", since = "1.0.0")]
182190
#[inline]
183191
pub fn is_infinite(self) -> bool {
184-
self == INFINITY || self == NEG_INFINITY
192+
self.abs_private() == INFINITY
185193
}
186194

187195
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -203,7 +211,9 @@ impl f32 {
203211
#[stable(feature = "rust1", since = "1.0.0")]
204212
#[inline]
205213
pub fn is_finite(self) -> bool {
206-
!(self.is_nan() || self.is_infinite())
214+
// There's no need to handle NaN separately: if self is NaN,
215+
// the comparison is not true, exactly as desired.
216+
self.abs_private() < INFINITY
207217
}
208218

209219
/// Returns `true` if the number is neither zero, infinite,

src/libcore/num/f64.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ impl f64 {
161161
self != self
162162
}
163163

164+
// FIXME(#50145): `abs` is publicly unavailable in libcore due to
165+
// concerns about portability, so this implementation is for
166+
// private use internally.
167+
#[inline]
168+
fn abs_private(self) -> f64 {
169+
f64::from_bits(self.to_bits() & 0x7fff_ffff_ffff_ffff)
170+
}
171+
164172
/// Returns `true` if this value is positive infinity or negative infinity and
165173
/// false otherwise.
166174
///
@@ -181,7 +189,7 @@ impl f64 {
181189
#[stable(feature = "rust1", since = "1.0.0")]
182190
#[inline]
183191
pub fn is_infinite(self) -> bool {
184-
self == INFINITY || self == NEG_INFINITY
192+
self.abs_private() == INFINITY
185193
}
186194

187195
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -203,7 +211,9 @@ impl f64 {
203211
#[stable(feature = "rust1", since = "1.0.0")]
204212
#[inline]
205213
pub fn is_finite(self) -> bool {
206-
!(self.is_nan() || self.is_infinite())
214+
// There's no need to handle NaN separately: if self is NaN,
215+
// the comparison is not true, exactly as desired.
216+
self.abs_private() < INFINITY
207217
}
208218

209219
/// Returns `true` if the number is neither zero, infinite,

src/libcore/str/pattern.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ impl<'a> Pattern<'a> for char {
425425
#[inline]
426426
fn into_searcher(self, haystack: &'a str) -> Self::Searcher {
427427
let mut utf8_encoded = [0; 4];
428-
self.encode_utf8(&mut utf8_encoded);
429-
let utf8_size = self.len_utf8();
428+
let utf8_size = self.encode_utf8(&mut utf8_encoded).len();
430429
CharSearcher {
431430
haystack,
432431
finger: 0,

src/librustc/infer/lexical_region_resolve/mod.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_data_structures::graph::implementation::{
1313
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
1414
};
1515
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
16+
use smallvec::SmallVec;
1617
use std::fmt;
1718
use std::u32;
1819
use ty::fold::TypeFoldable;
@@ -190,19 +191,24 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
190191
match *constraint {
191192
Constraint::RegSubVar(a_region, b_vid) => {
192193
let b_data = var_values.value_mut(b_vid);
193-
self.expand_node(a_region, b_vid, b_data)
194+
(self.expand_node(a_region, b_vid, b_data), false)
194195
}
195196
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
196-
VarValue::ErrorValue => false,
197+
VarValue::ErrorValue => (false, false),
197198
VarValue::Value(a_region) => {
198199
let b_node = var_values.value_mut(b_vid);
199-
self.expand_node(a_region, b_vid, b_node)
200+
let changed = self.expand_node(a_region, b_vid, b_node);
201+
let retain = match *b_node {
202+
VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
203+
_ => true
204+
};
205+
(changed, retain)
200206
}
201207
},
202208
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
203209
// These constraints are checked after expansion
204210
// is done, in `collect_errors`.
205-
false
211+
(false, false)
206212
}
207213
}
208214
})
@@ -268,6 +274,13 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
268274

269275
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
270276
let tcx = self.tcx();
277+
278+
// Equal scopes can show up quite often, if the fixed point
279+
// iteration converges slowly, skip them
280+
if a == b {
281+
return a;
282+
}
283+
271284
match (a, b) {
272285
(&ty::ReClosureBound(..), _)
273286
| (_, &ty::ReClosureBound(..))
@@ -710,21 +723,23 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
710723

711724
fn iterate_until_fixed_point<F>(&self, tag: &str, mut body: F)
712725
where
713-
F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> bool,
726+
F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> (bool, bool),
714727
{
728+
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.iter().collect();
715729
let mut iteration = 0;
716730
let mut changed = true;
717731
while changed {
718732
changed = false;
719733
iteration += 1;
720734
debug!("---- {} Iteration {}{}", "#", tag, iteration);
721-
for (constraint, origin) in &self.data.constraints {
722-
let edge_changed = body(constraint, origin);
735+
constraints.retain(|(constraint, origin)| {
736+
let (edge_changed, retain) = body(constraint, origin);
723737
if edge_changed {
724738
debug!("Updated due to constraint {:?}", constraint);
725739
changed = true;
726740
}
727-
}
741+
retain
742+
});
728743
}
729744
debug!("---- {} Complete after {} iteration(s)", tag, iteration);
730745
}

src/librustc/ty/context.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use std::hash::{Hash, Hasher};
5959
use std::fmt;
6060
use std::mem;
6161
use std::ops::{Deref, Bound};
62+
use std::ptr;
6263
use std::iter;
6364
use std::sync::mpsc;
6465
use std::sync::Arc;
@@ -168,7 +169,7 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
168169

169170
// Make sure we don't end up with inference
170171
// types/regions in the global interner
171-
if local as *const _ as usize == global as *const _ as usize {
172+
if ptr::eq(local, global) {
172173
bug!("Attempted to intern `{:?}` which contains \
173174
inference types/regions in the global type context",
174175
&ty_struct);
@@ -1135,9 +1136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11351136

11361137
/// Returns true if self is the same as self.global_tcx().
11371138
fn is_global(self) -> bool {
1138-
let local = self.interners as *const _;
1139-
let global = &self.global_interners as *const _;
1140-
local as usize == global as usize
1139+
ptr::eq(self.interners, &self.global_interners)
11411140
}
11421141

11431142
/// Create a type context and call the closure with a `TyCtxt` reference
@@ -1787,6 +1786,7 @@ pub mod tls {
17871786
use std::fmt;
17881787
use std::mem;
17891788
use std::marker::PhantomData;
1789+
use std::ptr;
17901790
use syntax_pos;
17911791
use ty::query;
17921792
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
@@ -2021,8 +2021,7 @@ pub mod tls {
20212021
{
20222022
with_context(|context| {
20232023
unsafe {
2024-
let gcx = tcx.gcx as *const _ as usize;
2025-
assert!(context.tcx.gcx as *const _ as usize == gcx);
2024+
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
20262025
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
20272026
f(context)
20282027
}
@@ -2040,10 +2039,8 @@ pub mod tls {
20402039
{
20412040
with_context(|context| {
20422041
unsafe {
2043-
let gcx = tcx.gcx as *const _ as usize;
2044-
let interners = tcx.interners as *const _ as usize;
2045-
assert!(context.tcx.gcx as *const _ as usize == gcx);
2046-
assert!(context.tcx.interners as *const _ as usize == interners);
2042+
assert!(ptr::eq(context.tcx.gcx, tcx.gcx));
2043+
assert!(ptr::eq(context.tcx.interners, tcx.interners));
20472044
let context: &ImplicitCtxt<'_, '_, '_> = mem::transmute(context);
20482045
f(context)
20492046
}

src/librustc_codegen_llvm/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax_pos::{self, Span, FileName};
4747

4848
impl PartialEq for llvm::Metadata {
4949
fn eq(&self, other: &Self) -> bool {
50-
self as *const _ == other as *const _
50+
ptr::eq(self, other)
5151
}
5252
}
5353

0 commit comments

Comments
 (0)