Skip to content

Commit 5684f68

Browse files
committed
Auto merge of #59433 - Centril:rollup, r=Centril
Rollup of 10 pull requests Successful merges: - #59150 (Expand suggestions for type ascription parse errors) - #59232 (Merge `Promoted` and `Static` in `mir::Place`) - #59267 (Provide suggestion when using field access instead of path) - #59315 (Add no_hash to query macro and move some queries over) - #59334 (Update build instructions in README.md) - #59362 (Demo `FromIterator` short-circuiting) - #59374 (Simplify checked_duration_since) - #59389 (replace redundant note in deprecation warning) - #59410 (Clarify `{Ord,f32,f64}::clamp` docs a little) - #59419 (Utilize `?` instead of `return None`.) Failed merges: r? @ghost
2 parents 54479c6 + 822b4fc commit 5684f68

File tree

101 files changed

+1191
-698
lines changed

Some content is hidden

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

101 files changed

+1191
-698
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,7 @@ dependencies = [
28112811
name = "rustc_macros"
28122812
version = "0.1.0"
28132813
dependencies = [
2814+
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
28142815
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
28152816
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
28162817
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",

Diff for: README.md

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ of the rustc-guide instead._
4545
$ ./x.py build && sudo ./x.py install
4646
```
4747

48+
If after running `sudo ./x.py install` you see an error message like
49+
50+
```
51+
error: failed to load source for a dependency on 'cc'
52+
```
53+
54+
then run these two commands and then try `sudo ./x.py install` again:
55+
56+
```
57+
$ cargo install cargo-vendor
58+
```
59+
60+
```
61+
$ cargo vendor
62+
```
63+
4864
> ***Note:*** Install locations can be adjusted by copying the config file
4965
> from `./config.toml.example` to `./config.toml`, and
5066
> adjusting the `prefix` option under `[install]`. Various other options, such

Diff for: src/libcore/cmp.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,14 @@ pub trait Ord: Eq + PartialOrd<Self> {
568568
if self <= other { self } else { other }
569569
}
570570

571-
/// Returns max if self is greater than max, and min if self is less than min.
572-
/// Otherwise this will return self. Panics if min > max.
571+
/// Restrict a value to a certain interval.
572+
///
573+
/// Returns `max` if `self` is greater than `max`, and `min` if `self` is
574+
/// less than `min`. Otherwise this returns `self`.
575+
///
576+
/// # Panics
577+
///
578+
/// Panics if `min > max`.
573579
///
574580
/// # Examples
575581
///
@@ -586,8 +592,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
586592
assert!(min <= max);
587593
if self < min {
588594
min
589-
}
590-
else if self > max {
595+
} else if self > max {
591596
max
592597
} else {
593598
self

Diff for: src/libcore/num/flt2dec/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ impl<'a> Formatted<'a> {
239239

240240
let mut written = self.sign.len();
241241
for part in self.parts {
242-
match part.write(&mut out[written..]) {
243-
Some(len) => { written += len; }
244-
None => { return None; }
245-
}
242+
let len = part.write(&mut out[written..])?;
243+
written += len;
246244
}
247245
Some(written)
248246
}

Diff for: src/libcore/option.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,26 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
13151315
/// Since the last element is zero, it would underflow. Thus, the resulting
13161316
/// value is `None`.
13171317
///
1318+
/// Here is a variation on the previous example, showing that no
1319+
/// further elements are taken from `iter` after the first `None`.
1320+
///
1321+
/// ```
1322+
/// let items = vec![3_u16, 2, 1, 10];
1323+
///
1324+
/// let mut shared = 0;
1325+
///
1326+
/// let res: Option<Vec<u16>> = items
1327+
/// .iter()
1328+
/// .map(|x| { shared += x; x.checked_sub(2) })
1329+
/// .collect();
1330+
///
1331+
/// assert_eq!(res, None);
1332+
/// assert_eq!(shared, 6);
1333+
/// ```
1334+
///
1335+
/// Since the third element caused an underflow, no further elements were taken,
1336+
/// so the final value of `shared` is 6 (= `3 + 2 + 1`), not 16.
1337+
///
13181338
/// [`Iterator`]: ../iter/trait.Iterator.html
13191339
#[inline]
13201340
fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {

Diff for: src/libcore/result.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,34 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
12021202
/// ).collect();
12031203
/// assert_eq!(res, Ok(vec![2, 3]));
12041204
/// ```
1205+
///
1206+
/// Here is another example that tries to subtract one from another list
1207+
/// of integers, this time checking for underflow:
1208+
///
1209+
/// ```
1210+
/// let v = vec![1, 2, 0];
1211+
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
1212+
/// x.checked_sub(1).ok_or("Underflow!")
1213+
/// ).collect();
1214+
/// assert_eq!(res, Err("Underflow!"));
1215+
/// ```
1216+
///
1217+
/// Here is a variation on the previous example, showing that no
1218+
/// further elements are taken from `iter` after the first `Err`.
1219+
///
1220+
/// ```
1221+
/// let v = vec![3, 2, 1, 10];
1222+
/// let mut shared = 0;
1223+
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32| {
1224+
/// shared += x;
1225+
/// x.checked_sub(2).ok_or("Underflow!")
1226+
/// }).collect();
1227+
/// assert_eq!(res, Err("Underflow!"));
1228+
/// assert_eq!(shared, 6);
1229+
/// ```
1230+
///
1231+
/// Since the third element caused an underflow, no further elements were taken,
1232+
/// so the final value of `shared` is 6 (= `3 + 2 + 1`), not 16.
12051233
#[inline]
12061234
fn from_iter<I: IntoIterator<Item=Result<A, E>>>(iter: I) -> Result<V, E> {
12071235
// FIXME(#11084): This could be replaced with Iterator::scan when this

Diff for: src/librustc/dep_graph/dep_node.rs

-19
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
461461

462462
// Represents the MIR for a fn; also used as the task node for
463463
// things read/modify that MIR.
464-
[] MirConstQualif(DefId),
465-
[] MirBuilt(DefId),
466-
[] MirConst(DefId),
467-
[] MirValidated(DefId),
468-
[] MirOptimized(DefId),
469464
[] MirShim { instance_def: InstanceDef<'tcx> },
470465

471466
[] BorrowCheckKrate,
@@ -485,7 +480,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
485480
[] CollectModItemTypes(DefId),
486481

487482
[] Reachability,
488-
[] MirKeys,
489483
[eval_always] CrateVariances,
490484

491485
// Nodes representing bits of computed IR in the tcx. Each shared
@@ -544,7 +538,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
544538
[anon] TraitSelect,
545539

546540
[] ParamEnv(DefId),
547-
[] Environment(DefId),
548541
[] DescribeDef(DefId),
549542

550543
// FIXME(mw): DefSpans are not really inputs since they are derived from
@@ -571,7 +564,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
571564
[] HasGlobalAllocator(CrateNum),
572565
[] HasPanicHandler(CrateNum),
573566
[input] ExternCrate(DefId),
574-
[eval_always] LintLevels,
575567
[] Specializes { impl1: DefId, impl2: DefId },
576568
[input] InScopeTraits(DefIndex),
577569
[input] ModuleExports(DefId),
@@ -621,14 +613,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
621613
[input] UsedCrateSource(CrateNum),
622614
[input] PostorderCnums,
623615

624-
// These queries are not expected to have inputs -- as a result, they
625-
// are not good candidates for "replay" because they are essentially
626-
// pure functions of their input (and hence the expectation is that
627-
// no caller would be green **apart** from just these
628-
// queries). Making them anonymous avoids hashing the result, which
629-
// may save a bit of time.
630-
[anon] EraseRegionsTy { ty: Ty<'tcx> },
631-
632616
[input] Freevars(DefId),
633617
[input] MaybeUnusedTraitImport(DefId),
634618
[input] MaybeUnusedExternCrates,
@@ -667,9 +651,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
667651

668652
[input] Features,
669653

670-
[] ProgramClausesFor(DefId),
671-
[] ProgramClausesForEnv(traits::Environment<'tcx>),
672-
[] WasmImportModuleMap(CrateNum),
673654
[] ForeignModules(CrateNum),
674655

675656
[] UpstreamMonomorphizations(CrateNum),

Diff for: src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
582582
if let hir::Node::Expr(_) = self.hir().get_by_hir_id(id) {
583583
diag.span_suggestion(
584584
span,
585-
&msg,
585+
"replace the use of the deprecated item",
586586
suggestion.to_string(),
587587
Applicability::MachineApplicable,
588588
);

Diff for: src/librustc/mir/mod.rs

+29-21
Original file line numberDiff line numberDiff line change
@@ -1913,22 +1913,24 @@ pub enum PlaceBase<'tcx> {
19131913

19141914
/// static or static mut variable
19151915
Static(Box<Static<'tcx>>),
1916-
1917-
/// Constant code promoted to an injected static
1918-
Promoted(Box<(Promoted, Ty<'tcx>)>),
19191916
}
19201917

1921-
/// The `DefId` of a static, along with its normalized type (which is
1922-
/// stored to avoid requiring normalization when reading MIR).
1918+
/// We store the normalized type to avoid requiring normalization when reading MIR
19231919
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
19241920
pub struct Static<'tcx> {
1925-
pub def_id: DefId,
19261921
pub ty: Ty<'tcx>,
1922+
pub kind: StaticKind,
1923+
}
1924+
1925+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, RustcEncodable, RustcDecodable)]
1926+
pub enum StaticKind {
1927+
Promoted(Promoted),
1928+
Static(DefId),
19271929
}
19281930

19291931
impl_stable_hash_for!(struct Static<'tcx> {
1930-
def_id,
1931-
ty
1932+
ty,
1933+
kind
19321934
});
19331935

19341936
/// The `Projection` data structure defines things of the form `B.x`
@@ -2048,7 +2050,7 @@ impl<'tcx> Place<'tcx> {
20482050
match self {
20492051
Place::Base(PlaceBase::Local(local)) => Some(*local),
20502052
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2051-
Place::Base(PlaceBase::Promoted(..)) | Place::Base(PlaceBase::Static(..)) => None,
2053+
Place::Base(PlaceBase::Static(..)) => None,
20522054
}
20532055
}
20542056
}
@@ -2059,18 +2061,24 @@ impl<'tcx> Debug for Place<'tcx> {
20592061

20602062
match *self {
20612063
Base(PlaceBase::Local(id)) => write!(fmt, "{:?}", id),
2062-
Base(PlaceBase::Static(box self::Static { def_id, ty })) => write!(
2063-
fmt,
2064-
"({}: {:?})",
2065-
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
2066-
ty
2067-
),
2068-
Base(PlaceBase::Promoted(ref promoted)) => write!(
2069-
fmt,
2070-
"({:?}: {:?})",
2071-
promoted.0,
2072-
promoted.1
2073-
),
2064+
Base(PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) })) => {
2065+
write!(
2066+
fmt,
2067+
"({}: {:?})",
2068+
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
2069+
ty
2070+
)
2071+
},
2072+
Base(PlaceBase::Static(
2073+
box self::Static { ty, kind: StaticKind::Promoted(promoted) })
2074+
) => {
2075+
write!(
2076+
fmt,
2077+
"({:?}: {:?})",
2078+
promoted,
2079+
ty
2080+
)
2081+
},
20742082
Projection(ref data) => match data.elem {
20752083
ProjectionElem::Downcast(ref adt_def, index) => {
20762084
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)

Diff for: src/librustc/mir/tcx.rs

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ impl<'tcx> Place<'tcx> {
160160
match *self {
161161
Place::Base(PlaceBase::Local(index)) =>
162162
PlaceTy::Ty { ty: local_decls.local_decls()[index].ty },
163-
Place::Base(PlaceBase::Promoted(ref data)) => PlaceTy::Ty { ty: data.1 },
164163
Place::Base(PlaceBase::Static(ref data)) =>
165164
PlaceTy::Ty { ty: data.ty },
166165
Place::Projection(ref proj) =>

Diff for: src/librustc/mir/visit.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ macro_rules! make_mir_visitor {
156156
self.super_place(place, context, location);
157157
}
158158

159-
fn visit_static(&mut self,
160-
static_: & $($mutability)? Static<'tcx>,
161-
context: PlaceContext<'tcx>,
162-
location: Location) {
163-
self.super_static(static_, context, location);
164-
}
165-
166159
fn visit_projection(&mut self,
167160
place: & $($mutability)? PlaceProjection<'tcx>,
168161
context: PlaceContext<'tcx>,
@@ -736,27 +729,18 @@ macro_rules! make_mir_visitor {
736729
Place::Base(PlaceBase::Local(local)) => {
737730
self.visit_local(local, context, location);
738731
}
739-
Place::Base(PlaceBase::Static(static_)) => {
740-
self.visit_static(static_, context, location);
732+
Place::Base(PlaceBase::Static(box Static { kind, ty })) => {
733+
if let StaticKind::Static(def_id) = kind {
734+
self.visit_def_id(& $($mutability)? *def_id, location)
735+
}
736+
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
741737
}
742-
Place::Base(PlaceBase::Promoted(promoted)) => {
743-
self.visit_ty(& $($mutability)? promoted.1, TyContext::Location(location));
744-
},
745738
Place::Projection(proj) => {
746739
self.visit_projection(proj, context, location);
747740
}
748741
}
749742
}
750743

751-
fn super_static(&mut self,
752-
static_: & $($mutability)? Static<'tcx>,
753-
_context: PlaceContext<'tcx>,
754-
location: Location) {
755-
let Static { def_id, ty } = static_;
756-
self.visit_def_id(def_id, location);
757-
self.visit_ty(ty, TyContext::Location(location));
758-
}
759-
760744
fn super_projection(&mut self,
761745
proj: & $($mutability)? PlaceProjection<'tcx>,
762746
context: PlaceContext<'tcx>,

0 commit comments

Comments
 (0)