Skip to content

Rollup of 6 pull requests #102515

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 12 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
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#![feature(exhaustive_patterns)]
#![feature(get_mut_unchecked)]
#![feature(if_let_guard)]
#![feature(map_first_last)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(extern_types)]
Expand Down
19 changes: 14 additions & 5 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2263,13 +2263,22 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
trait_impls.non_blanket_impls().len()
)
};

let mut suggestions = vec![(
trait_path_segment.ident.span.shrink_to_lo(),
format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())
)];
if let Some(generic_arg) = trait_path_segment.args {
let between_span = trait_path_segment.ident.span.between(generic_arg.span_ext);
// get rid of :: between Trait and <type>
// must be '::' between them, otherwise the parser won't accept the code
suggestions.push((between_span, "".to_string(),));
suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">")));
} else {
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">")));
}
err.multipart_suggestion(
message,
vec![
(trait_path_segment.ident.span.shrink_to_lo(), format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())),
(trait_path_segment.ident.span.shrink_to_hi(), format!(">"))
],
suggestions,
Applicability::MaybeIncorrect
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut spans_and_needs_box = vec![];

match liberated_sig.output().kind() {
ty::Dynamic(predicates, _, _) => {
ty::Dynamic(predicates, _, ty::Dyn) => {
let cause = ObligationCause::misc(ret_ty.span, fn_hir_id);
let param_env = ty::ParamEnv::empty();

Expand Down
1 change: 0 additions & 1 deletion library/alloc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![cfg(not(target_os = "android"))]
#![feature(btree_drain_filter)]
#![feature(iter_next_chunk)]
#![feature(map_first_last)]
#![feature(repr_simd)]
#![feature(slice_partition_dedup)]
#![feature(test)]
Expand Down
18 changes: 6 additions & 12 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// Basic usage:
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
Expand All @@ -712,7 +711,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// map.insert(2, "a");
/// assert_eq!(map.first_key_value(), Some((&1, &"b")));
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn first_key_value(&self) -> Option<(&K, &V)>
where
K: Ord,
Expand All @@ -727,7 +726,6 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// # Examples
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
Expand All @@ -741,7 +739,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// assert_eq!(*map.get(&1).unwrap(), "first");
/// assert_eq!(*map.get(&2).unwrap(), "b");
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>
where
K: Ord,
Expand All @@ -765,7 +763,6 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// Draining elements in ascending order, while keeping a usable map each iteration.
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
Expand All @@ -776,7 +773,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// }
/// assert!(map.is_empty());
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn pop_first(&mut self) -> Option<(K, V)>
where
K: Ord,
Expand All @@ -792,15 +789,14 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// Basic usage:
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1, "b");
/// map.insert(2, "a");
/// assert_eq!(map.last_key_value(), Some((&2, &"a")));
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn last_key_value(&self) -> Option<(&K, &V)>
where
K: Ord,
Expand All @@ -815,7 +811,6 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// # Examples
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
Expand All @@ -829,7 +824,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// assert_eq!(*map.get(&1).unwrap(), "a");
/// assert_eq!(*map.get(&2).unwrap(), "last");
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>
where
K: Ord,
Expand All @@ -853,7 +848,6 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// Draining elements in descending order, while keeping a usable map each iteration.
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
Expand All @@ -864,7 +858,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
/// }
/// assert!(map.is_empty());
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn pop_last(&mut self) -> Option<(K, V)>
where
K: Ord,
Expand Down
12 changes: 4 additions & 8 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// Basic usage:
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeSet;
///
/// let mut set = BTreeSet::new();
Expand All @@ -797,7 +796,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// assert_eq!(set.first(), Some(&1));
/// ```
#[must_use]
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn first(&self) -> Option<&T>
where
T: Ord,
Expand All @@ -813,7 +812,6 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// Basic usage:
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeSet;
///
/// let mut set = BTreeSet::new();
Expand All @@ -824,7 +822,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// assert_eq!(set.last(), Some(&2));
/// ```
#[must_use]
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn last(&self) -> Option<&T>
where
T: Ord,
Expand All @@ -838,7 +836,6 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// # Examples
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeSet;
///
/// let mut set = BTreeSet::new();
Expand All @@ -849,7 +846,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// }
/// assert!(set.is_empty());
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn pop_first(&mut self) -> Option<T>
where
T: Ord,
Expand All @@ -863,7 +860,6 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// # Examples
///
/// ```
/// #![feature(map_first_last)]
/// use std::collections::BTreeSet;
///
/// let mut set = BTreeSet::new();
Expand All @@ -874,7 +870,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
/// }
/// assert!(set.is_empty());
/// ```
#[unstable(feature = "map_first_last", issue = "62924")]
#[stable(feature = "map_first_last", since = "CURRENT_RUSTC_VERSION")]
pub fn pop_last(&mut self) -> Option<T>
where
T: Ord,
Expand Down
39 changes: 29 additions & 10 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ impl fmt::Debug for Duration {
/// to the formatter's `width`, if specified.
fn fmt_decimal(
f: &mut fmt::Formatter<'_>,
mut integer_part: u64,
integer_part: u64,
mut fractional_part: u32,
mut divisor: u32,
prefix: &str,
Expand Down Expand Up @@ -1075,7 +1075,7 @@ impl fmt::Debug for Duration {
// normal floating point numbers. However, we only need to do work
// when rounding up. This happens if the first digit of the
// remaining ones is >= 5.
if fractional_part > 0 && fractional_part >= divisor * 5 {
let integer_part = if fractional_part > 0 && fractional_part >= divisor * 5 {
// Round up the number contained in the buffer. We go through
// the buffer backwards and keep track of the carry.
let mut rev_pos = pos;
Expand All @@ -1099,9 +1099,18 @@ impl fmt::Debug for Duration {
// the whole buffer to '0's and need to increment the integer
// part.
if carry {
integer_part += 1;
// If `integer_part == u64::MAX` and precision < 9, any
// carry of the overflow during rounding of the
// `fractional_part` into the `integer_part` will cause the
// `integer_part` itself to overflow. Avoid this by using an
// `Option<u64>`, with `None` representing `u64::MAX + 1`.
integer_part.checked_add(1)
} else {
Some(integer_part)
}
}
} else {
Some(integer_part)
};

// Determine the end of the buffer: if precision is set, we just
// use as many digits from the buffer (capped to 9). If it isn't
Expand All @@ -1111,7 +1120,12 @@ impl fmt::Debug for Duration {
// This closure emits the formatted duration without emitting any
// padding (padding is calculated below).
let emit_without_padding = |f: &mut fmt::Formatter<'_>| {
write!(f, "{}{}", prefix, integer_part)?;
if let Some(integer_part) = integer_part {
write!(f, "{}{}", prefix, integer_part)?;
} else {
// u64::MAX + 1 == 18446744073709551616
write!(f, "{}18446744073709551616", prefix)?;
}

// Write the decimal point and the fractional part (if any).
if end > 0 {
Expand Down Expand Up @@ -1141,12 +1155,17 @@ impl fmt::Debug for Duration {
// 2. The postfix: can be "µs" so we have to count UTF8 characters.
let mut actual_w = prefix.len() + postfix.chars().count();
// 3. The integer part:
if let Some(log) = integer_part.checked_ilog10() {
// integer_part is > 0, so has length log10(x)+1
actual_w += 1 + log as usize;
if let Some(integer_part) = integer_part {
if let Some(log) = integer_part.checked_ilog10() {
// integer_part is > 0, so has length log10(x)+1
actual_w += 1 + log as usize;
} else {
// integer_part is 0, so has length 1.
actual_w += 1;
}
} else {
// integer_part is 0, so has length 1.
actual_w += 1;
// integer_part is u64::MAX + 1, so has length 20
actual_w += 20;
}
// 4. The fractional part (if any):
if end > 0 {
Expand Down
24 changes: 23 additions & 1 deletion library/core/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,31 @@ fn correct_sum() {
#[test]
fn debug_formatting_extreme_values() {
assert_eq!(
format!("{:?}", Duration::new(18_446_744_073_709_551_615, 123_456_789)),
format!("{:?}", Duration::new(u64::MAX, 123_456_789)),
"18446744073709551615.123456789s"
);
assert_eq!(format!("{:.0?}", Duration::MAX), "18446744073709551616s");
assert_eq!(format!("{:.0?}", Duration::new(u64::MAX, 500_000_000)), "18446744073709551616s");
assert_eq!(format!("{:.0?}", Duration::new(u64::MAX, 499_999_999)), "18446744073709551615s");
assert_eq!(
format!("{:.3?}", Duration::new(u64::MAX, 999_500_000)),
"18446744073709551616.000s"
);
assert_eq!(
format!("{:.3?}", Duration::new(u64::MAX, 999_499_999)),
"18446744073709551615.999s"
);
assert_eq!(
format!("{:.8?}", Duration::new(u64::MAX, 999_999_995)),
"18446744073709551616.00000000s"
);
assert_eq!(
format!("{:.8?}", Duration::new(u64::MAX, 999_999_994)),
"18446744073709551615.99999999s"
);
assert_eq!(format!("{:21.0?}", Duration::MAX), "18446744073709551616s");
assert_eq!(format!("{:22.0?}", Duration::MAX), "18446744073709551616s ");
assert_eq!(format!("{:24.0?}", Duration::MAX), "18446744073709551616s ");
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1245,13 +1245,11 @@ h3.variant {
font-weight: 600;
font-size: 1.125rem;
margin-bottom: 10px;
border-bottom: none;
}

.sub-variant h4 {
font-size: 1rem;
font-weight: 400;
border-bottom: none;
margin-top: 0;
margin-bottom: 0;
}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/stats/hir-stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// check-pass
// compile-flags: -Zhir-stats
// only-x86_64
// ignore-stage1

// The aim here is to include at least one of every different type of top-level
// AST/HIR node reported by `-Zhir-stats`.
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/type/issue-101866.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait TraitA<T> {
fn func();
}

struct StructA {}

impl TraitA<i32> for StructA {
fn func() {}
}

fn main() {
TraitA::<i32>::func();
//~^ ERROR: cannot call associated function on trait without specifying the corresponding `impl` type [E0790]
//~| help: use the fully-qualified path to the only available implementation
}
18 changes: 18 additions & 0 deletions src/test/ui/type/issue-101866.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> $DIR/issue-101866.rs:12:5
|
LL | fn func();
| ---------- `TraitA::func` defined here
...
LL | TraitA::<i32>::func();
| ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
|
help: use the fully-qualified path to the only available implementation
|
LL - TraitA::<i32>::func();
LL + <::StructA as TraitA<i32>>::func();
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0790`.