Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #80105

Merged
merged 30 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
77d80b2
Introduce if-let guards in the HIR
LeSeulArtichaut Oct 24, 2020
f9cc626
Implement typechecking if-let guards
LeSeulArtichaut Nov 11, 2020
cfaaa21
Implement liveness passes for if-let guards
LeSeulArtichaut Nov 11, 2020
bab2080
Introduce if-let guards in the THIR
LeSeulArtichaut Nov 11, 2020
f3d4aa6
Implement lowering of if-let guards to MIR
LeSeulArtichaut Nov 13, 2020
61e69bc
Handle `Guard::IfLet` in clippy
LeSeulArtichaut Nov 15, 2020
0917260
Add a few basic tests for if-let guards
LeSeulArtichaut Nov 15, 2020
c6f2d49
fix issue #78496
wecing Dec 10, 2020
78c0680
update comments
wecing Dec 10, 2020
3812f70
fix test case issue ref
wecing Dec 10, 2020
357565d
expand-yaml-anchors: Make the output directory separator-insensitive
JohnTitor Dec 14, 2020
a72b739
Remove unused `TyEncoder::tcx` required method
LeSeulArtichaut Dec 14, 2020
5afb95a
Test that `core::assert!` is valid
jyn514 Dec 16, 2020
1d6b455
Fixed conflict with drop elaboration and coverage
richkadel Dec 16, 2020
acc63bc
Add support for target aliases
kulikjak Dec 16, 2020
6893206
Revert "Auto merge of #78790 - Gankra:rust-src-vendor, r=Mark-Simulac…
ehuss Dec 16, 2020
1e1ca28
Allow `since="TBD"` for rustc_deprecated
Dec 9, 2020
f365de3
Add `popcount` and `popcnt` as doc aliases for `count_ones` methods.
SimonSapin Dec 16, 2020
bec1c27
Remove docs for non-existent parameters in `rustc_expand`
camelid Dec 17, 2020
1e1ba7c
Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
JohnTitor Dec 17, 2020
3d42c00
Rollup merge of #79877 - bstrie:depinfut, r=oli-obk
JohnTitor Dec 17, 2020
a611f8d
Rollup merge of #79882 - wecing:master, r=oli-obk
JohnTitor Dec 17, 2020
f645e30
Rollup merge of #80026 - JohnTitor:separator-insensitive, r=Mark-Simu…
JohnTitor Dec 17, 2020
2808038
Rollup merge of #80039 - LeSeulArtichaut:rm-tyencoder-tcx, r=matthewj…
JohnTitor Dec 17, 2020
3cf5bc8
Rollup merge of #80069 - jyn514:core-assert, r=dtolnay
JohnTitor Dec 17, 2020
a5b1d22
Rollup merge of #80072 - richkadel:llvm-coverage-counters-2.2.1, r=tm…
JohnTitor Dec 17, 2020
0b1e718
Rollup merge of #80073 - kulikjak:add-target-alias-support, r=varkor
JohnTitor Dec 17, 2020
5ce62da
Rollup merge of #80082 - ehuss:revert-rust-src-vendor, r=Mark-Simulacrum
JohnTitor Dec 17, 2020
e4735dd
Rollup merge of #80097 - SimonSapin:popcount, r=m-ou-se
JohnTitor Dec 17, 2020
e2582e4
Rollup merge of #80103 - camelid:remove-docs-old-params-rustc_expand,…
JohnTitor Dec 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
let pat = self.lower_pat(&arm.pat);
let guard = arm.guard.as_ref().map(|cond| {
if let ExprKind::Let(ref pat, ref scrutinee) = cond.kind {
hir::Guard::IfLet(self.lower_pat(pat), self.lower_expr(scrutinee))
} else {
hir::Guard::If(self.lower_expr(cond))
}
});
hir::Arm {
hir_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs),
pat: self.lower_pat(&arm.pat),
guard: match arm.guard {
Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),
_ => None,
},
pat,
guard,
body: self.lower_expr(&arm.body),
span: arm.span,
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This is an NFA-based parser, which calls out to the main rust parser for named non-terminals
//! This is an NFA-based parser, which calls out to the main Rust parser for named non-terminals
//! (which it commits to fully when it hits one in a grammar). There's a set of current NFA threads
//! and a set of next ones. Instead of NTs, we have a special case for Kleene star. The big-O, in
//! pathological cases, is worse than traditional use of NFA or Earley parsing, but it's an easier
Expand Down Expand Up @@ -422,16 +422,13 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
///
/// # Parameters
///
/// - `sess`: the parsing session into which errors are emitted.
/// - `cur_items`: the set of current items to be processed. This should be empty by the end of a
/// successful execution of this function.
/// - `next_items`: the set of newly generated items. These are used to replenish `cur_items` in
/// the function `parse`.
/// - `eof_items`: the set of items that would be valid if this was the EOF.
/// - `bb_items`: the set of items that are waiting for the black-box parser.
/// - `token`: the current token of the parser.
/// - `span`: the `Span` in the source code corresponding to the token trees we are trying to match
/// against the matcher positions in `cur_items`.
///
/// # Returns
///
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ pub struct Arm<'hir> {
#[derive(Debug, HashStable_Generic)]
pub enum Guard<'hir> {
If(&'hir Expr<'hir>),
IfLet(&'hir Pat<'hir>, &'hir Expr<'hir>),
}

#[derive(Debug, HashStable_Generic)]
Expand Down Expand Up @@ -1721,6 +1722,8 @@ pub enum MatchSource {
IfDesugar { contains_else_clause: bool },
/// An `if let _ = _ { .. }` (optionally with `else { .. }`).
IfLetDesugar { contains_else_clause: bool },
/// An `if let _ = _ => { .. }` match guard.
IfLetGuardDesugar,
/// A `while _ { .. }` (which was desugared to a `loop { match _ { .. } }`).
WhileDesugar,
/// A `while let _ = _ { .. }` (which was desugared to a
Expand All @@ -1739,7 +1742,7 @@ impl MatchSource {
use MatchSource::*;
match self {
Normal => "match",
IfDesugar { .. } | IfLetDesugar { .. } => "if",
IfDesugar { .. } | IfLetDesugar { .. } | IfLetGuardDesugar => "if",
WhileDesugar | WhileLetDesugar => "while",
ForLoopDesugar => "for",
TryDesugar => "?",
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,10 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
if let Some(ref g) = arm.guard {
match g {
Guard::If(ref e) => visitor.visit_expr(e),
Guard::IfLet(ref pat, ref e) => {
visitor.visit_pat(pat);
visitor.visit_expr(e);
}
}
}
visitor.visit_expr(&arm.body);
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,15 @@ impl<'a> State<'a> {
self.print_expr(&e);
self.s.space();
}
hir::Guard::IfLet(pat, e) => {
self.word_nbsp("if");
self.word_nbsp("let");
self.print_pat(&pat);
self.s.space();
self.word_space("=");
self.print_expr(&e);
self.s.space();
}
}
}
self.word_space("=>");
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
self.opaque.position()
}

fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
&mut self.type_shorthands
}
Expand Down
75 changes: 40 additions & 35 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,37 +132,37 @@ pub fn report_unstable(
/// Checks whether an item marked with `deprecated(since="X")` is currently
/// deprecated (i.e., whether X is not greater than the current rustc version).
pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool {
let since = if let Some(since) = since {
if is_since_rustc_version {
since
} else {
// We assume that the deprecation is in effect if it's not a
// rustc version.
return true;
}
} else {
// If since attribute is not set, then we're definitely in effect.
return true;
};
fn parse_version(ver: &str) -> Vec<u32> {
// We ignore non-integer components of the version (e.g., "nightly").
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
}

if let Some(rustc) = option_env!("CFG_RELEASE") {
let since: Vec<u32> = parse_version(&since);
let rustc: Vec<u32> = parse_version(rustc);
// We simply treat invalid `since` attributes as relating to a previous
// Rust version, thus always displaying the warning.
if since.len() != 3 {
return true;
}
since <= rustc
} else {
// By default, a deprecation warning applies to
// the current version of the compiler.
true
if !is_since_rustc_version {
// The `since` field doesn't have semantic purpose in the stable `deprecated`
// attribute, only in `rustc_deprecated`.
return true;
}

if let Some(since) = since {
if since == "TBD" {
return false;
}

if let Some(rustc) = option_env!("CFG_RELEASE") {
let since: Vec<u32> = parse_version(&since);
let rustc: Vec<u32> = parse_version(rustc);
// We simply treat invalid `since` attributes as relating to a previous
// Rust version, thus always displaying the warning.
if since.len() != 3 {
return true;
}
return since <= rustc;
}
};

// Assume deprecation is in effect if "since" field is missing
// or if we can't determine the current Rust version.
true
}

pub fn deprecation_suggestion(
Expand All @@ -182,19 +182,24 @@ pub fn deprecation_suggestion(
}

pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
let (message, lint) = if deprecation_in_effect(
depr.is_since_rustc_version,
depr.since.map(Symbol::as_str).as_deref(),
) {
let since = depr.since.map(Symbol::as_str);
let (message, lint) = if deprecation_in_effect(depr.is_since_rustc_version, since.as_deref()) {
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
} else {
(
format!(
"use of {} `{}` that will be deprecated in future version {}",
kind,
path,
depr.since.unwrap()
),
if since.as_deref() == Some("TBD") {
format!(
"use of {} `{}` that will be deprecated in a future Rust version",
kind, path
)
} else {
format!(
"use of {} `{}` that will be deprecated in future version {}",
kind,
path,
since.unwrap()
)
},
DEPRECATED_IN_FUTURE,
)
};
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl OpaqueEncoder for rustc_serialize::opaque::Encoder {
pub trait TyEncoder<'tcx>: Encoder {
const CLEAR_CROSS_CRATE: bool;

fn tcx(&self) -> TyCtxt<'tcx>;
fn position(&self) -> usize;
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>;
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize>;
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,6 @@ where
{
const CLEAR_CROSS_CRATE: bool = false;

fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn position(&self) -> usize {
self.encoder.encoder_position()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
inject_statement(
self.mir_body,
counter_kind,
self.bcb_last_bb(bcb),
self.bcb_leader_bb(bcb),
Some(make_code_region(file_name, &self.source_file, span, body_span)),
);
}
Expand Down Expand Up @@ -470,7 +470,7 @@ fn inject_statement(
code_region: some_code_region,
}),
};
data.statements.push(statement);
data.statements.insert(0, statement);
}

// Non-code expressions are injected into the coverage map, without generating executable code.
Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,33 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
return None;
}

// when the second place is a projection of the first one, it's not safe to calculate their discriminant values sequentially.
// for example, this should not be optimized:
//
// ```rust
// enum E<'a> { Empty, Some(&'a E<'a>), }
// let Some(Some(_)) = e;
// ```
//
// ```mir
// bb0: {
// _2 = discriminant(*_1)
// switchInt(_2) -> [...]
// }
// bb1: {
// _3 = discriminant(*(((*_1) as Some).0: &E))
// switchInt(_3) -> [...]
// }
// ```
let discr_place = discr_info.place_of_adt_discr_read;
let this_discr_place = this_bb_discr_info.place_of_adt_discr_read;
if discr_place.local == this_discr_place.local
&& this_discr_place.projection.starts_with(discr_place.projection)
{
trace!("NO: one target is the projection of another");
return None;
}

// if we reach this point, the optimization applies, and we should be able to optimize this case
// store the info that is needed to apply the optimization

Expand Down
Loading