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 #92593

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9a38ed1
Rename args to check_argument_types and add some comments for what t…
jackh726 Dec 24, 2021
45341a6
Rename a couple variables
jackh726 Dec 24, 2021
555119f
Introduce demand_compatible
jackh726 Dec 25, 2021
bbb8bde
Slight cleanup
jackh726 Dec 28, 2021
57ac317
Added regression test for issue 92015
chordtoll Dec 29, 2021
622a394
Allow handle_alloc_error to unwind
Amanieu Aug 17, 2021
f4545cc
Mark __rgl_oom and __rd_oom as "C-unwind"
Amanieu Oct 4, 2021
57b59af
Add note about non_exhaustive to variant_count
Mark-Simulacrum Jan 5, 2022
83487b8
Rustdoc: resolve associated traits for primitive types
mdibaiee Dec 30, 2021
19419f3
add a test case for each supported primitive type
mdibaiee Jan 3, 2022
973cf63
Remove unsupported types in primitive_to_ty conversion, add FIXME note
mdibaiee Jan 3, 2022
f3fe912
Switch to es6 for eslint
jsha Jan 2, 2022
8abb4bb
Move crate drop-down to search results page
jsha Jan 2, 2022
014f22a
Break the loop
ChrisDenton Jan 5, 2022
2758a54
Rollup merge of #92360 - jackh726:param-heuristics-1, r=davidtwco
matthiaskrgr Jan 5, 2022
6041442
Rollup merge of #92389 - chordtoll:test-92015, r=Mark-Simulacrum
matthiaskrgr Jan 5, 2022
0e21303
Rollup merge of #92443 - mdibaiee:90703/resolve-traits-of-primitive-t…
matthiaskrgr Jan 5, 2022
9f4ebd8
Rollup merge of #92490 - jsha:crates-in-results, r=GuillaumeGomez
matthiaskrgr Jan 5, 2022
2486a8a
Rollup merge of #92535 - Amanieu:oom_hook_unwind, r=m-ou-se
matthiaskrgr Jan 5, 2022
7f7b3b6
Rollup merge of #92568 - Mark-Simulacrum:non-exhaustive-variant-count…
matthiaskrgr Jan 5, 2022
cc59087
Rollup merge of #92589 - ChrisDenton:break-loop, r=Mark-Simulacrum
matthiaskrgr Jan 5, 2022
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
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr.span,
call_expr,
fn_sig.inputs(),
&expected_arg_tys,
expected_arg_tys,
arg_exprs,
fn_sig.c_variadic,
TupleArgumentsFlag::DontTupleArguments,
Expand Down Expand Up @@ -529,7 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr.span,
call_expr,
fn_sig.inputs(),
&expected_arg_tys,
expected_arg_tys,
arg_exprs,
fn_sig.c_variadic,
TupleArgumentsFlag::TupleArguments,
Expand Down
227 changes: 121 additions & 106 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ extern "Rust" {
// This is the magic symbol to call the global alloc error handler. rustc generates
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
// default implementations below (`__rdl_oom`) otherwise.
#[rustc_allocator_nounwind]
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

Expand All @@ -367,7 +366,6 @@ extern "Rust" {
#[stable(feature = "global_alloc", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
#[cfg(all(not(no_global_oom_handling), not(test)))]
#[rustc_allocator_nounwind]
#[cold]
pub const fn handle_alloc_error(layout: Layout) -> ! {
const fn ct_error(_: Layout) -> ! {
Expand Down Expand Up @@ -398,13 +396,13 @@ pub mod __alloc_error_handler {

// if there is no `#[alloc_error_handler]`
#[rustc_std_internal_symbol]
pub unsafe extern "C" fn __rdl_oom(size: usize, _align: usize) -> ! {
pub unsafe extern "C-unwind" fn __rdl_oom(size: usize, _align: usize) -> ! {
panic!("memory allocation of {} bytes failed", size)
}

// if there is an `#[alloc_error_handler]`
#[rustc_std_internal_symbol]
pub unsafe extern "C" fn __rg_oom(size: usize, align: usize) -> ! {
pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! {
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
extern "Rust" {
#[lang = "oom"]
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
#![cfg_attr(test, feature(test))]
#![feature(unboxed_closures)]
#![feature(unsized_fn_params)]
#![feature(c_unwind)]
//
// Rustdoc features:
#![feature(doc_cfg)]
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,10 @@ pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
/// return value is unspecified. Equally, if `T` is an enum with more variants than `usize::MAX`
/// the return value is unspecified. Uninhabited variants will be counted.
///
/// Note that an enum may be expanded with additional variants in the future
/// as a non-breaking change, for example if it is marked `#[non_exhaustive]`,
/// which will change the result of this function.
///
/// # Examples
///
/// ```
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import tarfile
import tempfile

from time import time
from time import time, sleep

# Acquire a lock on the build directory to make sure that
# we don't cause a race condition while building
Expand Down Expand Up @@ -42,8 +42,10 @@ def acquire_lock(build_dir):
while True:
try:
curs.execute("BEGIN EXCLUSIVE")
break
except sqlite3.OperationalError:
pass
sleep(0.25)
return curs
except ImportError:
print("warning: sqlite3 not available in python, skipping build directory lock")
Expand Down
10 changes: 5 additions & 5 deletions src/ci/docker/host-x86_64/mingw-check/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
mingw-w64

RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
RUN curl -sL https://nodejs.org/dist/v16.9.0/node-v16.9.0-linux-x64.tar.xz | tar -xJ
ENV PATH="/node-v16.9.0-linux-x64/bin:${PATH}"
# Install es-check
# Pin its version to prevent unrelated CI failures due to future es-check versions.
RUN npm install es-check@5.2.3 -g
RUN npm install eslint@7.20.0 -g
RUN npm install es-check@6.1.1 -g
RUN npm install eslint@8.6.0 -g

COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
Expand All @@ -40,5 +40,5 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \
/scripts/validate-toolstate.sh && \
/scripts/validate-error-codes.sh && \
# Runs checks to ensure that there are no ES5 issues in our JS code.
es-check es5 ../src/librustdoc/html/static/js/*.js && \
es-check es6 ../src/librustdoc/html/static/js/*.js && \
eslint ../src/librustdoc/html/static/js/*.js
18 changes: 12 additions & 6 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -862,18 +862,24 @@ h2.small-section-header > .anchor {
display: inline-flex;
width: calc(100% - 63px);
}
.search-results-title {
display: inline;
}
#search-settings {
font-size: 1.5rem;
font-weight: 500;
margin-bottom: 20px;
}
#crate-search {
min-width: 115px;
margin-top: 5px;
padding: 6px;
padding-right: 19px;
flex: none;
margin-left: 0.2em;
padding-left: 0.3em;
padding-right: 23px;
border: 0;
border-right: 0;
border-radius: 4px 0 0 4px;
border-radius: 4px;
outline: none;
cursor: pointer;
border-right: 1px solid;
-moz-appearance: none;
-webkit-appearance: none;
/* Removes default arrow from firefox */
Expand Down
39 changes: 22 additions & 17 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) {
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>";
}

function showResults(results, go_to_first) {
function showResults(results, go_to_first, filterCrates) {
var search = searchState.outputElement();
if (go_to_first || (results.others.length === 1
&& getSettingValue("go-to-only-result") === "true"
Expand Down Expand Up @@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) {
}
}

var output = "<h1>Results for " + escape(query.query) +
let crates = `<select id="crate-search"><option value="All crates">All crates</option>`;
for (let c of window.ALL_CRATES) {
crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`;
}
crates += `</select>`;
var output = `<div id="search-settings">
<h1 class="search-results-title">Results for ${escape(query.query)} ` +
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
"<div id=\"titles\">" +
` in ${crates} ` +
`</div><div id="titles">` +
makeTabHeader(0, "In Names", ret_others[1]) +
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
makeTabHeader(2, "In Return Types", ret_returned[1]) +
Expand All @@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) {
resultsElem.appendChild(ret_returned[0]);

search.innerHTML = output;
document.getElementById("crate-search").addEventListener("input", updateCrate);
search.appendChild(resultsElem);
// Reset focused elements.
searchState.focusedByTab = [null, null, null];
Expand Down Expand Up @@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) {
}

var filterCrates = getFilterCrates();
showResults(execSearch(query, searchWords, filterCrates), params["go_to_first"]);
showResults(execSearch(query, searchWords, filterCrates),
params["go_to_first"], filterCrates);
}

function buildIndex(rawSearchIndex) {
Expand Down Expand Up @@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) {
}
});


var selectCrate = document.getElementById("crate-search");
if (selectCrate) {
selectCrate.onchange = function() {
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
// In case you "cut" the entry from the search input, then change the crate filter
// before paste back the previous search, you get the old search results without
// the filter. To prevent this, we need to remove the previous results.
currentResults = null;
search(undefined, true);
};
}

// Push and pop states are used to add search results to the browser
// history.
if (searchState.browserSupportsHistoryApi()) {
Expand Down Expand Up @@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) {
};
}

function updateCrate(ev) {
updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value);
// In case you "cut" the entry from the search input, then change the crate filter
// before paste back the previous search, you get the old search results without
// the filter. To prevent this, we need to remove the previous results.
currentResults = null;
search(undefined, true);
}

searchWords = buildIndex(rawSearchIndex);
registerSearchEvents();
// If there's a search term in the URL, execute the search now.
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@
</div> {#- -#}
<form class="search-form"> {#- -#}
<div class="search-container"> {#- -#}
<div>{%- if layout.generate_search_filter -%}
<select id="crate-search"> {#- -#}
<option value="All crates">All crates</option> {#- -#}
</select> {#- -#}
{%- endif -%}
<div>
<input {# -#}
class="search-input" {# -#}
name="search" {# -#}
Expand Down
92 changes: 71 additions & 21 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_hir::def::{
PerNS,
};
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_middle::{bug, span_bug, ty};
use rustc_resolve::ParentScope;
use rustc_session::lint::Lint;
Expand Down Expand Up @@ -618,6 +618,39 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
})
}

/// Convert a PrimitiveType to a Ty, where possible.
///
/// This is used for resolving trait impls for primitives
fn primitive_type_to_ty(&mut self, prim: PrimitiveType) -> Option<Ty<'tcx>> {
use PrimitiveType::*;
let tcx = self.cx.tcx;

// FIXME: Only simple types are supported here, see if we can support
// other types such as Tuple, Array, Slice, etc.
// See https://github.com/rust-lang/rust/issues/90703#issuecomment-1004263455
Some(tcx.mk_ty(match prim {
Bool => ty::Bool,
Str => ty::Str,
Char => ty::Char,
Never => ty::Never,
I8 => ty::Int(ty::IntTy::I8),
I16 => ty::Int(ty::IntTy::I16),
I32 => ty::Int(ty::IntTy::I32),
I64 => ty::Int(ty::IntTy::I64),
I128 => ty::Int(ty::IntTy::I128),
Isize => ty::Int(ty::IntTy::Isize),
F32 => ty::Float(ty::FloatTy::F32),
F64 => ty::Float(ty::FloatTy::F64),
U8 => ty::Uint(ty::UintTy::U8),
U16 => ty::Uint(ty::UintTy::U16),
U32 => ty::Uint(ty::UintTy::U32),
U64 => ty::Uint(ty::UintTy::U64),
U128 => ty::Uint(ty::UintTy::U128),
Usize => ty::Uint(ty::UintTy::Usize),
_ => return None,
}))
}

/// Returns:
/// - None if no associated item was found
/// - Some((_, _, Some(_))) if an item was found and should go through a side channel
Expand All @@ -632,7 +665,25 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
let tcx = self.cx.tcx;

match root_res {
Res::Primitive(prim) => self.resolve_primitive_associated_item(prim, ns, item_name),
Res::Primitive(prim) => {
self.resolve_primitive_associated_item(prim, ns, item_name).or_else(|| {
let assoc_item = self
.primitive_type_to_ty(prim)
.map(|ty| {
resolve_associated_trait_item(ty, module_id, item_name, ns, self.cx)
})
.flatten();

assoc_item.map(|item| {
let kind = item.kind;
let fragment = UrlFragment::from_assoc_item(item_name, kind, false);
// HACK(jynelson): `clean` expects the type, not the associated item
// but the disambiguator logic expects the associated item.
// Store the kind in a side channel so that only the disambiguator logic looks at it.
(root_res, fragment, Some((kind.as_def_kind(), item.def_id)))
})
})
}
Res::Def(DefKind::TyAlias, did) => {
// Resolve the link on the type the alias points to.
// FIXME: if the associated item is defined directly on the type alias,
Expand Down Expand Up @@ -666,8 +717,13 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
// To handle that properly resolve() would have to support
// something like [`ambi_fn`](<SomeStruct as SomeTrait>::ambi_fn)
.or_else(|| {
let item =
resolve_associated_trait_item(did, module_id, item_name, ns, self.cx);
let item = resolve_associated_trait_item(
tcx.type_of(did),
module_id,
item_name,
ns,
self.cx,
);
debug!("got associated item {:?}", item);
item
});
Expand Down Expand Up @@ -767,20 +823,20 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
/// Given `[std::io::Error::source]`, where `source` is unresolved, this would
/// find `std::error::Error::source` and return
/// `<io::Error as error::Error>::source`.
fn resolve_associated_trait_item(
did: DefId,
fn resolve_associated_trait_item<'a>(
ty: Ty<'a>,
module: DefId,
item_name: Symbol,
ns: Namespace,
cx: &mut DocContext<'_>,
cx: &mut DocContext<'a>,
) -> Option<ty::AssocItem> {
// FIXME: this should also consider blanket impls (`impl<T> X for T`). Unfortunately
// `get_auto_trait_and_blanket_impls` is broken because the caching behavior is wrong. In the
// meantime, just don't look for these blanket impls.

// Next consider explicit impls: `impl MyTrait for MyType`
// Give precedence to inherent impls.
let traits = traits_implemented_by(cx, did, module);
let traits = traits_implemented_by(cx, ty, module);
debug!("considering traits {:?}", traits);
let mut candidates = traits.iter().filter_map(|&trait_| {
cx.tcx.associated_items(trait_).find_by_name_and_namespace(
Expand All @@ -799,7 +855,11 @@ fn resolve_associated_trait_item(
///
/// NOTE: this cannot be a query because more traits could be available when more crates are compiled!
/// So it is not stable to serialize cross-crate.
fn traits_implemented_by(cx: &mut DocContext<'_>, type_: DefId, module: DefId) -> FxHashSet<DefId> {
fn traits_implemented_by<'a>(
cx: &mut DocContext<'a>,
ty: Ty<'a>,
module: DefId,
) -> FxHashSet<DefId> {
let mut resolver = cx.resolver.borrow_mut();
let in_scope_traits = cx.module_trait_cache.entry(module).or_insert_with(|| {
resolver.access(|resolver| {
Expand All @@ -813,7 +873,6 @@ fn traits_implemented_by(cx: &mut DocContext<'_>, type_: DefId, module: DefId) -
});

let tcx = cx.tcx;
let ty = tcx.type_of(type_);
let iter = in_scope_traits.iter().flat_map(|&trait_| {
trace!("considering explicit impl for trait {:?}", trait_);

Expand All @@ -826,19 +885,10 @@ fn traits_implemented_by(cx: &mut DocContext<'_>, type_: DefId, module: DefId) -
"comparing type {} with kind {:?} against type {:?}",
impl_type,
impl_type.kind(),
type_
ty
);
// Fast path: if this is a primitive simple `==` will work
let saw_impl = impl_type == ty
|| match impl_type.kind() {
// Check if these are the same def_id
ty::Adt(def, _) => {
debug!("adt def_id: {:?}", def.did);
def.did == type_
}
ty::Foreign(def_id) => *def_id == type_,
_ => false,
};
let saw_impl = impl_type == ty;

if saw_impl { Some(trait_) } else { None }
})
Expand Down
Loading