Skip to content

Commit 2824a67

Browse files
committed
Auto merge of #55405 - alexcrichton:beta-next, r=pietroalbini
[beta]: Prepare the 1.31.0 beta release * Update to Cargo's branched 1.31.0 branch * Update the channel to `beta` Rolled up beta-accepted PRs: * #55362: Remove `cargo new --edition` from release notes. * #55325: Fix link to macros chapter * #55358: Remove redundant clone (2) * #55346: Shrink `Statement`. * #55274: Handle bindings in substructure of patterns with type ascriptions * #55297: Partial implementation of uniform paths 2.0 to land before beta * #55192: Fix ordering of nested modules in non-mod.rs mods * #55185: path suggestions in Rust 2018 should point out the change in semantics * #55423: back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch Note that **this does not update the bootstrap compiler** due to #55404
2 parents 4bd4e41 + 7c81496 commit 2824a67

File tree

126 files changed

+1292
-812
lines changed

Some content is hidden

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

126 files changed

+1292
-812
lines changed

RELEASES.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ Cargo
6464
- [`cargo run` doesn't require specifying a package in workspaces.][cargo/5877]
6565
- [`cargo doc` now supports `--message-format=json`.][cargo/5878] This is
6666
equivalent to calling `rustdoc --error-format=json`.
67-
- [You can specify which edition to create a project in cargo
68-
with `cargo new --edition`.][cargo/5984] Currently only `2015` is a
69-
valid option.
7067
- [Cargo will now provide a progress bar for builds.][cargo/5995]
7168

7269
Misc
@@ -100,9 +97,8 @@ Misc
10097
[54404]: https://github.com/rust-lang/rust/pull/54404/
10198
[cargo/5877]: https://github.com/rust-lang/cargo/pull/5877/
10299
[cargo/5878]: https://github.com/rust-lang/cargo/pull/5878/
103-
[cargo/5984]: https://github.com/rust-lang/cargo/pull/5984/
104100
[cargo/5995]: https://github.com/rust-lang/cargo/pull/5995/
105-
[proc-macros]: https://doc.rust-lang.org/book/2018-edition/ch19-06-macros.html
101+
[proc-macros]: https://doc.rust-lang.org/stable/book/2018-edition/ch19-06-macros.html
106102

107103
[`Ipv4Addr::BROADCAST`]: https://doc.rust-lang.org/nightly/std/net/struct.Ipv4Addr.html#associatedconstant.BROADCAST
108104
[`Ipv4Addr::LOCALHOST`]: https://doc.rust-lang.org/nightly/std/net/struct.Ipv4Addr.html#associatedconstant.LOCALHOST

src/bootstrap/dist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,8 @@ impl Step for Extended {
14471447
tarballs.extend(rls_installer.clone());
14481448
tarballs.extend(clippy_installer.clone());
14491449
tarballs.extend(rustfmt_installer.clone());
1450-
tarballs.extend(llvm_tools_installer.clone());
1451-
tarballs.extend(lldb_installer.clone());
1450+
tarballs.extend(llvm_tools_installer);
1451+
tarballs.extend(lldb_installer);
14521452
tarballs.push(analysis_installer);
14531453
tarballs.push(std_installer);
14541454
if builder.config.docs {

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl Step for Compiletest {
10521052
let hostflags = flags.clone();
10531053
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
10541054

1055-
let mut targetflags = flags.clone();
1055+
let mut targetflags = flags;
10561056
targetflags.push(format!(
10571057
"-Lnative={}",
10581058
builder.test_helpers_out(target).display()

src/ci/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fi
5151
#
5252
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
5353
# either automatically or manually.
54-
export RUST_RELEASE_CHANNEL=nightly
54+
export RUST_RELEASE_CHANNEL=beta
5555
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
5656
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
5757
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"

src/librustc/hir/lowering.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,8 @@ impl<'a> LoweringContext<'a> {
30943094
// Privatize the degenerate import base, used only to check
30953095
// the stability of `use a::{};`, to avoid it showing up as
30963096
// a re-export by accident when `pub`, e.g. in documentation.
3097-
let path = P(self.lower_path(id, &prefix, ParamMode::Explicit));
3097+
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
3098+
let path = P(self.lower_path_extra(def, &prefix, None, ParamMode::Explicit));
30983099
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
30993100
hir::ItemKind::Use(path, hir::UseKind::ListStem)
31003101
}

src/librustc/ich/impls_mir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,6 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<
606606
}
607607
}
608608
}
609+
610+
impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs });
611+
impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents });

src/librustc/infer/error_reporting/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
479479
err.span_label(arm_span, msg);
480480
}
481481
}
482-
hir::MatchSource::TryDesugar => {
483-
// Issue #51632
484-
if let Ok(try_snippet) = self.tcx.sess.source_map().span_to_snippet(arm_span) {
485-
err.span_suggestion_with_applicability(
486-
arm_span,
487-
"try wrapping with a success variant",
488-
format!("Ok({})", try_snippet),
489-
Applicability::MachineApplicable,
490-
);
491-
}
492-
}
482+
hir::MatchSource::TryDesugar => {}
493483
_ => {
494484
let msg = "match arm with an incompatible type";
495485
if self.tcx.sess.source_map().is_multiline(arm_span) {

src/librustc/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ where
458458
);
459459
debug!("projection_must_outlive: unique declared bound appears in trait ref");
460460
self.delegate
461-
.push_sub_region_constraint(origin.clone(), region, unique_bound);
461+
.push_sub_region_constraint(origin, region, unique_bound);
462462
return;
463463
}
464464

src/librustc/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
749749
a // LUB(a,a) = a
750750
}
751751

752-
_ => self.combine_vars(tcx, Lub, a, b, origin.clone()),
752+
_ => self.combine_vars(tcx, Lub, a, b, origin),
753753
}
754754
}
755755

@@ -771,7 +771,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
771771
a // GLB(a,a) = a
772772
}
773773

774-
_ => self.combine_vars(tcx, Glb, a, b, origin.clone()),
774+
_ => self.combine_vars(tcx, Glb, a, b, origin),
775775
}
776776
}
777777

src/librustc/mir/mod.rs

+123-4
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ pub struct LocalDecl<'tcx> {
710710
/// e.g. via `let x: T`, then we carry that type here. The MIR
711711
/// borrow checker needs this information since it can affect
712712
/// region inference.
713-
pub user_ty: Option<(UserTypeAnnotation<'tcx>, Span)>,
713+
pub user_ty: UserTypeProjections<'tcx>,
714714

715715
/// Name of the local, used in debuginfo and pretty-printing.
716716
///
@@ -882,7 +882,7 @@ impl<'tcx> LocalDecl<'tcx> {
882882
LocalDecl {
883883
mutability,
884884
ty,
885-
user_ty: None,
885+
user_ty: UserTypeProjections::none(),
886886
name: None,
887887
source_info: SourceInfo {
888888
span,
@@ -903,7 +903,7 @@ impl<'tcx> LocalDecl<'tcx> {
903903
LocalDecl {
904904
mutability: Mutability::Mut,
905905
ty: return_ty,
906-
user_ty: None,
906+
user_ty: UserTypeProjections::none(),
907907
source_info: SourceInfo {
908908
span,
909909
scope: OUTERMOST_SOURCE_SCOPE,
@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> {
16741674
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
16751675
/// invalidating statement indices in `Location`s.
16761676
pub fn make_nop(&mut self) {
1677+
// `Statement` contributes significantly to peak memory usage. Make
1678+
// sure it doesn't get bigger.
1679+
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
1680+
16771681
self.kind = StatementKind::Nop
16781682
}
16791683

@@ -1737,7 +1741,7 @@ pub enum StatementKind<'tcx> {
17371741
/// - `Contravariant` -- requires that `T_y :> T`
17381742
/// - `Invariant` -- requires that `T_y == T`
17391743
/// - `Bivariant` -- no effect
1740-
AscribeUserType(Place<'tcx>, ty::Variance, UserTypeAnnotation<'tcx>),
1744+
AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeProjection<'tcx>>),
17411745

17421746
/// No-op. Useful for deleting instructions without affecting statement indices.
17431747
Nop,
@@ -1940,6 +1944,10 @@ pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>;
19401944
/// and the index is a local.
19411945
pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
19421946

1947+
/// Alias for projections as they appear in `UserTypeProjection`, where we
1948+
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
1949+
pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>;
1950+
19431951
newtype_index! {
19441952
pub struct Field {
19451953
DEBUG_FORMAT = "field[{}]"
@@ -2445,6 +2453,117 @@ EnumLiftImpl! {
24452453
}
24462454
}
24472455

2456+
/// A collection of projections into user types.
2457+
///
2458+
/// They are projections because a binding can occur a part of a
2459+
/// parent pattern that has been ascribed a type.
2460+
///
2461+
/// Its a collection because there can be multiple type ascriptions on
2462+
/// the path from the root of the pattern down to the binding itself.
2463+
///
2464+
/// An example:
2465+
///
2466+
/// ```rust
2467+
/// struct S<'a>((i32, &'a str), String);
2468+
/// let S((_, w): (i32, &'static str), _): S = ...;
2469+
/// // ------ ^^^^^^^^^^^^^^^^^^^ (1)
2470+
/// // --------------------------------- ^ (2)
2471+
/// ```
2472+
///
2473+
/// The highlights labelled `(1)` show the subpattern `(_, w)` being
2474+
/// ascribed the type `(i32, &'static str)`.
2475+
///
2476+
/// The highlights labelled `(2)` show the whole pattern being
2477+
/// ascribed the type `S`.
2478+
///
2479+
/// In this example, when we descend to `w`, we will have built up the
2480+
/// following two projected types:
2481+
///
2482+
/// * base: `S`, projection: `(base.0).1`
2483+
/// * base: `(i32, &'static str)`, projection: `base.1`
2484+
///
2485+
/// The first will lead to the constraint `w: &'1 str` (for some
2486+
/// inferred region `'1`). The second will lead to the constraint `w:
2487+
/// &'static str`.
2488+
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
2489+
pub struct UserTypeProjections<'tcx> {
2490+
pub(crate) contents: Vec<(UserTypeProjection<'tcx>, Span)>,
2491+
}
2492+
2493+
BraceStructTypeFoldableImpl! {
2494+
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjections<'tcx> {
2495+
contents
2496+
}
2497+
}
2498+
2499+
impl<'tcx> UserTypeProjections<'tcx> {
2500+
pub fn none() -> Self {
2501+
UserTypeProjections { contents: vec![] }
2502+
}
2503+
2504+
pub fn from_projections(projs: impl Iterator<Item=(UserTypeProjection<'tcx>, Span)>) -> Self {
2505+
UserTypeProjections { contents: projs.collect() }
2506+
}
2507+
2508+
pub fn projections_and_spans(&self) -> impl Iterator<Item=&(UserTypeProjection<'tcx>, Span)> {
2509+
self.contents.iter()
2510+
}
2511+
2512+
pub fn projections(&self) -> impl Iterator<Item=&UserTypeProjection<'tcx>> {
2513+
self.contents.iter().map(|&(ref user_type, _span)| user_type)
2514+
}
2515+
}
2516+
2517+
/// Encodes the effect of a user-supplied type annotation on the
2518+
/// subcomponents of a pattern. The effect is determined by applying the
2519+
/// given list of proejctions to some underlying base type. Often,
2520+
/// the projection element list `projs` is empty, in which case this
2521+
/// directly encodes a type in `base`. But in the case of complex patterns with
2522+
/// subpatterns and bindings, we want to apply only a *part* of the type to a variable,
2523+
/// in which case the `projs` vector is used.
2524+
///
2525+
/// Examples:
2526+
///
2527+
/// * `let x: T = ...` -- here, the `projs` vector is empty.
2528+
///
2529+
/// * `let (x, _): T = ...` -- here, the `projs` vector would contain
2530+
/// `field[0]` (aka `.0`), indicating that the type of `s` is
2531+
/// determined by finding the type of the `.0` field from `T`.
2532+
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
2533+
pub struct UserTypeProjection<'tcx> {
2534+
pub base: UserTypeAnnotation<'tcx>,
2535+
pub projs: Vec<ProjectionElem<'tcx, (), ()>>,
2536+
}
2537+
2538+
impl<'tcx> Copy for ProjectionKind<'tcx> { }
2539+
2540+
CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, }
2541+
2542+
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> {
2543+
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
2544+
use mir::ProjectionElem::*;
2545+
2546+
let base = self.base.fold_with(folder);
2547+
let projs: Vec<_> = self.projs
2548+
.iter()
2549+
.map(|elem| {
2550+
match elem {
2551+
Deref => Deref,
2552+
Field(f, ()) => Field(f.clone(), ()),
2553+
Index(()) => Index(()),
2554+
elem => elem.clone(),
2555+
}})
2556+
.collect();
2557+
2558+
UserTypeProjection { base, projs }
2559+
}
2560+
2561+
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> bool {
2562+
self.base.visit_with(visitor)
2563+
// Note: there's nothing in `self.proj` to visit.
2564+
}
2565+
}
2566+
24482567
newtype_index! {
24492568
pub struct Promoted {
24502569
DEBUG_FORMAT = "promoted[{}]"

src/librustc/mir/tcx.rs

+53-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,59 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
4444
}
4545
}
4646

47+
/// `place_ty.field_ty(tcx, f)` computes the type at a given field
48+
/// of a record or enum-variant. (Most clients of `PlaceTy` can
49+
/// instead just extract the relevant type directly from their
50+
/// `PlaceElem`, but some instances of `ProjectionElem<V, T>` do
51+
/// not carry a `Ty` for `T`.)
52+
///
53+
/// Note that the resulting type has not been normalized.
54+
pub fn field_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, f: &Field) -> Ty<'tcx>
55+
{
56+
// Pass `0` here so it can be used as a "default" variant_index in first arm below
57+
let answer = match (self, 0) {
58+
(PlaceTy::Ty {
59+
ty: &ty::TyS { sty: ty::TyKind::Adt(adt_def, substs), .. } }, variant_index) |
60+
(PlaceTy::Downcast { adt_def, substs, variant_index }, _) => {
61+
let variant_def = &adt_def.variants[variant_index];
62+
let field_def = &variant_def.fields[f.index()];
63+
field_def.ty(tcx, substs)
64+
}
65+
(PlaceTy::Ty { ty }, _) => {
66+
match ty.sty {
67+
ty::Tuple(ref tys) => tys[f.index()],
68+
_ => bug!("extracting field of non-tuple non-adt: {:?}", self),
69+
}
70+
}
71+
};
72+
debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer);
73+
answer
74+
}
75+
76+
/// Convenience wrapper around `projection_ty_core` for
77+
/// `PlaceElem`, where we can just use the `Ty` that is already
78+
/// stored inline on field projection elems.
4779
pub fn projection_ty(self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
4880
elem: &PlaceElem<'tcx>)
4981
-> PlaceTy<'tcx>
5082
{
51-
match *elem {
83+
self.projection_ty_core(tcx, elem, |_, _, ty| ty)
84+
}
85+
86+
/// `place_ty.projection_ty_core(tcx, elem, |...| { ... })`
87+
/// projects `place_ty` onto `elem`, returning the appropriate
88+
/// `Ty` or downcast variant corresponding to that projection.
89+
/// The `handle_field` callback must map a `Field` to its `Ty`,
90+
/// (which should be trivial when `T` = `Ty`).
91+
pub fn projection_ty_core<V, T>(self,
92+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
93+
elem: &ProjectionElem<'tcx, V, T>,
94+
mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>)
95+
-> PlaceTy<'tcx>
96+
where
97+
V: ::std::fmt::Debug, T: ::std::fmt::Debug
98+
{
99+
let answer = match *elem {
52100
ProjectionElem::Deref => {
53101
let ty = self.to_ty(tcx)
54102
.builtin_deref(true)
@@ -94,8 +142,10 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
94142
bug!("cannot downcast non-ADT type: `{:?}`", self)
95143
}
96144
},
97-
ProjectionElem::Field(_, fty) => PlaceTy::Ty { ty: fty }
98-
}
145+
ProjectionElem::Field(ref f, ref fty) => PlaceTy::Ty { ty: handle_field(&self, f, fty) }
146+
};
147+
debug!("projection_ty self: {:?} elem: {:?} yields: {:?}", self, elem, answer);
148+
answer
99149
}
100150
}
101151

0 commit comments

Comments
 (0)