Skip to content
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

Rollup of 7 pull requests #86788

Closed
wants to merge 15 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: 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_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ fn instance_def_size_estimate<'tcx>(
match instance_def {
InstanceDef::Item(..) | InstanceDef::DropGlue(..) => {
let mir = tcx.instance_mir(instance_def);
mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum()
mir.basic_blocks().iter().map(|bb| bb.statements.len() + 1).sum()
}
// Estimate the size of other compiler-generated shims to be 1.
_ => 1,
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
80 changes: 62 additions & 18 deletions src/librustdoc/html/static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function levenshtein(s1, s2) {
window.initSearch = function(rawSearchIndex) {
var MAX_LEV_DISTANCE = 3;
var MAX_RESULTS = 200;
var GENERICS_DATA = 1;
var GENERICS_DATA = 2;
var NAME = 0;
var INPUTS_DATA = 0;
var OUTPUT_DATA = 1;
Expand Down Expand Up @@ -306,6 +306,9 @@ window.initSearch = function(rawSearchIndex) {
var elems = Object.create(null);
var elength = obj[GENERICS_DATA].length;
for (var x = 0; x < elength; ++x) {
if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0;
}
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
}
var total = 0;
Expand Down Expand Up @@ -354,10 +357,13 @@ window.initSearch = function(rawSearchIndex) {
if (literalSearch) {
if (val.generics && val.generics.length !== 0) {
if (obj.length > GENERICS_DATA &&
obj[GENERICS_DATA].length >= val.generics.length) {
obj[GENERICS_DATA].length > 0) {
var elems = Object.create(null);
len = obj[GENERICS_DATA].length;
for (x = 0; x < len; ++x) {
if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0;
}
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
}

Expand All @@ -375,26 +381,23 @@ window.initSearch = function(rawSearchIndex) {
if (allFound) {
return true;
}
} else {
return false;
}
return false;
}
return true;
}
// If the type has generics but don't match, then it won't return at this point.
// Otherwise, `checkGenerics` will return 0 and it'll return.
if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) {
var tmp_lev = checkGenerics(obj, val);
if (tmp_lev <= MAX_LEV_DISTANCE) {
return tmp_lev;
}
} else {
return 0;
// If the type has generics but don't match, then it won't return at this point.
// Otherwise, `checkGenerics` will return 0 and it'll return.
if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) {
var tmp_lev = checkGenerics(obj, val);
if (tmp_lev <= MAX_LEV_DISTANCE) {
return tmp_lev;
}
}
}
}
// Names didn't match so let's check if one of the generic types could.
if (literalSearch) {
if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
} else if (literalSearch) {
if ((!val.generics || val.generics.length === 0) &&
obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
return obj[GENERICS_DATA].some(
function(name) {
return name === val.name;
Expand Down Expand Up @@ -1167,7 +1170,48 @@ window.initSearch = function(rawSearchIndex) {
return ret;
}

var queries = query.raw.split(",");
// Split search query by ",", while respecting angle bracket nesting.
// Since "<" is an alias for the Ord family of traits, it also uses
// lookahead to distinguish "<"-as-less-than from "<"-as-angle-bracket.
//
// tokenizeQuery("A<B, C>, D") == ["A<B, C>", "D"]
// tokenizeQuery("A<B, C, D") == ["A<B", "C", "D"]
function tokenizeQuery(raw) {
var i, matched;
var l = raw.length;
var depth = 0;
var nextAngle = /(<|>)/g;
var ret = [];
var start = 0;
for (i = 0; i < l; ++i) {
switch (raw[i]) {
case "<":
nextAngle.lastIndex = i + 1;
matched = nextAngle.exec(raw);
if (matched && matched[1] === '>') {
depth += 1;
}
break;
case ">":
if (depth > 0) {
depth -= 1;
}
break;
case ",":
if (depth === 0) {
ret.push(raw.substring(start, i));
start = i + 1;
}
break;
}
}
if (start !== i) {
ret.push(raw.substring(start, i));
}
return ret;
}

var queries = tokenizeQuery(query.raw);
var results = {
"in_args": [],
"returned": [],
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-js-std/alias-4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const QUERY = '<';

const EXPECTED = {
'others': [
{ 'name': 'Ord' },
],
};
23 changes: 23 additions & 0 deletions src/test/rustdoc-js/generics-trait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const QUERY = [
'Result<SomeTrait>',
'OtherThingxxxxxxxx',
];

const EXPECTED = [
{
'in_args': [
{ 'path': 'generics_trait', 'name': 'beta' },
],
'returned': [
{ 'path': 'generics_trait', 'name': 'bet' },
],
},
{
'in_args': [
{ 'path': 'generics_trait', 'name': 'alpha' },
],
'returned': [
{ 'path': 'generics_trait', 'name': 'alef' },
],
},
];
8 changes: 8 additions & 0 deletions src/test/rustdoc-js/generics-trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub trait SomeTrait {}
pub trait OtherThingxxxxxxxx {}

pub fn alef<T: OtherThingxxxxxxxx>() -> Result<T, ()> { loop {} }
pub fn bet<T: SomeTrait>() -> Result<T, ()> { loop {} }

pub fn alpha<T: OtherThingxxxxxxxx>(_param: Result<T, ()>) { loop {} }
pub fn beta<T: SomeTrait>(_param: Result<T, ()>) { loop {} }
44 changes: 44 additions & 0 deletions src/test/rustdoc-js/generics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// exact-check

const QUERY = [
'"R<P>"',
'"P"',
'P',
'"ExtraCreditStructMulti<ExtraCreditInnerMulti, ExtraCreditInnerMulti>"',
];

const EXPECTED = [
{
'returned': [
{ 'path': 'generics', 'name': 'alef' },
],
'in_args': [
{ 'path': 'generics', 'name': 'alpha' },
],
},
{
'others': [
{ 'path': 'generics', 'name': 'P' },
],
'returned': [
{ 'path': 'generics', 'name': 'alef' },
],
'in_args': [
{ 'path': 'generics', 'name': 'alpha' },
],
},
{
'returned': [
{ 'path': 'generics', 'name': 'alef' },
],
'in_args': [
{ 'path': 'generics', 'name': 'alpha' },
],
},
{
'in_args': [
{ 'path': 'generics', 'name': 'extracreditlabhomework' },
],
'returned': [],
},
];
21 changes: 21 additions & 0 deletions src/test/rustdoc-js/generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub struct P;
pub struct Q;
pub struct R<T>(T);

// returns test
pub fn alef() -> R<P> { loop {} }
pub fn bet() -> R<Q> { loop {} }

// in_args test
pub fn alpha(_x: R<P>) { loop {} }
pub fn beta(_x: R<Q>) { loop {} }

// test case with multiple appearances of the same type
pub struct ExtraCreditStructMulti<T, U> { t: T, u: U }
pub struct ExtraCreditInnerMulti {}
pub fn extracreditlabhomework(
_param: ExtraCreditStructMulti<ExtraCreditInnerMulti, ExtraCreditInnerMulti>
) { loop {} }
pub fn redherringmatchforextracredit(
_param: ExtraCreditStructMulti<ExtraCreditInnerMulti, ()>
) { loop {} }
Loading