Skip to content

Commit 594fb25

Browse files
committed
Auto merge of #51258 - Mark-Simulacrum:stable-next, r=nikomatsakis
1.26.2 release This includes a backport of #51235 which fixes #51117 on stable. It has not been tested. r? @nikomatsakis since the backport was not clean. cc @rust-lang/core @rust-lang/release
2 parents 827013a + 7093b11 commit 594fb25

File tree

14 files changed

+139
-71
lines changed

14 files changed

+139
-71
lines changed

RELEASES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.26.2 (2018-06-05)
2+
==========================
3+
4+
Compatibility Notes
5+
-------------------
6+
7+
- [The borrow checker was fixed to avoid unsoundness when using match ergonomics][51117]
8+
9+
[51117]: https://github.com/rust-lang/rust/issues/51117
10+
111
Version 1.26.1 (2018-05-29)
212
==========================
313

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Build;
2424
use config::Config;
2525

2626
// The version number
27-
pub const CFG_RELEASE_NUM: &str = "1.26.1";
27+
pub const CFG_RELEASE_NUM: &str = "1.26.2";
2828

2929
pub struct GitInfo {
3030
inner: Option<Info>,

src/librustc/middle/expr_use_visitor.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -845,17 +845,24 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
845845
/// established up front, e.g. via `determine_pat_move_mode` (see
846846
/// also `walk_irrefutable_pat` for patterns that stand alone).
847847
fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat, match_mode: MatchMode) {
848-
debug!("walk_pat cmt_discr={:?} pat={:?}", cmt_discr, pat);
848+
debug!("walk_pat(cmt_discr={:?}, pat={:?})", cmt_discr, pat);
849849

850850
let ExprUseVisitor { ref mc, ref mut delegate, param_env } = *self;
851851
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
852852
if let PatKind::Binding(_, canonical_id, ..) = pat.node {
853-
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
853+
debug!(
854+
"walk_pat: binding cmt_pat={:?} pat={:?} match_mode={:?}",
855+
cmt_pat,
856+
pat,
857+
match_mode,
858+
);
854859
let bm = *mc.tables.pat_binding_modes().get(pat.hir_id)
855860
.expect("missing binding mode");
861+
debug!("walk_pat: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
856862

857863
// pat_ty: the type of the binding being produced.
858864
let pat_ty = return_if_err!(mc.node_ty(pat.hir_id));
865+
debug!("walk_pat: pat_ty={:?}", pat_ty);
859866

860867
// Each match binding is effectively an assignment to the
861868
// binding being produced.

src/librustc/middle/mem_categorization.rs

+47-47
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum Categorization<'tcx> {
9595
StaticItem,
9696
Upvar(Upvar), // upvar referenced by closure env
9797
Local(ast::NodeId), // local variable
98-
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
98+
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
9999
Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc
100100
Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1)
101101

@@ -120,9 +120,6 @@ pub enum PointerKind<'tcx> {
120120

121121
/// `*T`
122122
UnsafePtr(hir::Mutability),
123-
124-
/// Implicit deref of the `&T` that results from an overloaded index `[]`.
125-
Implicit(ty::BorrowKind, ty::Region<'tcx>),
126123
}
127124

128125
// We use the term "interior" to mean "something reachable from the
@@ -161,6 +158,7 @@ pub enum MutabilityCategory {
161158
pub enum Note {
162159
NoteClosureEnv(ty::UpvarId), // Deref through closure env
163160
NoteUpvarRef(ty::UpvarId), // Deref through by-ref upvar
161+
NoteIndex, // Deref as part of desugaring `x[]` into its two components
164162
NoteNone // Nothing special
165163
}
166164

@@ -224,8 +222,7 @@ impl<'tcx> cmt_<'tcx> {
224222

225223
pub fn immutability_blame(&self) -> Option<ImmutabilityBlame<'tcx>> {
226224
match self.cat {
227-
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) |
228-
Categorization::Deref(ref base_cmt, Implicit(ty::ImmBorrow, _)) => {
225+
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
229226
// try to figure out where the immutable reference came from
230227
match base_cmt.cat {
231228
Categorization::Local(node_id) =>
@@ -321,7 +318,7 @@ impl MutabilityCategory {
321318
Unique => {
322319
base_mutbl.inherit()
323320
}
324-
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
321+
BorrowedPtr(borrow_kind, _) => {
325322
MutabilityCategory::from_borrow_kind(borrow_kind)
326323
}
327324
UnsafePtr(m) => {
@@ -610,7 +607,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
610607
} else {
611608
previous()?
612609
};
613-
self.cat_deref(expr, base, false)
610+
self.cat_deref(expr, base, NoteNone)
614611
}
615612

616613
adjustment::Adjust::NeverToAny |
@@ -633,10 +630,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
633630
match expr.node {
634631
hir::ExprUnary(hir::UnDeref, ref e_base) => {
635632
if self.tables.is_method_call(expr) {
636-
self.cat_overloaded_place(expr, e_base, false)
633+
self.cat_overloaded_place(expr, e_base, NoteNone)
637634
} else {
638635
let base_cmt = self.cat_expr(&e_base)?;
639-
self.cat_deref(expr, base_cmt, false)
636+
self.cat_deref(expr, base_cmt, NoteNone)
640637
}
641638
}
642639

@@ -661,7 +658,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
661658
// The call to index() returns a `&T` value, which
662659
// is an rvalue. That is what we will be
663660
// dereferencing.
664-
self.cat_overloaded_place(expr, base, true)
661+
self.cat_overloaded_place(expr, base, NoteIndex)
665662
} else {
666663
let base_cmt = self.cat_expr(&base)?;
667664
self.cat_index(expr, base_cmt, expr_ty, InteriorOffsetKind::Index)
@@ -1012,12 +1009,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10121009
ret
10131010
}
10141011

1015-
fn cat_overloaded_place(&self,
1016-
expr: &hir::Expr,
1017-
base: &hir::Expr,
1018-
implicit: bool)
1019-
-> McResult<cmt<'tcx>> {
1020-
debug!("cat_overloaded_place: implicit={}", implicit);
1012+
fn cat_overloaded_place(
1013+
&self,
1014+
expr: &hir::Expr,
1015+
base: &hir::Expr,
1016+
note: Note,
1017+
) -> McResult<cmt<'tcx>> {
1018+
debug!(
1019+
"cat_overloaded_place(expr={:?}, base={:?}, note={:?})",
1020+
expr,
1021+
base,
1022+
note,
1023+
);
10211024

10221025
// Reconstruct the output assuming it's a reference with the
10231026
// same region and mutability as the receiver. This holds for
@@ -1037,14 +1040,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10371040
});
10381041

10391042
let base_cmt = self.cat_rvalue_node(expr.id, expr.span, ref_ty);
1040-
self.cat_deref(expr, base_cmt, implicit)
1043+
self.cat_deref(expr, base_cmt, note)
10411044
}
10421045

1043-
pub fn cat_deref<N:ast_node>(&self,
1044-
node: &N,
1045-
base_cmt: cmt<'tcx>,
1046-
implicit: bool)
1047-
-> McResult<cmt<'tcx>> {
1046+
pub fn cat_deref(
1047+
&self,
1048+
node: &impl ast_node,
1049+
base_cmt: cmt<'tcx>,
1050+
note: Note,
1051+
) -> McResult<cmt<'tcx>> {
10481052
debug!("cat_deref: base_cmt={:?}", base_cmt);
10491053

10501054
let base_cmt_ty = base_cmt.ty;
@@ -1060,9 +1064,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10601064
let ptr = match base_cmt.ty.sty {
10611065
ty::TyAdt(def, ..) if def.is_box() => Unique,
10621066
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
1063-
ty::TyRef(r, mt) => {
1064-
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);
1065-
if implicit { Implicit(bk, r) } else { BorrowedPtr(bk, r) }
1067+
ty::TyRef(r, ty) => {
1068+
let bk = ty::BorrowKind::from_mutbl(ty.mutbl);
1069+
BorrowedPtr(bk, r)
10661070
}
10671071
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
10681072
};
@@ -1073,7 +1077,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10731077
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
10741078
cat: Categorization::Deref(base_cmt, ptr),
10751079
ty: deref_ty,
1076-
note: NoteNone
1080+
note: note,
10771081
});
10781082
debug!("cat_deref ret {:?}", ret);
10791083
Ok(ret)
@@ -1207,7 +1211,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12071211
// step out of sync again. So you'll see below that we always
12081212
// get the type of the *subpattern* and use that.
12091213

1210-
debug!("cat_pattern: {:?} cmt={:?}", pat, cmt);
1214+
debug!("cat_pattern(pat={:?}, cmt={:?})", pat, cmt);
12111215

12121216
// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
12131217
// `cmt`s are constructed differently from patterns. For example, in
@@ -1245,10 +1249,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12451249
.pat_adjustments()
12461250
.get(pat.hir_id)
12471251
.map(|v| v.len())
1248-
.unwrap_or(0) {
1249-
cmt = self.cat_deref(pat, cmt, true /* implicit */)?;
1252+
.unwrap_or(0)
1253+
{
1254+
debug!("cat_pattern: applying adjustment to cmt={:?}", cmt);
1255+
cmt = self.cat_deref(pat, cmt, NoteNone)?;
12501256
}
12511257
let cmt = cmt; // lose mutability
1258+
debug!("cat_pattern: applied adjustment derefs to get cmt={:?}", cmt);
12521259

12531260
// Invoke the callback, but only now, after the `cmt` has adjusted.
12541261
//
@@ -1342,7 +1349,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13421349
// box p1, &p1, &mut p1. we can ignore the mutability of
13431350
// PatKind::Ref since that information is already contained
13441351
// in the type.
1345-
let subcmt = self.cat_deref(pat, cmt, false)?;
1352+
let subcmt = self.cat_deref(pat, cmt, NoteNone)?;
13461353
self.cat_pattern_(subcmt, &subpat, op)?;
13471354
}
13481355

@@ -1403,7 +1410,6 @@ impl<'tcx> cmt_<'tcx> {
14031410
Categorization::Local(..) |
14041411
Categorization::Deref(_, UnsafePtr(..)) |
14051412
Categorization::Deref(_, BorrowedPtr(..)) |
1406-
Categorization::Deref(_, Implicit(..)) |
14071413
Categorization::Upvar(..) => {
14081414
Rc::new((*self).clone())
14091415
}
@@ -1423,9 +1429,7 @@ impl<'tcx> cmt_<'tcx> {
14231429

14241430
match self.cat {
14251431
Categorization::Deref(ref b, BorrowedPtr(ty::MutBorrow, _)) |
1426-
Categorization::Deref(ref b, Implicit(ty::MutBorrow, _)) |
14271432
Categorization::Deref(ref b, BorrowedPtr(ty::UniqueImmBorrow, _)) |
1428-
Categorization::Deref(ref b, Implicit(ty::UniqueImmBorrow, _)) |
14291433
Categorization::Deref(ref b, Unique) |
14301434
Categorization::Downcast(ref b, _) |
14311435
Categorization::Interior(ref b, _) => {
@@ -1448,8 +1452,7 @@ impl<'tcx> cmt_<'tcx> {
14481452
}
14491453
}
14501454

1451-
Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) |
1452-
Categorization::Deref(_, Implicit(ty::ImmBorrow, _)) => {
1455+
Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) => {
14531456
FreelyAliasable(AliasableBorrowed)
14541457
}
14551458
}
@@ -1471,7 +1474,7 @@ impl<'tcx> cmt_<'tcx> {
14711474
_ => bug!()
14721475
})
14731476
}
1474-
NoteNone => None
1477+
NoteIndex | NoteNone => None
14751478
}
14761479
}
14771480

@@ -1500,17 +1503,17 @@ impl<'tcx> cmt_<'tcx> {
15001503
Some(_) => bug!(),
15011504
None => {
15021505
match pk {
1503-
Implicit(..) => {
1504-
format!("indexed content")
1505-
}
15061506
Unique => {
15071507
format!("`Box` content")
15081508
}
15091509
UnsafePtr(..) => {
15101510
format!("dereference of raw pointer")
15111511
}
15121512
BorrowedPtr(..) => {
1513-
format!("borrowed content")
1513+
match self.note {
1514+
NoteIndex => format!("indexed content"),
1515+
_ => format!("borrowed content"),
1516+
}
15141517
}
15151518
}
15161519
}
@@ -1541,12 +1544,9 @@ impl<'tcx> cmt_<'tcx> {
15411544
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15421545
match ptr {
15431546
Unique => "Box",
1544-
BorrowedPtr(ty::ImmBorrow, _) |
1545-
Implicit(ty::ImmBorrow, _) => "&",
1546-
BorrowedPtr(ty::MutBorrow, _) |
1547-
Implicit(ty::MutBorrow, _) => "&mut",
1548-
BorrowedPtr(ty::UniqueImmBorrow, _) |
1549-
Implicit(ty::UniqueImmBorrow, _) => "&unique",
1547+
BorrowedPtr(ty::ImmBorrow, _) => "&",
1548+
BorrowedPtr(ty::MutBorrow, _) => "&mut",
1549+
BorrowedPtr(ty::UniqueImmBorrow, _) => "&unique",
15501550
UnsafePtr(_) => "*",
15511551
}
15521552
}

src/librustc/traits/project.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,30 @@ impl<'tcx> ProjectionTyCandidateSet<'tcx> {
137137
fn push_candidate(&mut self, candidate: ProjectionTyCandidate<'tcx>) -> bool {
138138
use self::ProjectionTyCandidateSet::*;
139139
use self::ProjectionTyCandidate::*;
140+
141+
// This wacky variable is just used to try and
142+
// make code readable and avoid confusing paths.
143+
// It is assigned a "value" of `()` only on those
144+
// paths in which we wish to convert `*self` to
145+
// ambiguous (and return false, because the candidate
146+
// was not used). On other paths, it is not assigned,
147+
// and hence if those paths *could* reach the code that
148+
// comes after the match, this fn would not compile.
149+
let convert_to_ambigious;
150+
140151
match self {
141152
None => {
142153
*self = Single(candidate);
143-
true
154+
return true;
144155
}
156+
145157
Single(current) => {
146158
// Duplicates can happen inside ParamEnv. In the case, we
147159
// perform a lazy deduplication.
148160
if current == &candidate {
149161
return false;
150162
}
163+
151164
// Prefer where-clauses. As in select, if there are multiple
152165
// candidates, we prefer where-clause candidates over impls. This
153166
// may seem a bit surprising, since impls are the source of
@@ -156,17 +169,23 @@ impl<'tcx> ProjectionTyCandidateSet<'tcx> {
156169
// clauses are the safer choice. See the comment on
157170
// `select::SelectionCandidate` and #21974 for more details.
158171
match (current, candidate) {
159-
(ParamEnv(..), ParamEnv(..)) => { *self = Ambiguous; }
160-
(ParamEnv(..), _) => {}
172+
(ParamEnv(..), ParamEnv(..)) => convert_to_ambigious = (),
173+
(ParamEnv(..), _) => return false,
161174
(_, ParamEnv(..)) => { unreachable!(); }
162-
(_, _) => { *self = Ambiguous; }
175+
(_, _) => convert_to_ambigious = (),
163176
}
164-
false
165177
}
178+
166179
Ambiguous | Error(..) => {
167-
false
180+
return false;
168181
}
169182
}
183+
184+
// We only ever get here when we moved from a single candidate
185+
// to ambiguous.
186+
let () = convert_to_ambigious;
187+
*self = Ambiguous;
188+
false
170189
}
171190
}
172191

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
181181
-> Option<mc::cmt<'tcx>> {
182182
match cmt.cat {
183183
Categorization::Deref(_, mc::BorrowedPtr(..)) |
184-
Categorization::Deref(_, mc::Implicit(..)) |
185184
Categorization::Deref(_, mc::UnsafePtr(..)) |
186185
Categorization::StaticItem => {
187186
Some(cmt.clone())

src/librustc_borrowck/borrowck/gather_loans/lifetime.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
7575
Categorization::Local(..) | // L-Local
7676
Categorization::Upvar(..) |
7777
Categorization::Deref(_, mc::BorrowedPtr(..)) | // L-Deref-Borrowed
78-
Categorization::Deref(_, mc::Implicit(..)) |
7978
Categorization::Deref(_, mc::UnsafePtr(..)) => {
8079
self.check_scope(self.scope(cmt))
8180
}
@@ -123,8 +122,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
123122
Categorization::Deref(_, mc::UnsafePtr(..)) => {
124123
self.bccx.tcx.types.re_static
125124
}
126-
Categorization::Deref(_, mc::BorrowedPtr(_, r)) |
127-
Categorization::Deref(_, mc::Implicit(_, r)) => {
125+
Categorization::Deref(_, mc::BorrowedPtr(_, r)) => {
128126
r
129127
}
130128
Categorization::Downcast(ref cmt, _) |

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &'a BorrowckCtxt<'a, 'tcx>,
140140
-> DiagnosticBuilder<'a> {
141141
match move_from.cat {
142142
Categorization::Deref(_, mc::BorrowedPtr(..)) |
143-
Categorization::Deref(_, mc::Implicit(..)) |
144143
Categorization::Deref(_, mc::UnsafePtr(..)) |
145144
Categorization::StaticItem => {
146145
bccx.cannot_move_out_of(

0 commit comments

Comments
 (0)