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 #80093

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
7cb74ed
Remove memoization leftovers
Dec 8, 2020
de1cd4b
Extra assertions in eval_body_using_ecx to disallow queries for
Dec 9, 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
b6f7eef
Remove unnecessary check and fix local_def_id parameter
Dec 10, 2020
a03feaa
add missing constraints
Dec 11, 2020
ed80815
Move binder for dyn to each list item
jackh726 Dec 11, 2020
0f30b7d
fix panic if converting ZST Vec to VecDeque
Stupremee Dec 13, 2020
d75618e
replace assert! with assert_eq!
Stupremee Dec 13, 2020
94fd1d3
BTreeMap: more expressive local variables in merge
ssomers Nov 23, 2020
09d528e
fix typo
Stupremee Dec 13, 2020
6c7835e
BTreeSet: simplify implementation of pop_first/pop_last
ssomers Nov 20, 2020
357565d
expand-yaml-anchors: Make the output directory separator-insensitive
JohnTitor Dec 14, 2020
01c2520
Add explanation for skip_binder in relate
jackh726 Dec 14, 2020
777ca99
Optimization for bool's PartialOrd impl
ChayimFriedman2 Dec 14, 2020
cfc38d2
Take into account negative impls in "trait item not found" suggestions
LeSeulArtichaut Dec 7, 2020
1e1ca28
Allow `since="TBD"` for rustc_deprecated
Dec 9, 2020
cec4573
Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
Dylan-DPC Dec 16, 2020
553d632
Rollup merge of #79790 - LeSeulArtichaut:issue-79683, r=lcnr
Dylan-DPC Dec 16, 2020
3d8241d
Rollup merge of #79840 - dvtkrlbs:issue-79667, r=oli-obk
Dylan-DPC Dec 16, 2020
88e2ee1
Rollup merge of #79877 - bstrie:depinfut, r=oli-obk
Dylan-DPC Dec 16, 2020
bd93050
Rollup merge of #79882 - wecing:master, r=oli-obk
Dylan-DPC Dec 16, 2020
3dafad2
Rollup merge of #79945 - jackh726:existential_trait_ref, r=nikomatsakis
Dylan-DPC Dec 16, 2020
69db829
Rollup merge of #80003 - Stupremee:fix-zst-vecdeque-conversion-panic,…
Dylan-DPC Dec 16, 2020
6afef41
Rollup merge of #80006 - ssomers:btree_cleanup_6, r=Mark-Simulacrum
Dylan-DPC Dec 16, 2020
fe6910e
Rollup merge of #80022 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
Dylan-DPC Dec 16, 2020
6c7de3f
Rollup merge of #80026 - JohnTitor:separator-insensitive, r=Mark-Simu…
Dylan-DPC Dec 16, 2020
7496c37
Rollup merge of #80035 - ChayimFriedman2:patch-1, r=nagisa
Dylan-DPC Dec 16, 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
24 changes: 13 additions & 11 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,19 @@ impl<'tcx> CPlace<'tcx> {
// fn(&T) -> for<'l> fn(&'l T) is allowed
}
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
let from_traits = fx
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
let to_traits = fx
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to_traits);
assert_eq!(
from_traits, to_traits,
"Can't write trait object of incompatible traits {:?} to place with traits {:?}\n\n{:#?}",
from_traits, to_traits, fx,
);
for (from, to) in from_traits.iter().zip(to_traits) {
let from = fx
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from);
let to = fx
.tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to);
assert_eq!(
from, to,
"Can't write trait object of incompatible traits {:?} to place with traits {:?}\n\n{:#?}",
from_traits, to_traits, fx,
);
}
// dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed
}
_ => {
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
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

fn print_dyn_existential(
self,
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
_predicates: &'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'tcx>>>,
) -> Result<Self::DynExistential, Self::Error> {
Err(NonTrivialPath)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl<'tcx> LateContext<'tcx> {

fn print_dyn_existential(
self,
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
_predicates: &'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'tcx>>>,
) -> Result<Self::DynExistential, Self::Error> {
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
}
ty::Dynamic(binder, _) => {
let mut has_emitted = false;
for predicate in binder.skip_binder().iter() {
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate {
for predicate in binder.iter() {
if let ty::ExistentialPredicate::Trait(ref trait_ref) =
predicate.skip_binder()
{
let def_id = trait_ref.def_id;
let descr_post =
&format!(" trait object{}{}", plural_suffix, descr_post,);
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/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ pub use self::pointer::{Pointer, PointerArithmetic};
/// Uniquely identifies one of the following:
/// - A constant
/// - A static
/// - A const fn where all arguments (if any) are zero-sized types
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, Lift)]
pub struct GlobalId<'tcx> {
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,14 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
}
}

impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::ExistentialPredicate<'tcx>> {
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D>
for ty::List<ty::Binder<ty::ExistentialPredicate<'tcx>>>
{
fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> {
let len = decoder.read_usize()?;
Ok(decoder.tcx().mk_existential_predicates((0..len).map(|_| Decodable::decode(decoder)))?)
Ok(decoder
.tcx()
.mk_poly_existential_predicates((0..len).map(|_| Decodable::decode(decoder)))?)
}
}

Expand Down Expand Up @@ -373,7 +377,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [mir::abstract_const::N
impl_decodable_via_ref! {
&'tcx ty::TypeckResults<'tcx>,
&'tcx ty::List<Ty<'tcx>>,
&'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
&'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'tcx>>>,
&'tcx Allocation,
&'tcx mir::Body<'tcx>,
&'tcx mir::UnsafetyCheckResult,
Expand Down
34 changes: 21 additions & 13 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct CtxtInterners<'tcx> {
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
region: InternedSet<'tcx, RegionKind>,
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
poly_existential_predicates: InternedSet<'tcx, List<ty::Binder<ExistentialPredicate<'tcx>>>>,
predicate: InternedSet<'tcx, PredicateInner<'tcx>>,
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
projs: InternedSet<'tcx, List<ProjectionKind>>,
Expand All @@ -103,7 +103,7 @@ impl<'tcx> CtxtInterners<'tcx> {
type_list: Default::default(),
substs: Default::default(),
region: Default::default(),
existential_predicates: Default::default(),
poly_existential_predicates: Default::default(),
canonical_var_infos: Default::default(),
predicate: Default::default(),
predicates: Default::default(),
Expand Down Expand Up @@ -1623,7 +1623,7 @@ nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}

nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
nop_list_lift! {poly_existential_predicates; ty::Binder<ExistentialPredicate<'a>> => ty::Binder<ExistentialPredicate<'tcx>>}
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
Expand Down Expand Up @@ -2064,7 +2064,8 @@ slice_interners!(
type_list: _intern_type_list(Ty<'tcx>),
substs: _intern_substs(GenericArg<'tcx>),
canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>),
existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>),
poly_existential_predicates:
_intern_poly_existential_predicates(ty::Binder<ExistentialPredicate<'tcx>>),
predicates: _intern_predicates(Predicate<'tcx>),
projs: _intern_projs(ProjectionKind),
place_elems: _intern_place_elems(PlaceElem<'tcx>),
Expand Down Expand Up @@ -2295,7 +2296,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_dynamic(
self,
obj: ty::Binder<&'tcx List<ExistentialPredicate<'tcx>>>,
obj: &'tcx List<ty::Binder<ExistentialPredicate<'tcx>>>,
reg: ty::Region<'tcx>,
) -> Ty<'tcx> {
self.mk_ty(Dynamic(obj, reg))
Expand Down Expand Up @@ -2425,13 +2426,17 @@ impl<'tcx> TyCtxt<'tcx> {
Place { local: place.local, projection: self.intern_place_elems(&projection) }
}

pub fn intern_existential_predicates(
pub fn intern_poly_existential_predicates(
self,
eps: &[ExistentialPredicate<'tcx>],
) -> &'tcx List<ExistentialPredicate<'tcx>> {
eps: &[ty::Binder<ExistentialPredicate<'tcx>>],
) -> &'tcx List<ty::Binder<ExistentialPredicate<'tcx>>> {
assert!(!eps.is_empty());
assert!(eps.array_windows().all(|[a, b]| a.stable_cmp(self, b) != Ordering::Greater));
self._intern_existential_predicates(eps)
assert!(
eps.array_windows()
.all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder())
!= Ordering::Greater)
);
self._intern_poly_existential_predicates(eps)
}

pub fn intern_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List<Predicate<'tcx>> {
Expand Down Expand Up @@ -2488,13 +2493,16 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

pub fn mk_existential_predicates<
I: InternAs<[ExistentialPredicate<'tcx>], &'tcx List<ExistentialPredicate<'tcx>>>,
pub fn mk_poly_existential_predicates<
I: InternAs<
[ty::Binder<ExistentialPredicate<'tcx>>],
&'tcx List<ty::Binder<ExistentialPredicate<'tcx>>>,
>,
>(
self,
iter: I,
) -> I::Output {
iter.intern_with(|xs| self.intern_existential_predicates(xs))
iter.intern_with(|xs| self.intern_poly_existential_predicates(xs))
}

pub fn mk_predicates<I: InternAs<[Predicate<'tcx>], &'tcx List<Predicate<'tcx>>>>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum TypeError<'tcx> {
CyclicTy(Ty<'tcx>),
CyclicConst(&'tcx ty::Const<'tcx>),
ProjectionMismatched(ExpectedFound<DefId>),
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>),
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'tcx>>>>),
ObjectUnsafeCoercion(DefId),
ConstMismatch(ExpectedFound<&'tcx ty::Const<'tcx>>),

Expand Down
20 changes: 8 additions & 12 deletions compiler/rustc_middle/src/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,15 @@ impl FlagComputation {
}

&ty::Dynamic(obj, r) => {
self.bound_computation(obj, |computation, obj| {
for predicate in obj.iter() {
match predicate {
ty::ExistentialPredicate::Trait(tr) => {
computation.add_substs(tr.substs)
}
ty::ExistentialPredicate::Projection(p) => {
computation.add_existential_projection(&p);
}
ty::ExistentialPredicate::AutoTrait(_) => {}
for predicate in obj.iter() {
self.bound_computation(predicate, |computation, predicate| match predicate {
ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs),
ty::ExistentialPredicate::Projection(p) => {
computation.add_existential_projection(&p);
}
}
});
ty::ExistentialPredicate::AutoTrait(_) => {}
});
}

self.add_region(r);
}
Expand Down
Loading