Skip to content

Rollup of 11 pull requests #87909

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

Closed
wants to merge 28 commits into from
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ecb6686
Expand explanation of E0530
kornelski Aug 2, 2021
2a56a4f
removed references to parent/child from std::thread documentation
godmar Aug 7, 2021
eefd790
impl const From<num> for num
usbalbin Dec 27, 2020
09928a9
Add tests
usbalbin Mar 13, 2021
c8bf5ed
Add test for int to float
usbalbin Aug 7, 2021
d777cb8
less opt in const param of
BoxyUwU Aug 7, 2021
5f61271
fmt
BoxyUwU Aug 7, 2021
9a78489
Fix heading colours in Ayu theme
tsoutsman Aug 8, 2021
a4af040
Clarify terms in rustdoc book
tsoutsman Aug 8, 2021
f93cbed
Do not ICE on HIR based WF check when involving lifetimes
estebank Aug 6, 2021
3e123e4
Remove duplicate trait bounds in `rustc_data_structures::graph`
pierwill Aug 9, 2021
cb19d83
Proper table row formatting in platform support
badboy Aug 9, 2021
bc4ce79
Added the `Option::unzip()` method
Kixiron Jul 30, 2021
eea3520
Added some basic tests for `Option::unzip()` and `Option::zip()` (I n…
Kixiron Jul 30, 2021
9d8081e
Enabled unzip_option feature for core tests & unzip docs
Kixiron Jul 31, 2021
ab2c590
Added tracking issue to unstable attribute
Kixiron Aug 5, 2021
f3021b3
Use smaller spans when suggesting method call disambiguation
estebank Aug 9, 2021
839eaab
Rollup merge of #86840 - usbalbin:const_from, r=oli-obk
JohnTitor Aug 10, 2021
ef52055
Rollup merge of #87636 - Kixiron:unzip-option, r=scottmcm
JohnTitor Aug 10, 2021
45b7218
Rollup merge of #87700 - kornelski:e530text, r=oli-obk
JohnTitor Aug 10, 2021
fe34bc5
Rollup merge of #87811 - estebank:issue-87549, r=oli-obk
JohnTitor Aug 10, 2021
c2b83cc
Rollup merge of #87848 - godmar:@godmar/thread-join-documentation-fix…
JohnTitor Aug 10, 2021
d34d1d1
Rollup merge of #87854 - BoxyUwU:var-None, r=oli-obk
JohnTitor Aug 10, 2021
a887639
Rollup merge of #87861 - tsoutsman:patch-1, r=GuillaumeGomez
JohnTitor Aug 10, 2021
482bcb0
Rollup merge of #87865 - tsoutsman:master, r=GuillaumeGomez
JohnTitor Aug 10, 2021
7567f82
Rollup merge of #87880 - pierwill:graph-duplicate-trait-bound, r=LeSe…
JohnTitor Aug 10, 2021
22a1647
Rollup merge of #87881 - badboy:platform-support-formatting, r=ehuss
JohnTitor Aug 10, 2021
3aa861b
Rollup merge of #87889 - estebank:method-call-disambiguate, r=oli-obk
JohnTitor Aug 10, 2021
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
9 changes: 2 additions & 7 deletions compiler/rustc_data_structures/src/graph/mod.rs
Original file line number Diff line number Diff line change
@@ -60,18 +60,13 @@ pub trait WithStartNode: DirectedGraph {
}

pub trait ControlFlowGraph:
DirectedGraph + WithStartNode + WithPredecessors + WithStartNode + WithSuccessors + WithNumNodes
DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
{
// convenient trait
}

impl<T> ControlFlowGraph for T where
T: DirectedGraph
+ WithStartNode
+ WithPredecessors
+ WithStartNode
+ WithSuccessors
+ WithNumNodes
T: DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
{
}

53 changes: 39 additions & 14 deletions compiler/rustc_error_codes/src/error_codes/E0530.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
A binding shadowed something it shouldn't.

Erroneous code example:
A match arm or a variable has a name that is already used by
something else, e.g.

* struct name
* enum variant
* static
* associated constant

This error may also happen when an enum variant *with fields* is used
in a pattern, but without its fields.

```compile_fail
enum Enum {
WithField(i32)
}

use Enum::*;
match WithField(1) {
WithField => {} // error: missing (_)
}
```

Match bindings cannot shadow statics:

```compile_fail,E0530
static TEST: i32 = 0;

let r: (i32, i32) = (0, 0);
let r = 123;
match r {
TEST => {} // error: match bindings cannot shadow statics
TEST => {} // error: name of a static
}
```

To fix this error, just change the binding's name in order to avoid shadowing
one of the following:
Fixed examples:

* struct name
* struct/enum variant
* static
* const
* associated const
```
static TEST: i32 = 0;

Fixed example:
let r = 123;
match r {
some_value => {} // ok!
}
```

or

```
static TEST: i32 = 0;
const TEST: i32 = 0; // const, not static

let r: (i32, i32) = (0, 0);
let r = 123;
match r {
something => {} // ok!
TEST => {} // const is ok!
other_values => {}
}
```
Original file line number Diff line number Diff line change
@@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code.peel_derives()
{
if let Some(cause) =
self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone()))
{
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
tcx.erase_regions(obligation.predicate),
wf_loc.clone(),
)) {
obligation.cause = cause;
span = obligation.cause.span;
}
12 changes: 6 additions & 6 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
@@ -1695,8 +1695,8 @@ fn print_disambiguation_help(
source_map: &source_map::SourceMap,
) {
let mut applicability = Applicability::MachineApplicable;
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
format!(
let (span, sugg) = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
let args = format!(
"({}{})",
if rcvr_ty.is_region_ptr() {
if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" }
@@ -1710,12 +1710,12 @@ fn print_disambiguation_help(
}))
.collect::<Vec<_>>()
.join(", "),
)
);
(span, format!("{}::{}{}", trait_name, item_name, args))
} else {
String::new()
(span.with_hi(item_name.span.lo()), format!("{}::", trait_name))
};
let sugg = format!("{}::{}{}", trait_name, item_name, sugg_args);
err.span_suggestion(
err.span_suggestion_verbose(
span,
&format!(
"disambiguate the {} for {}",
7 changes: 5 additions & 2 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
@@ -190,8 +190,12 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
// Try to use the segment resolution if it is valid, otherwise we
// default to the path resolution.
let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res);
use def::CtorOf;
let generics = match res {
Res::Def(DefKind::Ctor(..), def_id) => {
Res::Def(DefKind::Ctor(CtorOf::Variant, _), def_id) => tcx.generics_of(
tcx.parent(def_id).and_then(|def_id| tcx.parent(def_id)).unwrap(),
),
Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Struct, _), def_id) => {
tcx.generics_of(tcx.parent(def_id).unwrap())
}
// Other `DefKind`s don't have generics and would ICE when calling
@@ -200,7 +204,6 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
DefKind::Struct
| DefKind::Union
| DefKind::Enum
| DefKind::Variant
| DefKind::Trait
| DefKind::OpaqueTy
| DefKind::TyAlias
15 changes: 10 additions & 5 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! impl_from {
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
#[$attr]
impl From<$Small> for $Large {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const From<$Small> for $Large {
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
// Rustdocs on functions do not.
#[doc = $doc]
@@ -172,7 +173,8 @@ impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
macro_rules! try_from_unbounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
@@ -190,7 +192,8 @@ macro_rules! try_from_unbounded {
macro_rules! try_from_lower_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
@@ -212,7 +215,8 @@ macro_rules! try_from_lower_bounded {
macro_rules! try_from_upper_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
@@ -234,7 +238,8 @@ macro_rules! try_from_upper_bounded {
macro_rules! try_from_both_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -99,6 +99,7 @@
#![feature(const_slice_from_raw_parts)]
#![feature(const_slice_ptr_len)]
#![feature(const_swap)]
#![feature(const_trait_impl)]
#![feature(const_type_id)]
#![feature(const_type_name)]
#![feature(const_unreachable_unchecked)]
27 changes: 27 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
@@ -1399,6 +1399,33 @@ impl<T> Option<T> {
}
}

impl<T, U> Option<(T, U)> {
/// Unzips an option containing a tuple of two options
///
/// If `self` is `Some((a, b))` this method returns `(Some(a), Some(b))`.
/// Otherwise, `(None, None)` is returned.
///
/// # Examples
///
/// ```
/// #![feature(unzip_option)]
///
/// let x = Some((1, "hi"));
/// let y = None::<(u8, u32)>;
///
/// assert_eq!(x.unzip(), (Some(1), Some("hi")));
/// assert_eq!(y.unzip(), (None, None));
/// ```
#[inline]
#[unstable(feature = "unzip_option", issue = "87800", reason = "recently added")]
pub const fn unzip(self) -> (Option<T>, Option<U>) {
match self {
Some((a, b)) => (Some(a), Some(b)),
None => (None, None),
}
}
}

impl<T: Copy> Option<&T> {
/// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
/// option.
3 changes: 3 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
#![feature(const_ptr_read)]
#![feature(const_ptr_write)]
#![feature(const_ptr_offset)]
#![feature(const_trait_impl)]
#![feature(const_num_from_num)]
#![feature(core_intrinsics)]
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
@@ -66,6 +68,7 @@
#![feature(slice_group_by)]
#![feature(trusted_random_access)]
#![feature(unsize)]
#![feature(unzip_option)]
#![deny(unsafe_op_in_unsafe_fn)]

extern crate test;
25 changes: 25 additions & 0 deletions library/core/tests/num/const_from.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[test]
fn from() {
use core::convert::TryFrom;
use core::num::TryFromIntError;

// From
const FROM: i64 = i64::from(1i32);
assert_eq!(FROM, 1i64);

// From int to float
const FROM_F64: f64 = f64::from(42u8);
assert_eq!(FROM_F64, 42f64);

// Upper bounded
const U8_FROM_U16: Result<u8, TryFromIntError> = u8::try_from(1u16);
assert_eq!(U8_FROM_U16, Ok(1u8));

// Both bounded
const I8_FROM_I16: Result<i8, TryFromIntError> = i8::try_from(1i16);
assert_eq!(I8_FROM_I16, Ok(1i8));

// Lower bounded
const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
assert_eq!(I16_FROM_U16, Ok(1i16));
}
2 changes: 2 additions & 0 deletions library/core/tests/num/mod.rs
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@ mod u64;
mod u8;

mod bignum;

mod const_from;
mod dec2flt;
mod flt2dec;
mod int_log;
34 changes: 33 additions & 1 deletion library/core/tests/option.rs
Original file line number Diff line number Diff line change
@@ -399,11 +399,43 @@ fn test_unwrap_drop() {
}

#[test]
pub fn option_ext() {
fn option_ext() {
let thing = "{{ f }}";
let f = thing.find("{{");

if f.is_none() {
println!("None!");
}
}

#[test]
fn zip_options() {
let x = Some(10);
let y = Some("foo");
let z: Option<usize> = None;

assert_eq!(x.zip(y), Some((10, "foo")));
assert_eq!(x.zip(z), None);
assert_eq!(z.zip(x), None);
}

#[test]
fn unzip_options() {
let x = Some((10, "foo"));
let y = None::<(bool, i32)>;

assert_eq!(x.unzip(), (Some(10), Some("foo")));
assert_eq!(y.unzip(), (None, None));
}

#[test]
fn zip_unzip_roundtrip() {
let x = Some(10);
let y = Some("foo");

let z = x.zip(y);
assert_eq!(z, Some((10, "foo")));

let a = z.unzip();
assert_eq!(a, (x, y));
}
Loading