Skip to content

Commit 06c9fef

Browse files
committed
Auto merge of #72422 - RalfJung:rollup-u81z4mw, r=RalfJung
Rollup of 7 pull requests Successful merges: - #71854 (Make `std::char` functions and constants associated to `char`.) - #72111 (rustc-book: Document `-Z strip=val` option) - #72272 (Fix going back in history to a search result page on firefox) - #72296 (Suggest installing VS Build Tools in more situations) - #72365 (Remove unused `StableHashingContext::node_to_hir_id` method) - #72371 (FIX - Char documentation for unexperienced users) - #72397 (llvm: Expose tiny code model to users) Failed merges: r? @ghost
2 parents 7f79e98 + e5a4550 commit 06c9fef

File tree

9 files changed

+318
-12
lines changed

9 files changed

+318
-12
lines changed

src/doc/rustc/src/codegen-options/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ specification.
2121

2222
Supported values for this option are:
2323

24-
<!-- - `tiny` - Tiny code model. -->
24+
- `tiny` - Tiny code model.
2525
- `small` - Small code model. This is the default model for majority of supported targets.
2626
- `kernel` - Kernel code model.
2727
- `medium` - Medium code model.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `strip`
2+
3+
The tracking issue for this feature is: [#72110](https://github.com/rust-lang/rust/issues/72110).
4+
5+
------------------------
6+
7+
Option `-Z strip=val` controls stripping of debuginfo and similar auxiliary data from binaries
8+
during linking.
9+
10+
Supported values for this option are:
11+
12+
- `none` - debuginfo and symbols (if they exist) are copied to the produced binary or separate files
13+
depending on the target (e.g. `.pdb` files in case of MSVC).
14+
- `debuginfo` - debuginfo sections and debuginfo symbols from the symbol table section
15+
are stripped at link time and are not copied to the produced binary or separate files.
16+
- `symbols` - same as `debuginfo`, but the rest of the symbol table section is stripped as well
17+
if the linker supports it.

src/libcore/char/methods.rs

+241-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,243 @@ use super::*;
99

1010
#[lang = "char"]
1111
impl char {
12+
/// The highest valid code point a `char` can have.
13+
///
14+
/// A `char` is a [Unicode Scalar Value], which means that it is a [Code
15+
/// Point], but only ones within a certain range. `MAX` is the highest valid
16+
/// code point that's a valid [Unicode Scalar Value].
17+
///
18+
/// [Unicode Scalar Value]: http://www.unicode.org/glossary/#unicode_scalar_value
19+
/// [Code Point]: http://www.unicode.org/glossary/#code_point
20+
#[unstable(feature = "assoc_char_consts", reason = "recently added", issue = "71763")]
21+
pub const MAX: char = '\u{10ffff}';
22+
23+
/// `U+FFFD REPLACEMENT CHARACTER` (�) is used in Unicode to represent a
24+
/// decoding error.
25+
///
26+
/// It can occur, for example, when giving ill-formed UTF-8 bytes to
27+
/// [`String::from_utf8_lossy`](string/struct.String.html#method.from_utf8_lossy).
28+
#[unstable(feature = "assoc_char_consts", reason = "recently added", issue = "71763")]
29+
pub const REPLACEMENT_CHARACTER: char = '\u{FFFD}';
30+
31+
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
32+
/// `char` and `str` methods are based on.
33+
///
34+
/// New versions of Unicode are released regularly and subsequently all methods
35+
/// in the standard library depending on Unicode are updated. Therefore the
36+
/// behavior of some `char` and `str` methods and the value of this constant
37+
/// changes over time. This is *not* considered to be a breaking change.
38+
///
39+
/// The version numbering scheme is explained in
40+
/// [Unicode 11.0 or later, Section 3.1 Versions of the Unicode Standard](https://www.unicode.org/versions/Unicode11.0.0/ch03.pdf#page=4).
41+
#[unstable(feature = "assoc_char_consts", reason = "recently added", issue = "71763")]
42+
pub const UNICODE_VERSION: (u8, u8, u8) = crate::unicode::UNICODE_VERSION;
43+
44+
/// Creates an iterator over the UTF-16 encoded code points in `iter`,
45+
/// returning unpaired surrogates as `Err`s.
46+
///
47+
/// # Examples
48+
///
49+
/// Basic usage:
50+
///
51+
/// ```
52+
/// use std::char::decode_utf16;
53+
///
54+
/// // 𝄞mus<invalid>ic<invalid>
55+
/// let v = [
56+
/// 0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834,
57+
/// ];
58+
///
59+
/// assert_eq!(
60+
/// decode_utf16(v.iter().cloned())
61+
/// .map(|r| r.map_err(|e| e.unpaired_surrogate()))
62+
/// .collect::<Vec<_>>(),
63+
/// vec![
64+
/// Ok('𝄞'),
65+
/// Ok('m'), Ok('u'), Ok('s'),
66+
/// Err(0xDD1E),
67+
/// Ok('i'), Ok('c'),
68+
/// Err(0xD834)
69+
/// ]
70+
/// );
71+
/// ```
72+
///
73+
/// A lossy decoder can be obtained by replacing `Err` results with the replacement character:
74+
///
75+
/// ```
76+
/// use std::char::{decode_utf16, REPLACEMENT_CHARACTER};
77+
///
78+
/// // 𝄞mus<invalid>ic<invalid>
79+
/// let v = [
80+
/// 0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834,
81+
/// ];
82+
///
83+
/// assert_eq!(
84+
/// decode_utf16(v.iter().cloned())
85+
/// .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
86+
/// .collect::<String>(),
87+
/// "𝄞mus�ic�"
88+
/// );
89+
/// ```
90+
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
91+
#[inline]
92+
pub fn decode_utf16<I: IntoIterator<Item = u16>>(iter: I) -> DecodeUtf16<I::IntoIter> {
93+
super::decode::decode_utf16(iter)
94+
}
95+
96+
/// Converts a `u32` to a `char`.
97+
///
98+
/// Note that all `char`s are valid [`u32`]s, and can be cast to one with
99+
/// `as`:
100+
///
101+
/// ```
102+
/// let c = '💯';
103+
/// let i = c as u32;
104+
///
105+
/// assert_eq!(128175, i);
106+
/// ```
107+
///
108+
/// However, the reverse is not true: not all valid [`u32`]s are valid
109+
/// `char`s. `from_u32()` will return `None` if the input is not a valid value
110+
/// for a `char`.
111+
///
112+
/// [`u32`]: primitive.u32.html
113+
///
114+
/// For an unsafe version of this function which ignores these checks, see
115+
/// [`from_u32_unchecked`].
116+
///
117+
/// [`from_u32_unchecked`]: #method.from_u32_unchecked
118+
///
119+
/// # Examples
120+
///
121+
/// Basic usage:
122+
///
123+
/// ```
124+
/// use std::char;
125+
///
126+
/// let c = char::from_u32(0x2764);
127+
///
128+
/// assert_eq!(Some('❤'), c);
129+
/// ```
130+
///
131+
/// Returning `None` when the input is not a valid `char`:
132+
///
133+
/// ```
134+
/// use std::char;
135+
///
136+
/// let c = char::from_u32(0x110000);
137+
///
138+
/// assert_eq!(None, c);
139+
/// ```
140+
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
141+
#[inline]
142+
pub fn from_u32(i: u32) -> Option<char> {
143+
super::convert::from_u32(i)
144+
}
145+
146+
/// Converts a `u32` to a `char`, ignoring validity.
147+
///
148+
/// Note that all `char`s are valid [`u32`]s, and can be cast to one with
149+
/// `as`:
150+
///
151+
/// ```
152+
/// let c = '💯';
153+
/// let i = c as u32;
154+
///
155+
/// assert_eq!(128175, i);
156+
/// ```
157+
///
158+
/// However, the reverse is not true: not all valid [`u32`]s are valid
159+
/// `char`s. `from_u32_unchecked()` will ignore this, and blindly cast to
160+
/// `char`, possibly creating an invalid one.
161+
///
162+
/// [`u32`]: primitive.u32.html
163+
///
164+
/// # Safety
165+
///
166+
/// This function is unsafe, as it may construct invalid `char` values.
167+
///
168+
/// For a safe version of this function, see the [`from_u32`] function.
169+
///
170+
/// [`from_u32`]: #method.from_u32
171+
///
172+
/// # Examples
173+
///
174+
/// Basic usage:
175+
///
176+
/// ```
177+
/// use std::char;
178+
///
179+
/// let c = unsafe { char::from_u32_unchecked(0x2764) };
180+
///
181+
/// assert_eq!('❤', c);
182+
/// ```
183+
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
184+
#[inline]
185+
pub unsafe fn from_u32_unchecked(i: u32) -> char {
186+
super::convert::from_u32_unchecked(i)
187+
}
188+
189+
/// Converts a digit in the given radix to a `char`.
190+
///
191+
/// A 'radix' here is sometimes also called a 'base'. A radix of two
192+
/// indicates a binary number, a radix of ten, decimal, and a radix of
193+
/// sixteen, hexadecimal, to give some common values. Arbitrary
194+
/// radices are supported.
195+
///
196+
/// `from_digit()` will return `None` if the input is not a digit in
197+
/// the given radix.
198+
///
199+
/// # Panics
200+
///
201+
/// Panics if given a radix larger than 36.
202+
///
203+
/// # Examples
204+
///
205+
/// Basic usage:
206+
///
207+
/// ```
208+
/// use std::char;
209+
///
210+
/// let c = char::from_digit(4, 10);
211+
///
212+
/// assert_eq!(Some('4'), c);
213+
///
214+
/// // Decimal 11 is a single digit in base 16
215+
/// let c = char::from_digit(11, 16);
216+
///
217+
/// assert_eq!(Some('b'), c);
218+
/// ```
219+
///
220+
/// Returning `None` when the input is not a digit:
221+
///
222+
/// ```
223+
/// use std::char;
224+
///
225+
/// let c = char::from_digit(20, 10);
226+
///
227+
/// assert_eq!(None, c);
228+
/// ```
229+
///
230+
/// Passing a large radix, causing a panic:
231+
///
232+
/// ```
233+
/// use std::thread;
234+
/// use std::char;
235+
///
236+
/// let result = thread::spawn(|| {
237+
/// // this panics
238+
/// let c = char::from_digit(1, 37);
239+
/// }).join();
240+
///
241+
/// assert!(result.is_err());
242+
/// ```
243+
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
244+
#[inline]
245+
pub fn from_digit(num: u32, radix: u32) -> Option<char> {
246+
super::convert::from_digit(num, radix)
247+
}
248+
12249
/// Checks if a `char` is a digit in the given radix.
13250
///
14251
/// A 'radix' here is sometimes also called a 'base'. A radix of two
@@ -575,8 +812,9 @@ impl char {
575812
/// assert!(!'A'.is_lowercase());
576813
/// assert!(!'Δ'.is_lowercase());
577814
///
578-
/// // The various Chinese scripts do not have case, and so:
815+
/// // The various Chinese scripts and punctuation do not have case, and so:
579816
/// assert!(!'中'.is_lowercase());
817+
/// assert!(!' '.is_lowercase());
580818
/// ```
581819
#[stable(feature = "rust1", since = "1.0.0")]
582820
#[inline]
@@ -606,8 +844,9 @@ impl char {
606844
/// assert!('A'.is_uppercase());
607845
/// assert!('Δ'.is_uppercase());
608846
///
609-
/// // The various Chinese scripts do not have case, and so:
847+
/// // The various Chinese scripts and punctuation do not have case, and so:
610848
/// assert!(!'中'.is_uppercase());
849+
/// assert!(!' '.is_uppercase());
611850
/// ```
612851
#[stable(feature = "rust1", since = "1.0.0")]
613852
#[inline]

src/libcore/char/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ const MAX_THREE_B: u32 = 0x10000;
9292
/// [Unicode Scalar Value]: http://www.unicode.org/glossary/#unicode_scalar_value
9393
/// [Code Point]: http://www.unicode.org/glossary/#code_point
9494
#[stable(feature = "rust1", since = "1.0.0")]
95-
pub const MAX: char = '\u{10ffff}';
95+
pub const MAX: char = char::MAX;
9696

9797
/// `U+FFFD REPLACEMENT CHARACTER` (�) is used in Unicode to represent a
9898
/// decoding error.
9999
///
100100
/// It can occur, for example, when giving ill-formed UTF-8 bytes to
101101
/// [`String::from_utf8_lossy`](../../std/string/struct.String.html#method.from_utf8_lossy).
102102
#[stable(feature = "decode_utf16", since = "1.9.0")]
103-
pub const REPLACEMENT_CHARACTER: char = '\u{FFFD}';
103+
pub const REPLACEMENT_CHARACTER: char = char::REPLACEMENT_CHARACTER;
104104

105105
/// Returns an iterator that yields the hexadecimal Unicode escape of a
106106
/// character, as `char`s.

src/librustc_codegen_llvm/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl CodegenBackend for LlvmCodegenBackend {
208208
}
209209
PrintRequest::CodeModels => {
210210
println!("Available code models:");
211-
for name in &["small", "kernel", "medium", "large"] {
211+
for name in &["tiny", "small", "kernel", "medium", "large"] {
212212
println!(" {}", name);
213213
}
214214
println!();

src/librustc_codegen_ssa/back/link.rs

+49
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,55 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
611611
.note(&format!("{:?}", &cmd))
612612
.note(&escape_string(&output))
613613
.emit();
614+
615+
// If MSVC's `link.exe` was expected but the return code
616+
// is not a Microsoft LNK error then suggest a way to fix or
617+
// install the Visual Studio build tools.
618+
if let Some(code) = prog.status.code() {
619+
if sess.target.target.options.is_like_msvc
620+
&& flavor == LinkerFlavor::Msvc
621+
// Respect the command line override
622+
&& sess.opts.cg.linker.is_none()
623+
// Match exactly "link.exe"
624+
&& linker_path.to_str() == Some("link.exe")
625+
// All Microsoft `link.exe` linking error codes are
626+
// four digit numbers in the range 1000 to 9999 inclusive
627+
&& (code < 1000 || code > 9999)
628+
{
629+
let is_vs_installed = windows_registry::find_vs_version().is_ok();
630+
let has_linker = windows_registry::find_tool(
631+
&sess.opts.target_triple.triple(),
632+
"link.exe",
633+
)
634+
.is_some();
635+
636+
sess.note_without_error("`link.exe` returned an unexpected error");
637+
if is_vs_installed && has_linker {
638+
// the linker is broken
639+
sess.note_without_error(
640+
"the Visual Studio build tools may need to be repaired \
641+
using the Visual Studio installer",
642+
);
643+
sess.note_without_error(
644+
"or a necessary component may be missing from the \
645+
\"C++ build tools\" workload",
646+
);
647+
} else if is_vs_installed {
648+
// the linker is not installed
649+
sess.note_without_error(
650+
"in the Visual Studio installer, ensure the \
651+
\"C++ build tools\" workload is selected",
652+
);
653+
} else {
654+
// visual studio is not installed
655+
sess.note_without_error(
656+
"you may need to install Visual Studio build tools with the \
657+
\"C++ build tools\" workload",
658+
);
659+
}
660+
}
661+
}
662+
614663
sess.abort_if_errors();
615664
}
616665
info!("linker stderr:\n{}", escape_string(&prog.stderr));

src/librustc_middle/ich/hcx.rs

-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ impl<'a> StableHashingContext<'a> {
135135
self.definitions.def_path_hash(def_id)
136136
}
137137

138-
#[inline]
139-
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
140-
self.definitions.node_id_to_hir_id(node_id)
141-
}
142-
143138
#[inline]
144139
pub fn hash_bodies(&self) -> bool {
145140
self.hash_bodies

src/librustc_target/spec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl FromStr for CodeModel {
322322

323323
fn from_str(s: &str) -> Result<CodeModel, ()> {
324324
Ok(match s {
325-
// "tiny" => CodeModel::Tiny, // Not exposed to users right now.
325+
"tiny" => CodeModel::Tiny,
326326
"small" => CodeModel::Small,
327327
"kernel" => CodeModel::Kernel,
328328
"medium" => CodeModel::Medium,

0 commit comments

Comments
 (0)