Skip to content

Commit

Permalink
Auto merge of rust-lang#112609 - matthiaskrgr:rollup-er6weld, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#112197 (Erase regions even if normalization fails in writeback (in new solver))
 - rust-lang#112495 (fix(resolve): update shadowed_glob more precision)
 - rust-lang#112520 (Fix the overflow issue for transmute_generic_consts)
 - rust-lang#112571 (rustdoc-search: search never type with `!`)
 - rust-lang#112581 ([rustdoc] Fix URL encoding of % sign)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 14, 2023
2 parents fa8762b + 623b1d4 commit 57c215b
Show file tree
Hide file tree
Showing 21 changed files with 331 additions and 39 deletions.
11 changes: 10 additions & 1 deletion compiler/rustc_hir_typeck/src/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Try to display a sensible error with as much information as possible.
let skeleton_string = |ty: Ty<'tcx>, sk| match sk {
Ok(SizeSkeleton::Known(size)) => format!("{} bits", size.bits()),
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"),
Ok(SizeSkeleton::Known(size)) => {
if let Some(v) = u128::from(size.bytes()).checked_mul(8) {
format!("{} bits", v)
} else {
// `u128` should definitely be able to hold the size of different architectures
// larger sizes should be reported as error `are too big for the current architecture`
// otherwise we have a bug somewhere
bug!("{:?} overflow for u128", size)
}
}
Ok(SizeSkeleton::Generic(size)) => {
if let Some(size) = size.try_eval_target_usize(tcx, self.param_env) {
format!("{size} bytes")
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) {
debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
assert!(!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions());
assert!(
!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
"{ty} can't be put into typeck results"
);
self.typeck_results.node_types_mut().insert(hir_id, ty);
}

Expand Down Expand Up @@ -803,7 +806,11 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
// We must normalize erasing regions here, since later lints
// expect that types that show up in the typeck are fully
// normalized.
self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t).unwrap_or(t)
if let Ok(t) = self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t) {
t
} else {
EraseEarlyRegions { tcx: self.fcx.tcx }.fold_ty(t)
}
}
Ok(t) => {
// Do not anonymize late-bound regions
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} else {
resolution.binding = Some(nonglob_binding);
}
resolution.shadowed_glob = Some(glob_binding);

if let Some(old_binding) = resolution.shadowed_glob {
assert!(old_binding.is_glob_import());
if glob_binding.res() != old_binding.res() {
resolution.shadowed_glob = Some(this.ambiguity(
AmbiguityKind::GlobVsGlob,
old_binding,
glob_binding,
));
} else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
resolution.shadowed_glob = Some(glob_binding);
}
} else {
resolution.shadowed_glob = Some(glob_binding);
}
}
(false, false) => {
return Err(old_binding);
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,6 @@ pub(crate) fn small_url_encode(s: String) -> String {
// While the same is not true for hashes, rustdoc only needs to be
// consistent with itself when encoding them.
st += "+";
} else if b == b'%' {
st += "%%";
} else {
write!(st, "%{:02X}", b).unwrap();
}
Expand Down
48 changes: 43 additions & 5 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,35 @@ function initSearch(rawSearchIndex) {
if (query.literalSearch && parserState.totalElems - parserState.genericsElems > 0) {
throw ["You cannot have more than one element if you use quotes"];
}
const typeFilter = parserState.typeFilter;
parserState.typeFilter = null;
if (name === "!") {
if (typeFilter !== null && typeFilter !== "primitive") {
throw [
"Invalid search type: primitive never type ",
"!",
" and ",
typeFilter,
" both specified",
];
}
if (generics.length !== 0) {
throw [
"Never type ",
"!",
" does not accept generic parameters",
];
}
return {
name: "never",
id: -1,
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
generics: [],
typeFilter: "primitive",
};
}
const pathSegments = name.split("::");
if (pathSegments.length > 1) {
for (let i = 0, len = pathSegments.length; i < len; ++i) {
Expand All @@ -399,6 +428,13 @@ function initSearch(rawSearchIndex) {
}
throw ["Unexpected ", "::::"];
}

if (pathSegment === "!") {
pathSegments[i] = "never";
if (i !== 0) {
throw ["Never type ", "!", " is not associated item"];
}
}
}
}
// In case we only have something like `<p>`, there is no name.
Expand All @@ -409,8 +445,6 @@ function initSearch(rawSearchIndex) {
if (isInGenerics) {
parserState.genericsElems += 1;
}
const typeFilter = parserState.typeFilter;
parserState.typeFilter = null;
return {
name: name,
id: -1,
Expand Down Expand Up @@ -459,10 +493,11 @@ function initSearch(rawSearchIndex) {
break;
}
if (foundExclamation !== -1) {
if (start <= (end - 2)) {
if (foundExclamation !== start &&
isIdentCharacter(parserState.userQuery[foundExclamation - 1])
) {
throw ["Cannot have associated items in macros"];
} else {
// if start == end - 1, we got the never type
// while the never type has no associated macros, we still
// can parse a path like that
foundExclamation = -1;
Expand All @@ -478,7 +513,10 @@ function initSearch(rawSearchIndex) {
end = parserState.pos;
}
// if start == end - 1, we got the never type
if (foundExclamation !== -1 && start <= (end - 2)) {
if (foundExclamation !== -1 &&
foundExclamation !== start &&
isIdentCharacter(parserState.userQuery[foundExclamation - 1])
) {
if (parserState.typeFilter === null) {
parserState.typeFilter = "macro";
} else if (parserState.typeFilter !== "macro") {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};

const ENTRY_LIMIT: usize = 900;
// FIXME: The following limits should be reduced eventually.
const ISSUES_ENTRY_LIMIT: usize = 1898;
const ISSUES_ENTRY_LIMIT: usize = 1896;
const ROOT_ENTRY_LIMIT: usize = 870;

const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
Expand Down
20 changes: 14 additions & 6 deletions tests/rustdoc-js-std/never.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const EXPECTED = {
'query': '!',
'others': [
{ 'path': 'std', 'name': 'never' },
],
};
const EXPECTED = [
{
'query': '!',
'others': [
{ 'path': 'std', 'name': 'never' },
],
},
{
'query': '!::clone',
'others': [
{ 'path': 'std::never', 'name': 'clone' },
],
},
];
9 changes: 9 additions & 0 deletions tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ const PARSED = [
userQuery: "mod:a!",
error: 'Invalid search type: macro `!` and `mod` both specified',
},
{
query: "mod:!",
elems: [],
foundElems: 0,
original: "mod:!",
returned: [],
userQuery: "mod:!",
error: 'Invalid search type: primitive never type `!` and `mod` both specified',
},
{
query: "a!::a",
elems: [],
Expand Down
80 changes: 71 additions & 9 deletions tests/rustdoc-js-std/parser-ident.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const PARSED = [
pathLast: "r",
generics: [
{
name: "!",
fullPath: ["!"],
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "!",
pathLast: "never",
generics: [],
typeFilter: 15,
},
],
typeFilter: -1,
Expand All @@ -26,12 +27,12 @@ const PARSED = [
{
query: "!",
elems: [{
name: "!",
fullPath: ["!"],
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "!",
pathLast: "never",
generics: [],
typeFilter: -1,
typeFilter: 15,
}],
foundElems: 1,
original: "!",
Expand Down Expand Up @@ -64,12 +65,21 @@ const PARSED = [
userQuery: "a!::b",
error: "Cannot have associated items in macros",
},
{
query: "!<T>",
elems: [],
foundElems: 0,
original: "!<T>",
returned: [],
userQuery: "!<t>",
error: "Never type `!` does not accept generic parameters",
},
{
query: "!::b",
elems: [{
name: "!::b",
fullPath: ["!", "b"],
pathWithoutLast: ["!"],
fullPath: ["never", "b"],
pathWithoutLast: ["never"],
pathLast: "b",
generics: [],
typeFilter: -1,
Expand All @@ -80,6 +90,58 @@ const PARSED = [
userQuery: "!::b",
error: null,
},
{
query: "b::!",
elems: [],
foundElems: 0,
original: "b::!",
returned: [],
userQuery: "b::!",
error: "Never type `!` is not associated item",
},
{
query: "!::!",
elems: [],
foundElems: 0,
original: "!::!",
returned: [],
userQuery: "!::!",
error: "Never type `!` is not associated item",
},
{
query: "b::!::c",
elems: [],
foundElems: 0,
original: "b::!::c",
returned: [],
userQuery: "b::!::c",
error: "Never type `!` is not associated item",
},
{
query: "!::b<T>",
elems: [{
name: "!::b",
fullPath: ["never", "b"],
pathWithoutLast: ["never"],
pathLast: "b",
generics: [
{
name: "t",
fullPath: ["t"],
pathWithoutLast: [],
pathLast: "t",
generics: [],
typeFilter: -1,
}
],
typeFilter: -1,
}],
foundElems: 1,
original: "!::b<T>",
returned: [],
userQuery: "!::b<t>",
error: null,
},
{
query: "a!::b!",
elems: [],
Expand Down
8 changes: 4 additions & 4 deletions tests/rustdoc-js-std/parser-returned.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ const PARSED = [
foundElems: 1,
original: "-> !",
returned: [{
name: "!",
fullPath: ["!"],
name: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "!",
pathLast: "never",
generics: [],
typeFilter: -1,
typeFilter: 15,
}],
userQuery: "-> !",
error: null,
Expand Down
46 changes: 46 additions & 0 deletions tests/rustdoc-js/never-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// exact-check

const EXPECTED = [
{
'query': '-> !',
'others': [
{ 'path': 'never_search', 'name': 'loops' },
],
},
{
'query': '-> never',
'others': [
{ 'path': 'never_search', 'name': 'loops' },
{ 'path': 'never_search', 'name': 'returns' },
],
},
{
'query': '!',
'in_args': [
{ 'path': 'never_search', 'name': 'impossible' },
{ 'path': 'never_search', 'name': 'box_impossible' },
],
},
{
'query': 'never',
'in_args': [
{ 'path': 'never_search', 'name': 'impossible' },
{ 'path': 'never_search', 'name': 'uninteresting' },
{ 'path': 'never_search', 'name': 'box_impossible' },
{ 'path': 'never_search', 'name': 'box_uninteresting' },
],
},
{
'query': 'box<!>',
'in_args': [
{ 'path': 'never_search', 'name': 'box_impossible' },
],
},
{
'query': 'box<never>',
'in_args': [
{ 'path': 'never_search', 'name': 'box_impossible' },
{ 'path': 'never_search', 'name': 'box_uninteresting' },
],
},
];
Loading

0 comments on commit 57c215b

Please sign in to comment.