Skip to content

Commit 69370dc

Browse files
committed
Auto merge of #153456 - JonathanBrouwer:rollup-SJuaNHc, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #153399 (constify `Vec::{into, from}_raw_parts{_in|_alloc}`) - #153436 (Use shlex instead of shell-words) - #150845 (bootstrap: minimal fix for ./x install src with build.docs = false) - #152906 (Make `const_lit_matches_ty` check literal suffixes for exact type match) - #153378 (Rename `QueryCache::iter` to `for_each`) - #153386 (Minor query cleanups) - #153422 (Add a comment explaining the 'tcx lifetime.) - #153435 (Fix obtaining def_id from unresolved segment) - #153453 (Fix ICEs due to incomplete typechecking on struct literals with syntax errors.)
2 parents 64b72a1 + 11c4bea commit 69370dc

30 files changed

Lines changed: 209 additions & 150 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,7 @@ version = "0.0.0"
41214121
dependencies = [
41224122
"cc",
41234123
"libc",
4124-
"shell-words",
4124+
"shlex",
41254125
]
41264126

41274127
[[package]]
@@ -5116,12 +5116,6 @@ dependencies = [
51165116
"lazy_static",
51175117
]
51185118

5119-
[[package]]
5120-
name = "shell-words"
5121-
version = "1.1.1"
5122-
source = "registry+https://github.com/rust-lang/crates.io-index"
5123-
checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
5124-
51255119
[[package]]
51265120
name = "shlex"
51275121
version = "1.3.0"

compiler/rustc_data_structures/src/vec_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ where
341341
}
342342
}
343343

344-
pub fn iter(&self, f: &mut dyn FnMut(&K, &V, I)) {
344+
pub fn for_each(&self, f: &mut dyn FnMut(&K, &V, I)) {
345345
for idx in 0..self.len.load(Ordering::Acquire) {
346346
let key = SlotIndex::from_index(idx as u32);
347347
match unsafe { key.get(&self.present) } {

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,17 +572,15 @@ fn get_delegation_user_specified_args<'tcx>(
572572
.opt_delegation_generics()
573573
.expect("Lowering delegation");
574574

575-
let get_segment = |hir_id: HirId| -> (&'tcx PathSegment<'tcx>, DefId) {
575+
let get_segment = |hir_id: HirId| -> Option<(&'tcx PathSegment<'tcx>, DefId)> {
576576
let segment = tcx.hir_node(hir_id).expect_path_segment();
577-
let def_id = segment.res.def_id();
578-
579-
(segment, def_id)
577+
segment.res.opt_def_id().map(|def_id| (segment, def_id))
580578
};
581579

582580
let ctx = ItemCtxt::new(tcx, delegation_id);
583581
let lowerer = ctx.lowerer();
584582

585-
let parent_args = info.parent_args_segment_id.map(get_segment).map(|(segment, def_id)| {
583+
let parent_args = info.parent_args_segment_id.and_then(get_segment).map(|(segment, def_id)| {
586584
let self_ty = get_delegation_self_ty(tcx, delegation_id);
587585

588586
lowerer
@@ -598,7 +596,7 @@ fn get_delegation_user_specified_args<'tcx>(
598596
.as_slice()
599597
});
600598

601-
let child_args = info.child_args_segment_id.map(get_segment).map(|(segment, def_id)| {
599+
let child_args = info.child_args_segment_id.and_then(get_segment).map(|(segment, def_id)| {
602600
let parent_args = if let Some(parent_args) = parent_args {
603601
parent_args
604602
} else {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,14 +2203,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22032203
};
22042204
self.typeck_results.borrow_mut().fru_field_types_mut().insert(expr.hir_id, fru_tys);
22052205
}
2206-
rustc_hir::StructTailExpr::NoneWithError(ErrorGuaranteed { .. }) => {
2206+
rustc_hir::StructTailExpr::NoneWithError(guaranteed) => {
22072207
// If parsing the struct recovered from a syntax error, do not report missing
22082208
// fields. This prevents spurious errors when a field is intended to be present
22092209
// but a preceding syntax error caused it not to be parsed. For example, if a
22102210
// struct type `StructName` has fields `foo` and `bar`, then
22112211
// StructName { foo(), bar: 2 }
22122212
// will not successfully parse a field `foo`, but we will not mention that,
22132213
// since the syntax error has already been reported.
2214+
2215+
// Signal that type checking has failed, even though we haven’t emitted a diagnostic
2216+
// about it ourselves.
2217+
self.infcx.set_tainted_by_errors(guaranteed);
22142218
}
22152219
rustc_hir::StructTailExpr::None => {
22162220
if adt_kind != AdtKind::Union

compiler/rustc_interface/src/passes.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,17 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
964964

965965
let incremental = dep_graph.is_fully_enabled();
966966

967+
// Note: this function body is the origin point of the widely-used 'tcx lifetime.
968+
//
969+
// `gcx_cell` is defined here and `&gcx_cell` is passed to `create_global_ctxt`, which then
970+
// actually creates the `GlobalCtxt` with a `gcx_cell.get_or_init(...)` call. This is done so
971+
// that the resulting reference has the type `&'tcx GlobalCtxt<'tcx>`, which is what `TyCtxt`
972+
// needs. If we defined and created the `GlobalCtxt` within `create_global_ctxt` then its type
973+
// would be `&'a GlobalCtxt<'tcx>`, with two lifetimes.
974+
//
975+
// Similarly, by creating `arena` here and passing in `&arena`, that reference has the type
976+
// `&'tcx WorkerLocal<Arena<'tcx>>`, also with one lifetime. And likewise for `hir_arena`.
977+
967978
let gcx_cell = OnceLock::new();
968979
let arena = WorkerLocal::new(|_| Arena::default());
969980
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());

compiler/rustc_llvm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ libc = "0.2.73"
1212
# tidy-alphabetical-start
1313
# `cc` updates often break things, so we pin it here.
1414
cc = "=1.2.16"
15-
shell-words = "1.1.1"
15+
shlex = "1.3.0"
1616
# tidy-alphabetical-end
1717

1818
[features]

compiler/rustc_llvm/build.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::fmt::Display;
55
use std::path::{Path, PathBuf};
66
use std::process::{Command, Output, Stdio};
77
use std::str::SplitWhitespace;
8-
use std::vec::IntoIter;
8+
9+
use shlex::Shlex;
910

1011
const OPTIONAL_COMPONENTS: &[&str] = &[
1112
"x86",
@@ -121,9 +122,8 @@ enum LlvmConfigOutput {
121122
UnquotedPaths(String),
122123
}
123124

124-
#[derive(Clone)]
125125
enum SplitLlvmConfigOutput<'a> {
126-
QuotedPaths(IntoIter<String>),
126+
QuotedPaths(Shlex<'a>),
127127
UnquotedPaths(SplitWhitespace<'a>),
128128
}
129129

@@ -137,14 +137,22 @@ impl<'a> Iterator for SplitLlvmConfigOutput<'a> {
137137
}
138138
}
139139

140+
impl Drop for SplitLlvmConfigOutput<'_> {
141+
fn drop(&mut self) {
142+
if let Self::QuotedPaths(shlex) = self {
143+
assert!(!shlex.had_error, "error parsing llvm-config output");
144+
}
145+
}
146+
}
147+
140148
impl<'a> IntoIterator for &'a LlvmConfigOutput {
141149
type Item = Cow<'a, str>;
142150
type IntoIter = SplitLlvmConfigOutput<'a>;
143151
fn into_iter(self) -> Self::IntoIter {
144152
match self {
145-
LlvmConfigOutput::QuotedPaths(output) => SplitLlvmConfigOutput::QuotedPaths(
146-
shell_words::split(&output).expect("matched quotes").into_iter(),
147-
),
153+
LlvmConfigOutput::QuotedPaths(output) => {
154+
SplitLlvmConfigOutput::QuotedPaths(Shlex::new(output))
155+
}
148156
LlvmConfigOutput::UnquotedPaths(output) => {
149157
SplitLlvmConfigOutput::UnquotedPaths(output.split_whitespace())
150158
}
@@ -229,7 +237,6 @@ fn main() {
229237
let mut cmd = Command::new(&llvm_config);
230238
cmd.arg("--cxxflags");
231239
let cxxflags = quoted_split(cmd);
232-
let mut cxxflags_iter = cxxflags.into_iter();
233240
let mut cfg = cc::Build::new();
234241
cfg.warnings(false);
235242

@@ -242,7 +249,7 @@ fn main() {
242249
if std::env::var_os("CI").is_some() && !target.contains("msvc") {
243250
cfg.warnings_into_errors(true);
244251
}
245-
for flag in cxxflags_iter.clone() {
252+
for flag in &cxxflags {
246253
// Ignore flags like `-m64` when we're doing a cross build
247254
if is_crossed && flag.starts_with("-m") {
248255
continue;
@@ -435,13 +442,16 @@ fn main() {
435442
// dependencies.
436443
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
437444
if let Some(s) = llvm_linker_flags {
438-
for lib in shell_words::split(&s.into_string().unwrap()).expect("matched quotes") {
445+
let linker_flags = s.into_string().unwrap();
446+
let mut shlex = Shlex::new(&linker_flags);
447+
for lib in shlex.by_ref() {
439448
if let Some(stripped) = lib.strip_prefix("-l") {
440449
println!("cargo:rustc-link-lib={stripped}");
441450
} else if let Some(stripped) = lib.strip_prefix("-L") {
442451
println!("cargo:rustc-link-search=native={stripped}");
443452
}
444453
}
454+
assert!(!shlex.had_error, "error parsing LLVM_LINKER_FLAGS");
445455
}
446456

447457
let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
@@ -476,15 +486,15 @@ fn main() {
476486
// C++ runtime library
477487
if !target.contains("msvc") {
478488
if let Some(s) = llvm_static_stdcpp {
479-
assert!(cxxflags_iter.all(|flag| flag != "-stdlib=libc++"));
489+
assert!(cxxflags.into_iter().all(|flag| flag != "-stdlib=libc++"));
480490
let path = PathBuf::from(s);
481491
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
482492
if target.contains("windows") {
483493
println!("cargo:rustc-link-lib=static:-bundle={stdcppname}");
484494
} else {
485495
println!("cargo:rustc-link-lib=static={stdcppname}");
486496
}
487-
} else if cxxflags_iter.any(|flag| flag == "-stdlib=libc++") {
497+
} else if cxxflags.into_iter().any(|flag| flag == "-stdlib=libc++") {
488498
println!("cargo:rustc-link-lib=c++");
489499
} else {
490500
println!("cargo:rustc-link-lib={stdcppname}");

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt::Debug;
22
use std::hash::Hash;
3-
use std::marker::PhantomData;
43
use std::sync::Arc;
54
use std::sync::atomic::{AtomicU32, Ordering};
65

@@ -1377,8 +1376,6 @@ pub struct TaskDeps {
13771376
/// scan. If the number is higher, a hashset has better perf. This field is that hashset. It's
13781377
/// only used if the number of elements in `reads` exceeds `LINEAR_SCAN_MAX`.
13791378
read_set: FxHashSet<DepNodeIndex>,
1380-
1381-
phantom_data: PhantomData<DepNode>,
13821379
}
13831380

13841381
impl TaskDeps {
@@ -1392,7 +1389,6 @@ impl TaskDeps {
13921389
node,
13931390
reads: EdgesVec::new(),
13941391
read_set: FxHashSet::with_capacity_and_hasher(read_set_capacity, Default::default()),
1395-
phantom_data: PhantomData,
13961392
}
13971393
}
13981394
}

compiler/rustc_middle/src/query/caches.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ pub trait QueryCache: Sized {
2828
/// value by executing the query or loading a cached value from disk.
2929
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);
3030

31-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
31+
/// Calls a closure on each entry in this cache.
32+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
3233

34+
/// Returns the number of entries currently in this cache.
35+
///
36+
/// Useful for reserving capacity in data structures that will hold the
37+
/// output of a call to [`Self::for_each`].
3338
fn len(&self) -> usize;
3439
}
3540

@@ -65,7 +70,7 @@ where
6570
self.cache.insert(key, (value, index));
6671
}
6772

68-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
73+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
6974
for shard in self.cache.lock_shards() {
7075
for (k, v) in shard.iter() {
7176
f(k, &v.0, v.1);
@@ -107,7 +112,7 @@ where
107112
self.cache.set((value, index)).ok();
108113
}
109114

110-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
115+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
111116
if let Some(value) = self.cache.get() {
112117
f(&(), &value.0, value.1)
113118
}
@@ -160,11 +165,11 @@ where
160165
}
161166
}
162167

163-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
164-
self.local.iter(&mut |key, value, index| {
168+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
169+
self.local.for_each(&mut |key, value, index| {
165170
f(&DefId { krate: LOCAL_CRATE, index: *key }, value, index);
166171
});
167-
self.foreign.iter(f);
172+
self.foreign.for_each(f);
168173
}
169174

170175
fn len(&self) -> usize {
@@ -190,8 +195,8 @@ where
190195
self.complete(key, value, index)
191196
}
192197

193-
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
194-
self.iter(f)
198+
fn for_each(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
199+
self.for_each(f)
195200
}
196201

197202
fn len(&self) -> usize {

compiler/rustc_middle/src/ty/consts/lit.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_ast::LitKind;
1+
use rustc_ast::{LitFloatType, LitIntType, LitKind};
22
use rustc_hir;
33
use rustc_macros::HashStable;
44

@@ -44,10 +44,17 @@ pub fn const_lit_matches_ty<'tcx>(
4444
{
4545
true
4646
}
47-
(LitKind::Int(..), ty::Uint(_)) if !neg => true,
48-
(LitKind::Int(..), ty::Int(_)) => true,
47+
(LitKind::Int(_, LitIntType::Unsigned(lit_ty)), ty::Uint(expect_ty)) if !neg => {
48+
lit_ty == *expect_ty
49+
}
50+
(LitKind::Int(_, LitIntType::Signed(lit_ty)), ty::Int(expect_ty)) => lit_ty == *expect_ty,
51+
(LitKind::Int(_, LitIntType::Unsuffixed), ty::Uint(_)) if !neg => true,
52+
(LitKind::Int(_, LitIntType::Unsuffixed), ty::Int(_)) => true,
4953
(LitKind::Bool(..), ty::Bool) => true,
50-
(LitKind::Float(..), ty::Float(_)) => true,
54+
(LitKind::Float(_, LitFloatType::Suffixed(lit_ty)), ty::Float(expect_ty)) => {
55+
lit_ty == *expect_ty
56+
}
57+
(LitKind::Float(_, LitFloatType::Unsuffixed), ty::Float(_)) => true,
5158
(LitKind::Char(..), ty::Char) => true,
5259
(LitKind::Err(..), _) => true,
5360
_ => false,

0 commit comments

Comments
 (0)