Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e5e33eb

Browse files
committed
Auto merge of rust-lang#75421 - tmandry:rollup-ctzmzn1, r=tmandry
Rollup of 7 pull requests Successful merges: - rust-lang#75036 (Prefer pattern matching over indexing) - rust-lang#75378 (Introduce `rustc_lexer::is_ident` and use it in couple of places) - rust-lang#75393 (Fully handle "?" shortcut) - rust-lang#75403 (Update comment for function) - rust-lang#75407 (Requested changes to [*mut T|*const T]::set_ptr_value) - rust-lang#75408 (Update MinGW comments in ci.yml) - rust-lang#75409 (Fix range term in alloc vec doc) Failed merges: r? @ghost
2 parents cbe7c5c + 5d9a0b0 commit e5e33eb

File tree

15 files changed

+88
-57
lines changed

15 files changed

+88
-57
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,7 @@ dependencies = [
32573257
"rustc_data_structures",
32583258
"rustc_errors",
32593259
"rustc_feature",
3260+
"rustc_lexer",
32603261
"rustc_macros",
32613262
"rustc_serialize",
32623263
"rustc_session",

library/alloc/src/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ impl<T> Vec<T> {
22692269
/// with the given `replace_with` iterator and yields the removed items.
22702270
/// `replace_with` does not need to be the same length as `range`.
22712271
///
2272-
/// The element range is removed even if the iterator is not consumed until the end.
2272+
/// `range` is removed even if the iterator is not consumed until the end.
22732273
///
22742274
/// It is unspecified how many elements are removed from the vector
22752275
/// if the `Splice` value is leaked.

library/core/src/ptr/const_ptr.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ impl<T: ?Sized> *const T {
662662
/// will only affect the pointer part, whereas for (thin) pointers to
663663
/// sized types, this has the same effect as a simple assignment.
664664
///
665+
/// The resulting pointer will have provenance of `val`, i.e., for a fat
666+
/// pointer, this operation is semantically the same as creating a new
667+
/// fat pointer with the data pointer value of `val` but the metadata of
668+
/// `self`.
669+
///
665670
/// # Examples
666671
///
667672
/// This function is primarily useful for allowing byte-wise pointer
@@ -673,13 +678,17 @@ impl<T: ?Sized> *const T {
673678
/// let arr: [i32; 3] = [1, 2, 3];
674679
/// let mut ptr = &arr[0] as *const dyn Debug;
675680
/// let thin = ptr as *const u8;
676-
/// ptr = ptr.set_ptr_value(unsafe { thin.add(8).cast() });
677-
/// assert_eq!(unsafe { *(ptr as *const i32) }, 3);
681+
/// unsafe {
682+
/// ptr = ptr.set_ptr_value(thin.add(8));
683+
/// # assert_eq!(*(ptr as *const i32), 3);
684+
/// println!("{:?}", &*ptr); // will print "3"
685+
/// }
678686
/// ```
679687
#[unstable(feature = "set_ptr_value", issue = "75091")]
688+
#[must_use = "returns a new pointer rather than modifying its argument"]
680689
#[inline]
681-
pub fn set_ptr_value(mut self, val: *const ()) -> Self {
682-
let thin = &mut self as *mut *const T as *mut *const ();
690+
pub fn set_ptr_value(mut self, val: *const u8) -> Self {
691+
let thin = &mut self as *mut *const T as *mut *const u8;
683692
// SAFETY: In case of a thin pointer, this operations is identical
684693
// to a simple assignment. In case of a fat pointer, with the current
685694
// fat pointer layout implementation, the first field of such a

library/core/src/ptr/mut_ptr.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ impl<T: ?Sized> *mut T {
718718
/// will only affect the pointer part, whereas for (thin) pointers to
719719
/// sized types, this has the same effect as a simple assignment.
720720
///
721+
/// The resulting pointer will have provenance of `val`, i.e., for a fat
722+
/// pointer, this operation is semantically the same as creating a new
723+
/// fat pointer with the data pointer value of `val` but the metadata of
724+
/// `self`.
725+
///
721726
/// # Examples
722727
///
723728
/// This function is primarily useful for allowing byte-wise pointer
@@ -729,13 +734,17 @@ impl<T: ?Sized> *mut T {
729734
/// let mut arr: [i32; 3] = [1, 2, 3];
730735
/// let mut ptr = &mut arr[0] as *mut dyn Debug;
731736
/// let thin = ptr as *mut u8;
732-
/// ptr = ptr.set_ptr_value(unsafe { thin.add(8).cast() });
733-
/// assert_eq!(unsafe { *(ptr as *mut i32) }, 3);
737+
/// unsafe {
738+
/// ptr = ptr.set_ptr_value(thin.add(8));
739+
/// # assert_eq!(*(ptr as *mut i32), 3);
740+
/// println!("{:?}", &*ptr); // will print "3"
741+
/// }
734742
/// ```
735743
#[unstable(feature = "set_ptr_value", issue = "75091")]
744+
#[must_use = "returns a new pointer rather than modifying its argument"]
736745
#[inline]
737-
pub fn set_ptr_value(mut self, val: *mut ()) -> Self {
738-
let thin = &mut self as *mut *mut T as *mut *mut ();
746+
pub fn set_ptr_value(mut self, val: *mut u8) -> Self {
747+
let thin = &mut self as *mut *mut T as *mut *mut u8;
739748
// SAFETY: In case of a thin pointer, this operations is identical
740749
// to a simple assignment. In case of a fat pointer, with the current
741750
// fat pointer layout implementation, the first field of such a

library/std/src/net/ip.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,8 @@ impl Ipv4Addr {
767767
/// ```
768768
#[stable(feature = "rust1", since = "1.0.0")]
769769
pub fn to_ipv6_compatible(&self) -> Ipv6Addr {
770-
let octets = self.octets();
771-
Ipv6Addr::from([
772-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, octets[0], octets[1], octets[2], octets[3],
773-
])
770+
let [a, b, c, d] = self.octets();
771+
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d])
774772
}
775773

776774
/// Converts this address to an IPv4-mapped [IPv6 address].
@@ -789,10 +787,8 @@ impl Ipv4Addr {
789787
/// ```
790788
#[stable(feature = "rust1", since = "1.0.0")]
791789
pub fn to_ipv6_mapped(&self) -> Ipv6Addr {
792-
let octets = self.octets();
793-
Ipv6Addr::from([
794-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, octets[0], octets[1], octets[2], octets[3],
795-
])
790+
let [a, b, c, d] = self.octets();
791+
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, a, b, c, d])
796792
}
797793
}
798794

@@ -1498,11 +1494,12 @@ impl Ipv6Addr {
14981494
/// ```
14991495
#[stable(feature = "rust1", since = "1.0.0")]
15001496
pub fn to_ipv4(&self) -> Option<Ipv4Addr> {
1501-
match self.segments() {
1502-
[0, 0, 0, 0, 0, f, g, h] if f == 0 || f == 0xffff => {
1503-
Some(Ipv4Addr::new((g >> 8) as u8, g as u8, (h >> 8) as u8, h as u8))
1504-
}
1505-
_ => None,
1497+
if let [0, 0, 0, 0, 0, 0 | 0xffff, ab, cd] = self.segments() {
1498+
let [a, b] = ab.to_be_bytes();
1499+
let [c, d] = cd.to_be_bytes();
1500+
Some(Ipv4Addr::new(a, b, c, d))
1501+
} else {
1502+
None
15061503
}
15071504
}
15081505

src/ci/github-actions/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,17 @@ jobs:
490490

491491
# 32/64-bit MinGW builds.
492492
#
493-
# We are using MinGW with posix threads since LLVM does not compile with
494-
# the win32 threads version due to missing support for C++'s std::thread.
493+
# We are using MinGW with POSIX threads since LLVM requires
494+
# C++'s std::thread which is disabled in libstdc++ with win32 threads.
495+
# FIXME: Libc++ doesn't have this limitation so we can avoid
496+
# winpthreads if we switch to it.
495497
#
496-
# Instead of relying on the MinGW version installed on appveryor we download
497-
# and install one ourselves so we won't be surprised by changes to appveyor's
498+
# Instead of relying on the MinGW version installed on CI we download
499+
# and install one ourselves so we won't be surprised by changes to CI's
498500
# build image.
499501
#
500502
# Finally, note that the downloads below are all in the `rust-lang-ci` S3
501-
# bucket, but they cleraly didn't originate there! The downloads originally
503+
# bucket, but they clearly didn't originate there! The downloads originally
502504
# came from the mingw-w64 SourceForge download site. Unfortunately
503505
# SourceForge is notoriously flaky, so we mirror it on our own infrastructure.
504506

src/librustc_attr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_errors = { path = "../librustc_errors" }
1616
rustc_span = { path = "../librustc_span" }
1717
rustc_data_structures = { path = "../librustc_data_structures" }
1818
rustc_feature = { path = "../librustc_feature" }
19+
rustc_lexer = { path = "../librustc_lexer" }
1920
rustc_macros = { path = "../librustc_macros" }
2021
rustc_session = { path = "../librustc_session" }
2122
rustc_ast = { path = "../librustc_ast" }

src/librustc_attr/builtin.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum AttrError {
2020
MultipleItem(String),
2121
UnknownMetaItem(String, &'static [&'static str]),
2222
MissingSince,
23+
NonIdentFeature,
2324
MissingFeature,
2425
MultipleStabilityLevels,
2526
UnsupportedLiteral(&'static str, /* is_bytestr */ bool),
@@ -40,6 +41,9 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
4041
AttrError::MissingSince => {
4142
struct_span_err!(diag, span, E0542, "missing 'since'").emit();
4243
}
44+
AttrError::NonIdentFeature => {
45+
struct_span_err!(diag, span, E0546, "'feature' is not an identifier").emit();
46+
}
4347
AttrError::MissingFeature => {
4448
struct_span_err!(diag, span, E0546, "missing 'feature'").emit();
4549
}
@@ -344,6 +348,14 @@ where
344348

345349
match (feature, reason, issue) {
346350
(Some(feature), reason, Some(_)) => {
351+
if !rustc_lexer::is_ident(&feature.as_str()) {
352+
handle_errors(
353+
&sess.parse_sess,
354+
attr.span,
355+
AttrError::NonIdentFeature,
356+
);
357+
continue;
358+
}
347359
let level = Unstable { reason, issue: issue_num, is_soft };
348360
if sym::unstable == meta_name {
349361
stab = Some(Stability { level, feature });

src/librustc_expand/proc_macro_server.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,10 @@ pub struct Ident {
319319
}
320320

321321
impl Ident {
322-
fn is_valid(string: &str) -> bool {
323-
let mut chars = string.chars();
324-
if let Some(start) = chars.next() {
325-
rustc_lexer::is_id_start(start) && chars.all(rustc_lexer::is_id_continue)
326-
} else {
327-
false
328-
}
329-
}
330322
fn new(sess: &ParseSess, sym: Symbol, is_raw: bool, span: Span) -> Ident {
331323
let sym = nfc_normalize(&sym.as_str());
332324
let string = sym.as_str();
333-
if !Self::is_valid(&string) {
325+
if !rustc_lexer::is_ident(&string) {
334326
panic!("`{:?}` is not a valid identifier", string)
335327
}
336328
if is_raw && !sym.can_be_raw() {

src/librustc_lexer/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,16 @@ pub fn is_id_continue(c: char) -> bool {
274274
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
275275
}
276276

277+
/// The passed string is lexically an identifier.
278+
pub fn is_ident(string: &str) -> bool {
279+
let mut chars = string.chars();
280+
if let Some(start) = chars.next() {
281+
is_id_start(start) && chars.all(is_id_continue)
282+
} else {
283+
false
284+
}
285+
}
286+
277287
impl Cursor<'_> {
278288
/// Parses a token from the input string.
279289
fn advance_token(&mut self) -> Token {

0 commit comments

Comments
 (0)