Skip to content

Commit 9b84d36

Browse files
committed
Auto merge of rust-lang#80105 - JohnTitor:rollup-8c030u5, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#79051 (Implement if-let match guards) - rust-lang#79877 (Allow `since="TBD"` for rustc_deprecated) - rust-lang#79882 (Fix issue rust-lang#78496) - rust-lang#80026 (expand-yaml-anchors: Make the output directory separator-insensitive) - rust-lang#80039 (Remove unused `TyEncoder::tcx` required method) - rust-lang#80069 (Test that `core::assert!` is valid) - rust-lang#80072 (Fixed conflict with drop elaboration and coverage) - rust-lang#80073 (Add support for target aliases) - rust-lang#80082 (Revert rust-lang#78790 - rust-src vendoring) - rust-lang#80097 (Add `popcount` and `popcnt` as doc aliases for `count_ones` methods.) - rust-lang#80103 (Remove docs for non-existent parameters in `rustc_expand`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a6491be + e2582e4 commit 9b84d36

File tree

64 files changed

+633
-285
lines changed

Some content is hidden

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

64 files changed

+633
-285
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
505505
}
506506

507507
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
508+
let pat = self.lower_pat(&arm.pat);
509+
let guard = arm.guard.as_ref().map(|cond| {
510+
if let ExprKind::Let(ref pat, ref scrutinee) = cond.kind {
511+
hir::Guard::IfLet(self.lower_pat(pat), self.lower_expr(scrutinee))
512+
} else {
513+
hir::Guard::If(self.lower_expr(cond))
514+
}
515+
});
508516
hir::Arm {
509517
hir_id: self.next_id(),
510518
attrs: self.lower_attrs(&arm.attrs),
511-
pat: self.lower_pat(&arm.pat),
512-
guard: match arm.guard {
513-
Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),
514-
_ => None,
515-
},
519+
pat,
520+
guard,
516521
body: self.lower_expr(&arm.body),
517522
span: arm.span,
518523
}

compiler/rustc_expand/src/mbe/macro_parser.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This is an NFA-based parser, which calls out to the main rust parser for named non-terminals
1+
//! This is an NFA-based parser, which calls out to the main Rust parser for named non-terminals
22
//! (which it commits to fully when it hits one in a grammar). There's a set of current NFA threads
33
//! and a set of next ones. Instead of NTs, we have a special case for Kleene star. The big-O, in
44
//! pathological cases, is worse than traditional use of NFA or Earley parsing, but it's an easier
@@ -422,16 +422,13 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
422422
///
423423
/// # Parameters
424424
///
425-
/// - `sess`: the parsing session into which errors are emitted.
426425
/// - `cur_items`: the set of current items to be processed. This should be empty by the end of a
427426
/// successful execution of this function.
428427
/// - `next_items`: the set of newly generated items. These are used to replenish `cur_items` in
429428
/// the function `parse`.
430429
/// - `eof_items`: the set of items that would be valid if this was the EOF.
431430
/// - `bb_items`: the set of items that are waiting for the black-box parser.
432431
/// - `token`: the current token of the parser.
433-
/// - `span`: the `Span` in the source code corresponding to the token trees we are trying to match
434-
/// against the matcher positions in `cur_items`.
435432
///
436433
/// # Returns
437434
///

compiler/rustc_hir/src/hir.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ pub struct Arm<'hir> {
11601160
#[derive(Debug, HashStable_Generic)]
11611161
pub enum Guard<'hir> {
11621162
If(&'hir Expr<'hir>),
1163+
IfLet(&'hir Pat<'hir>, &'hir Expr<'hir>),
11631164
}
11641165

11651166
#[derive(Debug, HashStable_Generic)]
@@ -1721,6 +1722,8 @@ pub enum MatchSource {
17211722
IfDesugar { contains_else_clause: bool },
17221723
/// An `if let _ = _ { .. }` (optionally with `else { .. }`).
17231724
IfLetDesugar { contains_else_clause: bool },
1725+
/// An `if let _ = _ => { .. }` match guard.
1726+
IfLetGuardDesugar,
17241727
/// A `while _ { .. }` (which was desugared to a `loop { match _ { .. } }`).
17251728
WhileDesugar,
17261729
/// A `while let _ = _ { .. }` (which was desugared to a
@@ -1739,7 +1742,7 @@ impl MatchSource {
17391742
use MatchSource::*;
17401743
match self {
17411744
Normal => "match",
1742-
IfDesugar { .. } | IfLetDesugar { .. } => "if",
1745+
IfDesugar { .. } | IfLetDesugar { .. } | IfLetGuardDesugar => "if",
17431746
WhileDesugar | WhileLetDesugar => "while",
17441747
ForLoopDesugar => "for",
17451748
TryDesugar => "?",

compiler/rustc_hir/src/intravisit.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,10 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
12281228
if let Some(ref g) = arm.guard {
12291229
match g {
12301230
Guard::If(ref e) => visitor.visit_expr(e),
1231+
Guard::IfLet(ref pat, ref e) => {
1232+
visitor.visit_pat(pat);
1233+
visitor.visit_expr(e);
1234+
}
12311235
}
12321236
}
12331237
visitor.visit_expr(&arm.body);

compiler/rustc_hir_pretty/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,15 @@ impl<'a> State<'a> {
20022002
self.print_expr(&e);
20032003
self.s.space();
20042004
}
2005+
hir::Guard::IfLet(pat, e) => {
2006+
self.word_nbsp("if");
2007+
self.word_nbsp("let");
2008+
self.print_pat(&pat);
2009+
self.s.space();
2010+
self.word_space("=");
2011+
self.print_expr(&e);
2012+
self.s.space();
2013+
}
20052014
}
20062015
}
20072016
self.word_space("=>");

compiler/rustc_metadata/src/rmeta/encoder.rs

-4
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
319319
self.opaque.position()
320320
}
321321

322-
fn tcx(&self) -> TyCtxt<'tcx> {
323-
self.tcx
324-
}
325-
326322
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
327323
&mut self.type_shorthands
328324
}

compiler/rustc_middle/src/middle/stability.rs

+40-35
Original file line numberDiff line numberDiff line change
@@ -132,37 +132,37 @@ pub fn report_unstable(
132132
/// Checks whether an item marked with `deprecated(since="X")` is currently
133133
/// deprecated (i.e., whether X is not greater than the current rustc version).
134134
pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool {
135-
let since = if let Some(since) = since {
136-
if is_since_rustc_version {
137-
since
138-
} else {
139-
// We assume that the deprecation is in effect if it's not a
140-
// rustc version.
141-
return true;
142-
}
143-
} else {
144-
// If since attribute is not set, then we're definitely in effect.
145-
return true;
146-
};
147135
fn parse_version(ver: &str) -> Vec<u32> {
148136
// We ignore non-integer components of the version (e.g., "nightly").
149137
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
150138
}
151139

152-
if let Some(rustc) = option_env!("CFG_RELEASE") {
153-
let since: Vec<u32> = parse_version(&since);
154-
let rustc: Vec<u32> = parse_version(rustc);
155-
// We simply treat invalid `since` attributes as relating to a previous
156-
// Rust version, thus always displaying the warning.
157-
if since.len() != 3 {
158-
return true;
159-
}
160-
since <= rustc
161-
} else {
162-
// By default, a deprecation warning applies to
163-
// the current version of the compiler.
164-
true
140+
if !is_since_rustc_version {
141+
// The `since` field doesn't have semantic purpose in the stable `deprecated`
142+
// attribute, only in `rustc_deprecated`.
143+
return true;
165144
}
145+
146+
if let Some(since) = since {
147+
if since == "TBD" {
148+
return false;
149+
}
150+
151+
if let Some(rustc) = option_env!("CFG_RELEASE") {
152+
let since: Vec<u32> = parse_version(&since);
153+
let rustc: Vec<u32> = parse_version(rustc);
154+
// We simply treat invalid `since` attributes as relating to a previous
155+
// Rust version, thus always displaying the warning.
156+
if since.len() != 3 {
157+
return true;
158+
}
159+
return since <= rustc;
160+
}
161+
};
162+
163+
// Assume deprecation is in effect if "since" field is missing
164+
// or if we can't determine the current Rust version.
165+
true
166166
}
167167

168168
pub fn deprecation_suggestion(
@@ -182,19 +182,24 @@ pub fn deprecation_suggestion(
182182
}
183183

184184
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
185-
let (message, lint) = if deprecation_in_effect(
186-
depr.is_since_rustc_version,
187-
depr.since.map(Symbol::as_str).as_deref(),
188-
) {
185+
let since = depr.since.map(Symbol::as_str);
186+
let (message, lint) = if deprecation_in_effect(depr.is_since_rustc_version, since.as_deref()) {
189187
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
190188
} else {
191189
(
192-
format!(
193-
"use of {} `{}` that will be deprecated in future version {}",
194-
kind,
195-
path,
196-
depr.since.unwrap()
197-
),
190+
if since.as_deref() == Some("TBD") {
191+
format!(
192+
"use of {} `{}` that will be deprecated in a future Rust version",
193+
kind, path
194+
)
195+
} else {
196+
format!(
197+
"use of {} `{}` that will be deprecated in future version {}",
198+
kind,
199+
path,
200+
since.unwrap()
201+
)
202+
},
198203
DEPRECATED_IN_FUTURE,
199204
)
200205
};

compiler/rustc_middle/src/ty/codec.rs

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ impl OpaqueEncoder for rustc_serialize::opaque::Encoder {
6969
pub trait TyEncoder<'tcx>: Encoder {
7070
const CLEAR_CROSS_CRATE: bool;
7171

72-
fn tcx(&self) -> TyCtxt<'tcx>;
7372
fn position(&self) -> usize;
7473
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>;
7574
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize>;

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,6 @@ where
10441044
{
10451045
const CLEAR_CROSS_CRATE: bool = false;
10461046

1047-
fn tcx(&self) -> TyCtxt<'tcx> {
1048-
self.tcx
1049-
}
10501047
fn position(&self) -> usize {
10511048
self.encoder.encoder_position()
10521049
}

compiler/rustc_mir/src/transform/coverage/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
310310
inject_statement(
311311
self.mir_body,
312312
counter_kind,
313-
self.bcb_last_bb(bcb),
313+
self.bcb_leader_bb(bcb),
314314
Some(make_code_region(file_name, &self.source_file, span, body_span)),
315315
);
316316
}
@@ -470,7 +470,7 @@ fn inject_statement(
470470
code_region: some_code_region,
471471
}),
472472
};
473-
data.statements.push(statement);
473+
data.statements.insert(0, statement);
474474
}
475475

476476
// Non-code expressions are injected into the coverage map, without generating executable code.

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

+27
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,33 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
284284
return None;
285285
}
286286

287+
// when the second place is a projection of the first one, it's not safe to calculate their discriminant values sequentially.
288+
// for example, this should not be optimized:
289+
//
290+
// ```rust
291+
// enum E<'a> { Empty, Some(&'a E<'a>), }
292+
// let Some(Some(_)) = e;
293+
// ```
294+
//
295+
// ```mir
296+
// bb0: {
297+
// _2 = discriminant(*_1)
298+
// switchInt(_2) -> [...]
299+
// }
300+
// bb1: {
301+
// _3 = discriminant(*(((*_1) as Some).0: &E))
302+
// switchInt(_3) -> [...]
303+
// }
304+
// ```
305+
let discr_place = discr_info.place_of_adt_discr_read;
306+
let this_discr_place = this_bb_discr_info.place_of_adt_discr_read;
307+
if discr_place.local == this_discr_place.local
308+
&& this_discr_place.projection.starts_with(discr_place.projection)
309+
{
310+
trace!("NO: one target is the projection of another");
311+
return None;
312+
}
313+
287314
// if we reach this point, the optimization applies, and we should be able to optimize this case
288315
// store the info that is needed to apply the optimization
289316

0 commit comments

Comments
 (0)