Skip to content

Commit 790d19c

Browse files
committed
Auto merge of rust-lang#77798 - JohnTitor:rollup-82u711m, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#77195 (Link to documentation-specific guidelines.) - rust-lang#77629 (Cleanup of `eat_while()` in lexer) - rust-lang#77709 (Link Vec leak doc to Box) - rust-lang#77738 (fix __rust_alloc_error_handler comment) - rust-lang#77748 (Dead code cleanup in windows-gnu std) - rust-lang#77754 (Add TraitDef::find_map_relevant_impl) - rust-lang#77766 (Clarify the debug-related values should take boolean) - rust-lang#77777 (doc: disambiguate stat in MetadataExt::as_raw_stat) - rust-lang#77782 (Fix typo in error code description) - rust-lang#77787 (Update `changelog-seen` in config.toml.example) Failed merges: r? `@ghost`
2 parents 7bc5839 + c98b3e8 commit 790d19c

File tree

15 files changed

+76
-125
lines changed

15 files changed

+76
-125
lines changed

compiler/rustc_error_codes/src/error_codes/E0424.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Foo {
2121
The `self` keyword can only be used inside methods, which are associated
2222
functions (functions defined inside of a `trait` or `impl` block) that have a
2323
`self` receiver as its first parameter, like `self`, `&self`, `&mut self` or
24-
`self: &mut Pin<Self>` (this last one is an example of an ["abitrary `self`
24+
`self: &mut Pin<Self>` (this last one is an example of an ["arbitrary `self`
2525
type"](https://github.com/rust-lang/rust/issues/44874)).
2626

2727
Check if the associated function's parameter list should have contained a `self`

compiler/rustc_lexer/src/lib.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Token {
4848
}
4949

5050
/// Enum representing common lexeme types.
51+
// perf note: Changing all `usize` to `u32` doesn't change performance. See #77629
5152
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
5253
pub enum TokenKind {
5354
// Multi-char tokens:
@@ -160,6 +161,7 @@ pub enum LiteralKind {
160161
/// - `r##~"abcde"##`: `InvalidStarter`
161162
/// - `r###"abcde"##`: `NoTerminator { expected: 3, found: 2, possible_terminator_offset: Some(11)`
162163
/// - Too many `#`s (>65535): `TooManyDelimiters`
164+
// perf note: It doesn't matter that this makes `Token` 36 bytes bigger. See #77629
163165
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
164166
pub enum RawStrError {
165167
/// Non `#` characters exist between `r` and `"` eg. `r#~"..`
@@ -689,7 +691,12 @@ impl Cursor<'_> {
689691
let mut max_hashes = 0;
690692

691693
// Count opening '#' symbols.
692-
let n_start_hashes = self.eat_while(|c| c == '#');
694+
let mut eaten = 0;
695+
while self.first() == '#' {
696+
eaten += 1;
697+
self.bump();
698+
}
699+
let n_start_hashes = eaten;
693700

694701
// Check that string is started.
695702
match self.bump() {
@@ -724,16 +731,11 @@ impl Cursor<'_> {
724731
// Note that this will not consume extra trailing `#` characters:
725732
// `r###"abcde"####` is lexed as a `RawStr { n_hashes: 3 }`
726733
// followed by a `#` token.
727-
let mut hashes_left = n_start_hashes;
728-
let is_closing_hash = |c| {
729-
if c == '#' && hashes_left != 0 {
730-
hashes_left -= 1;
731-
true
732-
} else {
733-
false
734-
}
735-
};
736-
let n_end_hashes = self.eat_while(is_closing_hash);
734+
let mut n_end_hashes = 0;
735+
while self.first() == '#' && n_end_hashes < n_start_hashes {
736+
n_end_hashes += 1;
737+
self.bump();
738+
}
737739

738740
if n_end_hashes == n_start_hashes {
739741
return (n_start_hashes, None);
@@ -807,17 +809,9 @@ impl Cursor<'_> {
807809
}
808810

809811
/// Eats symbols while predicate returns true or until the end of file is reached.
810-
/// Returns amount of eaten symbols.
811-
fn eat_while<F>(&mut self, mut predicate: F) -> usize
812-
where
813-
F: FnMut(char) -> bool,
814-
{
815-
let mut eaten: usize = 0;
812+
fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) {
816813
while predicate(self.first()) && !self.is_eof() {
817-
eaten += 1;
818814
self.bump();
819815
}
820-
821-
eaten
822816
}
823817
}

compiler/rustc_middle/src/ty/trait_def.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,26 @@ impl<'tcx> TyCtxt<'tcx> {
123123
self_ty: Ty<'tcx>,
124124
mut f: F,
125125
) {
126+
let _: Option<()> = self.find_map_relevant_impl(def_id, self_ty, |did| {
127+
f(did);
128+
None
129+
});
130+
}
131+
132+
/// Applies function to every impl that could possibly match the self type `self_ty` and returns
133+
/// the first non-none value.
134+
pub fn find_map_relevant_impl<T, F: FnMut(DefId) -> Option<T>>(
135+
self,
136+
def_id: DefId,
137+
self_ty: Ty<'tcx>,
138+
mut f: F,
139+
) -> Option<T> {
126140
let impls = self.trait_impls_of(def_id);
127141

128142
for &impl_def_id in impls.blanket_impls.iter() {
129-
f(impl_def_id);
143+
if let result @ Some(_) = f(impl_def_id) {
144+
return result;
145+
}
130146
}
131147

132148
// simplify_type(.., false) basically replaces type parameters and
@@ -157,14 +173,20 @@ impl<'tcx> TyCtxt<'tcx> {
157173
if let Some(simp) = fast_reject::simplify_type(self, self_ty, true) {
158174
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
159175
for &impl_def_id in impls {
160-
f(impl_def_id);
176+
if let result @ Some(_) = f(impl_def_id) {
177+
return result;
178+
}
161179
}
162180
}
163181
} else {
164182
for &impl_def_id in impls.non_blanket_impls.values().flatten() {
165-
f(impl_def_id);
183+
if let result @ Some(_) = f(impl_def_id) {
184+
return result;
185+
}
166186
}
167187
}
188+
189+
None
168190
}
169191

170192
/// Returns an iterator containing all impls

compiler/rustc_middle/src/ty/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ impl<'tcx> TyCtxt<'tcx> {
346346
let drop_trait = self.lang_items().drop_trait()?;
347347
self.ensure().coherent_trait(drop_trait);
348348

349-
let mut dtor_did = None;
350349
let ty = self.type_of(adt_did);
351-
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
350+
let dtor_did = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
352351
if let Some(item) = self.associated_items(impl_did).in_definition_order().next() {
353352
if validate(self, impl_did).is_ok() {
354-
dtor_did = Some(item.def_id);
353+
return Some(item.def_id);
355354
}
356355
}
356+
None
357357
});
358358

359359
Some(ty::Destructor { did: dtor_did? })

compiler/rustc_mir/src/transform/check_const_item_mutation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
3434

3535
fn is_const_item_without_destructor(&self, local: Local) -> Option<DefId> {
3636
let def_id = self.is_const_item(local)?;
37-
let mut any_dtor = |_tcx, _def_id| Ok(());
3837

3938
// We avoid linting mutation of a const item if the const's type has a
4039
// Drop impl. The Drop logic observes the mutation which was performed.
@@ -54,7 +53,7 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
5453
//
5554
// #[const_mutation_allowed]
5655
// pub const LOG: Log = Log { msg: "" };
57-
match self.tcx.calculate_dtor(def_id, &mut any_dtor) {
56+
match self.tcx.calculate_dtor(def_id, &mut |_, _| Ok(())) {
5857
Some(_) => None,
5958
None => Some(def_id),
6059
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1384,17 +1384,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13841384
trait_ref: &ty::PolyTraitRef<'tcx>,
13851385
) {
13861386
let get_trait_impl = |trait_def_id| {
1387-
let mut trait_impl = None;
1388-
self.tcx.for_each_relevant_impl(
1387+
self.tcx.find_map_relevant_impl(
13891388
trait_def_id,
13901389
trait_ref.skip_binder().self_ty(),
1391-
|impl_def_id| {
1392-
if trait_impl.is_none() {
1393-
trait_impl = Some(impl_def_id);
1394-
}
1395-
},
1396-
);
1397-
trait_impl
1390+
|impl_def_id| Some(impl_def_id),
1391+
)
13981392
};
13991393
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
14001394
let all_traits = self.tcx.all_traits(LOCAL_CRATE);

config.toml.example

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# If it does not match the version that is currently running,
1414
# `x.py` will prompt you to update it and read the changelog.
1515
# See `src/bootstrap/CHANGELOG.md` for more information.
16-
changelog-seen = 1
16+
changelog-seen = 2
1717

1818
# =============================================================================
1919
# Global Settings
@@ -370,13 +370,13 @@ changelog-seen = 1
370370
# binary, otherwise they are omitted.
371371
#
372372
# Defaults to rust.debug value
373-
#debug-assertions = debug
373+
#debug-assertions = rust.debug (boolean)
374374

375375
# Whether or not debug assertions are enabled for the standard library.
376376
# Overrides the `debug-assertions` option, if defined.
377377
#
378378
# Defaults to rust.debug-assertions value
379-
#debug-assertions-std = debug-assertions
379+
#debug-assertions-std = rust.debug-assertions (boolean)
380380

381381
# Whether or not to leave debug! and trace! calls in the rust binary.
382382
# Overrides the `debug-assertions` option, if defined.
@@ -386,7 +386,7 @@ changelog-seen = 1
386386
# If you see a message from `tracing` saying
387387
# `max_level_info` is enabled and means logging won't be shown,
388388
# set this value to `true`.
389-
#debug-logging = debug-assertions
389+
#debug-logging = rust.debug-assertions (boolean)
390390

391391
# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
392392
# `0` - no debug info

library/alloc/src/alloc.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ mod tests;
1414

1515
extern "Rust" {
1616
// These are the magic symbols to call the global allocator. rustc generates
17-
// them from the `#[global_allocator]` attribute if there is one, or uses the
18-
// default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
17+
// them to call `__rg_alloc` etc if there is a `#[global_allocator]` attribute
18+
// (the code expanding that attribute macro generates those functions), or to call
19+
// the default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
1920
// otherwise.
2021
#[rustc_allocator]
2122
#[rustc_allocator_nounwind]
@@ -26,8 +27,6 @@ extern "Rust" {
2627
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
2728
#[rustc_allocator_nounwind]
2829
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
29-
#[rustc_allocator_nounwind]
30-
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
3130
}
3231

3332
/// The global memory allocator.
@@ -323,6 +322,16 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
323322
}
324323
}
325324

325+
// # Allocation error handler
326+
327+
extern "Rust" {
328+
// This is the magic symbol to call the global alloc error handler. rustc generates
329+
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
330+
// default implementations below (`__rdl_oom`) otherwise.
331+
#[rustc_allocator_nounwind]
332+
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
333+
}
334+
326335
/// Abort on memory allocation error or failure.
327336
///
328337
/// Callers of memory allocation APIs wishing to abort computation
@@ -367,7 +376,7 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
367376
#[doc(hidden)]
368377
#[allow(unused_attributes)]
369378
#[unstable(feature = "alloc_internals", issue = "none")]
370-
pub mod __default_lib_allocator {
379+
pub mod __alloc_error_handler {
371380
use crate::alloc::Layout;
372381

373382
// called via generated `__rust_alloc_error_handler`

library/alloc/src/vec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,8 @@ impl<T> Vec<T> {
14761476
/// `'a`. If the type has only static references, or none at all, then this
14771477
/// may be chosen to be `'static`.
14781478
///
1479-
/// This function is similar to the `leak` function on `Box`.
1479+
/// This function is similar to the [`leak`][Box::leak] function on [`Box`]
1480+
/// except that there is no way to recover the leaked memory.
14801481
///
14811482
/// This function is mainly useful for data that lives for the remainder of
14821483
/// the program's life. Dropping the returned reference will cause a memory

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
//! # Contributing changes to the documentation
8686
//!
8787
//! Check out the rust contribution guidelines [here](
88-
//! https://rustc-dev-guide.rust-lang.org/getting-started.html).
88+
//! https://rustc-dev-guide.rust-lang.org/contributing.html#writing-documentation).
8989
//! The source for this documentation can be found on
9090
//! [GitHub](https://github.com/rust-lang/rust).
9191
//! To contribute changes, make sure you read the guidelines first, then submit

library/std/src/os/linux/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait MetadataExt {
2020
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
2121
/// cross-Unix abstractions contained within the raw stat.
2222
///
23-
/// [`stat`]: crate::os::linux::raw::stat
23+
/// [`stat`]: struct@crate::os::linux::raw::stat
2424
///
2525
/// # Examples
2626
///

library/std/src/sys/windows/c.rs

-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub type LPWCH = *mut WCHAR;
4747
pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
4848
pub type LPWSADATA = *mut WSADATA;
4949
pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
50-
pub type LPSTR = *mut CHAR;
5150
pub type LPWSTR = *mut WCHAR;
5251
pub type LPFILETIME = *mut FILETIME;
5352
pub type LPWSABUF = *mut WSABUF;
@@ -876,16 +875,6 @@ extern "system" {
876875
pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
877876
pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
878877
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
879-
pub fn WideCharToMultiByte(
880-
CodePage: UINT,
881-
dwFlags: DWORD,
882-
lpWideCharStr: LPCWSTR,
883-
cchWideChar: c_int,
884-
lpMultiByteStr: LPSTR,
885-
cbMultiByte: c_int,
886-
lpDefaultChar: LPCSTR,
887-
lpUsedDefaultChar: LPBOOL,
888-
) -> c_int;
889878

890879
pub fn closesocket(socket: SOCKET) -> c_int;
891880
pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, flags: c_int) -> c_int;

library/std/src/sys/windows/mod.rs

-53
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::ffi::{OsStr, OsString};
44
use crate::io::ErrorKind;
55
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
66
use crate::path::PathBuf;
7-
use crate::ptr;
87
use crate::time::Duration;
98

109
pub use self::rand::hashmap_random_keys;
@@ -206,58 +205,6 @@ fn os2path(s: &[u16]) -> PathBuf {
206205
PathBuf::from(OsString::from_wide(s))
207206
}
208207

209-
#[allow(dead_code)] // Only used in backtrace::gnu::get_executable_filename()
210-
fn wide_char_to_multi_byte(
211-
code_page: u32,
212-
flags: u32,
213-
s: &[u16],
214-
no_default_char: bool,
215-
) -> crate::io::Result<Vec<i8>> {
216-
unsafe {
217-
let mut size = c::WideCharToMultiByte(
218-
code_page,
219-
flags,
220-
s.as_ptr(),
221-
s.len() as i32,
222-
ptr::null_mut(),
223-
0,
224-
ptr::null(),
225-
ptr::null_mut(),
226-
);
227-
if size == 0 {
228-
return Err(crate::io::Error::last_os_error());
229-
}
230-
231-
let mut buf = Vec::with_capacity(size as usize);
232-
buf.set_len(size as usize);
233-
234-
let mut used_default_char = c::FALSE;
235-
size = c::WideCharToMultiByte(
236-
code_page,
237-
flags,
238-
s.as_ptr(),
239-
s.len() as i32,
240-
buf.as_mut_ptr(),
241-
buf.len() as i32,
242-
ptr::null(),
243-
if no_default_char { &mut used_default_char } else { ptr::null_mut() },
244-
);
245-
if size == 0 {
246-
return Err(crate::io::Error::last_os_error());
247-
}
248-
if no_default_char && used_default_char == c::TRUE {
249-
return Err(crate::io::Error::new(
250-
crate::io::ErrorKind::InvalidData,
251-
"string cannot be converted to requested code page",
252-
));
253-
}
254-
255-
buf.set_len(size as usize);
256-
257-
Ok(buf)
258-
}
259-
}
260-
261208
pub fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
262209
match unrolled_find_u16s(0, v) {
263210
// don't include the 0

library/unwind/src/libunwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extern "C" {
8989
}
9090

9191
cfg_if::cfg_if! {
92-
if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] {
92+
if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm")))] {
9393
// Not ARM EHABI
9494
#[repr(C)]
9595
#[derive(Copy, Clone, PartialEq)]

0 commit comments

Comments
 (0)