From c99224536152cff14639b64a3fa4f7a215fd037c Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sat, 9 Aug 2025 23:52:11 +0100 Subject: [PATCH 01/17] refactor: Include table sizes in comment at top of `unicode_data.rs` To make changes in table size obvious from git diffs --- library/core/src/unicode/unicode_data.rs | 10 ++++++++++ src/tools/unicode-table-generator/src/main.rs | 20 +++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index b57234bbee9a2..6059f7d6450b1 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -1,4 +1,14 @@ ///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually! +// Alphabetic : 1727 bytes, 142759 codepoints in 757 ranges (U+000041 - U+0323B0) using skiplist +// Case_Ignorable : 1053 bytes, 2749 codepoints in 452 ranges (U+000027 - U+0E01F0) using skiplist +// Cased : 407 bytes, 4578 codepoints in 159 ranges (U+000041 - U+01F18A) using skiplist +// Cc : 9 bytes, 65 codepoints in 2 ranges (U+000000 - U+0000A0) using skiplist +// Grapheme_Extend : 887 bytes, 2193 codepoints in 375 ranges (U+000300 - U+0E01F0) using skiplist +// Lowercase : 935 bytes, 2569 codepoints in 675 ranges (U+000061 - U+01E944) using bitset +// N : 457 bytes, 1911 codepoints in 144 ranges (U+000030 - U+01FBFA) using skiplist +// Uppercase : 799 bytes, 1978 codepoints in 656 ranges (U+000041 - U+01F18A) using bitset +// White_Space : 256 bytes, 25 codepoints in 10 ranges (U+000009 - U+003001) using cascading +// Total : 6530 bytes #[inline(always)] const fn bitset_search< diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index 6cdb82a87bdff..c1017142097f0 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -239,6 +239,11 @@ fn main() { std::fs::write(&path, generate_tests(&write_location, ranges_by_property)).unwrap(); } + let mut table_file = String::new(); + table_file.push_str( + "///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually!\n", + ); + let mut total_bytes = 0; let mut modules = Vec::new(); for (property, ranges) in ranges_by_property { @@ -252,8 +257,8 @@ fn main() { } modules.push((property.to_lowercase().to_string(), emitter.file)); - println!( - "{:15}: {} bytes, {} codepoints in {} ranges ({} - {}) using {}", + table_file.push_str(&format!( + "// {:16}: {:5} bytes, {:6} codepoints in {:3} ranges (U+{:06X} - U+{:06X}) using {}\n", property, emitter.bytes_used, datapoints, @@ -261,15 +266,10 @@ fn main() { ranges.first().unwrap().start, ranges.last().unwrap().end, emitter.desc, - ); + )); total_bytes += emitter.bytes_used; } - - let mut table_file = String::new(); - - table_file.push_str( - "///! This file is generated by `./x run src/tools/unicode-table-generator`; do not edit manually!\n", - ); + table_file.push_str(&format!("// {:16}: {:5} bytes\n", "Total", total_bytes)); // Include the range search function table_file.push('\n'); @@ -296,8 +296,6 @@ fn main() { } std::fs::write(&write_location, format!("{}\n", table_file.trim_end())).unwrap(); - - println!("Total table sizes: {total_bytes} bytes"); } fn version() -> String { From 69e1974bb0bfbcc679d29950b1e4540cd0b9b3ee Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sun, 10 Aug 2025 00:18:04 +0100 Subject: [PATCH 02/17] refactor: Include size of case conversion tables Include the sizes of the `to_lowercase` and `to_uppercase` tables in the total size calculations. --- library/core/src/unicode/unicode_data.rs | 12 +++--- .../src/case_mapping.rs | 41 +++++++++++++------ src/tools/unicode-table-generator/src/main.rs | 7 +++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index 6059f7d6450b1..787efcc091454 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -8,7 +8,9 @@ // N : 457 bytes, 1911 codepoints in 144 ranges (U+000030 - U+01FBFA) using skiplist // Uppercase : 799 bytes, 1978 codepoints in 656 ranges (U+000041 - U+01F18A) using bitset // White_Space : 256 bytes, 25 codepoints in 10 ranges (U+000009 - U+003001) using cascading -// Total : 6530 bytes +// to_lower : 11484 bytes +// to_upper : 13432 bytes +// Total : 31446 bytes #[inline(always)] const fn bitset_search< @@ -782,7 +784,7 @@ pub mod conversions { } } - static LOWERCASE_TABLE: &[(char, u32)] = &[ + static LOWERCASE_TABLE: &[(char, u32); 1434] = &[ ('\u{c0}', 224), ('\u{c1}', 225), ('\u{c2}', 226), ('\u{c3}', 227), ('\u{c4}', 228), ('\u{c5}', 229), ('\u{c6}', 230), ('\u{c7}', 231), ('\u{c8}', 232), ('\u{c9}', 233), ('\u{ca}', 234), ('\u{cb}', 235), ('\u{cc}', 236), ('\u{cd}', 237), ('\u{ce}', 238), @@ -1132,11 +1134,11 @@ pub mod conversions { ('\u{1e921}', 125251), ]; - static LOWERCASE_TABLE_MULTI: &[[char; 3]] = &[ + static LOWERCASE_TABLE_MULTI: &[[char; 3]; 1] = &[ ['i', '\u{307}', '\u{0}'], ]; - static UPPERCASE_TABLE: &[(char, u32)] = &[ + static UPPERCASE_TABLE: &[(char, u32); 1526] = &[ ('\u{b5}', 924), ('\u{df}', 4194304), ('\u{e0}', 192), ('\u{e1}', 193), ('\u{e2}', 194), ('\u{e3}', 195), ('\u{e4}', 196), ('\u{e5}', 197), ('\u{e6}', 198), ('\u{e7}', 199), ('\u{e8}', 200), ('\u{e9}', 201), ('\u{ea}', 202), ('\u{eb}', 203), ('\u{ec}', 204), @@ -1509,7 +1511,7 @@ pub mod conversions { ('\u{1e941}', 125215), ('\u{1e942}', 125216), ('\u{1e943}', 125217), ]; - static UPPERCASE_TABLE_MULTI: &[[char; 3]] = &[ + static UPPERCASE_TABLE_MULTI: &[[char; 3]; 102] = &[ ['S', 'S', '\u{0}'], ['\u{2bc}', 'N', '\u{0}'], ['J', '\u{30c}', '\u{0}'], ['\u{399}', '\u{308}', '\u{301}'], ['\u{3a5}', '\u{308}', '\u{301}'], ['\u{535}', '\u{552}', '\u{0}'], ['H', '\u{331}', '\u{0}'], ['T', '\u{308}', '\u{0}'], diff --git a/src/tools/unicode-table-generator/src/case_mapping.rs b/src/tools/unicode-table-generator/src/case_mapping.rs index 9c6454492e7e0..a8527ea9a429a 100644 --- a/src/tools/unicode-table-generator/src/case_mapping.rs +++ b/src/tools/unicode-table-generator/src/case_mapping.rs @@ -6,20 +6,22 @@ use crate::{UnicodeData, fmt_list}; const INDEX_MASK: u32 = 1 << 22; -pub(crate) fn generate_case_mapping(data: &UnicodeData) -> String { +pub(crate) fn generate_case_mapping(data: &UnicodeData) -> (String, [usize; 2]) { let mut file = String::new(); write!(file, "const INDEX_MASK: u32 = 0x{INDEX_MASK:x};").unwrap(); file.push_str("\n\n"); file.push_str(HEADER.trim_start()); file.push('\n'); - file.push_str(&generate_tables("LOWER", &data.to_lower)); + let (lower_tables, lower_size) = generate_tables("LOWER", &data.to_lower); + file.push_str(&lower_tables); file.push_str("\n\n"); - file.push_str(&generate_tables("UPPER", &data.to_upper)); - file + let (upper_tables, upper_size) = generate_tables("UPPER", &data.to_upper); + file.push_str(&upper_tables); + (file, [lower_size, upper_size]) } -fn generate_tables(case: &str, data: &BTreeMap) -> String { +fn generate_tables(case: &str, data: &BTreeMap) -> (String, usize) { let mut mappings = Vec::with_capacity(data.len()); let mut multis = Vec::new(); @@ -46,16 +48,31 @@ fn generate_tables(case: &str, data: &BTreeMap) -> String } let mut tables = String::new(); - - write!(tables, "static {}CASE_TABLE: &[(char, u32)] = &[{}];", case, fmt_list(mappings)) - .unwrap(); + let mut size = 0; + + size += size_of_val(mappings.as_slice()); + write!( + tables, + "static {}CASE_TABLE: &[(char, u32); {}] = &[{}];", + case, + mappings.len(), + fmt_list(mappings), + ) + .unwrap(); tables.push_str("\n\n"); - write!(tables, "static {}CASE_TABLE_MULTI: &[[char; 3]] = &[{}];", case, fmt_list(multis)) - .unwrap(); - - tables + size += size_of_val(multis.as_slice()); + write!( + tables, + "static {}CASE_TABLE_MULTI: &[[char; 3]; {}] = &[{}];", + case, + multis.len(), + fmt_list(multis), + ) + .unwrap(); + + (tables, size) } struct CharEscape(char); diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index c1017142097f0..f755ad048e4a4 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -269,6 +269,11 @@ fn main() { )); total_bytes += emitter.bytes_used; } + let (conversions, sizes) = case_mapping::generate_case_mapping(&unicode_data); + for (name, size) in ["to_lower", "to_upper"].iter().zip(sizes) { + table_file.push_str(&format!("// {:16}: {:5} bytes\n", name, size)); + total_bytes += size; + } table_file.push_str(&format!("// {:16}: {:5} bytes\n", "Total", total_bytes)); // Include the range search function @@ -280,7 +285,7 @@ fn main() { table_file.push('\n'); - modules.push((String::from("conversions"), case_mapping::generate_case_mapping(&unicode_data))); + modules.push((String::from("conversions"), conversions)); for (name, contents) in modules { table_file.push_str("#[rustfmt::skip]\n"); From 5d54ac5276eade9d9424fc4fbfa6f77bcd5d4940 Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sun, 10 Aug 2025 01:10:15 +0100 Subject: [PATCH 03/17] refactor: rewrite `ranges_from_set` The `merge_ranges` function was very complicated and hard to understand. Forunately, we can use `slice::chunk_by` to achieve the same thing. --- src/tools/unicode-table-generator/src/main.rs | 83 ++++--------------- 1 file changed, 17 insertions(+), 66 deletions(-) diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index f755ad048e4a4..bf0511a2c77ef 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -187,33 +187,19 @@ fn load_data() -> UnicodeData { } } - let mut properties: HashMap<&'static str, Vec>> = properties + let mut properties: Vec<(&'static str, Vec>)> = properties .into_iter() - .map(|(k, v)| { - ( - k, - v.into_iter() - .flat_map(|codepoints| match codepoints { - Codepoints::Single(c) => c - .scalar() - .map(|ch| ch as u32..ch as u32 + 1) - .into_iter() - .collect::>(), - Codepoints::Range(c) => c - .into_iter() - .flat_map(|c| c.scalar().map(|ch| ch as u32..ch as u32 + 1)) - .collect::>(), - }) - .collect::>>(), - ) + .map(|(prop, codepoints)| { + let codepoints = codepoints + .into_iter() + .flatten() + .flat_map(|cp| cp.scalar()) + .map(u32::from) + .collect::>(); + (prop, ranges_from_set(&codepoints)) }) .collect(); - for ranges in properties.values_mut() { - merge_ranges(ranges); - } - - let mut properties = properties.into_iter().collect::>(); properties.sort_by_key(|p| p.0); UnicodeData { ranges: properties, to_lower, to_upper } } @@ -402,48 +388,13 @@ fn generate_asserts(s: &mut String, property: &str, points: &[u32], truthy: bool } } +/// Group the elements of `set` into contigous ranges fn ranges_from_set(set: &[u32]) -> Vec> { - let mut ranges = set.iter().map(|e| (*e)..(*e + 1)).collect::>>(); - merge_ranges(&mut ranges); - ranges -} - -fn merge_ranges(ranges: &mut Vec>) { - loop { - let mut new_ranges = Vec::new(); - let mut idx_iter = 0..(ranges.len() - 1); - let mut should_insert_last = true; - while let Some(idx) = idx_iter.next() { - let cur = ranges[idx].clone(); - let next = ranges[idx + 1].clone(); - if cur.end == next.start { - if idx_iter.next().is_none() { - // We're merging the last element - should_insert_last = false; - } - new_ranges.push(cur.start..next.end); - } else { - // We're *not* merging the last element - should_insert_last = true; - new_ranges.push(cur); - } - } - if should_insert_last { - new_ranges.push(ranges.last().unwrap().clone()); - } - if new_ranges.len() == ranges.len() { - *ranges = new_ranges; - break; - } else { - *ranges = new_ranges; - } - } - - let mut last_end = None; - for range in ranges { - if let Some(last) = last_end { - assert!(range.start > last, "{range:?}"); - } - last_end = Some(range.end); - } + set.chunk_by(|a, b| a + 1 == *b) + .map(|chunk| { + let start = *chunk.first().unwrap(); + let end = *chunk.last().unwrap(); + start..(end + 1) + }) + .collect() } From 30d1bc7ba869c0f86bc6d2e1d9ed1ad3b58f7865 Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sun, 10 Aug 2025 01:46:00 +0100 Subject: [PATCH 04/17] refactor: `generate_tests` Rewrite `generate_tests` to be more idiomatic. --- src/tools/unicode-table-generator/src/main.rs | 97 +++++++++---------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index bf0511a2c77ef..c9530fec48a00 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -72,6 +72,8 @@ //! or not. use std::collections::{BTreeMap, HashMap}; +use std::fmt; +use std::fmt::Write; use std::ops::Range; use ucd_parse::Codepoints; @@ -222,7 +224,7 @@ fn main() { let ranges_by_property = &unicode_data.ranges; if let Some(path) = test_path { - std::fs::write(&path, generate_tests(&write_location, ranges_by_property)).unwrap(); + std::fs::write(&path, generate_tests(ranges_by_property).unwrap()).unwrap(); } let mut table_file = String::new(); @@ -326,66 +328,57 @@ fn fmt_list(values: impl IntoIterator) -> String { out } -fn generate_tests(data_path: &str, ranges: &[(&str, Vec>)]) -> String { +fn generate_tests(ranges: &[(&str, Vec>)]) -> Result { let mut s = String::new(); - s.push_str("#![allow(incomplete_features, unused)]\n"); - s.push_str("#![feature(const_generics)]\n\n"); - s.push_str("\n#[allow(unused)]\nuse std::hint;\n"); - s.push_str(&format!("#[path = \"{data_path}\"]\n")); - s.push_str("mod unicode_data;\n\n"); - - s.push_str("\nfn main() {\n"); - + writeln!(s, "#![feature(core_intrinsics)]")?; + writeln!(s, "#![allow(internal_features, dead_code)]")?; + writeln!(s, "// ignore-tidy-filelength")?; + writeln!(s, "use std::intrinsics;")?; + writeln!(s, "mod unicode_data;")?; + writeln!(s, "fn main() {{")?; for (property, ranges) in ranges { - s.push_str(&format!(r#" println!("Testing {property}");"#)); - s.push('\n'); - s.push_str(&format!(" {}_true();\n", property.to_lowercase())); - s.push_str(&format!(" {}_false();\n", property.to_lowercase())); - let mut is_true = Vec::new(); - let mut is_false = Vec::new(); - for ch_num in 0..(std::char::MAX as u32) { - if std::char::from_u32(ch_num).is_none() { - continue; - } - if ranges.iter().any(|r| r.contains(&ch_num)) { - is_true.push(ch_num); - } else { - is_false.push(ch_num); - } - } - - s.push_str(&format!(" fn {}_true() {{\n", property.to_lowercase())); - generate_asserts(&mut s, property, &is_true, true); - s.push_str(" }\n\n"); - s.push_str(&format!(" fn {}_false() {{\n", property.to_lowercase())); - generate_asserts(&mut s, property, &is_false, false); - s.push_str(" }\n\n"); + let prop = property.to_lowercase(); + writeln!(s, r#" println!("Testing {prop}");"#)?; + writeln!(s, " {prop}_true();")?; + writeln!(s, " {prop}_false();")?; + let (is_true, is_false): (Vec<_>, Vec<_>) = (char::MIN..=char::MAX) + .filter(|c| !c.is_ascii()) + .map(u32::from) + .partition(|c| ranges.iter().any(|r| r.contains(c))); + + writeln!(s, " fn {prop}_true() {{")?; + generate_asserts(&mut s, &prop, &is_true, true)?; + writeln!(s, " }}")?; + + writeln!(s, " fn {prop}_false() {{")?; + generate_asserts(&mut s, &prop, &is_false, false)?; + writeln!(s, " }}")?; } - s.push('}'); - s + writeln!(s, "}}")?; + Ok(s) } -fn generate_asserts(s: &mut String, property: &str, points: &[u32], truthy: bool) { +fn generate_asserts( + s: &mut String, + prop: &str, + points: &[u32], + truthy: bool, +) -> Result<(), fmt::Error> { + let truthy = if truthy { "" } else { "!" }; for range in ranges_from_set(points) { - if range.end == range.start + 1 { - s.push_str(&format!( - " assert!({}unicode_data::{}::lookup({:?}), \"{}\");\n", - if truthy { "" } else { "!" }, - property.to_lowercase(), - std::char::from_u32(range.start).unwrap(), - range.start, - )); - } else { - s.push_str(&format!(" for chn in {range:?}u32 {{\n")); - s.push_str(&format!( - " assert!({}unicode_data::{}::lookup(std::char::from_u32(chn).unwrap()), \"{{:?}}\", chn);\n", - if truthy { "" } else { "!" }, - property.to_lowercase(), - )); - s.push_str(" }\n"); + let start = char::from_u32(range.start).unwrap(); + let end = char::from_u32(range.end - 1).unwrap(); + match range.len() { + 1 => writeln!(s, " assert!({truthy}unicode_data::{prop}::lookup({start:?}));")?, + _ => { + writeln!(s, " for c in {start:?}..={end:?} {{")?; + writeln!(s, " assert!({truthy}unicode_data::{prop}::lookup(c));")?; + writeln!(s, " }}")?; + } } } + Ok(()) } /// Group the elements of `set` into contigous ranges From c3ce0796544152460554d8b8db4e56528fe362db Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Sun, 10 Aug 2025 02:13:03 +0100 Subject: [PATCH 05/17] refactor: Add tests for case conversions --- .../src/case_mapping.rs | 4 +- src/tools/unicode-table-generator/src/main.rs | 48 +++++++++++++++---- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/tools/unicode-table-generator/src/case_mapping.rs b/src/tools/unicode-table-generator/src/case_mapping.rs index a8527ea9a429a..49aef3ec33ec7 100644 --- a/src/tools/unicode-table-generator/src/case_mapping.rs +++ b/src/tools/unicode-table-generator/src/case_mapping.rs @@ -21,11 +21,11 @@ pub(crate) fn generate_case_mapping(data: &UnicodeData) -> (String, [usize; 2]) (file, [lower_size, upper_size]) } -fn generate_tables(case: &str, data: &BTreeMap) -> (String, usize) { +fn generate_tables(case: &str, data: &BTreeMap) -> (String, usize) { let mut mappings = Vec::with_capacity(data.len()); let mut multis = Vec::new(); - for (&key, &(a, b, c)) in data.iter() { + for (&key, &[a, b, c]) in data.iter() { let key = char::from_u32(key).unwrap(); if key.is_ascii() { diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index c9530fec48a00..1d70eebdbc6c2 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -100,11 +100,11 @@ static PROPERTIES: &[&str] = &[ struct UnicodeData { ranges: Vec<(&'static str, Vec>)>, - to_upper: BTreeMap, - to_lower: BTreeMap, + to_upper: BTreeMap, + to_lower: BTreeMap, } -fn to_mapping(origin: u32, codepoints: Vec) -> Option<(u32, u32, u32)> { +fn to_mapping(origin: u32, codepoints: Vec) -> Option<[u32; 3]> { let mut a = None; let mut b = None; let mut c = None; @@ -125,7 +125,7 @@ fn to_mapping(origin: u32, codepoints: Vec) -> Option<(u32 } } - Some((a.unwrap(), b.unwrap_or(0), c.unwrap_or(0))) + Some([a.unwrap(), b.unwrap_or(0), c.unwrap_or(0)]) } static UNICODE_DIRECTORY: &str = "unicode-downloads"; @@ -165,12 +165,12 @@ fn load_data() -> UnicodeData { if let Some(mapped) = row.simple_lowercase_mapping && mapped != row.codepoint { - to_lower.insert(row.codepoint.value(), (mapped.value(), 0, 0)); + to_lower.insert(row.codepoint.value(), [mapped.value(), 0, 0]); } if let Some(mapped) = row.simple_uppercase_mapping && mapped != row.codepoint { - to_upper.insert(row.codepoint.value(), (mapped.value(), 0, 0)); + to_upper.insert(row.codepoint.value(), [mapped.value(), 0, 0]); } } @@ -224,7 +224,7 @@ fn main() { let ranges_by_property = &unicode_data.ranges; if let Some(path) = test_path { - std::fs::write(&path, generate_tests(ranges_by_property).unwrap()).unwrap(); + std::fs::write(&path, generate_tests(&unicode_data).unwrap()).unwrap(); } let mut table_file = String::new(); @@ -328,7 +328,7 @@ fn fmt_list(values: impl IntoIterator) -> String { out } -fn generate_tests(ranges: &[(&str, Vec>)]) -> Result { +fn generate_tests(data: &UnicodeData) -> Result { let mut s = String::new(); writeln!(s, "#![feature(core_intrinsics)]")?; writeln!(s, "#![allow(internal_features, dead_code)]")?; @@ -336,7 +336,7 @@ fn generate_tests(ranges: &[(&str, Vec>)]) -> Result>)]) -> Result = (char::MIN..=char::MAX) + .filter(|c| !c.is_ascii()) + .map(u32::from) + .filter(|c| !conversion.contains_key(c)) + .collect(); + let unmapped_ranges = ranges_from_set(&unmapped); + for range in unmapped_ranges { + let start = char::from_u32(range.start).unwrap(); + let end = char::from_u32(range.end - 1).unwrap(); + writeln!(s, " for c in {start:?}..={end:?} {{")?; + writeln!( + s, + r#" assert_eq!(unicode_data::conversions::{name}(c), [c, '\0', '\0']);"# + )?; + + writeln!(s, " }}")?; + } + } + writeln!(s, "}}")?; Ok(s) } From 3b627b5a4909bf17ab55ceeb0b31e70280b49189 Mon Sep 17 00:00:00 2001 From: binarycat Date: Sun, 24 Aug 2025 10:37:19 -0500 Subject: [PATCH 06/17] editorconfig: don't use nonexistant syntax reading through the editorconfig spec, using `!` to negate an entire glob is simply not a feature. you can use `!` to negate a charachter class, but that's not what was going on here. --- .editorconfig | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index 1b137cf4ebefd..6c8560aa1f543 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,10 +8,13 @@ root = true end_of_line = lf charset = utf-8 insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 # some tests need trailing whitespace in output snapshots -[!tests/] -trim_trailing_whitespace = true +[tests/**] +trim_trailing_whitespace = false # for actual source code files of test, we still don't want trailing whitespace [tests/**.{rs,js}] trim_trailing_whitespace = true @@ -19,9 +22,9 @@ trim_trailing_whitespace = true [tests/ui/{frontmatter/frontmatter-whitespace-3.rs,parser/shebang/shebang-space.rs}] trim_trailing_whitespace = false -[!src/llvm-project] -indent_style = space -indent_size = 4 +[src/llvm-project] +indent_style = unset +indent_size = unset [*.rs] max_line_length = 100 From aa27cca79e7888deff3bafed84ea16a5a89cb7c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 26 Aug 2025 11:34:12 -0700 Subject: [PATCH 07/17] Add a sanity check to bootstrap for wasm-component-ld For `wasm32-wasip2`-and-beyond this tool is required, so in case it's disabled in `config.toml` add a sanity-check that it's present in the environment. --- src/bootstrap/src/core/sanity.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 099ec4883972f..04cf63f1c6d44 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -397,6 +397,16 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake ); } } + + // For testing `wasm32-wasip2`-and-beyond it's required to have + // `wasm-component-ld`. This is enabled by default via `tool_enabled` + // but if it's disabled then double-check it's present on the system. + if target.contains("wasip") + && !target.contains("wasip1") + && !build.tool_enabled("wasm-component-ld") + { + cmd_finder.must_have("wasm-component-ld"); + } } if let Some(ref s) = build.config.ccache { From 5d81f033a5ab2fce07898a22ad8c607380812cf7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 26 Aug 2025 13:53:11 -0700 Subject: [PATCH 08/17] std: Start supporting WASIp2 natively This commit is the start of an effort to support WASIp2 natively in the standard library. Before this commit the `wasm32-wasip2` target behaved exactly like `wasm32-wasip1` target by importing APIs from the core wasm module `wasi_snapshot_preview1`. These APIs are satisfied by the `wasm-component-ld` target by using an [adapter] which implements WASIp1 in terms of WASIp2. This adapter comes at a cost, however, in terms of runtime indirection and instantiation cost, so ideally the adapter would be removed entirely. The purpose of this adapter was to provide a smoother on-ramp from WASIp1 to WASIp2 when it was originally created. The `wasm32-wasip2` target has been around for long enough now that it's much more established. Additionally the only thing historically blocking using WASIp2 directly was implementation effort. Work is now underway to migrate wasi-libc itself to using WASIp2 directly and now seems as good a time as any to migrate the Rust standard library too. Implementation-wise the milestones here are: * The `wasm32-wasip2` target now also depends on the `wasi` crate at version 0.14.* in addition to the preexisting dependency of 0.11.*. The 0.14.* release series binds WASIp2 APIs instead of WASIp1 APIs. * Some preexisting naming around `mod wasi` or `wasi.rs` was renamed to `wasip1` where appropriate. For example `std::sys::pal::wasi` is now called `std::sys::pal::wasip1`. * More platform-specific WASI modules are now split between WASIp1 and WASIp2. For example getting the current time, randomness, and process arguments now use WASIp2 APIs directly instead of using WASIp1 APIs that require an adapter. It's worth pointing out that this PR does not migrate the entire standard library away from using WASIp1 APIs on the `wasm32-wasip2` target. Everything related to file descriptors and filesystem APIs is still using WASIp1. Migrating that is left for a future PR. In the meantime the goal of this change is to lay the groundwork necessary for migrating in the future. Eventually the goal is to drop the `wasi` 0.11.* dependency on the `wasm32-wasip2` target (the `wasm32-wasip1` target will continue to retain this dependency). [adapter]: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-preview1-component-adapter/README.md --- library/Cargo.lock | 24 +++++- library/std/Cargo.toml | 5 ++ library/std/src/sys/args/mod.rs | 10 ++- .../std/src/sys/args/{wasi.rs => wasip1.rs} | 0 library/std/src/sys/args/wasip2.rs | 6 ++ library/std/src/sys/pal/mod.rs | 6 +- .../src/sys/pal/{wasi => wasip1}/helpers.rs | 0 .../std/src/sys/pal/{wasi => wasip1}/mod.rs | 0 .../std/src/sys/pal/{wasi => wasip1}/os.rs | 0 .../src/sys/pal/{wasi => wasip1}/thread.rs | 0 .../std/src/sys/pal/{wasi => wasip1}/time.rs | 0 library/std/src/sys/pal/wasip2/mod.rs | 6 +- library/std/src/sys/pal/wasip2/thread.rs | 73 +++++++++++++++++++ library/std/src/sys/pal/wasip2/time.rs | 69 ++++++++++++++++++ library/std/src/sys/random/mod.rs | 11 ++- .../std/src/sys/random/{wasi.rs => wasip1.rs} | 0 library/std/src/sys/random/wasip2.rs | 9 +++ src/tools/tidy/src/deps.rs | 6 +- triagebot.toml | 3 +- 19 files changed, 212 insertions(+), 16 deletions(-) rename library/std/src/sys/args/{wasi.rs => wasip1.rs} (100%) create mode 100644 library/std/src/sys/args/wasip2.rs rename library/std/src/sys/pal/{wasi => wasip1}/helpers.rs (100%) rename library/std/src/sys/pal/{wasi => wasip1}/mod.rs (100%) rename library/std/src/sys/pal/{wasi => wasip1}/os.rs (100%) rename library/std/src/sys/pal/{wasi => wasip1}/thread.rs (100%) rename library/std/src/sys/pal/{wasi => wasip1}/time.rs (100%) create mode 100644 library/std/src/sys/pal/wasip2/thread.rs create mode 100644 library/std/src/sys/pal/wasip2/time.rs rename library/std/src/sys/random/{wasi.rs => wasip1.rs} (100%) create mode 100644 library/std/src/sys/random/wasip2.rs diff --git a/library/Cargo.lock b/library/Cargo.lock index 8b860f6949229..c16bb3eafbdac 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -327,7 +327,8 @@ dependencies = [ "rustc-demangle", "std_detect", "unwind", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", + "wasi 0.14.3+wasi-0.2.4", "windows-targets 0.0.0", ] @@ -399,6 +400,17 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "wasi" +version = "0.14.3+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" +dependencies = [ + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", + "wit-bindgen", +] + [[package]] name = "windows-sys" version = "0.59.0" @@ -475,3 +487,13 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wit-bindgen" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" +dependencies = [ + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", +] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index eff2562f03197..8b78fe53a3978 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -80,6 +80,11 @@ wasi = { version = "0.11.0", features = [ 'rustc-dep-of-std', ], default-features = false } +[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies] +wasip2 = { version = '0.14.3', features = [ + 'rustc-dep-of-std', +], default-features = false, package = 'wasi' } + [target.'cfg(target_os = "uefi")'.dependencies] r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] } r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] } diff --git a/library/std/src/sys/args/mod.rs b/library/std/src/sys/args/mod.rs index c9627322276d0..e11e8e5430f06 100644 --- a/library/std/src/sys/args/mod.rs +++ b/library/std/src/sys/args/mod.rs @@ -32,9 +32,13 @@ cfg_select! { mod uefi; pub use uefi::*; } - target_os = "wasi" => { - mod wasi; - pub use wasi::*; + all(target_os = "wasi", target_env = "p1") => { + mod wasip1; + pub use wasip1::*; + } + all(target_os = "wasi", target_env = "p2") => { + mod wasip2; + pub use wasip2::*; } target_os = "xous" => { mod xous; diff --git a/library/std/src/sys/args/wasi.rs b/library/std/src/sys/args/wasip1.rs similarity index 100% rename from library/std/src/sys/args/wasi.rs rename to library/std/src/sys/args/wasip1.rs diff --git a/library/std/src/sys/args/wasip2.rs b/library/std/src/sys/args/wasip2.rs new file mode 100644 index 0000000000000..a57e4b97786d0 --- /dev/null +++ b/library/std/src/sys/args/wasip2.rs @@ -0,0 +1,6 @@ +pub use super::common::Args; + +/// Returns the command line arguments +pub fn args() -> Args { + Args::new(wasip2::cli::environment::get_arguments().into_iter().map(|arg| arg.into()).collect()) +} diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs index 9376f5249f1c2..513121c6d30ee 100644 --- a/library/std/src/sys/pal/mod.rs +++ b/library/std/src/sys/pal/mod.rs @@ -49,9 +49,9 @@ cfg_select! { mod wasip2; pub use self::wasip2::*; } - target_os = "wasi" => { - mod wasi; - pub use self::wasi::*; + all(target_os = "wasi", target_env = "p1") => { + mod wasip1; + pub use self::wasip1::*; } target_family = "wasm" => { mod wasm; diff --git a/library/std/src/sys/pal/wasi/helpers.rs b/library/std/src/sys/pal/wasip1/helpers.rs similarity index 100% rename from library/std/src/sys/pal/wasi/helpers.rs rename to library/std/src/sys/pal/wasip1/helpers.rs diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasip1/mod.rs similarity index 100% rename from library/std/src/sys/pal/wasi/mod.rs rename to library/std/src/sys/pal/wasip1/mod.rs diff --git a/library/std/src/sys/pal/wasi/os.rs b/library/std/src/sys/pal/wasip1/os.rs similarity index 100% rename from library/std/src/sys/pal/wasi/os.rs rename to library/std/src/sys/pal/wasip1/os.rs diff --git a/library/std/src/sys/pal/wasi/thread.rs b/library/std/src/sys/pal/wasip1/thread.rs similarity index 100% rename from library/std/src/sys/pal/wasi/thread.rs rename to library/std/src/sys/pal/wasip1/thread.rs diff --git a/library/std/src/sys/pal/wasi/time.rs b/library/std/src/sys/pal/wasip1/time.rs similarity index 100% rename from library/std/src/sys/pal/wasi/time.rs rename to library/std/src/sys/pal/wasip1/time.rs diff --git a/library/std/src/sys/pal/wasip2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs index 47fe3221c9093..5f3fb6d6ddfbf 100644 --- a/library/std/src/sys/pal/wasip2/mod.rs +++ b/library/std/src/sys/pal/wasip2/mod.rs @@ -10,13 +10,11 @@ #[path = "../wasm/atomics/futex.rs"] pub mod futex; -#[path = "../wasi/os.rs"] +#[path = "../wasip1/os.rs"] pub mod os; #[path = "../unsupported/pipe.rs"] pub mod pipe; -#[path = "../wasi/thread.rs"] pub mod thread; -#[path = "../wasi/time.rs"] pub mod time; #[path = "../unsupported/common.rs"] @@ -26,7 +24,7 @@ mod common; pub use common::*; -#[path = "../wasi/helpers.rs"] +#[path = "../wasip1/helpers.rs"] mod helpers; // The following exports are listed individually to work around Rust's glob diff --git a/library/std/src/sys/pal/wasip2/thread.rs b/library/std/src/sys/pal/wasip2/thread.rs new file mode 100644 index 0000000000000..ad52918f15a13 --- /dev/null +++ b/library/std/src/sys/pal/wasip2/thread.rs @@ -0,0 +1,73 @@ +use crate::ffi::CStr; +use crate::io; +use crate::num::NonZero; +use crate::time::{Duration, Instant}; + +pub struct Thread(!); + +pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024; + +impl Thread { + pub unsafe fn new( + _stack: usize, + _name: Option<&str>, + _p: Box, + ) -> io::Result { + // Note that unlike WASIp1 even if the wasm `atomics` feature is enabled + // there is no support for threads, not even experimentally, not even in + // wasi-libc. Thus this is unconditionally unsupported. + crate::sys::unsupported() + } + + pub fn yield_now() { + // no API for this in WASIp2, but there's also no threads, so that's + // sort of expected. + } + + pub fn set_name(_name: &CStr) { + // nope + } + + pub fn sleep(dur: Duration) { + // Sleep in increments of `u64::MAX` nanoseconds until the `dur` is + // entirely drained. + let mut remaining = dur.as_nanos(); + while remaining > 0 { + let amt = u64::try_from(remaining).unwrap_or(u64::MAX); + wasip2::clocks::monotonic_clock::subscribe_duration(amt).block(); + remaining -= u128::from(amt); + } + } + + pub fn sleep_until(deadline: Instant) { + match u64::try_from(deadline.into_inner().as_duration().as_nanos()) { + // If the point in time we're sleeping to fits within a 64-bit + // number of nanoseconds then directly use `subscribe_instant`. + Ok(deadline) => { + wasip2::clocks::monotonic_clock::subscribe_instant(deadline).block(); + } + // ... otherwise we're sleeping for 500+ years relative to the + // "start" of what the system is using as a clock so speed/accuracy + // is not so much of a concern. Use `sleep` instead. + Err(_) => { + let now = Instant::now(); + + if let Some(delay) = deadline.checked_duration_since(now) { + Self::sleep(delay); + } + } + } + } + + pub fn join(self) { + self.0 + } +} + +pub(crate) fn current_os_id() -> Option { + None +} + +pub fn available_parallelism() -> io::Result> { + crate::sys::unsupported() +} diff --git a/library/std/src/sys/pal/wasip2/time.rs b/library/std/src/sys/pal/wasip2/time.rs new file mode 100644 index 0000000000000..f1f6839774b91 --- /dev/null +++ b/library/std/src/sys/pal/wasip2/time.rs @@ -0,0 +1,69 @@ +use crate::time::Duration; + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub struct Instant(Duration); + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub struct SystemTime(Duration); + +pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); + +impl Instant { + pub fn now() -> Instant { + Instant(Duration::from_nanos(wasip2::clocks::monotonic_clock::now())) + } + + pub fn checked_sub_instant(&self, other: &Instant) -> Option { + self.0.checked_sub(other.0) + } + + pub fn checked_add_duration(&self, other: &Duration) -> Option { + Some(Instant(self.0.checked_add(*other)?)) + } + + pub fn checked_sub_duration(&self, other: &Duration) -> Option { + Some(Instant(self.0.checked_sub(*other)?)) + } + + pub(super) fn as_duration(&self) -> &Duration { + &self.0 + } +} + +impl SystemTime { + pub fn now() -> SystemTime { + let now = wasip2::clocks::wall_clock::now(); + SystemTime(Duration::new(now.seconds, now.nanoseconds)) + } + + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn from_wasi_timestamp(ts: wasi::Timestamp) -> SystemTime { + SystemTime(Duration::from_nanos(ts)) + } + + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn to_wasi_timestamp(&self) -> Option { + // FIXME: const TryInto + let ns = self.0.as_nanos(); + if ns <= u64::MAX as u128 { Some(ns as u64) } else { None } + } + + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } + } + + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option { + Some(SystemTime(self.0.checked_add(*other)?)) + } + + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option { + Some(SystemTime(self.0.checked_sub(*other)?)) + } +} diff --git a/library/std/src/sys/random/mod.rs b/library/std/src/sys/random/mod.rs index a7fbae8609930..1e0eec07b5006 100644 --- a/library/std/src/sys/random/mod.rs +++ b/library/std/src/sys/random/mod.rs @@ -86,9 +86,13 @@ cfg_select! { mod vxworks; pub use vxworks::fill_bytes; } - target_os = "wasi" => { - mod wasi; - pub use wasi::fill_bytes; + all(target_os = "wasi", target_env = "p1") => { + mod wasip1; + pub use wasip1::fill_bytes; + } + all(target_os = "wasi", target_env = "p2") => { + mod wasip2; + pub use wasip2::{fill_bytes, hashmap_random_keys}; } target_os = "zkvm" => { mod zkvm; @@ -110,6 +114,7 @@ cfg_select! { target_os = "linux", target_os = "android", all(target_family = "wasm", target_os = "unknown"), + all(target_os = "wasi", target_env = "p2"), target_os = "xous", )))] pub fn hashmap_random_keys() -> (u64, u64) { diff --git a/library/std/src/sys/random/wasi.rs b/library/std/src/sys/random/wasip1.rs similarity index 100% rename from library/std/src/sys/random/wasi.rs rename to library/std/src/sys/random/wasip1.rs diff --git a/library/std/src/sys/random/wasip2.rs b/library/std/src/sys/random/wasip2.rs new file mode 100644 index 0000000000000..a67c8a6428d18 --- /dev/null +++ b/library/std/src/sys/random/wasip2.rs @@ -0,0 +1,9 @@ +pub fn fill_bytes(bytes: &mut [u8]) { + bytes.copy_from_slice(&wasip2::random::random::get_random_bytes( + u64::try_from(bytes.len()).unwrap(), + )); +} + +pub fn hashmap_random_keys() -> (u64, u64) { + wasip2::random::insecure_seed::insecure_seed() +} diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 6974ede624a4b..560f11ecf50ec 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -490,6 +490,7 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[ "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", + "wit-bindgen", // tidy-alphabetical-end ]; @@ -798,7 +799,10 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool) continue; } - if !seen_pkgs.insert(&*pkg.name) { + // Skip the `wasi` crate here which the standard library explicitly + // depends on two version of (one for the `wasm32-wasip1` target and + // another for the `wasm32-wasip2` target). + if pkg.name.to_string() != "wasi" && !seen_pkgs.insert(&*pkg.name) { tidy_error!( bad, "duplicate package `{}` is not allowed for the standard library", diff --git a/triagebot.toml b/triagebot.toml index 3b7b216c0d24e..cf2e95203fa40 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -450,7 +450,8 @@ trigger_files = [ [autolabel."O-wasi"] trigger_files = [ - "library/std/src/sys/pal/wasi", + "library/std/src/sys/pal/wasip1", + "library/std/src/sys/pal/wasip2", "library/std/src/os/wasi" ] From 8930d3a7504a7bda441782c65a9d6320e7674ba3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 28 Aug 2025 16:52:14 +0300 Subject: [PATCH 09/17] resolve: Avoid a regression from splitting prelude into two scopes --- compiler/rustc_resolve/src/ident.rs | 23 ++++++++++++++++--- .../imports/overwritten-extern-flag-ambig.rs | 13 +++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/ui/imports/overwritten-extern-flag-ambig.rs diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index dae42645becdd..bc06a22757113 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -422,6 +422,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // to detect potential ambiguities. let mut innermost_result: Option<(NameBinding<'_>, Flags)> = None; let mut determinacy = Determinacy::Determined; + let mut extern_prelude_item_binding = None; + let mut extern_prelude_flag_binding = None; // Shadowed bindings don't need to be marked as used or non-speculatively loaded. macro finalize_scope() { if innermost_result.is_none() { finalize } else { None } @@ -558,7 +560,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Scope::ExternPreludeItems => { // FIXME: use `finalize_scope` here. match this.reborrow().extern_prelude_get_item(ident, finalize.is_some()) { - Some(binding) => Ok((binding, Flags::empty())), + Some(binding) => { + extern_prelude_item_binding = Some(binding); + Ok((binding, Flags::empty())) + } None => Err(Determinacy::determined( this.graph_root.unexpanded_invocations.borrow().is_empty(), )), @@ -566,7 +571,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } Scope::ExternPreludeFlags => { match this.extern_prelude_get_flag(ident, finalize_scope!().is_some()) { - Some(binding) => Ok((binding, Flags::empty())), + Some(binding) => { + extern_prelude_flag_binding = Some(binding); + Ok((binding, Flags::empty())) + } None => Err(Determinacy::Determined), } } @@ -686,7 +694,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } else { None }; - if let Some(kind) = ambiguity_error_kind { + // Skip ambiguity errors for extern flag bindings "overridden" + // by extern item bindings. + // FIXME: Remove with lang team approval. + let issue_145575_hack = Some(binding) + == extern_prelude_flag_binding + && extern_prelude_item_binding.is_some() + && extern_prelude_item_binding != Some(innermost_binding); + if let Some(kind) = ambiguity_error_kind + && !issue_145575_hack + { let misc = |f: Flags| { if f.contains(Flags::MISC_SUGGEST_CRATE) { AmbiguityErrorMisc::SuggestCrate diff --git a/tests/ui/imports/overwritten-extern-flag-ambig.rs b/tests/ui/imports/overwritten-extern-flag-ambig.rs new file mode 100644 index 0000000000000..80f394d34de02 --- /dev/null +++ b/tests/ui/imports/overwritten-extern-flag-ambig.rs @@ -0,0 +1,13 @@ +// Test for issue #145575. + +//@ check-pass +//@ edition: 2018 + +extern crate core as std; + +mod inner { + use crate::*; + use std::str; // OK for now +} + +fn main() {} From 0b1bc65002371c36b6e796f8933f8cb96e5d31d8 Mon Sep 17 00:00:00 2001 From: WANG Rui Date: Sat, 30 Aug 2025 21:31:16 +0800 Subject: [PATCH 10/17] Explicity disable LSX feature for `loongarch64-unknown-none` target The `loongarch64-unknown-none` target is a bare-metal target with hardware floating-point support and should not enable SIMD extensions by default. However, LLVM's LoongArch64 backend enables LSX implicitly, inadvertently activating SIMD instructions for this target. This patch explicitly disable LSX feature to prevent unintended SIMD usage. --- .../rustc_target/src/spec/targets/loongarch64_unknown_none.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/targets/loongarch64_unknown_none.rs b/compiler/rustc_target/src/spec/targets/loongarch64_unknown_none.rs index 91e3064aaede3..b6a08958284fa 100644 --- a/compiler/rustc_target/src/spec/targets/loongarch64_unknown_none.rs +++ b/compiler/rustc_target/src/spec/targets/loongarch64_unknown_none.rs @@ -17,7 +17,7 @@ pub(crate) fn target() -> Target { arch: "loongarch64".into(), options: TargetOptions { cpu: "generic".into(), - features: "+f,+d".into(), + features: "+f,+d,-lsx".into(), linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), linker: Some("rust-lld".into()), llvm_abiname: "lp64d".into(), From 1c64d3e6d1fe6256cb11b8dd455ccad1b5f9848c Mon Sep 17 00:00:00 2001 From: ltdk Date: Mon, 11 Aug 2025 19:36:20 -0400 Subject: [PATCH 11/17] Constify conversion traits --- library/alloc/src/borrow.rs | 15 +++++-- library/alloc/src/collections/mod.rs | 6 ++- library/alloc/src/lib.rs | 3 +- library/alloctests/lib.rs | 1 + library/core/src/array/mod.rs | 26 +++++++---- library/core/src/ascii/ascii_char.rs | 2 +- library/core/src/borrow.rs | 19 +++++--- library/core/src/bstr/mod.rs | 45 ++++++++++++------- library/core/src/cell.rs | 18 +++++--- library/core/src/cell/once.rs | 3 +- library/core/src/char/convert.rs | 28 ++++++++---- library/core/src/convert/mod.rs | 40 ++++++++--------- library/core/src/convert/num.rs | 19 ++++---- library/core/src/ffi/c_str.rs | 3 +- library/core/src/mem/manually_drop.rs | 6 ++- library/core/src/net/ip_addr.rs | 24 +++++----- library/core/src/net/socket_addr.rs | 6 +-- library/core/src/num/error.rs | 4 +- library/core/src/num/mod.rs | 2 +- library/core/src/num/nonzero.rs | 2 +- library/core/src/ops/deref.rs | 10 ++--- library/core/src/option.rs | 22 ++++----- library/core/src/panic/unwind_safe.rs | 6 ++- library/core/src/pin.rs | 24 +++++++--- library/core/src/pin/unsafe_pinned.rs | 3 +- library/core/src/ptr/alignment.rs | 10 +++-- library/core/src/ptr/non_null.rs | 9 ++-- library/core/src/ptr/unique.rs | 6 ++- library/core/src/range.rs | 9 ++-- library/core/src/result.rs | 18 ++++---- library/core/src/str/mod.rs | 3 +- library/core/src/str/traits.rs | 2 +- library/core/src/sync/atomic.rs | 7 +-- library/core/src/sync/exclusive.rs | 3 +- library/core/src/task/poll.rs | 3 +- library/core/src/task/wake.rs | 3 +- library/core/src/tuple.rs | 2 + library/coretests/tests/lib.rs | 3 +- library/std/src/ffi/os_str.rs | 12 +++-- library/std/src/lib.rs | 1 + library/std/src/path.rs | 15 ++++--- .../const-traits/enforce-deref-on-adjust.rs | 2 +- .../non-const-op-in-closure-in-const.rs | 2 +- .../const-traits/reservation-impl-ice.rs | 2 +- 44 files changed, 278 insertions(+), 171 deletions(-) diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index 07f51b7614ff8..cb32896161e5c 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -17,9 +17,11 @@ use crate::fmt; use crate::string::String; #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, B: ?Sized> Borrow for Cow<'a, B> +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl<'a, B: ?Sized> const Borrow for Cow<'a, B> where B: ToOwned, + B::Owned: [const] Borrow, { fn borrow(&self) -> &B { &**self @@ -326,9 +328,10 @@ impl Cow<'_, B> { } #[stable(feature = "rust1", since = "1.0.0")] -impl Deref for Cow<'_, B> +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for Cow<'_, B> where - B::Owned: Borrow, + B::Owned: [const] Borrow, { type Target = B; @@ -439,7 +442,11 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef for Cow<'_, T> { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for Cow<'_, T> +where + T::Owned: [const] Borrow, +{ fn as_ref(&self) -> &T { self } diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index fac4d1a65abcb..212d7c8465b6e 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -128,8 +128,9 @@ pub use realalloc::collections::TryReserveErrorKind; reason = "Uncertain how much info should be exposed", issue = "48043" )] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[cfg(not(test))] -impl From for TryReserveError { +impl const From for TryReserveError { #[inline] fn from(kind: TryReserveErrorKind) -> Self { Self { kind } @@ -137,8 +138,9 @@ impl From for TryReserveError { } #[unstable(feature = "try_reserve_kind", reason = "new API", issue = "48043")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[cfg(not(test))] -impl From for TryReserveErrorKind { +impl const From for TryReserveErrorKind { /// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`]. #[inline] fn from(_: LayoutError) -> Self { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 711092ae8eb25..cba1ce40f75d5 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -107,10 +107,10 @@ #![feature(char_max_len)] #![feature(clone_to_uninit)] #![feature(coerce_unsized)] +#![feature(const_convert)] #![feature(const_default)] #![feature(const_eval_select)] #![feature(const_heap)] -#![feature(const_trait_impl)] #![feature(core_intrinsics)] #![feature(deprecated_suggestion)] #![feature(deref_pure_trait)] @@ -168,6 +168,7 @@ #![feature(allow_internal_unstable)] #![feature(cfg_sanitize)] #![feature(const_precise_live_drops)] +#![feature(const_trait_impl)] #![feature(coroutine_trait)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 97de7d6a701ca..0201c8752210c 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -49,6 +49,7 @@ // Language features: // tidy-alphabetical-start #![feature(cfg_sanitize)] +#![feature(const_trait_impl)] #![feature(dropck_eyepatch)] #![feature(lang_items)] #![feature(min_specialization)] diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 835ee57ce230b..915198e571f90 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -192,7 +192,7 @@ impl fmt::Display for TryFromSliceError { impl Error for TryFromSliceError {} #[stable(feature = "try_from_slice_error", since = "1.36.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for TryFromSliceError { fn from(x: Infallible) -> TryFromSliceError { match x {} @@ -200,7 +200,8 @@ impl const From for TryFromSliceError { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef<[T]> for [T; N] { #[inline] fn as_ref(&self) -> &[T] { &self[..] @@ -208,7 +209,8 @@ impl AsRef<[T]> for [T; N] { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsMut<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsMut<[T]> for [T; N] { #[inline] fn as_mut(&mut self) -> &mut [T] { &mut self[..] @@ -216,14 +218,16 @@ impl AsMut<[T]> for [T; N] { } #[stable(feature = "array_borrow", since = "1.4.0")] -impl Borrow<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Borrow<[T]> for [T; N] { fn borrow(&self) -> &[T] { self } } #[stable(feature = "array_borrow", since = "1.4.0")] -impl BorrowMut<[T]> for [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const BorrowMut<[T]> for [T; N] { fn borrow_mut(&mut self) -> &mut [T] { self } @@ -242,7 +246,8 @@ impl BorrowMut<[T]> for [T; N] { /// assert_eq!(512, u16::from_le_bytes(bytes_tail)); /// ``` #[stable(feature = "try_from", since = "1.34.0")] -impl TryFrom<&[T]> for [T; N] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom<&[T]> for [T; N] where T: Copy, { @@ -267,7 +272,8 @@ where /// assert_eq!(512, u16::from_le_bytes(bytes_tail)); /// ``` #[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")] -impl TryFrom<&mut [T]> for [T; N] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom<&mut [T]> for [T; N] where T: Copy, { @@ -292,7 +298,8 @@ where /// assert_eq!(512, u16::from_le_bytes(*bytes_tail)); /// ``` #[stable(feature = "try_from", since = "1.34.0")] -impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl<'a, T, const N: usize> const TryFrom<&'a [T]> for &'a [T; N] { type Error = TryFromSliceError; #[inline] @@ -314,7 +321,8 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { /// assert_eq!(512, u16::from_le_bytes(*bytes_tail)); /// ``` #[stable(feature = "try_from", since = "1.34.0")] -impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl<'a, T, const N: usize> const TryFrom<&'a mut [T]> for &'a mut [T; N] { type Error = TryFromSliceError; #[inline] diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 419e4694594f0..49d540314a245 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -1156,7 +1156,7 @@ macro_rules! into_int_impl { ($($ty:ty)*) => { $( #[unstable(feature = "ascii_char", issue = "110998")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for $ty { #[inline] fn from(chr: AsciiChar) -> $ty { diff --git a/library/core/src/borrow.rs b/library/core/src/borrow.rs index da05f236d2fef..6ce7e4656b99e 100644 --- a/library/core/src/borrow.rs +++ b/library/core/src/borrow.rs @@ -154,6 +154,8 @@ /// [`String`]: ../../std/string/struct.String.html #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Borrow"] +#[const_trait] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait Borrow { /// Immutably borrows from an owned value. /// @@ -185,6 +187,8 @@ pub trait Borrow { /// for more information on borrowing as another type. #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "BorrowMut"] +#[const_trait] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait BorrowMut: Borrow { /// Mutably borrows from an owned value. /// @@ -206,7 +210,8 @@ pub trait BorrowMut: Borrow { } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for T { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Borrow for T { #[rustc_diagnostic_item = "noop_method_borrow"] fn borrow(&self) -> &T { self @@ -214,28 +219,32 @@ impl Borrow for T { } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut for T { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const BorrowMut for T { fn borrow_mut(&mut self) -> &mut T { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for &T { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Borrow for &T { fn borrow(&self) -> &T { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow for &mut T { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Borrow for &mut T { fn borrow(&self) -> &T { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut for &mut T { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const BorrowMut for &mut T { fn borrow_mut(&mut self) -> &mut T { self } diff --git a/library/core/src/bstr/mod.rs b/library/core/src/bstr/mod.rs index 13127d645a257..e13dc5cd44d5c 100644 --- a/library/core/src/bstr/mod.rs +++ b/library/core/src/bstr/mod.rs @@ -63,14 +63,16 @@ impl ByteStr { /// ``` #[inline] #[unstable(feature = "bstr", issue = "134915")] - pub fn new>(bytes: &B) -> &Self { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn new>(bytes: &B) -> &Self { ByteStr::from_bytes(bytes.as_ref()) } #[doc(hidden)] #[unstable(feature = "bstr_internals", issue = "none")] #[inline] - pub fn from_bytes(slice: &[u8]) -> &Self { + #[rustc_const_unstable(feature = "bstr_internals", issue = "none")] + pub const fn from_bytes(slice: &[u8]) -> &Self { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`, so we can turn a reference to // the wrapped type into a reference to the wrapper type. unsafe { &*(slice as *const [u8] as *const Self) } @@ -79,7 +81,8 @@ impl ByteStr { #[doc(hidden)] #[unstable(feature = "bstr_internals", issue = "none")] #[inline] - pub fn from_bytes_mut(slice: &mut [u8]) -> &mut Self { + #[rustc_const_unstable(feature = "bstr_internals", issue = "none")] + pub const fn from_bytes_mut(slice: &mut [u8]) -> &mut Self { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`, so we can turn a reference to // the wrapped type into a reference to the wrapper type. unsafe { &mut *(slice as *mut [u8] as *mut Self) } @@ -88,20 +91,23 @@ impl ByteStr { #[doc(hidden)] #[unstable(feature = "bstr_internals", issue = "none")] #[inline] - pub fn as_bytes(&self) -> &[u8] { + #[rustc_const_unstable(feature = "bstr_internals", issue = "none")] + pub const fn as_bytes(&self) -> &[u8] { &self.0 } #[doc(hidden)] #[unstable(feature = "bstr_internals", issue = "none")] #[inline] - pub fn as_bytes_mut(&mut self) -> &mut [u8] { + #[rustc_const_unstable(feature = "bstr_internals", issue = "none")] + pub const fn as_bytes_mut(&mut self) -> &mut [u8] { &mut self.0 } } #[unstable(feature = "bstr", issue = "134915")] -impl Deref for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for ByteStr { type Target = [u8]; #[inline] @@ -111,7 +117,8 @@ impl Deref for ByteStr { } #[unstable(feature = "bstr", issue = "134915")] -impl DerefMut for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const DerefMut for ByteStr { #[inline] fn deref_mut(&mut self) -> &mut [u8] { &mut self.0 @@ -185,7 +192,8 @@ impl fmt::Display for ByteStr { } #[unstable(feature = "bstr", issue = "134915")] -impl AsRef<[u8]> for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef<[u8]> for ByteStr { #[inline] fn as_ref(&self) -> &[u8] { &self.0 @@ -193,7 +201,8 @@ impl AsRef<[u8]> for ByteStr { } #[unstable(feature = "bstr", issue = "134915")] -impl AsRef for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for ByteStr { #[inline] fn as_ref(&self) -> &ByteStr { self @@ -203,7 +212,8 @@ impl AsRef for ByteStr { // `impl AsRef for [u8]` omitted to avoid widespread inference failures #[unstable(feature = "bstr", issue = "134915")] -impl AsRef for str { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for str { #[inline] fn as_ref(&self) -> &ByteStr { ByteStr::new(self) @@ -211,7 +221,8 @@ impl AsRef for str { } #[unstable(feature = "bstr", issue = "134915")] -impl AsMut<[u8]> for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsMut<[u8]> for ByteStr { #[inline] fn as_mut(&mut self) -> &mut [u8] { &mut self.0 @@ -225,7 +236,8 @@ impl AsMut<[u8]> for ByteStr { // `impl Borrow for str` omitted to avoid widespread inference failures #[unstable(feature = "bstr", issue = "134915")] -impl Borrow<[u8]> for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Borrow<[u8]> for ByteStr { #[inline] fn borrow(&self) -> &[u8] { &self.0 @@ -235,7 +247,8 @@ impl Borrow<[u8]> for ByteStr { // `impl BorrowMut for [u8]` omitted to avoid widespread inference failures #[unstable(feature = "bstr", issue = "134915")] -impl BorrowMut<[u8]> for ByteStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const BorrowMut<[u8]> for ByteStr { #[inline] fn borrow_mut(&mut self) -> &mut [u8] { &mut self.0 @@ -303,7 +316,8 @@ impl<'a> Default for &'a mut ByteStr { // } #[unstable(feature = "bstr", issue = "134915")] -impl<'a> TryFrom<&'a ByteStr> for &'a str { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl<'a> const TryFrom<&'a ByteStr> for &'a str { type Error = crate::str::Utf8Error; #[inline] @@ -313,7 +327,8 @@ impl<'a> TryFrom<&'a ByteStr> for &'a str { } #[unstable(feature = "bstr", issue = "134915")] -impl<'a> TryFrom<&'a mut ByteStr> for &'a mut str { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl<'a> const TryFrom<&'a mut ByteStr> for &'a mut str { type Error = crate::str::Utf8Error; #[inline] diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 59a6aa7062023..9b53b75ebee80 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -390,7 +390,8 @@ impl Ord for Cell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for Cell { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for Cell { /// Creates a new `Cell` containing the given value. fn from(t: T) -> Cell { Cell::new(t) @@ -1402,7 +1403,8 @@ impl Ord for RefCell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for RefCell { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for RefCell { /// Creates a new `RefCell` containing the given value. fn from(t: T) -> RefCell { RefCell::new(t) @@ -1483,7 +1485,7 @@ pub struct Ref<'b, T: ?Sized + 'b> { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const Deref for Ref<'_, T> { type Target = T; @@ -1967,7 +1969,7 @@ pub struct RefMut<'b, T: ?Sized + 'b> { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const Deref for RefMut<'_, T> { type Target = T; @@ -1979,7 +1981,7 @@ impl const Deref for RefMut<'_, T> { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const DerefMut for RefMut<'_, T> { #[inline] fn deref_mut(&mut self) -> &mut T { @@ -2434,7 +2436,8 @@ impl const Default for UnsafeCell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for UnsafeCell { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for UnsafeCell { /// Creates a new `UnsafeCell` containing the given value. fn from(t: T) -> UnsafeCell { UnsafeCell::new(t) @@ -2539,7 +2542,8 @@ impl const Default for SyncUnsafeCell { } #[unstable(feature = "sync_unsafe_cell", issue = "95439")] -impl From for SyncUnsafeCell { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for SyncUnsafeCell { /// Creates a new `SyncUnsafeCell` containing the given value. fn from(t: T) -> SyncUnsafeCell { SyncUnsafeCell::new(t) diff --git a/library/core/src/cell/once.rs b/library/core/src/cell/once.rs index c6c96571d33c9..833be059d75f7 100644 --- a/library/core/src/cell/once.rs +++ b/library/core/src/cell/once.rs @@ -395,7 +395,8 @@ impl PartialEq for OnceCell { impl Eq for OnceCell {} #[stable(feature = "once_cell", since = "1.70.0")] -impl From for OnceCell { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for OnceCell { /// Creates a new `OnceCell` which already contains the given `value`. #[inline] fn from(value: T) -> Self { diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index cf5a91bf8ddb5..6380f42d320c6 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -36,7 +36,7 @@ pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char { } #[stable(feature = "char_convert", since = "1.13.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for u32 { /// Converts a [`char`] into a [`u32`]. /// @@ -54,7 +54,7 @@ impl const From for u32 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for u64 { /// Converts a [`char`] into a [`u64`]. /// @@ -74,7 +74,7 @@ impl const From for u64 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for u128 { /// Converts a [`char`] into a [`u128`]. /// @@ -98,7 +98,8 @@ impl const From for u128 { /// /// See [`impl From for char`](char#impl-From-for-char) for details on the encoding. #[stable(feature = "u8_from_char", since = "1.59.0")] -impl TryFrom for u8 { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom for u8 { type Error = TryFromCharError; /// Tries to convert a [`char`] into a [`u8`]. @@ -113,7 +114,11 @@ impl TryFrom for u8 { /// ``` #[inline] fn try_from(c: char) -> Result { - u8::try_from(u32::from(c)).map_err(|_| TryFromCharError(())) + // FIXME(const-hack): this should use map_err instead + match u8::try_from(u32::from(c)) { + Ok(b) => Ok(b), + Err(_) => Err(TryFromCharError(())), + } } } @@ -122,7 +127,8 @@ impl TryFrom for u8 { /// /// This corresponds to the UCS-2 encoding, as specified in ISO/IEC 10646:2003. #[stable(feature = "u16_from_char", since = "1.74.0")] -impl TryFrom for u16 { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom for u16 { type Error = TryFromCharError; /// Tries to convert a [`char`] into a [`u16`]. @@ -137,7 +143,11 @@ impl TryFrom for u16 { /// ``` #[inline] fn try_from(c: char) -> Result { - u16::try_from(u32::from(c)).map_err(|_| TryFromCharError(())) + // FIXME(const-hack): this should use map_err instead + match u16::try_from(u32::from(c)) { + Ok(x) => Ok(x), + Err(_) => Err(TryFromCharError(())), + } } } @@ -160,7 +170,7 @@ impl TryFrom for u16 { /// for a superset of Windows-1252 that fills the remaining blanks with corresponding /// C0 and C1 control codes. #[stable(feature = "char_convert", since = "1.13.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for char { /// Converts a [`u8`] into a [`char`]. /// @@ -246,7 +256,7 @@ const fn char_try_from_u32(i: u32) -> Result { } #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom for char { type Error = CharTryFromError; diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index a0a7b7928d16c..add21b491ad0d 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -217,7 +217,7 @@ pub const fn identity(x: T) -> T { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "AsRef"] #[const_trait] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait AsRef: PointeeSized { /// Converts this type into a shared reference of the (usually inferred) input type. #[stable(feature = "rust1", since = "1.0.0")] @@ -370,7 +370,7 @@ pub trait AsRef: PointeeSized { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "AsMut"] #[const_trait] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait AsMut: PointeeSized { /// Converts this type into a mutable reference of the (usually inferred) input type. #[stable(feature = "rust1", since = "1.0.0")] @@ -449,7 +449,7 @@ pub trait AsMut: PointeeSized { #[rustc_diagnostic_item = "Into"] #[stable(feature = "rust1", since = "1.0.0")] #[doc(search_unbox)] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[const_trait] pub trait Into: Sized { /// Converts this type into the (usually inferred) input type. @@ -586,7 +586,7 @@ pub trait Into: Sized { note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix", ))] #[doc(search_unbox)] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[const_trait] pub trait From: Sized { /// Converts to this type from the input type. @@ -615,7 +615,7 @@ pub trait From: Sized { /// [`Into`], see there for details. #[rustc_diagnostic_item = "TryInto"] #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[const_trait] pub trait TryInto: Sized { /// The type returned in the event of a conversion error. @@ -695,7 +695,7 @@ pub trait TryInto: Sized { /// [`try_from`]: TryFrom::try_from #[rustc_diagnostic_item = "TryFrom"] #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] #[const_trait] pub trait TryFrom: Sized { /// The type returned in the event of a conversion error. @@ -714,7 +714,7 @@ pub trait TryFrom: Sized { // As lifts over & #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsRef for &T where T: [const] AsRef, @@ -727,7 +727,7 @@ where // As lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsRef for &mut T where T: [const] AsRef, @@ -748,7 +748,7 @@ where // AsMut lifts over &mut #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsMut for &mut T where T: [const] AsMut, @@ -769,7 +769,7 @@ where // From implies Into #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const Into for T where U: [const] From, @@ -787,7 +787,7 @@ where // From (and thus Into) is reflexive #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for T { /// Returns the argument unchanged. #[inline(always)] @@ -804,7 +804,7 @@ impl const From for T { #[stable(feature = "convert_infallible", since = "1.34.0")] #[rustc_reservation_impl = "permitting this impl would forbid us from adding \ `impl From for T` later; see rust-lang/rust#64715 for details"] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for T { fn from(t: !) -> T { t @@ -813,7 +813,7 @@ impl const From for T { // TryFrom implies TryInto #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryInto for T where U: [const] TryFrom, @@ -829,7 +829,7 @@ where // Infallible conversions are semantically equivalent to fallible conversions // with an uninhabited error type. #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_from", issue = "143773")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom for T where U: [const] Into, @@ -847,7 +847,7 @@ where //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsRef<[T]> for [T] { #[inline(always)] fn as_ref(&self) -> &[T] { @@ -856,7 +856,7 @@ impl const AsRef<[T]> for [T] { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsMut<[T]> for [T] { #[inline(always)] fn as_mut(&mut self) -> &mut [T] { @@ -865,7 +865,7 @@ impl const AsMut<[T]> for [T] { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsRef for str { #[inline(always)] fn as_ref(&self) -> &str { @@ -874,7 +874,7 @@ impl const AsRef for str { } #[stable(feature = "as_mut_str_for_str", since = "1.51.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const AsMut for str { #[inline(always)] fn as_mut(&mut self) -> &mut str { @@ -936,7 +936,7 @@ impl const AsMut for str { pub enum Infallible {} #[stable(feature = "convert_infallible", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_clone", issue = "142757")] impl const Clone for Infallible { fn clone(&self) -> Infallible { match *self {} @@ -986,7 +986,7 @@ impl Ord for Infallible { } #[stable(feature = "convert_infallible", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for Infallible { #[inline] fn from(x: !) -> Self { diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index affb4eb64d39d..6ae588a4e044f 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -69,7 +69,7 @@ macro_rules! impl_from { }; ($Small:ty => $Large:ty, #[$attr:meta], $doc:expr $(,)?) => { #[$attr] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<$Small> for $Large { // Rustdocs on the impl block show a "[+] show undocumented items" toggle. // Rustdocs on functions do not. @@ -201,7 +201,7 @@ macro_rules! impl_float_from_bool { )? ) => { #[stable(feature = "float_from_bool", since = "1.68.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for $float { #[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")] /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values. @@ -252,7 +252,7 @@ impl_float_from_bool!( macro_rules! impl_try_from_unbounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom<$source> for $target { type Error = TryFromIntError; @@ -271,7 +271,7 @@ macro_rules! impl_try_from_unbounded { macro_rules! impl_try_from_lower_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom<$source> for $target { type Error = TryFromIntError; @@ -294,7 +294,7 @@ macro_rules! impl_try_from_lower_bounded { macro_rules! impl_try_from_upper_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom<$source> for $target { type Error = TryFromIntError; @@ -317,7 +317,7 @@ macro_rules! impl_try_from_upper_bounded { macro_rules! impl_try_from_both_bounded { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "try_from", since = "1.34.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom<$source> for $target { type Error = TryFromIntError; @@ -456,7 +456,7 @@ use crate::num::NonZero; macro_rules! impl_nonzero_int_from_nonzero_int { ($Small:ty => $Large:ty) => { #[stable(feature = "nz_int_conv", since = "1.41.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From> for NonZero<$Large> { // Rustdocs on the impl block show a "[+] show undocumented items" toggle. // Rustdocs on functions do not. @@ -515,7 +515,8 @@ impl_nonzero_int_from_nonzero_int!(u64 => i128); macro_rules! impl_nonzero_int_try_from_int { ($Int:ty) => { #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] - impl TryFrom<$Int> for NonZero<$Int> { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + impl const TryFrom<$Int> for NonZero<$Int> { type Error = TryFromIntError; // Rustdocs on the impl block show a "[+] show undocumented items" toggle. @@ -547,7 +548,7 @@ impl_nonzero_int_try_from_int!(isize); macro_rules! impl_nonzero_int_try_from_nonzero_int { ($source:ty => $($target:ty),+) => {$( #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const TryFrom> for NonZero<$target> { type Error = TryFromIntError; diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index e6b599fafcff8..d0b53e3a237f6 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -708,7 +708,8 @@ impl ops::Index> for CStr { } #[stable(feature = "cstring_asref", since = "1.7.0")] -impl AsRef for CStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for CStr { #[inline] fn as_ref(&self) -> &CStr { self diff --git a/library/core/src/mem/manually_drop.rs b/library/core/src/mem/manually_drop.rs index 02bb81792931e..8868f05f1b98f 100644 --- a/library/core/src/mem/manually_drop.rs +++ b/library/core/src/mem/manually_drop.rs @@ -258,7 +258,8 @@ impl ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl Deref for ManuallyDrop { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for ManuallyDrop { type Target = T; #[inline(always)] fn deref(&self) -> &T { @@ -267,7 +268,8 @@ impl Deref for ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl DerefMut for ManuallyDrop { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const DerefMut for ManuallyDrop { #[inline(always)] fn deref_mut(&mut self) -> &mut T { &mut self.value diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 3bf113d017ca9..9779fb8fe4d5e 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -1087,7 +1087,7 @@ impl fmt::Debug for IpAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for IpAddr { /// Copies this address to a new `IpAddr::V4`. /// @@ -1110,7 +1110,7 @@ impl const From for IpAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for IpAddr { /// Copies this address to a new `IpAddr::V6`. /// @@ -1221,7 +1221,7 @@ impl Ord for Ipv4Addr { } #[stable(feature = "ip_u32", since = "1.1.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for u32 { /// Uses [`Ipv4Addr::to_bits`] to convert an IPv4 address to a host byte order `u32`. #[inline] @@ -1231,7 +1231,7 @@ impl const From for u32 { } #[stable(feature = "ip_u32", since = "1.1.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for Ipv4Addr { /// Uses [`Ipv4Addr::from_bits`] to convert a host byte order `u32` into an IPv4 address. #[inline] @@ -1241,7 +1241,7 @@ impl const From for Ipv4Addr { } #[stable(feature = "from_slice_v4", since = "1.9.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u8; 4]> for Ipv4Addr { /// Creates an `Ipv4Addr` from a four element byte array. /// @@ -1260,7 +1260,7 @@ impl const From<[u8; 4]> for Ipv4Addr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u8; 4]> for IpAddr { /// Creates an `IpAddr::V4` from a four element byte array. /// @@ -2215,7 +2215,7 @@ impl Ord for Ipv6Addr { } #[stable(feature = "i128", since = "1.26.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for u128 { /// Uses [`Ipv6Addr::to_bits`] to convert an IPv6 address to a host byte order `u128`. #[inline] @@ -2224,7 +2224,7 @@ impl const From for u128 { } } #[stable(feature = "i128", since = "1.26.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for Ipv6Addr { /// Uses [`Ipv6Addr::from_bits`] to convert a host byte order `u128` to an IPv6 address. #[inline] @@ -2234,7 +2234,7 @@ impl const From for Ipv6Addr { } #[stable(feature = "ipv6_from_octets", since = "1.9.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u8; 16]> for Ipv6Addr { /// Creates an `Ipv6Addr` from a sixteen element byte array. /// @@ -2262,7 +2262,7 @@ impl const From<[u8; 16]> for Ipv6Addr { } #[stable(feature = "ipv6_from_segments", since = "1.16.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u16; 8]> for Ipv6Addr { /// Creates an `Ipv6Addr` from an eight element 16-bit array. /// @@ -2291,7 +2291,7 @@ impl const From<[u16; 8]> for Ipv6Addr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u8; 16]> for IpAddr { /// Creates an `IpAddr::V6` from a sixteen element byte array. /// @@ -2319,7 +2319,7 @@ impl const From<[u8; 16]> for IpAddr { } #[stable(feature = "ip_from_slice", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<[u16; 8]> for IpAddr { /// Creates an `IpAddr::V6` from an eight element 16-bit array. /// diff --git a/library/core/src/net/socket_addr.rs b/library/core/src/net/socket_addr.rs index df99e9b20c2ea..ccc53c156d3a1 100644 --- a/library/core/src/net/socket_addr.rs +++ b/library/core/src/net/socket_addr.rs @@ -592,7 +592,7 @@ impl SocketAddrV6 { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for SocketAddr { /// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`]. #[inline] @@ -602,7 +602,7 @@ impl const From for SocketAddr { } #[stable(feature = "ip_from_ip", since = "1.16.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for SocketAddr { /// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`]. #[inline] @@ -612,7 +612,7 @@ impl const From for SocketAddr { } #[stable(feature = "addr_from_into_ip", since = "1.17.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl> const From<(I, u16)> for SocketAddr { /// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`]. /// diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index faa52329827c1..8a353dc0fbe99 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -20,7 +20,7 @@ impl fmt::Display for TryFromIntError { impl Error for TryFromIntError {} #[stable(feature = "try_from", since = "1.34.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for TryFromIntError { fn from(x: Infallible) -> TryFromIntError { match x {} @@ -28,7 +28,7 @@ impl const From for TryFromIntError { } #[unstable(feature = "never_type", issue = "35121")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for TryFromIntError { #[inline] fn from(never: !) -> TryFromIntError { diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index acfe38b7a37b5..69c6a7dbd8976 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1378,7 +1378,7 @@ const fn from_ascii_radix_panic(radix: u32) -> ! { macro_rules! from_str_int_impl { ($signedness:ident $($int_ty:ty)+) => {$( #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const FromStr for $int_ty { type Err = ParseIntError; diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index e02d9260a1690..0f38081c355d1 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -297,7 +297,7 @@ where } #[stable(feature = "from_nonzero", since = "1.31.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From> for T where T: ZeroablePrimitive, diff --git a/library/core/src/ops/deref.rs b/library/core/src/ops/deref.rs index 5f68c1f55c254..877b83d3a6116 100644 --- a/library/core/src/ops/deref.rs +++ b/library/core/src/ops/deref.rs @@ -136,7 +136,7 @@ use crate::marker::PointeeSized; #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Deref"] #[const_trait] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait Deref: PointeeSized { /// The resulting type after dereferencing. #[stable(feature = "rust1", since = "1.0.0")] @@ -152,7 +152,7 @@ pub trait Deref: PointeeSized { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const Deref for &T { type Target = T; @@ -166,7 +166,7 @@ impl const Deref for &T { impl !DerefMut for &T {} #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const Deref for &mut T { type Target = T; @@ -268,7 +268,7 @@ impl const Deref for &mut T { #[doc(alias = "*")] #[stable(feature = "rust1", since = "1.0.0")] #[const_trait] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait DerefMut: [const] Deref + PointeeSized { /// Mutably dereferences the value. #[stable(feature = "rust1", since = "1.0.0")] @@ -277,7 +277,7 @@ pub trait DerefMut: [const] Deref + PointeeSized { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_deref", issue = "88955")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const DerefMut for &mut T { fn deref_mut(&mut self) -> &mut T { self diff --git a/library/core/src/option.rs b/library/core/src/option.rs index fa09409b6daab..2a57536500ad0 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1379,11 +1379,12 @@ impl Option { /// ``` #[inline] #[stable(feature = "option_deref", since = "1.40.0")] - pub fn as_deref(&self) -> Option<&T::Target> + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_deref(&self) -> Option<&T::Target> where - T: Deref, + T: [const] Deref, { - self.as_ref().map(|t| t.deref()) + self.as_ref().map(Deref::deref) } /// Converts from `Option` (or `&mut Option`) to `Option<&mut T::Target>`. @@ -1402,11 +1403,12 @@ impl Option { /// ``` #[inline] #[stable(feature = "option_deref", since = "1.40.0")] - pub fn as_deref_mut(&mut self) -> Option<&mut T::Target> + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_deref_mut(&mut self) -> Option<&mut T::Target> where - T: DerefMut, + T: [const] DerefMut, { - self.as_mut().map(|t| t.deref_mut()) + self.as_mut().map(DerefMut::deref_mut) } ///////////////////////////////////////////////////////////////////////// @@ -2180,7 +2182,7 @@ const fn expect_failed(msg: &str) -> ! { ///////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_clone", issue = "142757")] impl const Clone for Option where // FIXME(const_hack): the T: ~const Destruct should be inferred from the Self: ~const Destruct in clone_from. @@ -2269,7 +2271,7 @@ impl<'a, T> IntoIterator for &'a mut Option { } #[stable(since = "1.12.0", feature = "option_from")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for Option { /// Moves `val` into a new [`Some`]. /// @@ -2286,7 +2288,7 @@ impl const From for Option { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl<'a, T> const From<&'a Option> for Option<&'a T> { /// Converts from `&Option` to `Option<&T>`. /// @@ -2314,7 +2316,7 @@ impl<'a, T> const From<&'a Option> for Option<&'a T> { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl<'a, T> const From<&'a mut Option> for Option<&'a mut T> { /// Converts from `&mut Option` to `Option<&mut T>` /// diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs index a60f0799c0eae..722af55103839 100644 --- a/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs @@ -248,7 +248,8 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicBool {} impl RefUnwindSafe for crate::sync::atomic::AtomicPtr {} #[stable(feature = "catch_unwind", since = "1.9.0")] -impl Deref for AssertUnwindSafe { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for AssertUnwindSafe { type Target = T; fn deref(&self) -> &T { @@ -257,7 +258,8 @@ impl Deref for AssertUnwindSafe { } #[stable(feature = "catch_unwind", since = "1.9.0")] -impl DerefMut for AssertUnwindSafe { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const DerefMut for AssertUnwindSafe { fn deref_mut(&mut self) -> &mut T { &mut self.0 } diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 14bf7ba90150e..535830f2e749f 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1359,7 +1359,11 @@ impl Pin { /// ruled out by the contract of `Pin::new_unchecked`. #[stable(feature = "pin", since = "1.33.0")] #[inline(always)] - pub fn as_ref(&self) -> Pin<&Ptr::Target> { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_ref(&self) -> Pin<&Ptr::Target> + where + Ptr: [const] Deref, + { // SAFETY: see documentation on this function unsafe { Pin::new_unchecked(&*self.pointer) } } @@ -1403,7 +1407,11 @@ impl Pin { /// ``` #[stable(feature = "pin", since = "1.33.0")] #[inline(always)] - pub fn as_mut(&mut self) -> Pin<&mut Ptr::Target> { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_mut(&mut self) -> Pin<&mut Ptr::Target> + where + Ptr: [const] DerefMut, + { // SAFETY: see documentation on this function unsafe { Pin::new_unchecked(&mut *self.pointer) } } @@ -1418,7 +1426,11 @@ impl Pin { #[stable(feature = "pin_deref_mut", since = "1.84.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline(always)] - pub fn as_deref_mut(self: Pin<&mut Self>) -> Pin<&mut Ptr::Target> { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_deref_mut(self: Pin<&mut Self>) -> Pin<&mut Ptr::Target> + where + Ptr: [const] DerefMut, + { // SAFETY: What we're asserting here is that going from // // Pin<&mut Pin> @@ -1669,7 +1681,8 @@ impl Pin<&'static mut T> { } #[stable(feature = "pin", since = "1.33.0")] -impl Deref for Pin { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const Deref for Pin { type Target = Ptr::Target; fn deref(&self) -> &Ptr::Target { Pin::get_ref(Pin::as_ref(self)) @@ -1677,7 +1690,8 @@ impl Deref for Pin { } #[stable(feature = "pin", since = "1.33.0")] -impl> DerefMut for Pin { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl> const DerefMut for Pin { fn deref_mut(&mut self) -> &mut Ptr::Target { Pin::get_mut(Pin::as_mut(self)) } diff --git a/library/core/src/pin/unsafe_pinned.rs b/library/core/src/pin/unsafe_pinned.rs index ede6e0d6106bd..ae03809b4581f 100644 --- a/library/core/src/pin/unsafe_pinned.rs +++ b/library/core/src/pin/unsafe_pinned.rs @@ -148,7 +148,8 @@ impl Default for UnsafePinned { } #[unstable(feature = "unsafe_pinned", issue = "125735")] -impl From for UnsafePinned { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for UnsafePinned { /// Creates a new `UnsafePinned` containing the given value. fn from(value: T) -> Self { UnsafePinned::new(value) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 402634e49b37e..bc7d3a1de7151 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -171,7 +171,8 @@ impl fmt::Debug for Alignment { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl TryFrom> for Alignment { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom> for Alignment { type Error = num::TryFromIntError; #[inline] @@ -181,7 +182,8 @@ impl TryFrom> for Alignment { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl TryFrom for Alignment { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const TryFrom for Alignment { type Error = num::TryFromIntError; #[inline] @@ -191,7 +193,7 @@ impl TryFrom for Alignment { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for NonZero { #[inline] fn from(align: Alignment) -> NonZero { @@ -200,7 +202,7 @@ impl const From for NonZero { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for usize { #[inline] fn from(align: Alignment) -> usize { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 117eb18826e49..10f83120428b9 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1711,7 +1711,8 @@ impl hash::Hash for NonNull { } #[unstable(feature = "ptr_internals", issue = "none")] -impl From> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From> for NonNull { #[inline] fn from(unique: Unique) -> Self { unique.as_non_null_ptr() @@ -1719,7 +1720,8 @@ impl From> for NonNull { } #[stable(feature = "nonnull", since = "1.25.0")] -impl From<&mut T> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From<&mut T> for NonNull { /// Converts a `&mut T` to a `NonNull`. /// /// This conversion is safe and infallible since references cannot be null. @@ -1730,7 +1732,8 @@ impl From<&mut T> for NonNull { } #[stable(feature = "nonnull", since = "1.25.0")] -impl From<&T> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From<&T> for NonNull { /// Converts a `&T` to a `NonNull`. /// /// This conversion is safe and infallible since references cannot be null. diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index 4302c1b1e4451..cdc8b6cc936df 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -189,7 +189,8 @@ impl fmt::Pointer for Unique { } #[unstable(feature = "ptr_internals", issue = "none")] -impl From<&mut T> for Unique { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From<&mut T> for Unique { /// Converts a `&mut T` to a `Unique`. /// /// This conversion is infallible since references cannot be null. @@ -200,7 +201,8 @@ impl From<&mut T> for Unique { } #[unstable(feature = "ptr_internals", issue = "none")] -impl From> for Unique { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From> for Unique { /// Converts a `NonNull` to a `Unique`. /// /// This conversion is infallible since `NonNull` cannot be null. diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 7158fa0fcf069..332ae51d8484e 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -192,7 +192,7 @@ impl IntoBounds for Range { } #[unstable(feature = "new_range_api", issue = "125687")] -#[rustc_const_unstable(feature = "const_index", issue = "143775")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From> for legacy::Range { #[inline] fn from(value: Range) -> Self { @@ -201,7 +201,7 @@ impl const From> for legacy::Range { } #[unstable(feature = "new_range_api", issue = "125687")] -#[rustc_const_unstable(feature = "const_index", issue = "143775")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From> for Range { #[inline] fn from(value: legacy::Range) -> Self { @@ -377,7 +377,7 @@ impl IntoBounds for RangeInclusive { } #[unstable(feature = "new_range_api", issue = "125687")] -#[rustc_const_unstable(feature = "const_index", issue = "143775")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From> for legacy::RangeInclusive { #[inline] fn from(value: RangeInclusive) -> Self { @@ -385,7 +385,8 @@ impl const From> for legacy::RangeInclusive { } } #[unstable(feature = "new_range_api", issue = "125687")] -impl From> for RangeInclusive { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From> for RangeInclusive { #[inline] fn from(value: legacy::RangeInclusive) -> Self { assert!( diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 6148bdb866ad0..7dffab9b316f6 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1034,11 +1034,12 @@ impl Result { /// ``` #[inline] #[stable(feature = "inner_deref", since = "1.47.0")] - pub fn as_deref(&self) -> Result<&T::Target, &E> + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_deref(&self) -> Result<&T::Target, &E> where - T: Deref, + T: [const] Deref, { - self.as_ref().map(|t| t.deref()) + self.as_ref().map(Deref::deref) } /// Converts from `Result` (or `&mut Result`) to `Result<&mut ::Target, &mut E>`. @@ -1061,11 +1062,12 @@ impl Result { /// ``` #[inline] #[stable(feature = "inner_deref", since = "1.47.0")] - pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> where - T: DerefMut, + T: [const] DerefMut, { - self.as_mut().map(|t| t.deref_mut()) + self.as_mut().map(DerefMut::deref_mut) } ///////////////////////////////////////////////////////////////////////// @@ -1347,7 +1349,7 @@ impl Result { #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] #[rustc_allow_const_fn_unstable(const_precise_live_drops)] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub const fn into_ok(self) -> T where E: [const] Into, @@ -1384,7 +1386,7 @@ impl Result { #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] #[inline] #[rustc_allow_const_fn_unstable(const_precise_live_drops)] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub const fn into_err(self) -> E where T: [const] Into, diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 1a055a0a5adc8..005793a6635a4 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -3078,7 +3078,8 @@ impl str { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[u8]> for str { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef<[u8]> for str { #[inline] fn as_ref(&self) -> &[u8] { self.as_bytes() diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index dc88f35eca7ea..971c8e829c648 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -826,7 +826,7 @@ unsafe impl const SliceIndex for ops::RangeToInclusive { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[const_trait] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] pub trait FromStr: Sized { /// The associated error which can be returned from parsing. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 44a6895f90ac6..d4d72c111707b 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -2523,7 +2523,7 @@ impl AtomicPtr { #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "atomic_bool_from", since = "1.24.0")] -#[rustc_const_unstable(feature = "const_try", issue = "74935")] +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From for AtomicBool { /// Converts a `bool` into an `AtomicBool`. /// @@ -2542,7 +2542,8 @@ impl const From for AtomicBool { #[cfg(target_has_atomic_load_store = "ptr")] #[stable(feature = "atomic_from", since = "1.23.0")] -impl From<*mut T> for AtomicPtr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From<*mut T> for AtomicPtr { /// Converts a `*mut T` into an `AtomicPtr`. #[inline] fn from(p: *mut T) -> Self { @@ -2621,7 +2622,7 @@ macro_rules! atomic_int { } #[$stable_from] - #[rustc_const_unstable(feature = "const_try", issue = "74935")] + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] impl const From<$int_type> for $atomic_type { #[doc = concat!("Converts an `", stringify!($int_type), "` into an `", stringify!($atomic_type), "`.")] #[inline] diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index 340b0b79e40a3..cf086bf4f5080 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -163,7 +163,8 @@ impl Exclusive { } #[unstable(feature = "exclusive_wrapper", issue = "98407")] -impl From for Exclusive { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for Exclusive { #[inline] fn from(t: T) -> Self { Self::new(t) diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 59ffe7ad49c05..380abac0ae95f 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -215,7 +215,8 @@ impl Poll>> { } #[stable(feature = "futures_api", since = "1.36.0")] -impl From for Poll { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const From for Poll { /// Moves the value into a [`Poll::Ready`] to make a `Poll`. /// /// # Example diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index bb7efe582f7a3..97eb9ec7dc5b0 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -901,7 +901,8 @@ impl Clone for LocalWaker { } #[unstable(feature = "local_waker", issue = "118959")] -impl AsRef for Waker { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for Waker { fn as_ref(&self) -> &LocalWaker { // SAFETY: LocalWaker is just Waker without thread safety unsafe { transmute(self) } diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 23a0a6877df77..2cdee1803a9a2 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -133,6 +133,7 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "array_tuple_conv", since = "1.71.0")] + // can't do const From due to https://github.com/rust-lang/rust/issues/144280 impl From<[T; ${count($T)}]> for ($(${ignore($T)} T,)+) { #[inline] #[allow(non_snake_case)] @@ -146,6 +147,7 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "array_tuple_conv", since = "1.71.0")] + // can't do const From due to https://github.com/rust-lang/rust/issues/144280 impl From<($(${ignore($T)} T,)+)> for [T; ${count($T)}] { #[inline] #[allow(non_snake_case)] diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index b9b768f29d788..8e197e33ba647 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -15,10 +15,9 @@ #![feature(cfg_target_has_reliable_f16_f128)] #![feature(char_max_len)] #![feature(clone_to_uninit)] -#![feature(const_deref)] +#![feature(const_convert)] #![feature(const_destruct)] #![feature(const_eval_select)] -#![feature(const_from)] #![feature(const_ops)] #![feature(const_option_ops)] #![feature(const_ref_cell)] diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 1214490caadf3..a39565d215924 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -828,7 +828,8 @@ impl OsStr { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn new + ?Sized>(s: &S) -> &OsStr { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn new + ?Sized>(s: &S) -> &OsStr { s.as_ref() } @@ -876,14 +877,16 @@ impl OsStr { } #[inline] - fn from_inner(inner: &Slice) -> &OsStr { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + const fn from_inner(inner: &Slice) -> &OsStr { // SAFETY: OsStr is just a wrapper of Slice, // therefore converting &Slice to &OsStr is safe. unsafe { &*(inner as *const Slice as *const OsStr) } } #[inline] - fn from_inner_mut(inner: &mut Slice) -> &mut OsStr { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + const fn from_inner_mut(inner: &mut Slice) -> &mut OsStr { // SAFETY: OsStr is just a wrapper of Slice, // therefore converting &mut Slice to &mut OsStr is safe. // Any method that mutates OsStr must be careful not to @@ -1681,7 +1684,8 @@ impl ToOwned for OsStr { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef for OsStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for OsStr { #[inline] fn as_ref(&self) -> &OsStr { self diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 30a1b10881784..a2f7701a5b390 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -334,6 +334,7 @@ #![feature(char_internals)] #![feature(clone_to_uninit)] #![feature(const_cmp)] +#![feature(const_convert)] #![feature(const_ops)] #![feature(const_option_ops)] #![feature(const_try)] diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 470d300d2d95b..5ccea1c972c16 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2264,11 +2264,13 @@ impl Path { /// assert_eq!(from_string, from_path); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new + ?Sized>(s: &S) -> &Path { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + pub const fn new + ?Sized>(s: &S) -> &Path { unsafe { &*(s.as_ref() as *const OsStr as *const Path) } } - fn from_inner_mut(inner: &mut OsStr) -> &mut Path { + #[rustc_const_unstable(feature = "const_convert", issue = "143773")] + const fn from_inner_mut(inner: &mut OsStr) -> &mut Path { // SAFETY: Path is just a wrapper around OsStr, // therefore converting &mut OsStr to &mut Path is safe. unsafe { &mut *(inner as *mut OsStr as *mut Path) } @@ -3337,7 +3339,8 @@ unsafe impl CloneToUninit for Path { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef for Path { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for Path { #[inline] fn as_ref(&self) -> &OsStr { &self.inner @@ -3507,7 +3510,8 @@ impl Ord for Path { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef for Path { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for Path { #[inline] fn as_ref(&self) -> &Path { self @@ -3515,7 +3519,8 @@ impl AsRef for Path { } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef for OsStr { +#[rustc_const_unstable(feature = "const_convert", issue = "143773")] +impl const AsRef for OsStr { #[inline] fn as_ref(&self) -> &Path { Path::new(self) diff --git a/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs index d5240b7e18ddb..cba207f095309 100644 --- a/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs +++ b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs @@ -1,6 +1,6 @@ //@ check-pass -#![feature(const_deref)] +#![feature(const_convert)] #![feature(const_trait_impl)] use std::ops::Deref; diff --git a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs index d5f80acc15b54..50c985096d127 100644 --- a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs +++ b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.rs @@ -1,4 +1,4 @@ -#![feature(const_trait_impl, const_from)] +#![feature(const_trait_impl, const_convert)] //@ check-pass diff --git a/tests/ui/traits/const-traits/reservation-impl-ice.rs b/tests/ui/traits/const-traits/reservation-impl-ice.rs index efaea1cc6b2bf..7fefb4ec54399 100644 --- a/tests/ui/traits/const-traits/reservation-impl-ice.rs +++ b/tests/ui/traits/const-traits/reservation-impl-ice.rs @@ -1,5 +1,5 @@ //@ compile-flags: -Znext-solver -#![feature(const_from, never_type, const_trait_impl)] +#![feature(const_convert, never_type, const_trait_impl)] const fn impls_from>() {} From b2962c367a7f38a8d6fb372ae4744f77f9079619 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Aug 2025 16:09:54 -0500 Subject: [PATCH 12/17] test(lexer): Ensure frontmatter w/ crlf works --- tests/ui/.gitattributes | 1 + tests/ui/frontmatter/frontmatter-crlf.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/ui/frontmatter/frontmatter-crlf.rs diff --git a/tests/ui/.gitattributes b/tests/ui/.gitattributes index 9ea3d3fb0e1f1..4923ac100e172 100644 --- a/tests/ui/.gitattributes +++ b/tests/ui/.gitattributes @@ -3,4 +3,5 @@ json-bom-plus-crlf.rs -text json-bom-plus-crlf-multifile.rs -text json-bom-plus-crlf-multifile-aux.rs -text trailing-carriage-return-in-string.rs -text +frontmatter-crlf.rs -text *.bin -text diff --git a/tests/ui/frontmatter/frontmatter-crlf.rs b/tests/ui/frontmatter/frontmatter-crlf.rs new file mode 100644 index 0000000000000..b46cc9ddbb0e0 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-crlf.rs @@ -0,0 +1,14 @@ +#!/usr/bin/env -S cargo -Zscript +--- +[dependencies] +clap = "4" +--- + +//@ check-pass +// ignore-tidy-cr + +// crlf line endings should be accepted + +#![feature(frontmatter)] + +fn main() {} From 159be09c4f70b109cc859a55beeb4150b8e452e6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 29 Aug 2025 13:30:48 -0500 Subject: [PATCH 13/17] test(lexer): Ensure frontmatter can contain unicode whitespace --- .../frontmatter-contains-whitespace.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/ui/frontmatter/frontmatter-contains-whitespace.rs diff --git a/tests/ui/frontmatter/frontmatter-contains-whitespace.rs b/tests/ui/frontmatter/frontmatter-contains-whitespace.rs new file mode 100644 index 0000000000000..11df822f793cf --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-contains-whitespace.rs @@ -0,0 +1,22 @@ +#!/usr/bin/env -S cargo -Zscript +---cargo +# Beware editing: it has numerous whitespace characters which are important. +# It contains one ranges from the 'PATTERN_WHITE_SPACE' property outlined in +# https://unicode.org/Public/UNIDATA/PropList.txt +# +# The characters in the first expression of the assertion can be generated +# from: "4\u{0C}+\n\t\r7\t*\u{20}2\u{85}/\u{200E}3\u{200F}*\u{2028}2\u{2029}" +package.description = """ +4 + + +7 * 2…/‎3‏*
2 +""" +--- + +//@ check-pass + +// Ensure the frontmatter can contain any whitespace + +#![feature(frontmatter)] + +fn main() {} From 9304aa19366a51aea23a516ea44e45bc4a3e84e7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 29 Aug 2025 13:47:22 -0500 Subject: [PATCH 14/17] test(lexer): Ensure tabs are accepted for horizontal whitespace --- tests/ui/frontmatter/frontmatter-whitespace-3.rs | 5 +++-- tests/ui/frontmatter/frontmatter-whitespace-4.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/ui/frontmatter/frontmatter-whitespace-3.rs b/tests/ui/frontmatter/frontmatter-whitespace-3.rs index 95e0981e2ae8b..6580514fba2d2 100644 --- a/tests/ui/frontmatter/frontmatter-whitespace-3.rs +++ b/tests/ui/frontmatter/frontmatter-whitespace-3.rs @@ -1,7 +1,7 @@ ----cargo ---- +---cargo +--- // please note the whitespace characters after the first four lines. // This ensures that we accept whitespaces before the frontmatter, after @@ -10,6 +10,7 @@ //@ check-pass // ignore-tidy-end-whitespace // ignore-tidy-leading-newlines +// ignore-tidy-tab #![feature(frontmatter)] diff --git a/tests/ui/frontmatter/frontmatter-whitespace-4.rs b/tests/ui/frontmatter/frontmatter-whitespace-4.rs index 3bda3227838c7..1e7c5556647b0 100644 --- a/tests/ui/frontmatter/frontmatter-whitespace-4.rs +++ b/tests/ui/frontmatter/frontmatter-whitespace-4.rs @@ -1,7 +1,8 @@ ---- cargo +--- cargo --- //@ check-pass +// ignore-tidy-tab // A frontmatter infostring can have leading whitespace. #![feature(frontmatter)] From 428e413414e0719a7758676ac49e07b85eb86dec Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Aug 2025 14:18:42 -0500 Subject: [PATCH 15/17] docs(lexer): Organize and document whitespace by Pattern_White_Space --- compiler/rustc_lexer/src/lib.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index d10b192034354..e347a76f6a2ae 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -331,24 +331,22 @@ pub fn is_whitespace(c: char) -> bool { matches!( c, - // Usual ASCII suspects - '\u{0009}' // \t - | '\u{000A}' // \n + // End-of-line characters + | '\u{000A}' // line feed (\n) | '\u{000B}' // vertical tab | '\u{000C}' // form feed - | '\u{000D}' // \r - | '\u{0020}' // space - - // NEXT LINE from latin1 - | '\u{0085}' + | '\u{000D}' // carriage return (\r) + | '\u{0085}' // next line (from latin1) + | '\u{2028}' // LINE SEPARATOR + | '\u{2029}' // PARAGRAPH SEPARATOR - // Bidi markers + // `Default_Ignorable_Code_Point` characters | '\u{200E}' // LEFT-TO-RIGHT MARK | '\u{200F}' // RIGHT-TO-LEFT MARK - // Dedicated whitespace characters from Unicode - | '\u{2028}' // LINE SEPARATOR - | '\u{2029}' // PARAGRAPH SEPARATOR + // Horizontal space characters + | '\u{0009}' // tab (\t) + | '\u{0020}' // space ) } From 6f0da976c5f422ff5b1124d409e7d7e063fc4225 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Aug 2025 15:15:41 -0500 Subject: [PATCH 16/17] fix(lexer): Only allow horizontal whitespace in frontmatter In writing up the reference for frontmatter, I realized that we probably shouldn't be accepting Unicode Line Ending characters between the code fence and infostring or trailing after the infostring or a code fence. In digging into the unicode specification we use for Whitespace, it divides it up into categories, so I'm deferring to what it says for horizontal whitespace for what should be used within a line. Note, I am leaving out support for Unicde Default Ignorable characters. I figure that can be discussed outside of this change within the reference and tracking issue. --- compiler/rustc_lexer/src/lib.rs | 21 ++++++++++++++++++--- compiler/rustc_parse/src/lexer/mod.rs | 6 +++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index e347a76f6a2ae..c29ab569f4795 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -350,6 +350,21 @@ pub fn is_whitespace(c: char) -> bool { ) } +/// True if `c` is considered horizontal whitespace according to Rust language definition. +pub fn is_horizontal_whitespace(c: char) -> bool { + // This is Pattern_White_Space. + // + // Note that this set is stable (ie, it doesn't change with different + // Unicode versions), so it's ok to just hard-code the values. + + matches!( + c, + // Horizontal space characters + '\u{0009}' // tab (\t) + | '\u{0020}' // space + ) +} + /// True if `c` is valid as a first character of an identifier. /// See [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html) for /// a formal definition of valid identifier name. @@ -536,7 +551,7 @@ impl Cursor<'_> { debug_assert!(length_opening >= 3); // whitespace between the opening and the infostring. - self.eat_while(|ch| ch != '\n' && is_whitespace(ch)); + self.eat_while(|ch| ch != '\n' && is_horizontal_whitespace(ch)); // copied from `eat_identifier`, but allows `-` and `.` in infostring to allow something like // `---Cargo.toml` as a valid opener @@ -545,7 +560,7 @@ impl Cursor<'_> { self.eat_while(|c| is_id_continue(c) || c == '-' || c == '.'); } - self.eat_while(|ch| ch != '\n' && is_whitespace(ch)); + self.eat_while(|ch| ch != '\n' && is_horizontal_whitespace(ch)); let invalid_infostring = self.first() != '\n'; let mut found = false; @@ -586,7 +601,7 @@ impl Cursor<'_> { // on a standalone line. Might be wrong. while let Some(closing) = rest.find("---") { let preceding_chars_start = rest[..closing].rfind("\n").map_or(0, |i| i + 1); - if rest[preceding_chars_start..closing].chars().all(is_whitespace) { + if rest[preceding_chars_start..closing].chars().all(is_horizontal_whitespace) { // candidate found potential_closing = Some(closing); break; diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 9792240a54850..e3bd6a9a3270f 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -6,7 +6,7 @@ use rustc_ast::util::unicode::{TEXT_FLOW_CONTROL_CHARS, contains_text_flow_contr use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, StashKey}; use rustc_lexer::{ - Base, Cursor, DocStyle, FrontmatterAllowed, LiteralKind, RawStrError, is_whitespace, + Base, Cursor, DocStyle, FrontmatterAllowed, LiteralKind, RawStrError, is_horizontal_whitespace, }; use rustc_literal_escaper::{EscapeError, Mode, check_for_errors}; use rustc_session::lint::BuiltinLintDiag; @@ -597,7 +597,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { let last_line_start = within.rfind('\n').map_or(0, |i| i + 1); let last_line = &within[last_line_start..]; - let last_line_trimmed = last_line.trim_start_matches(is_whitespace); + let last_line_trimmed = last_line.trim_start_matches(is_horizontal_whitespace); let last_line_start_pos = frontmatter_opening_end_pos + BytePos(last_line_start as u32); let frontmatter_span = self.mk_sp(frontmatter_opening_pos, self.pos); @@ -640,7 +640,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { }); } - if !rest.trim_matches(is_whitespace).is_empty() { + if !rest.trim_matches(is_horizontal_whitespace).is_empty() { let span = self.mk_sp(last_line_start_pos, self.pos); self.dcx().emit_err(errors::FrontmatterExtraCharactersAfterClose { span }); } From 03bffa88011c6f59c0b62940aeb98fce212e4e82 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 3 Sep 2025 10:46:34 +0200 Subject: [PATCH 17/17] CI: rfl: move job forward to Linux v6.17-rc3 plus 2 commits This upgrades the Rust CI from v6.16-rc1 plus a temporary commit for the >= 1.91 target spec [1] to v6.17-rc3 with two commits pending to be merged upstream -- one for the same target spec format change [1] and another for the `file_as_c_str` change [2]. Link: https://github.com/rust-lang/rust/pull/144443 [1] Link: https://github.com/rust-lang/rust/pull/145928 [2] Signed-off-by: Miguel Ojeda --- src/ci/docker/scripts/rfl-build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index 70ff5d0d2c722..7e0fb5794f47c 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -3,7 +3,8 @@ set -euo pipefail # https://github.com/rust-lang/rust/pull/144443 -LINUX_VERSION=7770d51bce622b13195b2d3c85407282fc9c27e5 +# https://github.com/rust-lang/rust/pull/145928 +LINUX_VERSION=8851e27d2cb947ea8bbbe8e812068f7bf5cbd00b # Build rustc, rustdoc, cargo, clippy-driver and rustfmt ../x.py build --stage 2 library rustdoc clippy rustfmt