Skip to content

Commit c5c7d2b

Browse files
committed
Auto merge of rust-lang#108421 - Dylan-DPC:rollup-mpeovxd, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - rust-lang#106541 (implement const iterator using `rustc_do_not_const_check`) - rust-lang#106918 (Rebuild BinaryHeap on unwind from retain) - rust-lang#106923 (Restore behavior when primary bundle is missing) - rust-lang#108169 (Make query keys `Copy`) - rust-lang#108287 (Add test for bad cast with deferred projection equality) - rust-lang#108370 (std: time: Avoid to use "was created" in elapsed() description) - rust-lang#108377 (Fix ICE in 'duplicate diagnostic item' diagnostic) - rust-lang#108388 (parser: provide better suggestions and errors on closures with braces missing) - rust-lang#108391 (Fix `is_terminal`'s handling of long paths on Windows.) - rust-lang#108401 (diagnostics: remove inconsistent English article "this" from E0107) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 07c993e + c77cf40 commit c5c7d2b

File tree

144 files changed

+741
-408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+741
-408
lines changed

compiler/rustc_error_messages/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ pub fn fluent_bundle(
135135

136136
let fallback_locale = langid!("en-US");
137137
let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
138-
138+
trace!(?requested_fallback_locale);
139+
if requested_fallback_locale && additional_ftl_path.is_none() {
140+
return Ok(None);
141+
}
139142
// If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
140143
// provided locale.
141144
let locale = requested_locale.clone().unwrap_or(fallback_locale);
@@ -153,7 +156,7 @@ pub fn fluent_bundle(
153156
bundle.set_use_isolating(with_directionality_markers);
154157

155158
// If the user requests the default locale then don't try to load anything.
156-
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
159+
if let Some(requested_locale) = requested_locale {
157160
let mut found_resources = false;
158161
for sysroot in user_provided_sysroot.iter_mut().chain(sysroot_candidates.iter_mut()) {
159162
sysroot.push("share");

compiler/rustc_errors/src/translation.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::TranslateError;
1+
use crate::error::{TranslateError, TranslateErrorKind};
22
use crate::snippet::Style;
33
use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle};
44
use rustc_data_structures::sync::Lrc;
@@ -95,6 +95,16 @@ pub trait Translate {
9595
// The primary bundle was present and translation succeeded
9696
Some(Ok(t)) => t,
9797

98+
// If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
99+
// just that the primary bundle doesn't contain the message being translated, so
100+
// proceed to the fallback bundle.
101+
Some(Err(
102+
primary @ TranslateError::One {
103+
kind: TranslateErrorKind::MessageMissing, ..
104+
},
105+
)) => translate_with_bundle(self.fallback_fluent_bundle())
106+
.map_err(|fallback| primary.and(fallback))?,
107+
98108
// Always yeet out for errors on debug (unless
99109
// `RUSTC_TRANSLATION_NO_DEBUG_ASSERT` is set in the environment - this allows
100110
// local runs of the test suites, of builds with debug assertions, to test the
@@ -106,9 +116,8 @@ pub trait Translate {
106116
do yeet primary
107117
}
108118

109-
// If `translate_with_bundle` returns `Err` with the primary bundle, this is likely
110-
// just that the primary bundle doesn't contain the message being translated or
111-
// something else went wrong) so proceed to the fallback bundle.
119+
// ..otherwise, for end users, an error about this wouldn't be useful or actionable, so
120+
// just hide it and try with the fallback bundle.
112121
Some(Err(primary)) => translate_with_bundle(self.fallback_fluent_bundle())
113122
.map_err(|fallback| primary.and(fallback))?,
114123

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
462462

463463
if self.gen_args.span_ext().is_some() {
464464
format!(
465-
"this {} takes {}{} {} argument{} but {} {} supplied",
465+
"{} takes {}{} {} argument{} but {} {} supplied",
466466
def_kind,
467467
quantifier,
468468
bound,

compiler/rustc_hir_typeck/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
7171
use rustc_session::config;
7272
use rustc_session::Session;
7373
use rustc_span::def_id::{DefId, LocalDefId};
74-
use rustc_span::Span;
74+
use rustc_span::{sym, Span};
7575

7676
fluent_messages! { "../locales/en-US.ftl" }
7777

@@ -207,6 +207,11 @@ fn typeck_with_fallback<'tcx>(
207207

208208
let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
209209
let param_env = tcx.param_env(def_id);
210+
let param_env = if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
211+
param_env.without_const()
212+
} else {
213+
param_env
214+
};
210215
let mut fcx = FnCtxt::new(&inh, param_env, def_id);
211216

212217
if let Some(hir::FnSig { header, decl, .. }) = fn_sig {

compiler/rustc_parse/src/parser/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,11 @@ impl<'a> Parser<'a> {
982982
let initial_semicolon = self.token.span;
983983

984984
while self.eat(&TokenKind::Semi) {
985-
let _ = self.parse_stmt(ForceCollect::Yes)?;
985+
let _ =
986+
self.parse_stmt_without_recovery(false, ForceCollect::Yes).unwrap_or_else(|e| {
987+
e.cancel();
988+
None
989+
});
986990
}
987991

988992
expect_err.set_primary_message(

compiler/rustc_passes/locales/en-US.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ passes_duplicate_diagnostic_item =
407407
408408
passes_duplicate_diagnostic_item_in_crate =
409409
duplicate diagnostic item in crate `{$crate_name}`: `{$name}`.
410+
.note = the diagnostic item is first defined in crate `{$orig_crate_name}`.
410411
411412
passes_diagnostic_item_first_defined =
412413
the diagnostic item is first defined here
413-
.note = the diagnostic item is first defined in crate `{$orig_crate_name}`.
414414
415415
passes_abi =
416416
abi: {$abi}

compiler/rustc_query_system/src/query/caches.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait QueryStorage {
2121
}
2222

2323
pub trait QueryCache: QueryStorage + Sized {
24-
type Key: Hash + Eq + Clone + Debug;
24+
type Key: Hash + Eq + Copy + Debug;
2525

2626
/// Checks if the query is already computed and in the cache.
2727
/// It returns the shard index and a lock guard to the shard,
@@ -61,7 +61,7 @@ impl<K: Eq + Hash, V: Copy + Debug> QueryStorage for DefaultCache<K, V> {
6161

6262
impl<K, V> QueryCache for DefaultCache<K, V>
6363
where
64-
K: Eq + Hash + Clone + Debug,
64+
K: Eq + Hash + Copy + Debug,
6565
V: Copy + Debug,
6666
{
6767
type Key = K;
@@ -179,7 +179,7 @@ impl<K: Eq + Idx, V: Copy + Debug> QueryStorage for VecCache<K, V> {
179179

180180
impl<K, V> QueryCache for VecCache<K, V>
181181
where
182-
K: Eq + Idx + Clone + Debug,
182+
K: Eq + Idx + Copy + Debug,
183183
V: Copy + Debug,
184184
{
185185
type Key = K;

compiler/rustc_query_system/src/query/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub type TryLoadFromDisk<Qcx, Q> =
1919
pub trait QueryConfig<Qcx: QueryContext> {
2020
const NAME: &'static str;
2121

22-
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Clone + Debug;
22+
// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
23+
// but it isn't necessary.
24+
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
2325
type Value: Debug + Copy;
2426

2527
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;

compiler/rustc_query_system/src/query/plumbing.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum QueryResult<D: DepKind> {
4848

4949
impl<K, D> QueryState<K, D>
5050
where
51-
K: Eq + Hash + Clone + Debug,
51+
K: Eq + Hash + Copy + Debug,
5252
D: DepKind,
5353
{
5454
pub fn all_inactive(&self) -> bool {
@@ -77,7 +77,7 @@ where
7777
for shard in shards.iter() {
7878
for (k, v) in shard.iter() {
7979
if let QueryResult::Started(ref job) = *v {
80-
let query = make_query(qcx, k.clone());
80+
let query = make_query(qcx, *k);
8181
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
8282
}
8383
}
@@ -91,7 +91,7 @@ where
9191
// really hurt much.)
9292
for (k, v) in self.active.try_lock()?.iter() {
9393
if let QueryResult::Started(ref job) = *v {
94-
let query = make_query(qcx, k.clone());
94+
let query = make_query(qcx, *k);
9595
jobs.insert(job.id, QueryJobInfo { query, job: job.clone() });
9696
}
9797
}
@@ -111,7 +111,7 @@ impl<K, D: DepKind> Default for QueryState<K, D> {
111111
/// This will poison the relevant query if dropped.
112112
struct JobOwner<'tcx, K, D: DepKind>
113113
where
114-
K: Eq + Hash + Clone,
114+
K: Eq + Hash + Copy,
115115
{
116116
state: &'tcx QueryState<K, D>,
117117
key: K,
@@ -163,7 +163,7 @@ where
163163

164164
impl<'tcx, K, D: DepKind> JobOwner<'tcx, K, D>
165165
where
166-
K: Eq + Hash + Clone,
166+
K: Eq + Hash + Copy,
167167
{
168168
/// Either gets a `JobOwner` corresponding the query, allowing us to
169169
/// start executing the query, or returns with the result of the query.
@@ -195,7 +195,7 @@ where
195195
let job = qcx.current_query_job();
196196
let job = QueryJob::new(id, span, job);
197197

198-
let key = entry.key().clone();
198+
let key = *entry.key();
199199
entry.insert(QueryResult::Started(job));
200200

201201
let owner = JobOwner { state, id, key };
@@ -274,7 +274,7 @@ where
274274

275275
impl<'tcx, K, D> Drop for JobOwner<'tcx, K, D>
276276
where
277-
K: Eq + Hash + Clone,
277+
K: Eq + Hash + Copy,
278278
D: DepKind,
279279
{
280280
#[inline(never)]
@@ -291,7 +291,7 @@ where
291291
QueryResult::Started(job) => job,
292292
QueryResult::Poisoned => panic!(),
293293
};
294-
shard.insert(self.key.clone(), QueryResult::Poisoned);
294+
shard.insert(self.key, QueryResult::Poisoned);
295295
job
296296
};
297297
// Also signal the completion of the job, so waiters
@@ -310,7 +310,7 @@ pub(crate) struct CycleError<D: DepKind> {
310310
/// The result of `try_start`.
311311
enum TryGetJob<'tcx, K, D>
312312
where
313-
K: Eq + Hash + Clone,
313+
K: Eq + Hash + Copy,
314314
D: DepKind,
315315
{
316316
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
@@ -358,10 +358,9 @@ where
358358
Q: QueryConfig<Qcx>,
359359
Qcx: QueryContext,
360360
{
361-
match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, span, key.clone()) {
361+
match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, span, key) {
362362
TryGetJob::NotYetStarted(job) => {
363-
let (result, dep_node_index) =
364-
execute_job::<Q, Qcx>(qcx, key.clone(), dep_node, job.id);
363+
let (result, dep_node_index) = execute_job::<Q, Qcx>(qcx, key, dep_node, job.id);
365364
if Q::FEEDABLE {
366365
// We should not compute queries that also got a value via feeding.
367366
// This can't happen, as query feeding adds the very dependencies to the fed query
@@ -551,7 +550,7 @@ where
551550
let prof_timer = qcx.dep_context().profiler().query_provider();
552551

553552
// The dep-graph for this computation is already in-place.
554-
let result = dep_graph.with_ignore(|| Q::compute(qcx, key.clone()));
553+
let result = dep_graph.with_ignore(|| Q::compute(qcx, *key));
555554

556555
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
557556

library/alloc/src/collections/binary_heap/mod.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -851,18 +851,30 @@ impl<T: Ord> BinaryHeap<T> {
851851
where
852852
F: FnMut(&T) -> bool,
853853
{
854-
let mut first_removed = self.len();
854+
struct RebuildOnDrop<'a, T: Ord> {
855+
heap: &'a mut BinaryHeap<T>,
856+
first_removed: usize,
857+
}
858+
859+
let mut guard = RebuildOnDrop { first_removed: self.len(), heap: self };
860+
855861
let mut i = 0;
856-
self.data.retain(|e| {
862+
guard.heap.data.retain(|e| {
857863
let keep = f(e);
858-
if !keep && i < first_removed {
859-
first_removed = i;
864+
if !keep && i < guard.first_removed {
865+
guard.first_removed = i;
860866
}
861867
i += 1;
862868
keep
863869
});
864-
// data[0..first_removed] is untouched, so we only need to rebuild the tail:
865-
self.rebuild_tail(first_removed);
870+
871+
impl<'a, T: Ord> Drop for RebuildOnDrop<'a, T> {
872+
fn drop(&mut self) {
873+
// data[..first_removed] is untouched, so we only need to
874+
// rebuild the tail:
875+
self.heap.rebuild_tail(self.first_removed);
876+
}
877+
}
866878
}
867879
}
868880

library/alloc/src/collections/binary_heap/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,25 @@ fn test_retain() {
474474
assert!(a.is_empty());
475475
}
476476

477+
#[test]
478+
fn test_retain_catch_unwind() {
479+
let mut heap = BinaryHeap::from(vec![3, 1, 2]);
480+
481+
// Removes the 3, then unwinds out of retain.
482+
let _ = catch_unwind(AssertUnwindSafe(|| {
483+
heap.retain(|e| {
484+
if *e == 1 {
485+
panic!();
486+
}
487+
false
488+
});
489+
}));
490+
491+
// Naively this would be [1, 2] (an invalid heap) if BinaryHeap delegates to
492+
// Vec's retain impl and then does not rebuild the heap after that unwinds.
493+
assert_eq!(heap.into_vec(), [2, 1]);
494+
}
495+
477496
// old binaryheap failed this test
478497
//
479498
// Integrity means that all elements are present after a comparison panics,

0 commit comments

Comments
 (0)