Skip to content

Commit

Permalink
Auto merge of rust-lang#86791 - JohnTitor:rollup-96ltzpz, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#86148 (Check the number of generic lifetime and const parameters of intrinsics)
 - rust-lang#86659 (fix(rustdoc): generics search)
 - rust-lang#86768 (Add myself to mailmap)
 - rust-lang#86775 (Test for const trait impls behind feature gates)
 - rust-lang#86779 (Allow anyone to add or remove any label starting with perf-)
 - rust-lang#86783 (Move Mutex::unlock to T: ?Sized)
 - rust-lang#86785 (proc_macro/bridge: Remove dead code Slice type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 1, 2021
2 parents 7100b31 + 76bf7c0 commit 56dee7c
Show file tree
Hide file tree
Showing 25 changed files with 389 additions and 121 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Daniel Ramos <dan@daramos.com>
David Klein <david.klein@baesystemsdetica.com>
David Manescu <david.manescu@gmail.com> <dman2626@uni.sydney.edu.au>
David Ross <daboross@daboross.net>
Deadbeef <ent3rm4n@gmail.com> <fee1-dead-beef@protonmail.com>
Derek Chiang <derekchiang93@gmail.com> Derek Chiang (Enchi Jiang) <derekchiang93@gmail.com>
Diggory Hardy <diggory.hardy@gmail.com> Diggory Hardy <github@dhardy.name>
Donough Liu <ldm2993593805@163.com> <donoughliu@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0094.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
An invalid number of type parameters was given to an intrinsic function.
An invalid number of generic parameters was passed to an intrinsic function.

Erroneous code example:

Expand Down
61 changes: 35 additions & 26 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use crate::errors::{
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
WrongNumberOfTypeArgumentsToInstrinsic,
WrongNumberOfGenericArgumentsToIntrinsic,
};
use crate::require_same_types;

use rustc_errors::struct_span_err;
use rustc_errors::{pluralize, struct_span_err};
use rustc_hir as hir;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::subst::Subst;
Expand All @@ -21,36 +21,45 @@ fn equate_intrinsic_type<'tcx>(
tcx: TyCtxt<'tcx>,
it: &hir::ForeignItem<'_>,
n_tps: usize,
n_lts: usize,
sig: ty::PolyFnSig<'tcx>,
) {
match it.kind {
hir::ForeignItemKind::Fn(..) => {}
let (own_counts, span) = match &it.kind {
hir::ForeignItemKind::Fn(.., generics) => {
let own_counts = tcx.generics_of(it.def_id.to_def_id()).own_counts();
(own_counts, generics.span)
}
_ => {
struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function")
.span_label(it.span, "expected a function")
.emit();
return;
}
}
};

let i_n_tps = tcx.generics_of(it.def_id).own_counts().types;
if i_n_tps != n_tps {
let span = match it.kind {
hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span,
_ => bug!(),
};
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
if found != expected {
tcx.sess.emit_err(WrongNumberOfGenericArgumentsToIntrinsic {
span,
found,
expected,
expected_pluralize: pluralize!(expected),
descr,
});
false
} else {
true
}
};

tcx.sess.emit_err(WrongNumberOfTypeArgumentsToInstrinsic {
span,
found: i_n_tps,
expected: n_tps,
});
return;
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
&& gen_count_ok(own_counts.types, n_tps, "type")
&& gen_count_ok(own_counts.consts, 0, "const")
{
let fty = tcx.mk_fn_ptr(sig);
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
}

let fty = tcx.mk_fn_ptr(sig);
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
}

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

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

Expand All @@ -143,7 +152,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
return;
}
};
(n_tps, inputs, output, hir::Unsafety::Unsafe)
(n_tps, 0, inputs, output, hir::Unsafety::Unsafe)
} else {
let unsafety = intrinsic_operation_unsafety(intrinsic_name);
let (n_tps, inputs, output) = match intrinsic_name {
Expand Down Expand Up @@ -372,11 +381,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
return;
}
};
(n_tps, inputs, output, unsafety)
(n_tps, 0, inputs, output, unsafety)
};
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
equate_intrinsic_type(tcx, it, n_tps, sig)
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
}

/// Type-check `extern "platform-intrinsic" { ... }` functions.
Expand Down Expand Up @@ -472,5 +481,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
Abi::PlatformIntrinsic,
);
let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, it, n_tps, sig)
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
}
8 changes: 5 additions & 3 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ pub struct UnrecognizedAtomicOperation<'a> {

#[derive(SessionDiagnostic)]
#[error = "E0094"]
pub struct WrongNumberOfTypeArgumentsToInstrinsic {
#[message = "intrinsic has wrong number of type \
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
#[message = "intrinsic has wrong number of {descr} \
parameters: found {found}, expected {expected}"]
#[label = "expected {expected} type parameter"]
#[label = "expected {expected} {descr} parameter{expected_pluralize}"]
pub span: Span,
pub found: usize,
pub expected: usize,
pub expected_pluralize: &'a str,
pub descr: &'a str,
}

#[derive(SessionDiagnostic)]
Expand Down
29 changes: 0 additions & 29 deletions library/proc_macro/src/bridge/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,6 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use std::slice;

#[repr(C)]
struct Slice<'a, T> {
data: &'a [T; 0],
len: usize,
}

unsafe impl<'a, T: Sync> Sync for Slice<'a, T> {}
unsafe impl<'a, T: Sync> Send for Slice<'a, T> {}

impl<T> Copy for Slice<'a, T> {}
impl<T> Clone for Slice<'a, T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> From<&'a [T]> for Slice<'a, T> {
fn from(xs: &'a [T]) -> Self {
Slice { data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, len: xs.len() }
}
}

impl<T> Deref for Slice<'a, T> {
type Target = [T];
fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self.data.as_ptr(), self.len) }
}
}

#[repr(C)]
pub struct Buffer<T: Copy> {
data: *mut T,
Expand Down
40 changes: 20 additions & 20 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,26 +217,6 @@ impl<T> Mutex<T> {
data: UnsafeCell::new(t),
}
}

/// Immediately drops the guard, and consequently unlocks the mutex.
///
/// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
/// Alternately, the guard will be automatically dropped when it goes out of scope.
///
/// ```
/// #![feature(mutex_unlock)]
///
/// use std::sync::Mutex;
/// let mutex = Mutex::new(0);
///
/// let mut guard = mutex.lock().unwrap();
/// *guard += 20;
/// Mutex::unlock(guard);
/// ```
#[unstable(feature = "mutex_unlock", issue = "81872")]
pub fn unlock(guard: MutexGuard<'_, T>) {
drop(guard);
}
}

impl<T: ?Sized> Mutex<T> {
Expand Down Expand Up @@ -333,6 +313,26 @@ impl<T: ?Sized> Mutex<T> {
}
}

/// Immediately drops the guard, and consequently unlocks the mutex.
///
/// This function is equivalent to calling [`drop`] on the guard but is more self-documenting.
/// Alternately, the guard will be automatically dropped when it goes out of scope.
///
/// ```
/// #![feature(mutex_unlock)]
///
/// use std::sync::Mutex;
/// let mutex = Mutex::new(0);
///
/// let mut guard = mutex.lock().unwrap();
/// *guard += 20;
/// Mutex::unlock(guard);
/// ```
#[unstable(feature = "mutex_unlock", issue = "81872")]
pub fn unlock(guard: MutexGuard<'_, T>) {
drop(guard);
}

/// Determines whether the mutex is poisoned.
///
/// If another thread is active, the mutex can still become poisoned at any
Expand Down
18 changes: 18 additions & 0 deletions src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ crate fn get_index_search_type<'tcx>(
fn get_index_type(clean_type: &clean::Type) -> RenderType {
RenderType {
name: get_index_type_name(clean_type, true).map(|s| s.as_str().to_ascii_lowercase()),
generics: get_generics(clean_type),
}
}

Expand Down Expand Up @@ -251,6 +252,23 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
}
}

/// Return a list of generic parameters for use in the search index.
///
/// This function replaces bounds with types, so that `T where T: Debug` just becomes `Debug`.
/// It does return duplicates, and that's intentional, since search queries like `Result<usize, usize>`
/// are supposed to match only results where both parameters are `usize`.
fn get_generics(clean_type: &clean::Type) -> Option<Vec<String>> {
clean_type.generics().and_then(|types| {
let r = types
.iter()
.filter_map(|t| {
get_index_type_name(t, false).map(|name| name.as_str().to_ascii_lowercase())
})
.collect::<Vec<_>>();
if r.is_empty() { None } else { Some(r) }
})
}

/// The point of this function is to replace bounds with types.
///
/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return
Expand Down
9 changes: 8 additions & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ crate struct IndexItem {
#[derive(Debug)]
crate struct RenderType {
name: Option<String>,
generics: Option<Vec<String>>,
}

/// Full type of functions/methods in the search index.
Expand Down Expand Up @@ -149,7 +150,13 @@ impl Serialize for TypeWithKind {
where
S: Serializer,
{
(&self.ty.name, self.kind).serialize(serializer)
let mut seq = serializer.serialize_seq(None)?;
seq.serialize_element(&self.ty.name)?;
seq.serialize_element(&self.kind)?;
if let Some(generics) = &self.ty.generics {
seq.serialize_element(generics)?;
}
seq.end()
}
}

Expand Down
Loading

0 comments on commit 56dee7c

Please sign in to comment.