Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #74073

Merged
merged 34 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b4337ab
added .collect() into String from Box<str> with fake feature/stabilit…
djugei May 27, 2020
f772587
Add unstable docs for rustc_attrs
pickfire Jun 27, 2020
725918f
Update src/doc/unstable-book/src/language-features/rustc-attrs.md
pickfire Jun 27, 2020
0e6f109
Add preamable on rustc-attrs doc discussion
pickfire Jun 28, 2020
49b4804
Ignore example compile in rustc-attrs doc
pickfire Jun 29, 2020
aab37fe
Add test for issue #56175
da-x Jun 27, 2020
5427d3b
Fix try_print_visible_def_path for Rust 2018
da-x Jun 29, 2020
f77b6fe
Review fix
da-x Jul 1, 2020
4030b73
Use `Span`s to identify unreachable subpatterns in or-patterns
Nadrieril Jul 2, 2020
7a3081b
add `lazy_normalization_consts` feature gate
lcnr Jul 3, 2020
8900502
Remove unnecessary release from Arc::try_unwrap
tmiasko Jul 4, 2020
20d6941
ConstCx to LocalDefId
lcnr Jul 4, 2020
dbcabc2
instantiate_opaque_types LocalDefId
lcnr Jul 4, 2020
f5305c3
nit
lcnr Jul 4, 2020
66fb778
Make `rustc_peek` a safe intrinsic
oli-obk Jun 27, 2020
394b8cd
Match on `Symbol` instead of `&str` for type-checking intrinsics.
oli-obk Jun 28, 2020
dcbe85a
Explain exhaustive matching on {usize,isize} maximum values
JohnTitor Jul 1, 2020
b93ecc1
Address code reviews
JohnTitor Jul 4, 2020
3cb31b6
Fix #71977
Nadrieril Jul 2, 2020
bc0d619
Fix spacing in Iterator fold doc
pickfire Jul 5, 2020
016e9f8
expected found `&T` -> `T`
lcnr Jul 5, 2020
9cb1ffd
variant_count: avoid incorrect dummy implementation
RalfJung Jul 5, 2020
5311daa
Rollup merge of #72688 - djugei:master, r=Amanieu
Manishearth Jul 5, 2020
e2ae88d
Rollup merge of #73787 - pickfire:rustc-attrs, r=RalfJung
Manishearth Jul 5, 2020
fed2013
Rollup merge of #73834 - oli-obk:safe_intrinsics, r=ecstatic-morse
Manishearth Jul 5, 2020
3e78eac
Rollup merge of #73871 - da-x:private-types-2018-no-extern, r=petroch…
Manishearth Jul 5, 2020
a1ac4d6
Rollup merge of #73937 - JohnTitor:note-exhaustive-sized-int, r=varkor
Manishearth Jul 5, 2020
e450646
Rollup merge of #73973 - Nadrieril:fix-71977, r=matthewjasper
Manishearth Jul 5, 2020
0eadeda
Rollup merge of #74000 - lcnr:lazy_normalisation_consts, r=varkor
Manishearth Jul 5, 2020
aef2ca6
Rollup merge of #74025 - tmiasko:try-unwrap, r=Amanieu
Manishearth Jul 5, 2020
a1c076f
Rollup merge of #74027 - lcnr:ConstCx-local-def-id, r=varkor
Manishearth Jul 5, 2020
4591b0f
Rollup merge of #74055 - pickfire:patch-1, r=jonas-schievink
Manishearth Jul 5, 2020
b4710bd
Rollup merge of #74057 - lcnr:expected_found, r=davidtwco
Manishearth Jul 5, 2020
e624363
Rollup merge of #74064 - RalfJung:variant-count-bootstrap, r=kennytm
Manishearth Jul 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/doc/unstable-book/src/language-features/rustc-attrs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# `rustc_attrs`

This feature has no tracking issue, and is therefore internal to
the compiler, not being intended for general use.

Note: `rustc_attrs` enables many rustc-internal attributes and this page
only discuss a few of them.

------------------------

The `rustc_attrs` feature allows debugging rustc type layouts by using
`#[rustc_layout(...)]` to debug layout at compile time (it even works
with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
that is way more verbose.

Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `abi`.
Note that it only work best with sized type without generics.

## Examples

```rust,ignore
#![feature(rustc_attrs)]

#[rustc_layout(abi, size)]
pub enum X {
Y(u8, u8, u8),
Z(isize),
}
```

When that is compiled, the compiler will error with something like

```text
error: abi: Aggregate { sized: true }
--> src/lib.rs:4:1
|
4 | / pub enum T {
5 | | Y(u8, u8, u8),
6 | | Z(isize),
7 | | }
| |_^

error: size: Size { raw: 16 }
--> src/lib.rs:4:1
|
4 | / pub enum T {
5 | | Y(u8, u8, u8),
6 | | Z(isize),
7 | | }
| |_^

error: aborting due to 2 previous errors
```
16 changes: 16 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,15 @@ impl FromIterator<String> for String {
}
}

#[stable(feature = "box_str2", since = "1.45.0")]
impl FromIterator<Box<str>> for String {
fn from_iter<I: IntoIterator<Item = Box<str>>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
}

#[stable(feature = "herd_cows", since = "1.19.0")]
impl<'a> FromIterator<Cow<'a, str>> for String {
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
Expand Down Expand Up @@ -1842,6 +1851,13 @@ impl<'a> Extend<&'a str> for String {
}
}

#[stable(feature = "box_str2", since = "1.45.0")]
impl Extend<Box<str>> for String {
fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I) {
iter.into_iter().for_each(move |s| self.push_str(&s));
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ impl<T> Arc<T> {
#[inline]
#[stable(feature = "arc_unique", since = "1.4.0")]
pub fn try_unwrap(this: Self) -> Result<T, Self> {
// See `drop` for why all these atomics are like this
if this.inner().strong.compare_exchange(1, 0, Release, Relaxed).is_err() {
if this.inner().strong.compare_exchange(1, 0, Relaxed, Relaxed).is_err() {
return Err(this);
}

Expand Down
6 changes: 0 additions & 6 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,12 +2004,6 @@ extern "rust-intrinsic" {
pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
}

#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
#[cfg(bootstrap)]
pub const fn variant_count<T>() -> usize {
0
}

// Some functions are defined here because they accidentally got made
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
// (`transmute` also falls into this category, but it cannot be wrapped due to the
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ pub trait Iterator {
///
/// let iter = a.iter();
///
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i);
///
/// assert_eq!(sum, 6);
///
Expand All @@ -1535,7 +1535,7 @@ pub trait Iterator {
/// let mut iter = a.iter();
///
/// // instead, we add in a .by_ref()
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i);
///
/// assert_eq!(sum, 3);
///
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
#![feature(unsized_locals)]
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
#![feature(variant_count)]
#![cfg_attr(not(bootstrap), feature(variant_count))]
#![feature(doc_alias)]
#![feature(mmx_target_feature)]
#![feature(tbm_target_feature)]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
/// assert_eq!(mem::variant_count::<Result<!, !>>(), 2);
/// ```
#[inline(always)]
#[cfg(not(bootstrap))]
#[unstable(feature = "variant_count", issue = "73662")]
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
pub const fn variant_count<T>() -> usize {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ declare_features! (
/// Allows capturing variables in scope using format_args!
(active, format_args_capture, "1.46.0", Some(67984), None),

/// Lazily evaluate constants. This allows constants to depend on type parameters.
(active, lazy_normalization_consts, "1.46.0", Some(72219), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand All @@ -586,5 +589,6 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
sym::lazy_normalization_consts,
sym::specialization,
];
8 changes: 4 additions & 4 deletions src/librustc_infer/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {

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

_ => ty::relate::super_relate_tys(relation, a, b),
Expand Down Expand Up @@ -701,21 +701,21 @@ pub fn const_unification_error<'tcx>(
a_is_expected: bool,
(a, b): (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>),
) -> TypeError<'tcx> {
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
}

fn int_unification_error<'tcx>(
a_is_expected: bool,
v: (ty::IntVarValue, ty::IntVarValue),
) -> TypeError<'tcx> {
let (a, b) = v;
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
TypeError::IntMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
}

fn float_unification_error<'tcx>(
a_is_expected: bool,
v: (ty::FloatVarValue, ty::FloatVarValue),
) -> TypeError<'tcx> {
let (ty::FloatVarValue(a), ty::FloatVarValue(b)) = v;
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
TypeError::FloatMismatch(ty::relate::expected_found_bool(a_is_expected, a, b))
}
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// we still evaluate them eagerly.
#[inline]
pub fn lazy_normalization(self) -> bool {
self.features().const_generics
self.features().const_generics || self.features().lazy_normalization_consts
}

#[inline]
Expand Down
35 changes: 18 additions & 17 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
// where there is no explicit `extern crate`, we just prepend
// the crate name.
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate {
src: ExternCrateSource::Extern(def_id),
dependency_of: LOCAL_CRATE,
span,
..
}) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
(ExternCrateSource::Path, LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
},
None => {
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
}
}

Expand Down
Loading