Skip to content

Rollup of 10 pull requests #102150

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

Merged
merged 22 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0f4d7b6
OpTy: fix a method taking self rather than &self
RalfJung Sep 21, 2022
7a718f3
rustdoc: use block flex for line-number CSS
notriddle Sep 21, 2022
f66769f
rustdoc: dynamically show-hide line numbers on code examples
notriddle Sep 21, 2022
8b4c0d9
rustdoc: adjust test to cope with slightly different scrolling behaviour
notriddle Sep 21, 2022
51c752a
Add note to clippy::non_expressive_names doc
schteve Sep 21, 2022
876c707
rustdoc: remove no-op CSS `.content .item-info { position: relative }`
notriddle Sep 22, 2022
2d7f987
use appropriate variable names
TaKO8Ki Sep 22, 2022
13438ee
Const unification is already infallible, remove the error handling logic
oli-obk Sep 22, 2022
d3f97a3
Improve some AllTypes fields name
GuillaumeGomez Sep 22, 2022
e859425
use valtrees for comparison
b-naber Sep 22, 2022
5a5138d
Constify {FormResidual, Try} for ControlFlow
onestacked Sep 22, 2022
8abf487
rustdoc: remove no-op CSS `.location:empty { border: none }`
notriddle Sep 22, 2022
41ad726
Rollup merge of #102113 - RalfJung:opty-assert-mem, r=oli-obk
matthiaskrgr Sep 22, 2022
ecbc00f
Rollup merge of #102118 - notriddle:notriddle/line-numbers, r=Guillau…
matthiaskrgr Sep 22, 2022
86acea4
Rollup merge of #102123 - schteve:clippy-note, r=Manishearth
matthiaskrgr Sep 22, 2022
dee0c42
Rollup merge of #102125 - notriddle:notriddle/content-item-info, r=Gu…
matthiaskrgr Sep 22, 2022
c5d2230
Rollup merge of #102127 - TaKO8Ki:use-appropriate-variable-names, r=lcnr
matthiaskrgr Sep 22, 2022
b93c9a7
Rollup merge of #102128 - oli-obk:const_unification, r=lcnr
matthiaskrgr Sep 22, 2022
aa38483
Rollup merge of #102133 - b-naber:use-valtrees-in-fast-reject, r=lcnr
matthiaskrgr Sep 22, 2022
a99e675
Rollup merge of #102135 - GuillaumeGomez:rename-alltypes-fields, r=no…
matthiaskrgr Sep 22, 2022
2337063
Rollup merge of #102144 - chriss0612:const_convert_control_flow, r=sc…
matthiaskrgr Sep 22, 2022
dfeff64
Rollup merge of #102147 - notriddle:notriddle/location-border-none, r…
matthiaskrgr Sep 22, 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
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'tcx, Prov: Provenance> PlaceTy<'tcx, Prov> {

#[inline(always)]
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
pub fn assert_mem_place(self) -> MPlaceTy<'tcx, Prov> {
pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Prov> {
self.try_as_mplace().unwrap()
}
}
Expand Down
37 changes: 11 additions & 26 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
ty::ConstKind::Infer(InferConst::Var(a_vid)),
ty::ConstKind::Infer(InferConst::Var(b_vid)),
) => {
self.inner
.borrow_mut()
.const_unification_table()
.unify_var_var(a_vid, b_vid)
.map_err(|e| const_unification_error(a_is_expected, e))?;
self.inner.borrow_mut().const_unification_table().union(a_vid, b_vid);
return Ok(a);
}

Expand Down Expand Up @@ -246,21 +242,17 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
let value = ConstInferUnifier { infcx: self, span, param_env, for_universe, target_vid }
.relate(ct, ct)?;

self.inner
.borrow_mut()
.const_unification_table()
.unify_var_value(
target_vid,
ConstVarValue {
origin: ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstInference,
span: DUMMY_SP,
},
val: ConstVariableValue::Known { value },
self.inner.borrow_mut().const_unification_table().union_value(
target_vid,
ConstVarValue {
origin: ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstInference,
span: DUMMY_SP,
},
)
.map(|()| value)
.map_err(|e| const_unification_error(vid_is_expected, e))
val: ConstVariableValue::Known { value },
},
);
Ok(value)
}

fn unify_integral_variable(
Expand Down Expand Up @@ -768,13 +760,6 @@ pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
fn const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>);
}

pub fn const_unification_error<'tcx>(
a_is_expected: bool,
(a, b): (ty::Const<'tcx>, ty::Const<'tcx>),
) -> TypeError<'tcx> {
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b))
}

fn int_unification_error<'tcx>(
a_is_expected: bool,
v: (ty::IntVarValue, ty::IntVarValue),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
}

impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
type Error = (ty::Const<'tcx>, ty::Const<'tcx>);
type Error = NoError;

fn unify_values(&value1: &Self, &value2: &Self) -> Result<Self, Self::Error> {
Ok(match (value1.val, value2.val) {
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_middle/src/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,7 @@ impl DeepRejectCtxt {
// they might unify with any value.
ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => true,
ty::ConstKind::Value(obl) => match k {
ty::ConstKind::Value(imp) => {
// FIXME(valtrees): Once we have valtrees, we can just
// compare them directly here.
match (obl.try_to_scalar_int(), imp.try_to_scalar_int()) {
(Some(obl), Some(imp)) => obl == imp,
_ => true,
}
}
ty::ConstKind::Value(imp) => obl == imp,
_ => true,
},

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub(crate) fn target_from_impl_item<'tcx>(
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Fn(..) => {
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
let containing_item = tcx.hir().expect_item(parent_hir_id);
let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id());
let containing_item = tcx.hir().expect_item(parent_def_id);
let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
_ => bug!("parent of an ImplItem must be an Impl"),
Expand Down Expand Up @@ -640,17 +640,17 @@ impl CheckAttrVisitor<'_> {
let span = meta.span();
if let Some(location) = match target {
Target::AssocTy => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_def_id);
if Target::from_item(containing_item) == Target::Impl {
Some("type alias in implementation block")
} else {
None
}
}
Target::AssocConst => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_def_id);
// We can't link to trait impl's consts.
let err = "associated constant in trait implementation block";
match containing_item.kind {
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub enum ControlFlow<B, C = ()> {
}

#[unstable(feature = "try_trait_v2", issue = "84277")]
impl<B, C> ops::Try for ControlFlow<B, C> {
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
impl<B, C> const ops::Try for ControlFlow<B, C> {
type Output = C;
type Residual = ControlFlow<B, convert::Infallible>;

Expand All @@ -114,7 +115,8 @@ impl<B, C> ops::Try for ControlFlow<B, C> {
}

#[unstable(feature = "try_trait_v2", issue = "84277")]
impl<B, C> ops::FromResidual for ControlFlow<B, C> {
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
impl<B, C> const ops::FromResidual for ControlFlow<B, C> {
#[inline]
fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
match residual {
Expand Down
22 changes: 12 additions & 10 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ struct AllTypes {
opaque_tys: FxHashSet<ItemEntry>,
statics: FxHashSet<ItemEntry>,
constants: FxHashSet<ItemEntry>,
attributes: FxHashSet<ItemEntry>,
derives: FxHashSet<ItemEntry>,
attribute_macros: FxHashSet<ItemEntry>,
derive_macros: FxHashSet<ItemEntry>,
trait_aliases: FxHashSet<ItemEntry>,
}

Expand All @@ -259,8 +259,8 @@ impl AllTypes {
opaque_tys: new_set(100),
statics: new_set(100),
constants: new_set(100),
attributes: new_set(100),
derives: new_set(100),
attribute_macros: new_set(100),
derive_macros: new_set(100),
trait_aliases: new_set(100),
}
}
Expand All @@ -283,8 +283,10 @@ impl AllTypes {
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)),
ItemType::ProcDerive => self.derives.insert(ItemEntry::new(new_url, name)),
ItemType::ProcAttribute => {
self.attribute_macros.insert(ItemEntry::new(new_url, name))
}
ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)),
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
_ => true,
};
Expand Down Expand Up @@ -327,10 +329,10 @@ impl AllTypes {
if !self.constants.is_empty() {
sections.insert(ItemSection::Constants);
}
if !self.attributes.is_empty() {
if !self.attribute_macros.is_empty() {
sections.insert(ItemSection::AttributeMacros);
}
if !self.derives.is_empty() {
if !self.derive_macros.is_empty() {
sections.insert(ItemSection::DeriveMacros);
}
if !self.trait_aliases.is_empty() {
Expand Down Expand Up @@ -373,8 +375,8 @@ impl AllTypes {
print_entries(f, &self.primitives, ItemSection::PrimitiveTypes);
print_entries(f, &self.traits, ItemSection::Traits);
print_entries(f, &self.macros, ItemSection::Macros);
print_entries(f, &self.attributes, ItemSection::AttributeMacros);
print_entries(f, &self.derives, ItemSection::DeriveMacros);
print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros);
print_entries(f, &self.derive_macros, ItemSection::DeriveMacros);
print_entries(f, &self.functions, ItemSection::Functions);
print_entries(f, &self.typedefs, ItemSection::TypeDefinitions);
print_entries(f, &self.trait_aliases, ItemSection::TraitAliases);
Expand Down
11 changes: 1 addition & 10 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,6 @@ img {
width: 100px;
}

.location:empty {
border: none;
}

.block ul, .block li {
padding: 0;
margin: 0;
Expand Down Expand Up @@ -577,13 +573,9 @@ h2.location a {
}

.rustdoc .example-wrap {
display: inline-flex;
display: flex;
margin-bottom: 10px;
}

.example-wrap {
position: relative;
width: 100%;
}

.example-wrap > pre.line-number {
Expand Down Expand Up @@ -745,7 +737,6 @@ pre, .rustdoc.source .example-wrap {
}

.content .item-info {
position: relative;
margin-left: 24px;
}

Expand Down
41 changes: 30 additions & 11 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,20 +697,39 @@ function loadCss(cssFileName) {
}
}());

window.rustdoc_add_line_numbers_to_examples = () => {
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
const parent = x.parentNode;
const line_numbers = parent.querySelectorAll(".line-number");
if (line_numbers.length > 0) {
return;
}
const count = x.textContent.split("\n").length;
const elems = [];
for (let i = 0; i < count; ++i) {
elems.push(i + 1);
}
const node = document.createElement("pre");
addClass(node, "line-number");
node.innerHTML = elems.join("\n");
parent.insertBefore(node, x);
});
};

window.rustdoc_remove_line_numbers_from_examples = () => {
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
const parent = x.parentNode;
const line_numbers = parent.querySelectorAll(".line-number");
for (const node of line_numbers) {
parent.removeChild(node);
}
});
};

(function() {
// To avoid checking on "rustdoc-line-numbers" value on every loop...
if (getSettingValue("line-numbers") === "true") {
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
const count = x.textContent.split("\n").length;
const elems = [];
for (let i = 0; i < count; ++i) {
elems.push(i + 1);
}
const node = document.createElement("pre");
addClass(node, "line-number");
node.innerHTML = elems.join("\n");
x.parentNode.insertBefore(node, x);
});
window.rustdoc_add_line_numbers_to_examples();
}
}());

Expand Down
7 changes: 7 additions & 0 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
updateSystemTheme();
updateLightAndDark();
break;
case "line-numbers":
if (value === true) {
window.rustdoc_add_line_numbers_to_examples();
} else {
window.rustdoc_remove_line_numbers_from_examples();
}
break;
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc-gui/docblock-code-block-line-number.goml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ assert-css: ("pre.line-number", {
})
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
assert-text: ("pre.line-number", "1\n2")

// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
// and make sure it goes away.

// First, open the settings menu.
click: "#settings-menu"
wait-for: "#settings"
assert-css: ("#settings", {"display": "block"})

// Then, click the toggle button.
click: "input#line-numbers + .slider"
wait-for: 100 // wait-for-false does not exist
assert-false: "pre.line-number"

// Finally, turn it on again.
click: "input#line-numbers + .slider"
wait-for: "pre.line-number"
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/source-anchor-scroll.goml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assert-property: ("html", {"scrollTop": "0"})
click: '//a[text() = "barbar"]'
assert-property: ("html", {"scrollTop": "125"})
click: '//a[text() = "bar"]'
assert-property: ("html", {"scrollTop": "166"})
assert-property: ("html", {"scrollTop": "156"})
click: '//a[text() = "sub_fn"]'
assert-property: ("html", {"scrollTop": "53"})

Expand Down
4 changes: 4 additions & 0 deletions src/tools/clippy/clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ declare_clippy_lint! {
/// ### What it does
/// Checks for names that are very similar and thus confusing.
///
/// Note: this lint looks for similar names throughout each
/// scope. To allow it, you need to allow it on the scope
/// level, not on the name that is reported.
///
/// ### Why is this bad?
/// It's hard to distinguish between names that differ only
/// by a single character.
Expand Down