Skip to content

Commit b92c6ee

Browse files
committed
Auto merge of #69172 - JohnTitor:rollup-6cbmwcw, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #68129 (Correct inference of primitive operand type behind binary operation) - #68475 (Use a `ParamEnvAnd<Predicate>` for caching in `ObligationForest`) - #68856 (typeck: clarify def_bm adjustments & add tests for or-patterns) - #69051 (simplify_try: address some of eddyb's comments) - #69128 (Fix extra subslice lowering) - #69150 (Follow-up to #68848) - #69164 (Update pulldown-cmark dependency) Failed merges: r? @ghost
2 parents 433aae9 + a6ff1db commit b92c6ee

20 files changed

+715
-207
lines changed

Cargo.lock

+12-18
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ dependencies = [
15641564
"rand_xoshiro",
15651565
"sized-chunks",
15661566
"typenum",
1567-
"version_check 0.9.1",
1567+
"version_check",
15681568
]
15691569

15701570
[[package]]
@@ -2014,9 +2014,9 @@ dependencies = [
20142014

20152015
[[package]]
20162016
name = "memchr"
2017-
version = "2.2.0"
2017+
version = "2.3.2"
20182018
source = "registry+https://github.com/rust-lang/crates.io-index"
2019-
checksum = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
2019+
checksum = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978"
20202020

20212021
[[package]]
20222022
name = "memmap"
@@ -2604,23 +2604,23 @@ dependencies = [
26042604

26052605
[[package]]
26062606
name = "pulldown-cmark"
2607-
version = "0.5.3"
2607+
version = "0.6.1"
26082608
source = "registry+https://github.com/rust-lang/crates.io-index"
2609-
checksum = "77043da1282374688ee212dc44b3f37ff929431de9c9adc3053bd3cee5630357"
2609+
checksum = "1c205cc82214f3594e2d50686730314f817c67ffa80fe800cf0db78c3c2b9d9e"
26102610
dependencies = [
26112611
"bitflags",
2612+
"getopts",
26122613
"memchr",
26132614
"unicase",
26142615
]
26152616

26162617
[[package]]
26172618
name = "pulldown-cmark"
2618-
version = "0.6.1"
2619+
version = "0.7.0"
26192620
source = "registry+https://github.com/rust-lang/crates.io-index"
2620-
checksum = "1c205cc82214f3594e2d50686730314f817c67ffa80fe800cf0db78c3c2b9d9e"
2621+
checksum = "2c2d7fd131800e0d63df52aff46201acaab70b431a4a1ec6f0343fe8e64f35a4"
26212622
dependencies = [
26222623
"bitflags",
2623-
"getopts",
26242624
"memchr",
26252625
"unicase",
26262626
]
@@ -4160,7 +4160,7 @@ version = "0.0.0"
41604160
dependencies = [
41614161
"itertools 0.8.0",
41624162
"minifier",
4163-
"pulldown-cmark 0.5.3",
4163+
"pulldown-cmark 0.7.0",
41644164
"rustc-rayon",
41654165
"serde",
41664166
"serde_json",
@@ -5160,11 +5160,11 @@ checksum = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
51605160

51615161
[[package]]
51625162
name = "unicase"
5163-
version = "2.5.1"
5163+
version = "2.6.0"
51645164
source = "registry+https://github.com/rust-lang/crates.io-index"
5165-
checksum = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150"
5165+
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
51665166
dependencies = [
5167-
"version_check 0.1.5",
5167+
"version_check",
51685168
]
51695169

51705170
[[package]]
@@ -5334,12 +5334,6 @@ dependencies = [
53345334
"failure",
53355335
]
53365336

5337-
[[package]]
5338-
name = "version_check"
5339-
version = "0.1.5"
5340-
source = "registry+https://github.com/rust-lang/crates.io-index"
5341-
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
5342-
53435337
[[package]]
53445338
name = "version_check"
53455339
version = "0.9.1"

src/librustc/traits/fulfill.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ use super::{FulfillmentError, FulfillmentErrorCode};
1818
use super::{ObligationCause, PredicateObligation};
1919

2020
impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
21-
type Predicate = ty::Predicate<'tcx>;
21+
/// Note that we include both the `ParamEnv` and the `Predicate`,
22+
/// as the `ParamEnv` can influence whether fulfillment succeeds
23+
/// or fails.
24+
type CacheKey = ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>;
2225

23-
fn as_predicate(&self) -> &Self::Predicate {
24-
&self.obligation.predicate
26+
fn as_cache_key(&self) -> Self::CacheKey {
27+
self.obligation.param_env.and(self.obligation.predicate)
2528
}
2629
}
2730

src/librustc_ast_lowering/pat.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
128128
let mut slice = None;
129129
let mut prev_rest_span = None;
130130

131+
// Lowers `$bm $ident @ ..` to `$bm $ident @ _`.
132+
let lower_rest_sub = |this: &mut Self, pat, bm, ident, sub| {
133+
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
134+
let node = this.lower_pat_ident(pat, bm, ident, lower_sub);
135+
this.pat_with_node_id_of(pat, node)
136+
};
137+
131138
let mut iter = pats.iter();
132139
// Lower all the patterns until the first occurrence of a sub-slice pattern.
133140
for pat in iter.by_ref() {
@@ -142,9 +149,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
142149
// Record, lower it to `$binding_mode $ident @ _`, and stop here.
143150
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
144151
prev_rest_span = Some(sub.span);
145-
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
146-
let node = self.lower_pat_ident(pat, bm, ident, lower_sub);
147-
slice = Some(self.pat_with_node_id_of(pat, node));
152+
slice = Some(lower_rest_sub(self, pat, bm, ident, sub));
148153
break;
149154
}
150155
// It was not a subslice pattern so lower it normally.
@@ -157,9 +162,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
157162
// There was a previous subslice pattern; make sure we don't allow more.
158163
let rest_span = match pat.kind {
159164
PatKind::Rest => Some(pat.span),
160-
PatKind::Ident(.., Some(ref sub)) if sub.is_rest() => {
161-
// The `HirValidator` is merciless; add a `_` pattern to avoid ICEs.
162-
after.push(self.pat_wild_with_node_id_of(pat));
165+
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
166+
// #69103: Lower into `binding @ _` as above to avoid ICEs.
167+
after.push(lower_rest_sub(self, pat, bm, ident, sub));
163168
Some(sub.span)
164169
}
165170
_ => None,

src/librustc_data_structures/obligation_forest/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a, O: ForestObligation + 'a> dot::Labeller<'a> for &'a ObligationForest<O>
5252

5353
fn node_label(&self, index: &Self::Node) -> dot::LabelText<'_> {
5454
let node = &self.nodes[*index];
55-
let label = format!("{:?} ({:?})", node.obligation.as_predicate(), node.state.get());
55+
let label = format!("{:?} ({:?})", node.obligation.as_cache_key(), node.state.get());
5656

5757
dot::LabelText::LabelStr(label.into())
5858
}

src/librustc_data_structures/obligation_forest/mod.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ mod graphviz;
8686
mod tests;
8787

8888
pub trait ForestObligation: Clone + Debug {
89-
type Predicate: Clone + hash::Hash + Eq + Debug;
89+
type CacheKey: Clone + hash::Hash + Eq + Debug;
9090

91-
fn as_predicate(&self) -> &Self::Predicate;
91+
/// Converts this `ForestObligation` suitable for use as a cache key.
92+
/// If two distinct `ForestObligations`s return the same cache key,
93+
/// then it must be sound to use the result of processing one obligation
94+
/// (e.g. success for error) for the other obligation
95+
fn as_cache_key(&self) -> Self::CacheKey;
9296
}
9397

9498
pub trait ObligationProcessor {
@@ -138,12 +142,12 @@ pub struct ObligationForest<O: ForestObligation> {
138142
nodes: Vec<Node<O>>,
139143

140144
/// A cache of predicates that have been successfully completed.
141-
done_cache: FxHashSet<O::Predicate>,
145+
done_cache: FxHashSet<O::CacheKey>,
142146

143147
/// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
144148
/// its contents are not guaranteed to match those of `nodes`. See the
145149
/// comments in `process_obligation` for details.
146-
active_cache: FxHashMap<O::Predicate, usize>,
150+
active_cache: FxHashMap<O::CacheKey, usize>,
147151

148152
/// A vector reused in compress(), to avoid allocating new vectors.
149153
node_rewrites: Vec<usize>,
@@ -157,7 +161,7 @@ pub struct ObligationForest<O: ForestObligation> {
157161
/// See [this][details] for details.
158162
///
159163
/// [details]: https://github.com/rust-lang/rust/pull/53255#issuecomment-421184780
160-
error_cache: FxHashMap<ObligationTreeId, FxHashSet<O::Predicate>>,
164+
error_cache: FxHashMap<ObligationTreeId, FxHashSet<O::CacheKey>>,
161165
}
162166

163167
#[derive(Debug)]
@@ -305,11 +309,12 @@ impl<O: ForestObligation> ObligationForest<O> {
305309

306310
// Returns Err(()) if we already know this obligation failed.
307311
fn register_obligation_at(&mut self, obligation: O, parent: Option<usize>) -> Result<(), ()> {
308-
if self.done_cache.contains(obligation.as_predicate()) {
312+
if self.done_cache.contains(&obligation.as_cache_key()) {
313+
debug!("register_obligation_at: ignoring already done obligation: {:?}", obligation);
309314
return Ok(());
310315
}
311316

312-
match self.active_cache.entry(obligation.as_predicate().clone()) {
317+
match self.active_cache.entry(obligation.as_cache_key().clone()) {
313318
Entry::Occupied(o) => {
314319
let node = &mut self.nodes[*o.get()];
315320
if let Some(parent_index) = parent {
@@ -333,7 +338,7 @@ impl<O: ForestObligation> ObligationForest<O> {
333338
&& self
334339
.error_cache
335340
.get(&obligation_tree_id)
336-
.map(|errors| errors.contains(obligation.as_predicate()))
341+
.map(|errors| errors.contains(&obligation.as_cache_key()))
337342
.unwrap_or(false);
338343

339344
if already_failed {
@@ -380,7 +385,7 @@ impl<O: ForestObligation> ObligationForest<O> {
380385
self.error_cache
381386
.entry(node.obligation_tree_id)
382387
.or_default()
383-
.insert(node.obligation.as_predicate().clone());
388+
.insert(node.obligation.as_cache_key().clone());
384389
}
385390

386391
/// Performs a pass through the obligation list. This must
@@ -618,11 +623,11 @@ impl<O: ForestObligation> ObligationForest<O> {
618623
// `self.nodes`. See the comment in `process_obligation`
619624
// for more details.
620625
if let Some((predicate, _)) =
621-
self.active_cache.remove_entry(node.obligation.as_predicate())
626+
self.active_cache.remove_entry(&node.obligation.as_cache_key())
622627
{
623628
self.done_cache.insert(predicate);
624629
} else {
625-
self.done_cache.insert(node.obligation.as_predicate().clone());
630+
self.done_cache.insert(node.obligation.as_cache_key().clone());
626631
}
627632
if do_completed == DoCompleted::Yes {
628633
// Extract the success stories.
@@ -635,7 +640,7 @@ impl<O: ForestObligation> ObligationForest<O> {
635640
// We *intentionally* remove the node from the cache at this point. Otherwise
636641
// tests must come up with a different type on every type error they
637642
// check against.
638-
self.active_cache.remove(node.obligation.as_predicate());
643+
self.active_cache.remove(&node.obligation.as_cache_key());
639644
self.insert_into_error_cache(index);
640645
node_rewrites[index] = orig_nodes_len;
641646
dead_nodes += 1;

src/librustc_data_structures/obligation_forest/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::fmt;
44
use std::marker::PhantomData;
55

66
impl<'a> super::ForestObligation for &'a str {
7-
type Predicate = &'a str;
7+
type CacheKey = &'a str;
88

9-
fn as_predicate(&self) -> &Self::Predicate {
9+
fn as_cache_key(&self) -> Self::CacheKey {
1010
self
1111
}
1212
}

src/librustc_expand/mbe/macro_rules.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fn generic_extension<'cx>(
191191
let mut best_failure: Option<(Token, &str)> = None;
192192

193193
// We create a base parser that can be used for the "black box" parts.
194-
// Every iteration needs a fresh copy of that base parser. However, the
195-
// parser is not mutated on many of the iterations, particularly when
196-
// dealing with macros like this:
194+
// Every iteration needs a fresh copy of that parser. However, the parser
195+
// is not mutated on many of the iterations, particularly when dealing with
196+
// macros like this:
197197
//
198198
// macro_rules! foo {
199199
// ("a") => (A);
@@ -209,11 +209,9 @@ fn generic_extension<'cx>(
209209
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210210
// 68836 suggests a more comprehensive but more complex change to deal with
211211
// this situation.)
212-
let base_parser = base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
212+
let parser = parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
213213

214214
for (i, lhs) in lhses.iter().enumerate() {
215-
let mut parser = Cow::Borrowed(&base_parser);
216-
217215
// try each arm's matchers
218216
let lhs_tt = match *lhs {
219217
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
@@ -224,13 +222,14 @@ fn generic_extension<'cx>(
224222
// This is used so that if a matcher is not `Success(..)`ful,
225223
// then the spans which became gated when parsing the unsuccessful matcher
226224
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
227-
let mut gated_spans_snaphot = mem::take(&mut *cx.parse_sess.gated_spans.spans.borrow_mut());
225+
let mut gated_spans_snapshot =
226+
mem::take(&mut *cx.parse_sess.gated_spans.spans.borrow_mut());
228227

229-
match parse_tt(&mut parser, lhs_tt) {
228+
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
230229
Success(named_matches) => {
231230
// The matcher was `Success(..)`ful.
232231
// Merge the gated spans from parsing the matcher with the pre-existing ones.
233-
cx.parse_sess.gated_spans.merge(gated_spans_snaphot);
232+
cx.parse_sess.gated_spans.merge(gated_spans_snapshot);
234233

235234
let rhs = match rhses[i] {
236235
// ignore delimiters
@@ -291,9 +290,9 @@ fn generic_extension<'cx>(
291290

292291
// The matcher was not `Success(..)`ful.
293292
// Restore to the state before snapshotting and maybe try again.
294-
mem::swap(&mut gated_spans_snaphot, &mut cx.parse_sess.gated_spans.spans.borrow_mut());
293+
mem::swap(&mut gated_spans_snapshot, &mut cx.parse_sess.gated_spans.spans.borrow_mut());
295294
}
296-
drop(base_parser);
295+
drop(parser);
297296

298297
let (token, label) = best_failure.expect("ran no matchers");
299298
let span = token.span.substitute_dummy(sp);
@@ -311,9 +310,8 @@ fn generic_extension<'cx>(
311310
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
312311
_ => continue,
313312
};
314-
let base_parser =
315-
base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
316-
match parse_tt(&mut Cow::Borrowed(&base_parser), lhs_tt) {
313+
let parser = parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
314+
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
317315
Success(_) => {
318316
if comma_span.is_dummy() {
319317
err.note("you might be missing a comma");
@@ -395,8 +393,8 @@ pub fn compile_declarative_macro(
395393
),
396394
];
397395

398-
let base_parser = Parser::new(sess, body, None, true, true, rustc_parse::MACRO_ARGUMENTS);
399-
let argument_map = match parse_tt(&mut Cow::Borrowed(&base_parser), &argument_gram) {
396+
let parser = Parser::new(sess, body, None, true, true, rustc_parse::MACRO_ARGUMENTS);
397+
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram) {
400398
Success(m) => m,
401399
Failure(token, msg) => {
402400
let s = parse_failure_msg(&token);
@@ -1212,7 +1210,7 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
12121210
}
12131211
}
12141212

1215-
fn base_parser_from_cx<'cx>(
1213+
fn parser_from_cx<'cx>(
12161214
current_expansion: &'cx ExpansionData,
12171215
sess: &'cx ParseSess,
12181216
tts: TokenStream,

src/librustc_mir/transform/simplify_try.rs

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
5252
Some(x) => x,
5353
};
5454
if local_tmp_s0 != local_tmp_s1
55+
// Avoid moving into ourselves.
56+
|| local_0 == local_1
5557
// The field-and-variant information match up.
5658
|| vf_s0 != vf_s1
5759
// Source and target locals have the same type.
@@ -64,6 +66,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
6466
}
6567

6668
// Right shape; transform!
69+
s0.source_info = s2.source_info;
6770
match &mut s0.kind {
6871
StatementKind::Assign(box (place, rvalue)) => {
6972
*place = local_0.into();

0 commit comments

Comments
 (0)