Skip to content

Commit 877877a

Browse files
committed
Auto merge of rust-lang#102520 - matthiaskrgr:rollup-7nreat0, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#102276 (Added more const_closure functionality) - rust-lang#102382 (Manually order `DefId` on 64-bit big-endian) - rust-lang#102421 (remove the unused :: between trait and type to give user correct diag…) - rust-lang#102495 (Reinstate `hir-stats.rs` test for stage 1.) - rust-lang#102505 (rustdoc: remove no-op CSS `h3.variant, .sub-variant h4 { border-bottom: none }`) - rust-lang#102506 (Specify `DynKind::Dyn`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 75d3027 + a877758 commit 877877a

File tree

9 files changed

+107
-36
lines changed

9 files changed

+107
-36
lines changed

Diff for: compiler/rustc_span/src/def_id.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ impl<D: Decoder> Decodable<D> for DefIndex {
218218
/// index and a def index.
219219
///
220220
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
221-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
221+
#[derive(Clone, PartialEq, Eq, Copy)]
222+
// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
223+
#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
222224
// On below-64 bit systems we can simply use the derived `Hash` impl
223225
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
224226
#[repr(C)]
@@ -260,6 +262,22 @@ impl Hash for DefId {
260262
}
261263
}
262264

265+
// Implement the same comparison as derived with the other field order.
266+
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
267+
impl Ord for DefId {
268+
#[inline]
269+
fn cmp(&self, other: &DefId) -> std::cmp::Ordering {
270+
Ord::cmp(&(self.index, self.krate), &(other.index, other.krate))
271+
}
272+
}
273+
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
274+
impl PartialOrd for DefId {
275+
#[inline]
276+
fn partial_cmp(&self, other: &DefId) -> Option<std::cmp::Ordering> {
277+
Some(Ord::cmp(self, other))
278+
}
279+
}
280+
263281
impl DefId {
264282
/// Makes a local `DefId` from the given `DefIndex`.
265283
#[inline]

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -2263,13 +2263,22 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
22632263
trait_impls.non_blanket_impls().len()
22642264
)
22652265
};
2266-
2266+
let mut suggestions = vec![(
2267+
trait_path_segment.ident.span.shrink_to_lo(),
2268+
format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())
2269+
)];
2270+
if let Some(generic_arg) = trait_path_segment.args {
2271+
let between_span = trait_path_segment.ident.span.between(generic_arg.span_ext);
2272+
// get rid of :: between Trait and <type>
2273+
// must be '::' between them, otherwise the parser won't accept the code
2274+
suggestions.push((between_span, "".to_string(),));
2275+
suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">")));
2276+
} else {
2277+
suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">")));
2278+
}
22672279
err.multipart_suggestion(
22682280
message,
2269-
vec![
2270-
(trait_path_segment.ident.span.shrink_to_lo(), format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())),
2271-
(trait_path_segment.ident.span.shrink_to_hi(), format!(">"))
2272-
],
2281+
suggestions,
22732282
Applicability::MaybeIncorrect
22742283
);
22752284
}

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
14251425
let mut spans_and_needs_box = vec![];
14261426

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

Diff for: library/core/src/const_closure.rs

+39-25
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ use crate::marker::Destruct;
1616
/// assert!(7 == cl(2));
1717
/// assert!(8 == cl(1));
1818
/// ```
19-
pub(crate) struct ConstFnMutClosure<'a, CapturedData: ?Sized, Function> {
20-
data: &'a mut CapturedData,
21-
func: Function,
19+
pub(crate) struct ConstFnMutClosure<CapturedData, Function> {
20+
/// The Data captured by the Closure.
21+
/// Must be either a (mutable) reference or a tuple of (mutable) references.
22+
pub data: CapturedData,
23+
/// The Function of the Closure, must be: Fn(CapturedData, ClosureArgs) -> ClosureReturn
24+
pub func: Function,
2225
}
23-
24-
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Function> {
26+
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<&'a mut CapturedData, Function> {
2527
/// Function for creating a new closure.
2628
///
2729
/// `data` is the a mutable borrow of data that is captured from the environment.
30+
/// If you want Data to be a tuple of mutable Borrows, the struct must be constructed manually.
2831
///
2932
/// `func` is the function of the closure, it gets the data and a tuple of the arguments closure
3033
/// and return the return value of the closure.
@@ -39,25 +42,36 @@ impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Fun
3942
}
4043
}
4144

42-
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
43-
FnOnce<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
44-
where
45-
Function:
46-
~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct,
47-
{
48-
type Output = ClosureReturnValue;
45+
macro_rules! impl_fn_mut_tuple {
46+
($($var:ident)*) => {
47+
#[allow(unused_parens)]
48+
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
49+
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
50+
where
51+
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct,
52+
{
53+
type Output = ClosureReturnValue;
4954

50-
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
51-
self.call_mut(args)
52-
}
53-
}
54-
55-
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
56-
FnMut<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
57-
where
58-
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
59-
{
60-
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
61-
(self.func)(self.data, args)
62-
}
55+
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
56+
self.call_mut(args)
57+
}
58+
}
59+
#[allow(unused_parens)]
60+
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
61+
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
62+
where
63+
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
64+
{
65+
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
66+
#[allow(non_snake_case)]
67+
let ($($var),*) = &mut self.data;
68+
(self.func)(($($var),*), args)
69+
}
70+
}
71+
};
6372
}
73+
impl_fn_mut_tuple!(A);
74+
impl_fn_mut_tuple!(A B);
75+
impl_fn_mut_tuple!(A B C);
76+
impl_fn_mut_tuple!(A B C D);
77+
impl_fn_mut_tuple!(A B C D E);

Diff for: library/core/src/ops/try_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub(crate) type ChangeOutputType<T, V> = <<T as Try>::Residual as Residual<V>>::
379379
pub(crate) struct NeverShortCircuit<T>(pub T);
380380

381381
impl<T> NeverShortCircuit<T> {
382-
/// Wrap a binary `FnMut` to return its result wrapped in a `NeverShortCircuit`.
382+
/// Implementation for building `ConstFnMutClosure` for wrapping the output of a ~const FnMut in a `NeverShortCircuit`.
383383
#[inline]
384384
pub const fn wrap_mut_2_imp<A, B, F: ~const FnMut(A, B) -> T>(
385385
f: &mut F,

Diff for: src/librustdoc/html/static/css/rustdoc.css

-2
Original file line numberDiff line numberDiff line change
@@ -1245,13 +1245,11 @@ h3.variant {
12451245
font-weight: 600;
12461246
font-size: 1.125rem;
12471247
margin-bottom: 10px;
1248-
border-bottom: none;
12491248
}
12501249

12511250
.sub-variant h4 {
12521251
font-size: 1rem;
12531252
font-weight: 400;
1254-
border-bottom: none;
12551253
margin-top: 0;
12561254
margin-bottom: 0;
12571255
}

Diff for: src/test/ui/stats/hir-stats.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// check-pass
22
// compile-flags: -Zhir-stats
33
// only-x86_64
4-
// ignore-stage1
54

65
// The aim here is to include at least one of every different type of top-level
76
// AST/HIR node reported by `-Zhir-stats`.

Diff for: src/test/ui/type/issue-101866.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait TraitA<T> {
2+
fn func();
3+
}
4+
5+
struct StructA {}
6+
7+
impl TraitA<i32> for StructA {
8+
fn func() {}
9+
}
10+
11+
fn main() {
12+
TraitA::<i32>::func();
13+
//~^ ERROR: cannot call associated function on trait without specifying the corresponding `impl` type [E0790]
14+
//~| help: use the fully-qualified path to the only available implementation
15+
}

Diff for: src/test/ui/type/issue-101866.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
2+
--> $DIR/issue-101866.rs:12:5
3+
|
4+
LL | fn func();
5+
| ---------- `TraitA::func` defined here
6+
...
7+
LL | TraitA::<i32>::func();
8+
| ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
9+
|
10+
help: use the fully-qualified path to the only available implementation
11+
|
12+
LL - TraitA::<i32>::func();
13+
LL + <::StructA as TraitA<i32>>::func();
14+
|
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0790`.

0 commit comments

Comments
 (0)