Skip to content

Commit bc4d574

Browse files
committed
Auto merge of #102150 - matthiaskrgr:rollup-6xmd8f3, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #102113 (OpTy: fix a method taking self rather than &self) - #102118 (rustdoc: clean up line numbers on code examples) - #102123 (Add note to clippy::non_expressive_names doc) - #102125 (rustdoc: remove no-op CSS `.content .item-info { position: relative }`) - #102127 (Use appropriate variable names) - #102128 (Const unification is already infallible, remove the error handling logic) - #102133 (Use valtrees for comparison) - #102135 (Improve some AllTypes fields name) - #102144 (Extend const_convert with const {FormResidual, Try} for ControlFlow.) - #102147 (rustdoc: remove no-op CSS `.location:empty { border: none }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 77e7e88 + dfeff64 commit bc4d574

File tree

13 files changed

+96
-76
lines changed

13 files changed

+96
-76
lines changed

compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'tcx, Prov: Provenance> PlaceTy<'tcx, Prov> {
280280

281281
#[inline(always)]
282282
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
283-
pub fn assert_mem_place(self) -> MPlaceTy<'tcx, Prov> {
283+
pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Prov> {
284284
self.try_as_mplace().unwrap()
285285
}
286286
}

compiler/rustc_infer/src/infer/combine.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
147147
ty::ConstKind::Infer(InferConst::Var(a_vid)),
148148
ty::ConstKind::Infer(InferConst::Var(b_vid)),
149149
) => {
150-
self.inner
151-
.borrow_mut()
152-
.const_unification_table()
153-
.unify_var_var(a_vid, b_vid)
154-
.map_err(|e| const_unification_error(a_is_expected, e))?;
150+
self.inner.borrow_mut().const_unification_table().union(a_vid, b_vid);
155151
return Ok(a);
156152
}
157153

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

249-
self.inner
250-
.borrow_mut()
251-
.const_unification_table()
252-
.unify_var_value(
253-
target_vid,
254-
ConstVarValue {
255-
origin: ConstVariableOrigin {
256-
kind: ConstVariableOriginKind::ConstInference,
257-
span: DUMMY_SP,
258-
},
259-
val: ConstVariableValue::Known { value },
245+
self.inner.borrow_mut().const_unification_table().union_value(
246+
target_vid,
247+
ConstVarValue {
248+
origin: ConstVariableOrigin {
249+
kind: ConstVariableOriginKind::ConstInference,
250+
span: DUMMY_SP,
260251
},
261-
)
262-
.map(|()| value)
263-
.map_err(|e| const_unification_error(vid_is_expected, e))
252+
val: ConstVariableValue::Known { value },
253+
},
254+
);
255+
Ok(value)
264256
}
265257

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

771-
pub fn const_unification_error<'tcx>(
772-
a_is_expected: bool,
773-
(a, b): (ty::Const<'tcx>, ty::Const<'tcx>),
774-
) -> TypeError<'tcx> {
775-
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a, b))
776-
}
777-
778763
fn int_unification_error<'tcx>(
779764
a_is_expected: bool,
780765
v: (ty::IntVarValue, ty::IntVarValue),

compiler/rustc_middle/src/infer/unify_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
129129
}
130130

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

134134
fn unify_values(&value1: &Self, &value2: &Self) -> Result<Self, Self::Error> {
135135
Ok(match (value1.val, value2.val) {

compiler/rustc_middle/src/ty/fast_reject.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,7 @@ impl DeepRejectCtxt {
384384
// they might unify with any value.
385385
ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => true,
386386
ty::ConstKind::Value(obl) => match k {
387-
ty::ConstKind::Value(imp) => {
388-
// FIXME(valtrees): Once we have valtrees, we can just
389-
// compare them directly here.
390-
match (obl.try_to_scalar_int(), imp.try_to_scalar_int()) {
391-
(Some(obl), Some(imp)) => obl == imp,
392-
_ => true,
393-
}
394-
}
387+
ty::ConstKind::Value(imp) => obl == imp,
395388
_ => true,
396389
},
397390

compiler/rustc_passes/src/check_attr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub(crate) fn target_from_impl_item<'tcx>(
3535
match impl_item.kind {
3636
hir::ImplItemKind::Const(..) => Target::AssocConst,
3737
hir::ImplItemKind::Fn(..) => {
38-
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
39-
let containing_item = tcx.hir().expect_item(parent_hir_id);
38+
let parent_def_id = tcx.hir().get_parent_item(impl_item.hir_id());
39+
let containing_item = tcx.hir().expect_item(parent_def_id);
4040
let containing_impl_is_for_trait = match &containing_item.kind {
4141
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
4242
_ => bug!("parent of an ImplItem must be an Impl"),
@@ -640,17 +640,17 @@ impl CheckAttrVisitor<'_> {
640640
let span = meta.span();
641641
if let Some(location) = match target {
642642
Target::AssocTy => {
643-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
644-
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
643+
let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
644+
let containing_item = self.tcx.hir().expect_item(parent_def_id);
645645
if Target::from_item(containing_item) == Target::Impl {
646646
Some("type alias in implementation block")
647647
} else {
648648
None
649649
}
650650
}
651651
Target::AssocConst => {
652-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
653-
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
652+
let parent_def_id = self.tcx.hir().get_parent_item(hir_id);
653+
let containing_item = self.tcx.hir().expect_item(parent_def_id);
654654
// We can't link to trait impl's consts.
655655
let err = "associated constant in trait implementation block";
656656
match containing_item.kind {

library/core/src/ops/control_flow.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ pub enum ControlFlow<B, C = ()> {
9595
}
9696

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

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

116117
#[unstable(feature = "try_trait_v2", issue = "84277")]
117-
impl<B, C> ops::FromResidual for ControlFlow<B, C> {
118+
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
119+
impl<B, C> const ops::FromResidual for ControlFlow<B, C> {
118120
#[inline]
119121
fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
120122
match residual {

src/librustdoc/html/render/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ struct AllTypes {
239239
opaque_tys: FxHashSet<ItemEntry>,
240240
statics: FxHashSet<ItemEntry>,
241241
constants: FxHashSet<ItemEntry>,
242-
attributes: FxHashSet<ItemEntry>,
243-
derives: FxHashSet<ItemEntry>,
242+
attribute_macros: FxHashSet<ItemEntry>,
243+
derive_macros: FxHashSet<ItemEntry>,
244244
trait_aliases: FxHashSet<ItemEntry>,
245245
}
246246

@@ -259,8 +259,8 @@ impl AllTypes {
259259
opaque_tys: new_set(100),
260260
statics: new_set(100),
261261
constants: new_set(100),
262-
attributes: new_set(100),
263-
derives: new_set(100),
262+
attribute_macros: new_set(100),
263+
derive_macros: new_set(100),
264264
trait_aliases: new_set(100),
265265
}
266266
}
@@ -283,8 +283,10 @@ impl AllTypes {
283283
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
284284
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
285285
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
286-
ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)),
287-
ItemType::ProcDerive => self.derives.insert(ItemEntry::new(new_url, name)),
286+
ItemType::ProcAttribute => {
287+
self.attribute_macros.insert(ItemEntry::new(new_url, name))
288+
}
289+
ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)),
288290
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
289291
_ => true,
290292
};
@@ -327,10 +329,10 @@ impl AllTypes {
327329
if !self.constants.is_empty() {
328330
sections.insert(ItemSection::Constants);
329331
}
330-
if !self.attributes.is_empty() {
332+
if !self.attribute_macros.is_empty() {
331333
sections.insert(ItemSection::AttributeMacros);
332334
}
333-
if !self.derives.is_empty() {
335+
if !self.derive_macros.is_empty() {
334336
sections.insert(ItemSection::DeriveMacros);
335337
}
336338
if !self.trait_aliases.is_empty() {
@@ -373,8 +375,8 @@ impl AllTypes {
373375
print_entries(f, &self.primitives, ItemSection::PrimitiveTypes);
374376
print_entries(f, &self.traits, ItemSection::Traits);
375377
print_entries(f, &self.macros, ItemSection::Macros);
376-
print_entries(f, &self.attributes, ItemSection::AttributeMacros);
377-
print_entries(f, &self.derives, ItemSection::DeriveMacros);
378+
print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros);
379+
print_entries(f, &self.derive_macros, ItemSection::DeriveMacros);
378380
print_entries(f, &self.functions, ItemSection::Functions);
379381
print_entries(f, &self.typedefs, ItemSection::TypeDefinitions);
380382
print_entries(f, &self.trait_aliases, ItemSection::TraitAliases);

src/librustdoc/html/static/css/rustdoc.css

+1-10
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,6 @@ img {
522522
width: 100px;
523523
}
524524

525-
.location:empty {
526-
border: none;
527-
}
528-
529525
.block ul, .block li {
530526
padding: 0;
531527
margin: 0;
@@ -577,13 +573,9 @@ h2.location a {
577573
}
578574

579575
.rustdoc .example-wrap {
580-
display: inline-flex;
576+
display: flex;
581577
margin-bottom: 10px;
582-
}
583-
584-
.example-wrap {
585578
position: relative;
586-
width: 100%;
587579
}
588580

589581
.example-wrap > pre.line-number {
@@ -745,7 +737,6 @@ pre, .rustdoc.source .example-wrap {
745737
}
746738

747739
.content .item-info {
748-
position: relative;
749740
margin-left: 24px;
750741
}
751742

src/librustdoc/html/static/js/main.js

+30-11
Original file line numberDiff line numberDiff line change
@@ -697,20 +697,39 @@ function loadCss(cssFileName) {
697697
}
698698
}());
699699

700+
window.rustdoc_add_line_numbers_to_examples = () => {
701+
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
702+
const parent = x.parentNode;
703+
const line_numbers = parent.querySelectorAll(".line-number");
704+
if (line_numbers.length > 0) {
705+
return;
706+
}
707+
const count = x.textContent.split("\n").length;
708+
const elems = [];
709+
for (let i = 0; i < count; ++i) {
710+
elems.push(i + 1);
711+
}
712+
const node = document.createElement("pre");
713+
addClass(node, "line-number");
714+
node.innerHTML = elems.join("\n");
715+
parent.insertBefore(node, x);
716+
});
717+
};
718+
719+
window.rustdoc_remove_line_numbers_from_examples = () => {
720+
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
721+
const parent = x.parentNode;
722+
const line_numbers = parent.querySelectorAll(".line-number");
723+
for (const node of line_numbers) {
724+
parent.removeChild(node);
725+
}
726+
});
727+
};
728+
700729
(function() {
701730
// To avoid checking on "rustdoc-line-numbers" value on every loop...
702731
if (getSettingValue("line-numbers") === "true") {
703-
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
704-
const count = x.textContent.split("\n").length;
705-
const elems = [];
706-
for (let i = 0; i < count; ++i) {
707-
elems.push(i + 1);
708-
}
709-
const node = document.createElement("pre");
710-
addClass(node, "line-number");
711-
node.innerHTML = elems.join("\n");
712-
x.parentNode.insertBefore(node, x);
713-
});
732+
window.rustdoc_add_line_numbers_to_examples();
714733
}
715734
}());
716735

src/librustdoc/html/static/js/settings.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
updateSystemTheme();
2020
updateLightAndDark();
2121
break;
22+
case "line-numbers":
23+
if (value === true) {
24+
window.rustdoc_add_line_numbers_to_examples();
25+
} else {
26+
window.rustdoc_remove_line_numbers_from_examples();
27+
}
28+
break;
2229
}
2330
}
2431

src/test/rustdoc-gui/docblock-code-block-line-number.goml

+17
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ assert-css: ("pre.line-number", {
2020
})
2121
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
2222
assert-text: ("pre.line-number", "1\n2")
23+
24+
// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
25+
// and make sure it goes away.
26+
27+
// First, open the settings menu.
28+
click: "#settings-menu"
29+
wait-for: "#settings"
30+
assert-css: ("#settings", {"display": "block"})
31+
32+
// Then, click the toggle button.
33+
click: "input#line-numbers + .slider"
34+
wait-for: 100 // wait-for-false does not exist
35+
assert-false: "pre.line-number"
36+
37+
// Finally, turn it on again.
38+
click: "input#line-numbers + .slider"
39+
wait-for: "pre.line-number"

src/test/rustdoc-gui/source-anchor-scroll.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ assert-property: ("html", {"scrollTop": "0"})
1010
click: '//a[text() = "barbar"]'
1111
assert-property: ("html", {"scrollTop": "125"})
1212
click: '//a[text() = "bar"]'
13-
assert-property: ("html", {"scrollTop": "166"})
13+
assert-property: ("html", {"scrollTop": "156"})
1414
click: '//a[text() = "sub_fn"]'
1515
assert-property: ("html", {"scrollTop": "53"})
1616

src/tools/clippy/clippy_lints/src/non_expressive_names.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ declare_clippy_lint! {
1515
/// ### What it does
1616
/// Checks for names that are very similar and thus confusing.
1717
///
18+
/// Note: this lint looks for similar names throughout each
19+
/// scope. To allow it, you need to allow it on the scope
20+
/// level, not on the name that is reported.
21+
///
1822
/// ### Why is this bad?
1923
/// It's hard to distinguish between names that differ only
2024
/// by a single character.

0 commit comments

Comments
 (0)