Skip to content

Commit 56dee7c

Browse files
committed
Auto merge of #86791 - JohnTitor:rollup-96ltzpz, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #86148 (Check the number of generic lifetime and const parameters of intrinsics) - #86659 (fix(rustdoc): generics search) - #86768 (Add myself to mailmap) - #86775 (Test for const trait impls behind feature gates) - #86779 (Allow anyone to add or remove any label starting with perf-) - #86783 (Move Mutex::unlock to T: ?Sized) - #86785 (proc_macro/bridge: Remove dead code Slice type) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7100b31 + 76bf7c0 commit 56dee7c

File tree

25 files changed

+389
-121
lines changed

25 files changed

+389
-121
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Daniel Ramos <[email protected]>
7272
David Klein <[email protected]>
7373
7474
David Ross <[email protected]>
75+
7576
Derek Chiang <[email protected]> Derek Chiang (Enchi Jiang) <[email protected]>
7677
Diggory Hardy <[email protected]> Diggory Hardy <[email protected]>
7778

compiler/rustc_error_codes/src/error_codes/E0094.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
An invalid number of type parameters was given to an intrinsic function.
1+
An invalid number of generic parameters was passed to an intrinsic function.
22

33
Erroneous code example:
44

compiler/rustc_typeck/src/check/intrinsic.rs

+35-26
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
44
use crate::errors::{
55
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
6-
WrongNumberOfTypeArgumentsToInstrinsic,
6+
WrongNumberOfGenericArgumentsToIntrinsic,
77
};
88
use crate::require_same_types;
99

10-
use rustc_errors::struct_span_err;
10+
use rustc_errors::{pluralize, struct_span_err};
1111
use rustc_hir as hir;
1212
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
1313
use rustc_middle::ty::subst::Subst;
@@ -21,36 +21,45 @@ fn equate_intrinsic_type<'tcx>(
2121
tcx: TyCtxt<'tcx>,
2222
it: &hir::ForeignItem<'_>,
2323
n_tps: usize,
24+
n_lts: usize,
2425
sig: ty::PolyFnSig<'tcx>,
2526
) {
26-
match it.kind {
27-
hir::ForeignItemKind::Fn(..) => {}
27+
let (own_counts, span) = match &it.kind {
28+
hir::ForeignItemKind::Fn(.., generics) => {
29+
let own_counts = tcx.generics_of(it.def_id.to_def_id()).own_counts();
30+
(own_counts, generics.span)
31+
}
2832
_ => {
2933
struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function")
3034
.span_label(it.span, "expected a function")
3135
.emit();
3236
return;
3337
}
34-
}
38+
};
3539

36-
let i_n_tps = tcx.generics_of(it.def_id).own_counts().types;
37-
if i_n_tps != n_tps {
38-
let span = match it.kind {
39-
hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span,
40-
_ => bug!(),
41-
};
40+
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
41+
if found != expected {
42+
tcx.sess.emit_err(WrongNumberOfGenericArgumentsToIntrinsic {
43+
span,
44+
found,
45+
expected,
46+
expected_pluralize: pluralize!(expected),
47+
descr,
48+
});
49+
false
50+
} else {
51+
true
52+
}
53+
};
4254

43-
tcx.sess.emit_err(WrongNumberOfTypeArgumentsToInstrinsic {
44-
span,
45-
found: i_n_tps,
46-
expected: n_tps,
47-
});
48-
return;
55+
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
56+
&& gen_count_ok(own_counts.types, n_tps, "type")
57+
&& gen_count_ok(own_counts.consts, 0, "const")
58+
{
59+
let fty = tcx.mk_fn_ptr(sig);
60+
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
61+
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
4962
}
50-
51-
let fty = tcx.mk_fn_ptr(sig);
52-
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
53-
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
5463
}
5564

5665
/// Returns the unsafety of the given intrinsic.
@@ -121,7 +130,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
121130
})
122131
};
123132

124-
let (n_tps, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
133+
let (n_tps, n_lts, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
125134
let split: Vec<&str> = name_str.split('_').collect();
126135
assert!(split.len() >= 2, "Atomic intrinsic in an incorrect format");
127136

@@ -143,7 +152,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
143152
return;
144153
}
145154
};
146-
(n_tps, inputs, output, hir::Unsafety::Unsafe)
155+
(n_tps, 0, inputs, output, hir::Unsafety::Unsafe)
147156
} else {
148157
let unsafety = intrinsic_operation_unsafety(intrinsic_name);
149158
let (n_tps, inputs, output) = match intrinsic_name {
@@ -372,11 +381,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
372381
return;
373382
}
374383
};
375-
(n_tps, inputs, output, unsafety)
384+
(n_tps, 0, inputs, output, unsafety)
376385
};
377386
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
378387
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
379-
equate_intrinsic_type(tcx, it, n_tps, sig)
388+
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
380389
}
381390

382391
/// Type-check `extern "platform-intrinsic" { ... }` functions.
@@ -472,5 +481,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
472481
Abi::PlatformIntrinsic,
473482
);
474483
let sig = ty::Binder::dummy(sig);
475-
equate_intrinsic_type(tcx, it, n_tps, sig)
484+
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
476485
}

compiler/rustc_typeck/src/errors.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ pub struct UnrecognizedAtomicOperation<'a> {
2424

2525
#[derive(SessionDiagnostic)]
2626
#[error = "E0094"]
27-
pub struct WrongNumberOfTypeArgumentsToInstrinsic {
28-
#[message = "intrinsic has wrong number of type \
27+
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
28+
#[message = "intrinsic has wrong number of {descr} \
2929
parameters: found {found}, expected {expected}"]
30-
#[label = "expected {expected} type parameter"]
30+
#[label = "expected {expected} {descr} parameter{expected_pluralize}"]
3131
pub span: Span,
3232
pub found: usize,
3333
pub expected: usize,
34+
pub expected_pluralize: &'a str,
35+
pub descr: &'a str,
3436
}
3537

3638
#[derive(SessionDiagnostic)]

library/proc_macro/src/bridge/buffer.rs

-29
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,6 @@ use std::mem;
55
use std::ops::{Deref, DerefMut};
66
use std::slice;
77

8-
#[repr(C)]
9-
struct Slice<'a, T> {
10-
data: &'a [T; 0],
11-
len: usize,
12-
}
13-
14-
unsafe impl<'a, T: Sync> Sync for Slice<'a, T> {}
15-
unsafe impl<'a, T: Sync> Send for Slice<'a, T> {}
16-
17-
impl<T> Copy for Slice<'a, T> {}
18-
impl<T> Clone for Slice<'a, T> {
19-
fn clone(&self) -> Self {
20-
*self
21-
}
22-
}
23-
24-
impl<T> From<&'a [T]> for Slice<'a, T> {
25-
fn from(xs: &'a [T]) -> Self {
26-
Slice { data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, len: xs.len() }
27-
}
28-
}
29-
30-
impl<T> Deref for Slice<'a, T> {
31-
type Target = [T];
32-
fn deref(&self) -> &[T] {
33-
unsafe { slice::from_raw_parts(self.data.as_ptr(), self.len) }
34-
}
35-
}
36-
378
#[repr(C)]
389
pub struct Buffer<T: Copy> {
3910
data: *mut T,

library/std/src/sync/mutex.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -217,26 +217,6 @@ impl<T> Mutex<T> {
217217
data: UnsafeCell::new(t),
218218
}
219219
}
220-
221-
/// Immediately drops the guard, and consequently unlocks the mutex.
222-
///
223-
/// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
224-
/// Alternately, the guard will be automatically dropped when it goes out of scope.
225-
///
226-
/// ```
227-
/// #![feature(mutex_unlock)]
228-
///
229-
/// use std::sync::Mutex;
230-
/// let mutex = Mutex::new(0);
231-
///
232-
/// let mut guard = mutex.lock().unwrap();
233-
/// *guard += 20;
234-
/// Mutex::unlock(guard);
235-
/// ```
236-
#[unstable(feature = "mutex_unlock", issue = "81872")]
237-
pub fn unlock(guard: MutexGuard<'_, T>) {
238-
drop(guard);
239-
}
240220
}
241221

242222
impl<T: ?Sized> Mutex<T> {
@@ -333,6 +313,26 @@ impl<T: ?Sized> Mutex<T> {
333313
}
334314
}
335315

316+
/// Immediately drops the guard, and consequently unlocks the mutex.
317+
///
318+
/// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
319+
/// Alternately, the guard will be automatically dropped when it goes out of scope.
320+
///
321+
/// ```
322+
/// #![feature(mutex_unlock)]
323+
///
324+
/// use std::sync::Mutex;
325+
/// let mutex = Mutex::new(0);
326+
///
327+
/// let mut guard = mutex.lock().unwrap();
328+
/// *guard += 20;
329+
/// Mutex::unlock(guard);
330+
/// ```
331+
#[unstable(feature = "mutex_unlock", issue = "81872")]
332+
pub fn unlock(guard: MutexGuard<'_, T>) {
333+
drop(guard);
334+
}
335+
336336
/// Determines whether the mutex is poisoned.
337337
///
338338
/// If another thread is active, the mutex can still become poisoned at any

src/librustdoc/html/render/cache.rs

+18
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ crate fn get_index_search_type<'tcx>(
219219
fn get_index_type(clean_type: &clean::Type) -> RenderType {
220220
RenderType {
221221
name: get_index_type_name(clean_type, true).map(|s| s.as_str().to_ascii_lowercase()),
222+
generics: get_generics(clean_type),
222223
}
223224
}
224225

@@ -251,6 +252,23 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
251252
}
252253
}
253254

255+
/// Return a list of generic parameters for use in the search index.
256+
///
257+
/// This function replaces bounds with types, so that `T where T: Debug` just becomes `Debug`.
258+
/// It does return duplicates, and that's intentional, since search queries like `Result<usize, usize>`
259+
/// are supposed to match only results where both parameters are `usize`.
260+
fn get_generics(clean_type: &clean::Type) -> Option<Vec<String>> {
261+
clean_type.generics().and_then(|types| {
262+
let r = types
263+
.iter()
264+
.filter_map(|t| {
265+
get_index_type_name(t, false).map(|name| name.as_str().to_ascii_lowercase())
266+
})
267+
.collect::<Vec<_>>();
268+
if r.is_empty() { None } else { Some(r) }
269+
})
270+
}
271+
254272
/// The point of this function is to replace bounds with types.
255273
///
256274
/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return

src/librustdoc/html/render/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ crate struct IndexItem {
9696
#[derive(Debug)]
9797
crate struct RenderType {
9898
name: Option<String>,
99+
generics: Option<Vec<String>>,
99100
}
100101

101102
/// Full type of functions/methods in the search index.
@@ -149,7 +150,13 @@ impl Serialize for TypeWithKind {
149150
where
150151
S: Serializer,
151152
{
152-
(&self.ty.name, self.kind).serialize(serializer)
153+
let mut seq = serializer.serialize_seq(None)?;
154+
seq.serialize_element(&self.ty.name)?;
155+
seq.serialize_element(&self.kind)?;
156+
if let Some(generics) = &self.ty.generics {
157+
seq.serialize_element(generics)?;
158+
}
159+
seq.end()
153160
}
154161
}
155162

0 commit comments

Comments
 (0)