Skip to content

Commit 033aa09

Browse files
committed
Auto merge of rust-lang#110919 - JohnTitor:rollup-9phs2vx, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#109702 (configure --set support list as arguments) - rust-lang#110620 (Document `const {}` syntax for `std::thread_local`.) - rust-lang#110721 (format panic message only once) - rust-lang#110881 (refactor(docs): remove macro resolution fallback) - rust-lang#110893 (remove inline const deadcode in typeck) - rust-lang#110898 (Remove unused std::sys_common::thread_local_key::Key) - rust-lang#110909 (Skip `rustc` version detection on macOS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9a3258f + 00b9ce5 commit 033aa09

File tree

11 files changed

+110
-117
lines changed

11 files changed

+110
-117
lines changed

compiler/rustc_hir_typeck/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ fn typeck_with_fallback<'tcx>(
221221
}))
222222
} else if let Node::AnonConst(_) = node {
223223
match tcx.hir().get(tcx.hir().parent_id(id)) {
224-
Node::Expr(&hir::Expr {
225-
kind: hir::ExprKind::ConstBlock(ref anon_const), ..
226-
}) if anon_const.hir_id == id => Some(fcx.next_ty_var(TypeVariableOrigin {
227-
kind: TypeVariableOriginKind::TypeInference,
228-
span,
229-
})),
230224
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), .. })
231225
if anon_const.hir_id == id =>
232226
{

library/std/src/sys_common/thread_local_key.rs

-61
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,6 @@ pub struct StaticKey {
8787
dtor: Option<unsafe extern "C" fn(*mut u8)>,
8888
}
8989

90-
/// A type for a safely managed OS-based TLS slot.
91-
///
92-
/// This type allocates an OS TLS key when it is initialized and will deallocate
93-
/// the key when it falls out of scope. When compared with `StaticKey`, this
94-
/// type is entirely safe to use.
95-
///
96-
/// Implementations will likely, however, contain unsafe code as this type only
97-
/// operates on `*mut u8`, a raw pointer.
98-
///
99-
/// # Examples
100-
///
101-
/// ```ignore (cannot-doctest-private-modules)
102-
/// use tls::os::Key;
103-
///
104-
/// let key = Key::new(None);
105-
/// assert!(key.get().is_null());
106-
/// key.set(1 as *mut u8);
107-
/// assert!(!key.get().is_null());
108-
///
109-
/// drop(key); // deallocate this TLS slot.
110-
/// ```
111-
pub struct Key {
112-
key: imp::Key,
113-
}
114-
11590
/// Constant initialization value for static TLS keys.
11691
///
11792
/// This value specifies no destructor by default.
@@ -194,39 +169,3 @@ impl StaticKey {
194169
}
195170
}
196171
}
197-
198-
impl Key {
199-
/// Creates a new managed OS TLS key.
200-
///
201-
/// This key will be deallocated when the key falls out of scope.
202-
///
203-
/// The argument provided is an optionally-specified destructor for the
204-
/// value of this TLS key. When a thread exits and the value for this key
205-
/// is non-null the destructor will be invoked. The TLS value will be reset
206-
/// to null before the destructor is invoked.
207-
///
208-
/// Note that the destructor will not be run when the `Key` goes out of
209-
/// scope.
210-
#[inline]
211-
pub fn new(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
212-
Key { key: unsafe { imp::create(dtor) } }
213-
}
214-
215-
/// See StaticKey::get
216-
#[inline]
217-
pub fn get(&self) -> *mut u8 {
218-
unsafe { imp::get(self.key) }
219-
}
220-
221-
/// See StaticKey::set
222-
#[inline]
223-
pub fn set(&self, val: *mut u8) {
224-
unsafe { imp::set(self.key, val) }
225-
}
226-
}
227-
228-
impl Drop for Key {
229-
fn drop(&mut self) {
230-
unsafe { imp::destroy(self.key) }
231-
}
232-
}

library/std/src/sys_common/thread_local_key/tests.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
use super::{Key, StaticKey};
1+
use super::StaticKey;
22
use core::ptr;
33

4-
fn assert_sync<T: Sync>() {}
5-
fn assert_send<T: Send>() {}
6-
7-
#[test]
8-
fn smoke() {
9-
assert_sync::<Key>();
10-
assert_send::<Key>();
11-
12-
let k1 = Key::new(None);
13-
let k2 = Key::new(None);
14-
assert!(k1.get().is_null());
15-
assert!(k2.get().is_null());
16-
k1.set(ptr::invalid_mut(1));
17-
k2.set(ptr::invalid_mut(2));
18-
assert_eq!(k1.get() as usize, 1);
19-
assert_eq!(k2.get() as usize, 2);
20-
}
21-
224
#[test]
235
fn statik() {
246
static K1: StaticKey = StaticKey::new(None);

library/std/src/thread/local.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,28 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
134134
/// thread_local! {
135135
/// pub static FOO: RefCell<u32> = RefCell::new(1);
136136
///
137-
/// #[allow(unused)]
138137
/// static BAR: RefCell<f32> = RefCell::new(1.0);
139138
/// }
140-
/// # fn main() {}
139+
///
140+
/// FOO.with(|foo| assert_eq!(*foo.borrow(), 1));
141+
/// BAR.with(|bar| assert_eq!(*bar.borrow(), 1.0));
142+
/// ```
143+
///
144+
/// This macro supports a special `const {}` syntax that can be used
145+
/// when the initialization expression can be evaluated as a constant.
146+
/// This can enable a more efficient thread local implementation that
147+
/// can avoid lazy initialization. For types that do not
148+
/// [need to be dropped][crate::mem::needs_drop], this can enable an
149+
/// even more efficient implementation that does not need to
150+
/// track any additional state.
151+
///
152+
/// ```
153+
/// use std::cell::Cell;
154+
/// thread_local! {
155+
/// pub static FOO: Cell<u32> = const { Cell::new(1) };
156+
/// }
157+
///
158+
/// FOO.with(|foo| assert_eq!(foo.get(), 1));
141159
/// ```
142160
///
143161
/// See [`LocalKey` documentation][`std::thread::LocalKey`] for more

src/bootstrap/bootstrap.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,25 @@ def default_build_triple(verbose):
209209
# install, use their preference. This fixes most issues with Windows builds
210210
# being detected as GNU instead of MSVC.
211211
default_encoding = sys.getdefaultencoding()
212-
try:
213-
version = subprocess.check_output(["rustc", "--version", "--verbose"],
214-
stderr=subprocess.DEVNULL)
215-
version = version.decode(default_encoding)
216-
host = next(x for x in version.split('\n') if x.startswith("host: "))
217-
triple = host.split("host: ")[1]
218-
if verbose:
219-
print("detected default triple {} from pre-installed rustc".format(triple))
220-
return triple
221-
except Exception as e:
212+
213+
if sys.platform == 'darwin':
222214
if verbose:
223-
print("pre-installed rustc not detected: {}".format(e))
215+
print("not using rustc detection as it is unreliable on macOS")
224216
print("falling back to auto-detect")
217+
else:
218+
try:
219+
version = subprocess.check_output(["rustc", "--version", "--verbose"],
220+
stderr=subprocess.DEVNULL)
221+
version = version.decode(default_encoding)
222+
host = next(x for x in version.split('\n') if x.startswith("host: "))
223+
triple = host.split("host: ")[1]
224+
if verbose:
225+
print("detected default triple {} from pre-installed rustc".format(triple))
226+
return triple
227+
except Exception as e:
228+
if verbose:
229+
print("pre-installed rustc not detected: {}".format(e))
230+
print("falling back to auto-detect")
225231

226232
required = sys.platform != 'win32'
227233
ostype = require(["uname", "-s"], exit=required)

src/bootstrap/bootstrap_test.py

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ def test_set_top_level(self):
112112
build = self.serialize_and_parse(["--set", "profile=compiler"])
113113
self.assertEqual(build.get_toml("profile"), 'compiler')
114114

115+
def test_set_codegen_backends(self):
116+
build = self.serialize_and_parse(["--set", "rust.codegen-backends=cranelift"])
117+
self.assertNotEqual(build.config_toml.find("codegen-backends = ['cranelift']"), -1)
118+
build = self.serialize_and_parse(["--set", "rust.codegen-backends=cranelift,llvm"])
119+
self.assertNotEqual(build.config_toml.find("codegen-backends = ['cranelift', 'llvm']"), -1)
120+
build = self.serialize_and_parse(["--enable-full-tools"])
121+
self.assertNotEqual(build.config_toml.find("codegen-backends = ['llvm']"), -1)
122+
115123
if __name__ == '__main__':
116124
SUITE = unittest.TestSuite()
117125
TEST_LOADER = unittest.TestLoader()

src/bootstrap/configure.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ def v(*args):
153153
"experimental LLVM targets to build")
154154
v("release-channel", "rust.channel", "the name of the release channel to build")
155155
v("release-description", "rust.description", "optional descriptive string for version output")
156-
v("dist-compression-formats", None,
157-
"comma-separated list of compression formats to use")
156+
v("dist-compression-formats", None, "List of compression formats to use")
158157

159158
# Used on systems where "cc" is unavailable
160159
v("default-linker", "rust.default-linker", "the default linker")
@@ -168,8 +167,8 @@ def v(*args):
168167
v("tools", None, "List of extended tools will be installed")
169168
v("codegen-backends", None, "List of codegen backends to build")
170169
v("build", "build.build", "GNUs ./configure syntax LLVM build triple")
171-
v("host", None, "GNUs ./configure syntax LLVM host triples")
172-
v("target", None, "GNUs ./configure syntax LLVM target triples")
170+
v("host", None, "List of GNUs ./configure syntax LLVM host triples")
171+
v("target", None, "List of GNUs ./configure syntax LLVM target triples")
173172

174173
v("set", None, "set arbitrary key/value pairs in TOML configuration")
175174

@@ -182,6 +181,11 @@ def err(msg):
182181
print("configure: error: " + msg)
183182
sys.exit(1)
184183

184+
def is_value_list(key):
185+
for option in options:
186+
if option.name == key and option.desc.startswith('List of'):
187+
return True
188+
return False
185189

186190
if '--help' in sys.argv or '-h' in sys.argv:
187191
print('Usage: ./configure [options]')
@@ -295,6 +299,8 @@ def set(key, value, config):
295299
parts = key.split('.')
296300
for i, part in enumerate(parts):
297301
if i == len(parts) - 1:
302+
if is_value_list(part) and isinstance(value, str):
303+
value = value.split(',')
298304
arr[part] = value
299305
else:
300306
if part not in arr:

src/librustdoc/passes/collect_intra_doc_links.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,8 @@ impl LinkCollector<'_, '_> {
12951295
}
12961296
}
12971297
}
1298-
resolution_failure(self, diag, path_str, disambiguator, smallvec![err])
1298+
resolution_failure(self, diag, path_str, disambiguator, smallvec![err]);
1299+
return vec![];
12991300
}
13001301
}
13011302
}
@@ -1331,13 +1332,14 @@ impl LinkCollector<'_, '_> {
13311332
.fold(0, |acc, res| if let Ok(res) = res { acc + res.len() } else { acc });
13321333

13331334
if len == 0 {
1334-
return resolution_failure(
1335+
resolution_failure(
13351336
self,
13361337
diag,
13371338
path_str,
13381339
disambiguator,
13391340
candidates.into_iter().filter_map(|res| res.err()).collect(),
13401341
);
1342+
return vec![];
13411343
} else if len == 1 {
13421344
candidates.into_iter().filter_map(|res| res.ok()).flatten().collect::<Vec<_>>()
13431345
} else {
@@ -1642,9 +1644,8 @@ fn resolution_failure(
16421644
path_str: &str,
16431645
disambiguator: Option<Disambiguator>,
16441646
kinds: SmallVec<[ResolutionFailure<'_>; 3]>,
1645-
) -> Vec<(Res, Option<DefId>)> {
1647+
) {
16461648
let tcx = collector.cx.tcx;
1647-
let mut recovered_res = None;
16481649
report_diagnostic(
16491650
tcx,
16501651
BROKEN_INTRA_DOC_LINKS,
@@ -1736,19 +1737,25 @@ fn resolution_failure(
17361737

17371738
if !path_str.contains("::") {
17381739
if disambiguator.map_or(true, |d| d.ns() == MacroNS)
1739-
&& let Some(&res) = collector.cx.tcx.resolutions(()).all_macro_rules
1740-
.get(&Symbol::intern(path_str))
1740+
&& collector
1741+
.cx
1742+
.tcx
1743+
.resolutions(())
1744+
.all_macro_rules
1745+
.get(&Symbol::intern(path_str))
1746+
.is_some()
17411747
{
17421748
diag.note(format!(
17431749
"`macro_rules` named `{path_str}` exists in this crate, \
17441750
but it is not in scope at this link's location"
17451751
));
1746-
recovered_res = res.try_into().ok().map(|res| (res, None));
17471752
} else {
17481753
// If the link has `::` in it, assume it was meant to be an
17491754
// intra-doc link. Otherwise, the `[]` might be unrelated.
1750-
diag.help("to escape `[` and `]` characters, \
1751-
add '\\' before them like `\\[` or `\\]`");
1755+
diag.help(
1756+
"to escape `[` and `]` characters, \
1757+
add '\\' before them like `\\[` or `\\]`",
1758+
);
17521759
}
17531760
}
17541761

@@ -1854,11 +1861,6 @@ fn resolution_failure(
18541861
}
18551862
},
18561863
);
1857-
1858-
match recovered_res {
1859-
Some(r) => vec![r],
1860-
None => Vec::new(),
1861-
}
18621864
}
18631865

18641866
fn report_multiple_anchors(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>) {

tests/rustdoc/issue-106142.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @has 'issue_106142/a/index.html'
2+
// @count 'issue_106142/a/index.html' '//ul[@class="item-table"]//li//a' 1
3+
4+
#![allow(rustdoc::broken_intra_doc_links)]
5+
6+
pub mod a {
7+
/// [`m`]
8+
pub fn f() {}
9+
10+
#[macro_export]
11+
macro_rules! m {
12+
() => {};
13+
}
14+
}

tests/ui/panics/fmt-only-once.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-fail
2+
// check-run-results
3+
// exec-env:RUST_BACKTRACE=0
4+
5+
// Test that we format the panic message only once.
6+
// Regression test for https://github.com/rust-lang/rust/issues/110717
7+
8+
use std::fmt;
9+
10+
struct PrintOnFmt;
11+
12+
impl fmt::Display for PrintOnFmt {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
eprintln!("fmt");
15+
f.write_str("PrintOnFmt")
16+
}
17+
}
18+
19+
fn main() {
20+
panic!("{}", PrintOnFmt)
21+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fmt
2+
thread 'main' panicked at 'PrintOnFmt', $DIR/fmt-only-once.rs:20:5
3+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)