Skip to content

Commit 0c03aee

Browse files
committed
Auto merge of #74073 - Manishearth:rollup-faqo9lx, r=Manishearth
Rollup of 12 pull requests Successful merges: - #72688 (added .collect() into String from Box<str>) - #73787 (Add unstable docs for rustc_attrs) - #73834 (Some refactoring around intrinsic type checking) - #73871 (Fix try_print_visible_def_path for Rust 2018) - #73937 (Explain exhaustive matching on {usize,isize} maximum values) - #73973 (Use `Span`s to identify unreachable subpatterns in or-patterns) - #74000 (add `lazy_normalization_consts` feature gate) - #74025 (Remove unnecessary release from Arc::try_unwrap) - #74027 (Convert more `DefId`s to `LocalDefId`s) - #74055 (Fix spacing in Iterator fold doc) - #74057 (expected_found `&T` -> `T`) - #74064 (variant_count: avoid incorrect dummy implementation) Failed merges: r? @ghost
2 parents 2753fab + e624363 commit 0c03aee

Some content is hidden

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

56 files changed

+796
-332
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `rustc_attrs`
2+
3+
This feature has no tracking issue, and is therefore internal to
4+
the compiler, not being intended for general use.
5+
6+
Note: `rustc_attrs` enables many rustc-internal attributes and this page
7+
only discuss a few of them.
8+
9+
------------------------
10+
11+
The `rustc_attrs` feature allows debugging rustc type layouts by using
12+
`#[rustc_layout(...)]` to debug layout at compile time (it even works
13+
with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
14+
that is way more verbose.
15+
16+
Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `abi`.
17+
Note that it only work best with sized type without generics.
18+
19+
## Examples
20+
21+
```rust,ignore
22+
#![feature(rustc_attrs)]
23+
24+
#[rustc_layout(abi, size)]
25+
pub enum X {
26+
Y(u8, u8, u8),
27+
Z(isize),
28+
}
29+
```
30+
31+
When that is compiled, the compiler will error with something like
32+
33+
```text
34+
error: abi: Aggregate { sized: true }
35+
--> src/lib.rs:4:1
36+
|
37+
4 | / pub enum T {
38+
5 | | Y(u8, u8, u8),
39+
6 | | Z(isize),
40+
7 | | }
41+
| |_^
42+
43+
error: size: Size { raw: 16 }
44+
--> src/lib.rs:4:1
45+
|
46+
4 | / pub enum T {
47+
5 | | Y(u8, u8, u8),
48+
6 | | Z(isize),
49+
7 | | }
50+
| |_^
51+
52+
error: aborting due to 2 previous errors
53+
```

src/liballoc/string.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,15 @@ impl FromIterator<String> for String {
17741774
}
17751775
}
17761776

1777+
#[stable(feature = "box_str2", since = "1.45.0")]
1778+
impl FromIterator<Box<str>> for String {
1779+
fn from_iter<I: IntoIterator<Item = Box<str>>>(iter: I) -> String {
1780+
let mut buf = String::new();
1781+
buf.extend(iter);
1782+
buf
1783+
}
1784+
}
1785+
17771786
#[stable(feature = "herd_cows", since = "1.19.0")]
17781787
impl<'a> FromIterator<Cow<'a, str>> for String {
17791788
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
@@ -1842,6 +1851,13 @@ impl<'a> Extend<&'a str> for String {
18421851
}
18431852
}
18441853

1854+
#[stable(feature = "box_str2", since = "1.45.0")]
1855+
impl Extend<Box<str>> for String {
1856+
fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I) {
1857+
iter.into_iter().for_each(move |s| self.push_str(&s));
1858+
}
1859+
}
1860+
18451861
#[stable(feature = "extend_string", since = "1.4.0")]
18461862
impl Extend<String> for String {
18471863
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {

src/liballoc/sync.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,7 @@ impl<T> Arc<T> {
419419
#[inline]
420420
#[stable(feature = "arc_unique", since = "1.4.0")]
421421
pub fn try_unwrap(this: Self) -> Result<T, Self> {
422-
// See `drop` for why all these atomics are like this
423-
if this.inner().strong.compare_exchange(1, 0, Release, Relaxed).is_err() {
422+
if this.inner().strong.compare_exchange(1, 0, Relaxed, Relaxed).is_err() {
424423
return Err(this);
425424
}
426425

src/libcore/intrinsics.rs

-6
Original file line numberDiff line numberDiff line change
@@ -2004,12 +2004,6 @@ extern "rust-intrinsic" {
20042004
pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
20052005
}
20062006

2007-
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
2008-
#[cfg(bootstrap)]
2009-
pub const fn variant_count<T>() -> usize {
2010-
0
2011-
}
2012-
20132007
// Some functions are defined here because they accidentally got made
20142008
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
20152009
// (`transmute` also falls into this category, but it cannot be wrapped due to the

src/libcore/iter/traits/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ pub trait Iterator {
15211521
///
15221522
/// let iter = a.iter();
15231523
///
1524-
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
1524+
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i);
15251525
///
15261526
/// assert_eq!(sum, 6);
15271527
///
@@ -1535,7 +1535,7 @@ pub trait Iterator {
15351535
/// let mut iter = a.iter();
15361536
///
15371537
/// // instead, we add in a .by_ref()
1538-
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
1538+
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i);
15391539
///
15401540
/// assert_eq!(sum, 3);
15411541
///

src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
#![feature(unsized_locals)]
126126
#![feature(untagged_unions)]
127127
#![feature(unwind_attributes)]
128-
#![feature(variant_count)]
128+
#![cfg_attr(not(bootstrap), feature(variant_count))]
129129
#![feature(doc_alias)]
130130
#![feature(mmx_target_feature)]
131131
#![feature(tbm_target_feature)]

src/libcore/mem/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
10371037
/// assert_eq!(mem::variant_count::<Result<!, !>>(), 2);
10381038
/// ```
10391039
#[inline(always)]
1040+
#[cfg(not(bootstrap))]
10401041
#[unstable(feature = "variant_count", issue = "73662")]
10411042
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
10421043
pub const fn variant_count<T>() -> usize {

src/librustc_feature/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ declare_features! (
570570
/// Allows capturing variables in scope using format_args!
571571
(active, format_args_capture, "1.46.0", Some(67984), None),
572572

573+
/// Lazily evaluate constants. This allows constants to depend on type parameters.
574+
(active, lazy_normalization_consts, "1.46.0", Some(72219), None),
575+
573576
// -------------------------------------------------------------------------
574577
// feature-group-end: actual feature gates
575578
// -------------------------------------------------------------------------
@@ -586,5 +589,6 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
586589
sym::raw_dylib,
587590
sym::const_trait_impl,
588591
sym::const_trait_bound_opt_out,
592+
sym::lazy_normalization_consts,
589593
sym::specialization,
590594
];

src/librustc_infer/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
112112

113113
// All other cases of inference are errors
114114
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
115-
Err(TypeError::Sorts(ty::relate::expected_found(relation, &a, &b)))
115+
Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
116116
}
117117

118118
_ => ty::relate::super_relate_tys(relation, a, b),
@@ -701,21 +701,21 @@ pub fn const_unification_error<'tcx>(
701701
a_is_expected: bool,
702702
(a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
703703
) -> TypeError<'tcx> {
704-
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
704+
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
705705
}
706706

707707
fn int_unification_error<'tcx>(
708708
a_is_expected: bool,
709709
v: (ty::IntVarValue, ty::IntVarValue),
710710
) -> TypeError<'tcx> {
711711
let (a, b) = v;
712-
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
712+
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
713713
}
714714

715715
fn float_unification_error<'tcx>(
716716
a_is_expected: bool,
717717
v: (ty::FloatVarValue, ty::FloatVarValue),
718718
) -> TypeError<'tcx> {
719719
let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
720-
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
720+
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
721721
}

src/librustc_middle/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ impl<'tcx> TyCtxt<'tcx> {
13701370
/// we still evaluate them eagerly.
13711371
#[inline]
13721372
pub fn lazy_normalization(self) -> bool {
1373-
self.features().const_generics
1373+
self.features().const_generics || self.features().lazy_normalization_consts
13741374
}
13751375

13761376
#[inline]

src/librustc_middle/ty/print/pretty.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
282282
// where there is no explicit `extern crate`, we just prepend
283283
// the crate name.
284284
match self.tcx().extern_crate(def_id) {
285-
Some(&ExternCrate {
286-
src: ExternCrateSource::Extern(def_id),
287-
dependency_of: LOCAL_CRATE,
288-
span,
289-
..
290-
}) => {
291-
debug!("try_print_visible_def_path: def_id={:?}", def_id);
292-
return Ok((
293-
if !span.is_dummy() {
294-
self.print_def_path(def_id, &[])?
295-
} else {
296-
self.path_crate(cnum)?
297-
},
298-
true,
299-
));
300-
}
285+
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
286+
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
287+
debug!("try_print_visible_def_path: def_id={:?}", def_id);
288+
return Ok((
289+
if !span.is_dummy() {
290+
self.print_def_path(def_id, &[])?
291+
} else {
292+
self.path_crate(cnum)?
293+
},
294+
true,
295+
));
296+
}
297+
(ExternCrateSource::Path, LOCAL_CRATE) => {
298+
debug!("try_print_visible_def_path: def_id={:?}", def_id);
299+
return Ok((self.path_crate(cnum)?, true));
300+
}
301+
_ => {}
302+
},
301303
None => {
302304
return Ok((self.path_crate(cnum)?, true));
303305
}
304-
_ => {}
305306
}
306307
}
307308

0 commit comments

Comments
 (0)