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 5 pull requests #99546

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
}

fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
self.pretty_print_const(ct, true)
self.pretty_print_const(ct, false)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
}
let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span));
match concrete {
Err(ErrorHandled::TooGeneric) => Err(if !uv.has_infer_types_or_consts() {
Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() {
NotConstEvaluatable::MentionsInfer
} else if uv.has_param_types_or_consts() {
infcx
.tcx
.sess
.delay_span_bug(span, &format!("unexpected `TooGeneric` for {:?}", uv));
NotConstEvaluatable::MentionsParam
} else {
NotConstEvaluatable::MentionsInfer
let guar = infcx.tcx.sess.delay_span_bug(
span,
format!("Missing value for constant, but no error reported?"),
);
NotConstEvaluatable::Error(guar)
}),
Err(ErrorHandled::Linted) => {
let reported = infcx
Expand Down Expand Up @@ -240,8 +246,11 @@ pub fn is_const_evaluatable<'cx, 'tcx>(

Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() {
NotConstEvaluatable::MentionsInfer
} else {
} else if uv.has_param_types_or_consts() {
NotConstEvaluatable::MentionsParam
} else {
let guar = infcx.tcx.sess.delay_span_bug(span, format!("Missing value for constant, but no error reported?"));
NotConstEvaluatable::Error(guar)
}),
Err(ErrorHandled::Linted) => {
let reported =
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ fn resolve_associated_item<'tcx>(
return Ok(None);
}

// If the item does not have a value, then we cannot return an instance.
if !leaf_def.item.defaultness.has_value() {
return Ok(None);
}

let substs = tcx.erase_regions(substs);

// Check if we just resolved an associated `const` declaration from
Expand Down
30 changes: 26 additions & 4 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub struct BTreeMap<
length: usize,
/// `ManuallyDrop` to control drop order (needs to be dropped after all the nodes).
pub(super) alloc: ManuallyDrop<A>,
// For dropck; the `Box` avoids making the `Unpin` impl more strict than before
_marker: PhantomData<crate::boxed::Box<(K, V)>>,
}

#[stable(feature = "btree_drop", since = "1.7.0")]
Expand All @@ -187,6 +189,19 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V, A: Allocator + Clone> Drop for BTr
}
}

// FIXME: This implementation is "wrong", but changing it would be a breaking change.
// (The bounds of the automatic `UnwindSafe` implementation have been like this since Rust 1.50.)
// Maybe we can fix it nonetheless with a crater run, or if the `UnwindSafe`
// traits are deprecated, or disarmed (no longer causing hard errors) in the future.
#[stable(feature = "btree_unwindsafe", since = "1.64.0")]
impl<K, V, A: Allocator + Clone> core::panic::UnwindSafe for BTreeMap<K, V, A>
where
A: core::panic::UnwindSafe,
K: core::panic::RefUnwindSafe,
V: core::panic::RefUnwindSafe,
{
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
fn clone(&self) -> BTreeMap<K, V, A> {
Expand All @@ -204,6 +219,7 @@ impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
root: Some(Root::new(alloc.clone())),
length: 0,
alloc: ManuallyDrop::new(alloc),
_marker: PhantomData,
};

{
Expand Down Expand Up @@ -567,7 +583,7 @@ impl<K, V> BTreeMap<K, V> {
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
#[must_use]
pub const fn new() -> BTreeMap<K, V> {
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global) }
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global), _marker: PhantomData }
}
}

Expand All @@ -593,6 +609,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
root: mem::replace(&mut self.root, None),
length: mem::replace(&mut self.length, 0),
alloc: self.alloc.clone(),
_marker: PhantomData,
});
}

Expand All @@ -615,7 +632,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// ```
#[unstable(feature = "btreemap_alloc", issue = "32838")]
pub fn new_in(alloc: A) -> BTreeMap<K, V, A> {
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(alloc) }
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(alloc), _marker: PhantomData }
}
}

Expand Down Expand Up @@ -1320,7 +1337,12 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
let (new_left_len, right_len) = Root::calc_split_length(total_num, &left_root, &right_root);
self.length = new_left_len;

BTreeMap { root: Some(right_root), length: right_len, alloc: self.alloc.clone() }
BTreeMap {
root: Some(right_root),
length: right_len,
alloc: self.alloc.clone(),
_marker: PhantomData,
}
}

/// Creates an iterator that visits all elements (key-value pairs) in
Expand Down Expand Up @@ -1445,7 +1467,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
let mut root = Root::new(alloc.clone());
let mut length = 0;
root.bulk_push(DedupSortedIter::new(iter.into_iter()), &mut length, alloc.clone());
BTreeMap { root: Some(root), length, alloc: ManuallyDrop::new(alloc) }
BTreeMap { root: Some(root), length, alloc: ManuallyDrop::new(alloc), _marker: PhantomData }
}
}

Expand Down
35 changes: 35 additions & 0 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ impl<B, C> ControlFlow<B, C> {
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
}
}

/// Converts the `ControlFlow` into an `Option` which is `Some` if the
/// `ControlFlow` was `Continue` and `None` otherwise.
///
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// assert_eq!(ControlFlow::<i32, String>::Break(3).continue_value(), None);
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).continue_value(), Some(3));
/// ```
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn continue_value(self) -> Option<C> {
match self {
ControlFlow::Continue(x) => Some(x),
ControlFlow::Break(..) => None,
}
}

/// Maps `ControlFlow<B, C>` to `ControlFlow<B, T>` by applying a function
/// to the continue value in case it exists.
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
where
F: FnOnce(C) -> T,
{
match self {
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
ControlFlow::Break(x) => ControlFlow::Break(x),
}
}
}

/// These are used only as part of implementing the iterator adapters.
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl From<OwnedFd> for crate::net::UdpSocket {
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
#[stable(feature = "asfd_ptrs", since = "1.64.0")]
/// This impl allows implementing traits that require `AsFd` on Arc.
/// ```
/// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
Expand All @@ -379,7 +379,7 @@ impl<T: AsFd> AsFd for crate::sync::Arc<T> {
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
#[stable(feature = "asfd_ptrs", since = "1.64.0")]
impl<T: AsFd> AsFd for Box<T> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/add-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Simd<T, const WIDTH: usize> {
inner: T,
}

// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16_usize>> for Simd<u8, 16>'
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
impl Add for Simd<u8, 16> {
type Output = Self;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/const-generic-defaults.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]

// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
// 'pub struct Foo<const M: usize = 10_usize, const N: usize = M, T = i32>(_);'
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);
4 changes: 2 additions & 2 deletions src/test/rustdoc/const-generics/const-generics-docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub use extern_crate::WTrait;

// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
// 'pub trait Trait<const N: usize>'
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1_usize> for u8'
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2_usize> for u8'
// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8'
// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8'
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
// 'impl<const N: usize> Trait<N> for [u8; N]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ struct WithParameters<T, const N: usize, M = u32> {
}

impl<T> WithParameters<T, 1> {
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize>` by reference
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
}

impl<T> WithParameters<T, 1, u8> {
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize, u8>` by reference
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ error: passing `Foo` by reference
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `Foo`

error: passing `WithParameters<T, 1_usize>` by reference
error: passing `WithParameters<T, 1>` by reference
--> $DIR/rustc_pass_by_value_self.rs:47:17
|
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize>`
| ^^^^^ help: try passing by value: `WithParameters<T, 1>`

error: passing `WithParameters<T, 1_usize, u8>` by reference
error: passing `WithParameters<T, 1, u8>` by reference
--> $DIR/rustc_pass_by_value_self.rs:51:17
|
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize, u8>`
| ^^^^^ help: try passing by value: `WithParameters<T, 1, u8>`

error: aborting due to 5 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/match_arr_unknown_len.rs:3:9
|
LL | [1, 2] => true,
| ^^^^^^ expected `2_usize`, found `N`
| ^^^^^^ expected `2`, found `N`
|
= note: expected array `[u32; 2]`
found array `[u32; N]`
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/btreemap/btreemap_dropck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct PrintOnDrop<'a>(&'a str);

impl Drop for PrintOnDrop<'_> {
fn drop(&mut self) {
println!("printint: {}", self.0);
}
}

use std::collections::BTreeMap;
use std::iter::FromIterator;

fn main() {
let s = String::from("Hello World!");
let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
drop(s); //~ ERROR cannot move out of `s` because it is borrowed
}
13 changes: 13 additions & 0 deletions src/test/ui/btreemap/btreemap_dropck.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0505]: cannot move out of `s` because it is borrowed
--> $DIR/btreemap_dropck.rs:15:10
|
LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
| -- borrow of `s` occurs here
LL | drop(s);
| ^ move out of `s` occurs here
LL | }
| - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0505`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
LL | type Assoc = u16;
| ^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the trait `Bar<3_usize>` is implemented for `u16`
= help: the trait `Bar<3>` is implemented for `u16`
note: required by a bound in `Foo::Assoc`
--> $DIR/associated-type-bound-fail.rs:4:17
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0308]: mismatched types
--> $DIR/generic-expr-default-concrete.rs:10:5
|
LL | Foo::<10, 12>
| ^^^^^^^^^^^^^ expected `11_usize`, found `12_usize`
| ^^^^^^^^^^^^^ expected `11`, found `12`
|
= note: expected type `11_usize`
found type `12_usize`
= note: expected type `11`
found type `12`

error: aborting due to previous error

Expand Down
22 changes: 11 additions & 11 deletions src/test/ui/const-generics/defaults/mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
pub struct Example<const N: usize=13>;
pub struct Example2<T=u32, const N: usize=13>(T);
pub struct Example3<const N: usize=13, T=u32>(T);
pub struct Example4<const N: usize=13, const M: usize=4>;
pub struct Example<const N: usize = 13>;
pub struct Example2<T = u32, const N: usize = 13>(T);
pub struct Example3<const N: usize = 13, T = u32>(T);
pub struct Example4<const N: usize = 13, const M: usize = 4>;

fn main() {
let e: Example::<13> = ();
let e: Example<13> = ();
//~^ Error: mismatched types
//~| expected struct `Example`
let e: Example2::<u32, 13> = ();
let e: Example2<u32, 13> = ();
//~^ Error: mismatched types
//~| expected struct `Example2`
let e: Example3::<13, u32> = ();
let e: Example3<13, u32> = ();
//~^ Error: mismatched types
//~| expected struct `Example3`
let e: Example3::<7> = ();
let e: Example3<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example3<7_usize>`
let e: Example4::<7> = ();
//~| expected struct `Example3<7>`
let e: Example4<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example4<7_usize>`
//~| expected struct `Example4<7>`
}
Loading