Skip to content

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

+1
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

+1-1
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

+13-4
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

+13-4
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

+10-13
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

+7-5
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

+1
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

+12
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

+1-9
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

+10
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 {

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn new_lint_store(no_interleave_lints: bool, internal_lints: bool) -> LintSt
219219

220220
/// Tell the `LintStore` about all the built-in lints (the ones
221221
/// defined in this crate and the ones defined in
222-
/// `rustc::lint::builtin`).
222+
/// `rustc_session::lint::builtin`).
223223
fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
224224
macro_rules! add_lint_group {
225225
($name:expr, $($lint:ident),*) => (

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ impl Clean<Stability> for attr::Stability {
23582358
fn clean(&self, _: &DocContext<'_>) -> Stability {
23592359
Stability {
23602360
level: stability::StabilityLevel::from_attr_level(&self.level),
2361-
feature: Some(self.feature.to_string()).filter(|f| !f.is_empty()),
2361+
feature: self.feature.to_string(),
23622362
since: match self.level {
23632363
attr::Stable { ref since } => since.to_string(),
23642364
_ => String::new(),

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ pub struct ProcMacro {
15251525
#[derive(Clone, Debug)]
15261526
pub struct Stability {
15271527
pub level: stability::StabilityLevel,
1528-
pub feature: Option<String>,
1528+
pub feature: String,
15291529
pub since: String,
15301530
pub unstable_reason: Option<String>,
15311531
pub issue: Option<NonZeroU32>,

src/librustdoc/html/render/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ fn stability_tags(item: &clean::Item) -> String {
21442144
if item
21452145
.stability
21462146
.as_ref()
2147-
.map(|s| s.level == stability::Unstable && s.feature.as_deref() != Some("rustc_private"))
2147+
.map(|s| s.level == stability::Unstable && s.feature != "rustc_private")
21482148
== Some(true)
21492149
{
21502150
tags += &tag_html("unstable", "Experimental");
@@ -2195,25 +2195,25 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
21952195

21962196
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
21972197
// Those crates are permanently unstable so it makes no sense to render "unstable" everywhere.
2198-
if let Some(stab) = item.stability.as_ref().filter(|stab| {
2199-
stab.level == stability::Unstable && stab.feature.as_deref() != Some("rustc_private")
2200-
}) {
2198+
if let Some(stab) = item
2199+
.stability
2200+
.as_ref()
2201+
.filter(|stab| stab.level == stability::Unstable && stab.feature != "rustc_private")
2202+
{
22012203
let mut message =
22022204
"<span class='emoji'>🔬</span> This is a nightly-only experimental API.".to_owned();
22032205

2204-
if let Some(feature) = stab.feature.as_deref() {
2205-
let mut feature = format!("<code>{}</code>", Escape(&feature));
2206-
if let (Some(url), Some(issue)) = (&cx.shared.issue_tracker_base_url, stab.issue) {
2207-
feature.push_str(&format!(
2208-
"&nbsp;<a href=\"{url}{issue}\">#{issue}</a>",
2209-
url = url,
2210-
issue = issue
2211-
));
2212-
}
2213-
2214-
message.push_str(&format!(" ({})", feature));
2206+
let mut feature = format!("<code>{}</code>", Escape(&stab.feature));
2207+
if let (Some(url), Some(issue)) = (&cx.shared.issue_tracker_base_url, stab.issue) {
2208+
feature.push_str(&format!(
2209+
"&nbsp;<a href=\"{url}{issue}\">#{issue}</a>",
2210+
url = url,
2211+
issue = issue
2212+
));
22152213
}
22162214

2215+
message.push_str(&format!(" ({})", feature));
2216+
22172217
if let Some(unstable_reason) = &stab.unstable_reason {
22182218
let mut ids = cx.id_map.borrow_mut();
22192219
message = format!(

src/librustdoc/html/static/main.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ function defocusSearchBar() {
408408
break;
409409

410410
case "?":
411-
if (ev.shiftKey) {
412-
displayHelp(true, ev);
413-
}
411+
displayHelp(true, ev);
414412
break;
415413
}
416414
}

0 commit comments

Comments
 (0)