Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 0bc815d

Browse files
committed
Auto merge of #194 - Swatinem:rustup, r=JohnTitor
Update to nightly-2021-05-21 This needed mostly changes around `Predicate` and `Binder`. Also re-blessed snapshots, some of which improved by pointing only to the item signature instead of its whole body. This is the first time I am touching rustc internals, so I am not 100% confident with that change, however all the tests pass, and some of the snapshots are even improving.
2 parents 96c1a21 + 2f8bd8c commit 0bc815d

22 files changed

+212
-262
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ repository and compiled from source or installed from
2727
of the nightly toolchain is supported at any given time.
2828

2929
<!-- NOTE: Keep in sync with nightly date on rust-toolchain. -->
30-
It's recommended to use `nightly-2020-12-20` toolchain.
31-
You can install it by using `rustup install nightly-2020-12-20` if you already have rustup.
30+
It's recommended to use `nightly-2021-05-21` toolchain.
31+
You can install it by using `rustup install nightly-2021-05-21` if you already have rustup.
3232
Then you can do:
3333

3434
```sh
35-
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2020-12-20
36-
$ cargo +nightly-2020-12-20 install --git https://github.com/rust-lang/rust-semverver
35+
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-05-21
36+
$ cargo +nightly-2021-05-21 install --git https://github.com/rust-lang/rust-semverver
3737
```
3838

3939
You'd also need `cmake` for some dependencies, and a few common libraries (if you hit

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# NOTE: Keep in sync with nightly date on README
22
[toolchain]
3-
channel = "nightly-2020-12-20"
3+
channel = "nightly-2021-05-21"
44
components = ["llvm-tools-preview", "rustc-dev"]

src/changes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ impl<'a> Serialize for RSpan<'a> {
8888

8989
assert!(lo.file.name == hi.file.name);
9090
let file_name = if let FileName::Real(ref name) = lo.file.name {
91-
format!("{}", name.local_path().display())
91+
name.local_path().map(|p| format!("{}", p.display()))
9292
} else {
93-
"no file name".to_owned()
94-
};
93+
None
94+
}
95+
.unwrap_or_else(|| "no file name".to_owned());
9596

9697
let mut state = serializer.serialize_struct("Span", 5)?;
9798
state.serialize_field("file", &file_name)?;

src/mapping.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl IdMapping {
181181
match param.kind {
182182
GenericParamDefKind::Lifetime => unreachable!(),
183183
GenericParamDefKind::Type { .. } => (),
184-
GenericParamDefKind::Const => unreachable!(),
184+
GenericParamDefKind::Const { .. } => unreachable!(),
185185
};
186186

187187
self.type_params.insert(param.def_id, param.clone());
@@ -237,10 +237,8 @@ impl IdMapping {
237237
Some(new.1.def_id())
238238
} else if let Some(new) = self.trait_item_mapping.get(&old) {
239239
Some(new.1.def_id())
240-
} else if let Some(new_def_id) = self.internal_mapping.get(&old) {
241-
Some(*new_def_id)
242240
} else {
243-
None
241+
self.internal_mapping.get(&old).copied()
244242
}
245243
} else {
246244
Some(old)

src/mismatch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> {
305305

306306
fn binders<T: Relate<'tcx>>(
307307
&mut self,
308-
a: ty::Binder<T>,
309-
b: ty::Binder<T>,
310-
) -> RelateResult<'tcx, ty::Binder<T>> {
308+
a: ty::Binder<'tcx, T>,
309+
b: ty::Binder<'tcx, T>,
310+
) -> RelateResult<'tcx, ty::Binder<'tcx, T>> {
311311
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
312312
}
313313
}

src/translate.rs

Lines changed: 88 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
148148
self.tcx.mk_param_from_def(def)
149149
}
150150
}
151-
GenericParamDefKind::Const => unreachable!(),
151+
GenericParamDefKind::Const { .. } => unreachable!(),
152152
});
153153

154154
if success.get() {
@@ -214,7 +214,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
214214
p.map_bound(|p| {
215215
match p {
216216
Trait(existential_trait_ref) => {
217-
let trait_ref = Binder::bind(existential_trait_ref)
217+
let trait_ref = Binder::dummy(existential_trait_ref)
218218
.with_self_ty(self.tcx, dummy_self);
219219
let did = trait_ref.skip_binder().def_id;
220220
let substs = trait_ref.skip_binder().substs;
@@ -238,7 +238,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
238238
}
239239
Projection(existential_projection) => {
240240
let projection_pred =
241-
Binder::bind(existential_projection)
241+
Binder::dummy(existential_projection)
242242
.with_self_ty(self.tcx, dummy_self);
243243
let item_def_id = projection_pred
244244
.skip_binder()
@@ -332,7 +332,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
332332

333333
/// Translate a region.
334334
fn translate_region(&self, region: Region<'tcx>) -> Region<'tcx> {
335-
use rustc_middle::ty::BoundRegion::BrNamed;
335+
use rustc_middle::ty::BoundRegionKind::*;
336336
use rustc_middle::ty::RegionKind::*;
337337
use rustc_middle::ty::{EarlyBoundRegion, FreeRegion};
338338

@@ -376,102 +376,97 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
376376
predicate: Predicate<'tcx>,
377377
) -> Option<Predicate<'tcx>> {
378378
use rustc_middle::ty::{
379-
Binder, OutlivesPredicate, PredicateAtom, PredicateKind, ProjectionPredicate,
380-
ProjectionTy, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam,
379+
OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, SubtypePredicate,
380+
ToPredicate, TraitPredicate, WithOptConstParam,
381381
};
382382

383-
Some(match predicate.skip_binders() {
384-
PredicateAtom::Trait(pred, constness) => Binder::bind(PredicateAtom::Trait(
385-
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
386-
index_map,
387-
pred.trait_ref.def_id,
388-
pred.trait_ref.substs,
389-
) {
390-
TraitPredicate {
391-
trait_ref: TraitRef {
392-
def_id: target_def_id,
393-
substs: target_substs,
394-
},
383+
Some(
384+
match predicate.kind().skip_binder() {
385+
PredicateKind::Trait(pred, constness) => PredicateKind::Trait(
386+
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
387+
index_map,
388+
pred.trait_ref.def_id,
389+
pred.trait_ref.substs,
390+
) {
391+
TraitPredicate {
392+
trait_ref: TraitRef {
393+
def_id: target_def_id,
394+
substs: target_substs,
395+
},
396+
}
397+
} else {
398+
return None;
399+
},
400+
constness,
401+
),
402+
PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({
403+
let l = self.translate_region(pred.0);
404+
let r = self.translate_region(pred.1);
405+
OutlivesPredicate(l, r)
406+
}),
407+
PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({
408+
let l = self.translate(index_map, pred.0);
409+
let r = self.translate_region(pred.1);
410+
OutlivesPredicate(l, r)
411+
}),
412+
PredicateKind::Projection(pred) => PredicateKind::Projection(
413+
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
414+
index_map,
415+
pred.projection_ty.item_def_id,
416+
pred.projection_ty.substs,
417+
) {
418+
ProjectionPredicate {
419+
projection_ty: ProjectionTy {
420+
substs: target_substs,
421+
item_def_id: target_def_id,
422+
},
423+
ty: self.translate(index_map, &pred.ty),
424+
}
425+
} else {
426+
return None;
427+
},
428+
),
429+
PredicateKind::WellFormed(ty) => {
430+
PredicateKind::WellFormed(self.translate(index_map, ty))
431+
}
432+
PredicateKind::ObjectSafe(did) => {
433+
PredicateKind::ObjectSafe(self.translate_orig(did))
434+
}
435+
PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind(
436+
self.translate_orig(did),
437+
self.translate(index_map, &substs),
438+
kind,
439+
),
440+
PredicateKind::Subtype(pred) => PredicateKind::Subtype({
441+
let l = self.translate(index_map, pred.a);
442+
let r = self.translate(index_map, pred.b);
443+
SubtypePredicate {
444+
a_is_expected: pred.a_is_expected,
445+
a: l,
446+
b: r,
395447
}
396-
} else {
397-
return None;
398-
},
399-
constness,
400-
))
401-
.potentially_quantified(self.tcx, PredicateKind::ForAll),
402-
PredicateAtom::RegionOutlives(pred) => Binder::bind(PredicateAtom::RegionOutlives({
403-
let l = self.translate_region(pred.0);
404-
let r = self.translate_region(pred.1);
405-
OutlivesPredicate(l, r)
406-
}))
407-
.potentially_quantified(self.tcx, PredicateKind::ForAll),
408-
PredicateAtom::TypeOutlives(pred) => Binder::bind(PredicateAtom::TypeOutlives({
409-
let l = self.translate(index_map, pred.0);
410-
let r = self.translate_region(pred.1);
411-
OutlivesPredicate(l, r)
412-
}))
413-
.potentially_quantified(self.tcx, PredicateKind::ForAll),
414-
PredicateAtom::Projection(pred) => Binder::bind(PredicateAtom::Projection(
415-
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
416-
index_map,
417-
pred.projection_ty.item_def_id,
418-
pred.projection_ty.substs,
419-
) {
420-
ProjectionPredicate {
421-
projection_ty: ProjectionTy {
422-
substs: target_substs,
423-
item_def_id: target_def_id,
424-
},
425-
ty: self.translate(index_map, &pred.ty),
448+
}),
449+
PredicateKind::ConstEvaluatable(param, orig_substs) => {
450+
if let Some((target_def_id, target_substs)) =
451+
self.translate_orig_substs(index_map, param.did, orig_substs)
452+
{
453+
// TODO: We could probably use translated version for
454+
// `WithOptConstParam::const_param_did`
455+
let const_param = WithOptConstParam::unknown(target_def_id);
456+
PredicateKind::ConstEvaluatable(const_param, target_substs)
457+
} else {
458+
return None;
426459
}
427-
} else {
428-
return None;
429-
},
430-
))
431-
.potentially_quantified(self.tcx, PredicateKind::ForAll),
432-
PredicateAtom::WellFormed(ty) => {
433-
PredicateAtom::WellFormed(self.translate(index_map, ty)).to_predicate(self.tcx)
434-
}
435-
PredicateAtom::ObjectSafe(did) => {
436-
PredicateAtom::ObjectSafe(self.translate_orig(did)).to_predicate(self.tcx)
437-
}
438-
PredicateAtom::ClosureKind(did, substs, kind) => PredicateAtom::ClosureKind(
439-
self.translate_orig(did),
440-
self.translate(index_map, &substs),
441-
kind,
442-
)
443-
.to_predicate(self.tcx),
444-
PredicateAtom::Subtype(pred) => PredicateAtom::Subtype({
445-
let l = self.translate(index_map, pred.a);
446-
let r = self.translate(index_map, pred.b);
447-
SubtypePredicate {
448-
a_is_expected: pred.a_is_expected,
449-
a: l,
450-
b: r,
451-
}
452-
})
453-
.to_predicate(self.tcx),
454-
PredicateAtom::ConstEvaluatable(param, orig_substs) => {
455-
if let Some((target_def_id, target_substs)) =
456-
self.translate_orig_substs(index_map, param.did, orig_substs)
457-
{
458-
// TODO: We could probably use translated version for
459-
// `WithOptConstParam::const_param_did`
460-
let const_param = WithOptConstParam::unknown(target_def_id);
461-
PredicateAtom::ConstEvaluatable(const_param, target_substs)
462-
.to_predicate(self.tcx)
463-
} else {
464-
return None;
465460
}
461+
PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate(
462+
self.translate(index_map, &c1),
463+
self.translate(index_map, &c2),
464+
),
465+
// NOTE: Only used for Chalk trait solver
466+
PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(),
466467
}
467-
PredicateAtom::ConstEquate(c1, c2) => PredicateAtom::ConstEquate(
468-
self.translate(index_map, &c1),
469-
self.translate(index_map, &c2),
470-
)
471468
.to_predicate(self.tcx),
472-
// NOTE: Only used for Chalk trait solver
473-
PredicateAtom::TypeWellFormedFromEnv(_) => unimplemented!(),
474-
})
469+
)
475470
}
476471

477472
/// Translate a slice of predicates in the context of an item.

src/traverse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ fn diff_traits<'tcx>(
568568
) {
569569
use rustc_hir::Unsafety::Unsafe;
570570
use rustc_middle::ty::subst::GenericArgKind::Type;
571-
use rustc_middle::ty::{ParamTy, PredicateAtom};
571+
use rustc_middle::ty::{ParamTy, PredicateKind};
572572

573573
debug!(
574574
"diff_traits: old: {:?}, new: {:?}, output: {:?}",
@@ -590,7 +590,7 @@ fn diff_traits<'tcx>(
590590
let old_param_env = tcx.param_env(old);
591591

592592
for bound in old_param_env.caller_bounds() {
593-
if let PredicateAtom::Trait(pred, _) = bound.skip_binders() {
593+
if let PredicateKind::Trait(pred, _) = bound.kind().skip_binder() {
594594
let trait_ref = pred.trait_ref;
595595

596596
debug!("trait_ref substs (old): {:?}", trait_ref.substs);

src/typeck.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use rustc_middle::{
1818
error::TypeError,
1919
fold::TypeFoldable,
2020
subst::{GenericArg, InternalSubsts, SubstsRef},
21-
GenericParamDefKind, ParamEnv, Predicate, PredicateAtom, PredicateKind, TraitRef, Ty,
22-
TyCtxt,
21+
GenericParamDefKind, ParamEnv, Predicate, PredicateKind, TraitRef, Ty, TyCtxt,
2322
},
2423
};
2524
use rustc_trait_selection::traits::FulfillmentContext;
@@ -74,15 +73,15 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> {
7473
/// Register the trait bound represented by a `TraitRef`.
7574
pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) {
7675
use rustc_hir::Constness;
77-
use rustc_middle::ty::{Binder, TraitPredicate};
76+
use rustc_middle::ty::{ToPredicate, TraitPredicate};
7877

79-
let predicate = Binder::bind(PredicateAtom::Trait(
78+
let predicate = PredicateKind::Trait(
8079
TraitPredicate {
8180
trait_ref: checked_trait_ref,
8281
},
8382
Constness::NotConst,
84-
))
85-
.potentially_quantified(self.infcx.tcx, PredicateKind::ForAll);
83+
)
84+
.to_predicate(self.infcx.tcx);
8685
let obligation = Obligation::new(ObligationCause::dummy(), self.given_param_env, predicate);
8786
self.fulfill_cx
8887
.register_predicate_obligation(self.infcx, obligation);
@@ -205,7 +204,7 @@ impl<'a, 'tcx> TypeComparisonContext<'a, 'tcx> {
205204
self.infcx.tcx.mk_param_from_def(def)
206205
}
207206
}
208-
GenericParamDefKind::Const => unreachable!(),
207+
GenericParamDefKind::Const { .. } => unreachable!(),
209208
})
210209
}
211210

tests/cases/func/new.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_fn)]
21
pub fn abc() {}
32

43
pub fn bcd(_: u8) {}

tests/cases/func/old.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_fn)]
21
pub fn abc() {}
32

43
pub fn bcd() {}

0 commit comments

Comments
 (0)