mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Auto merge of #102520 - matthiaskrgr:rollup-7nreat0, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #102276 (Added more const_closure functionality) - #102382 (Manually order `DefId` on 64-bit big-endian) - #102421 (remove the unused :: between trait and type to give user correct diag…) - #102495 (Reinstate `hir-stats.rs` test for stage 1.) - #102505 (rustdoc: remove no-op CSS `h3.variant, .sub-variant h4 { border-bottom: none }`) - #102506 (Specify `DynKind::Dyn`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
877877a19a
@ -218,7 +218,9 @@ impl<D: Decoder> Decodable<D> for DefIndex {
|
||||
/// index and a def index.
|
||||
///
|
||||
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
|
||||
#[derive(Clone, PartialEq, Eq, Copy)]
|
||||
// Don't derive order on 64-bit big-endian, so we can be consistent regardless of field order.
|
||||
#[cfg_attr(not(all(target_pointer_width = "64", target_endian = "big")), derive(PartialOrd, Ord))]
|
||||
// On below-64 bit systems we can simply use the derived `Hash` impl
|
||||
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
|
||||
#[repr(C)]
|
||||
@ -260,6 +262,22 @@ impl Hash for DefId {
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the same comparison as derived with the other field order.
|
||||
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
|
||||
impl Ord for DefId {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &DefId) -> std::cmp::Ordering {
|
||||
Ord::cmp(&(self.index, self.krate), &(other.index, other.krate))
|
||||
}
|
||||
}
|
||||
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
|
||||
impl PartialOrd for DefId {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &DefId) -> Option<std::cmp::Ordering> {
|
||||
Some(Ord::cmp(self, other))
|
||||
}
|
||||
}
|
||||
|
||||
impl DefId {
|
||||
/// Makes a local `DefId` from the given `DefIndex`.
|
||||
#[inline]
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -16,15 +16,18 @@ use crate::marker::Destruct;
|
||||
/// assert!(7 == cl(2));
|
||||
/// assert!(8 == cl(1));
|
||||
/// ```
|
||||
pub(crate) struct ConstFnMutClosure<'a, CapturedData: ?Sized, Function> {
|
||||
data: &'a mut CapturedData,
|
||||
func: Function,
|
||||
pub(crate) struct ConstFnMutClosure<CapturedData, Function> {
|
||||
/// The Data captured by the Closure.
|
||||
/// Must be either a (mutable) reference or a tuple of (mutable) references.
|
||||
pub data: CapturedData,
|
||||
/// The Function of the Closure, must be: Fn(CapturedData, ClosureArgs) -> ClosureReturn
|
||||
pub func: Function,
|
||||
}
|
||||
|
||||
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Function> {
|
||||
impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<&'a mut CapturedData, Function> {
|
||||
/// Function for creating a new closure.
|
||||
///
|
||||
/// `data` is the a mutable borrow of data that is captured from the environment.
|
||||
/// If you want Data to be a tuple of mutable Borrows, the struct must be constructed manually.
|
||||
///
|
||||
/// `func` is the function of the closure, it gets the data and a tuple of the arguments closure
|
||||
/// and return the return value of the closure.
|
||||
@ -39,25 +42,36 @@ impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<'a, CapturedData, Fun
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
|
||||
FnOnce<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
|
||||
where
|
||||
Function:
|
||||
~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue + ~const Destruct,
|
||||
{
|
||||
type Output = ClosureReturnValue;
|
||||
macro_rules! impl_fn_mut_tuple {
|
||||
($($var:ident)*) => {
|
||||
#[allow(unused_parens)]
|
||||
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
||||
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||
where
|
||||
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct,
|
||||
{
|
||||
type Output = ClosureReturnValue;
|
||||
|
||||
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
|
||||
self.call_mut(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, CapturedData: ?Sized, ClosureArguments, Function, ClosureReturnValue> const
|
||||
FnMut<ClosureArguments> for ConstFnMutClosure<'a, CapturedData, Function>
|
||||
where
|
||||
Function: ~const Fn(&mut CapturedData, ClosureArguments) -> ClosureReturnValue,
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
|
||||
(self.func)(self.data, args)
|
||||
}
|
||||
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
|
||||
self.call_mut(args)
|
||||
}
|
||||
}
|
||||
#[allow(unused_parens)]
|
||||
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
||||
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||
where
|
||||
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
|
||||
#[allow(non_snake_case)]
|
||||
let ($($var),*) = &mut self.data;
|
||||
(self.func)(($($var),*), args)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
impl_fn_mut_tuple!(A);
|
||||
impl_fn_mut_tuple!(A B);
|
||||
impl_fn_mut_tuple!(A B C);
|
||||
impl_fn_mut_tuple!(A B C D);
|
||||
impl_fn_mut_tuple!(A B C D E);
|
||||
|
@ -379,7 +379,7 @@ pub(crate) type ChangeOutputType<T, V> = <<T as Try>::Residual as Residual<V>>::
|
||||
pub(crate) struct NeverShortCircuit<T>(pub T);
|
||||
|
||||
impl<T> NeverShortCircuit<T> {
|
||||
/// Wrap a binary `FnMut` to return its result wrapped in a `NeverShortCircuit`.
|
||||
/// Implementation for building `ConstFnMutClosure` for wrapping the output of a ~const FnMut in a `NeverShortCircuit`.
|
||||
#[inline]
|
||||
pub const fn wrap_mut_2_imp<A, B, F: ~const FnMut(A, B) -> T>(
|
||||
f: &mut F,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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`.
|
||||
|
15
src/test/ui/type/issue-101866.rs
Normal file
15
src/test/ui/type/issue-101866.rs
Normal file
@ -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
src/test/ui/type/issue-101866.stderr
Normal file
18
src/test/ui/type/issue-101866.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user