Skip to content

Commit 9f13083

Browse files
committed
Auto merge of rust-lang#90416 - matthiaskrgr:rollup-55lzqng, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#89876 (Make most std::ops traits const on numeric types) - rust-lang#90371 (Fix incorrect doc link) - rust-lang#90374 (Unify titles in rustdoc book doc attributes chapter) - rust-lang#90377 (Make `core::slice::from_raw_parts[_mut]` const) - rust-lang#90395 (Restrict liveness of mutable borrow of inner infcx in ConstInferUnifier::consts) - rust-lang#90396 (Prevent type flags assertions being thrown in default_anon_const_substs if errors occurred) - rust-lang#90402 (Add a few query descriptions) - rust-lang#90412 (Remove unnecessary `macro_use`s in rustdoc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2b643e9 + 19b5b0f commit 9f13083

File tree

24 files changed

+393
-146
lines changed

24 files changed

+393
-146
lines changed

compiler/rustc_infer/src/infer/combine.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
866866
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
867867
}
868868

869+
#[tracing::instrument(level = "debug", skip(self))]
869870
fn tys(&mut self, t: Ty<'tcx>, _t: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
870871
debug_assert_eq!(t, _t);
871872
debug!("ConstInferUnifier: t={:?}", t);
@@ -941,6 +942,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
941942
}
942943
}
943944

945+
#[tracing::instrument(level = "debug", skip(self))]
944946
fn consts(
945947
&mut self,
946948
c: &'tcx ty::Const<'tcx>,
@@ -951,29 +953,38 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
951953

952954
match c.val {
953955
ty::ConstKind::Infer(InferConst::Var(vid)) => {
954-
let mut inner = self.infcx.inner.borrow_mut();
955-
let variable_table = &mut inner.const_unification_table();
956-
957956
// Check if the current unification would end up
958957
// unifying `target_vid` with a const which contains
959958
// an inference variable which is unioned with `target_vid`.
960959
//
961960
// Not doing so can easily result in stack overflows.
962-
if variable_table.unioned(self.target_vid, vid) {
961+
if self
962+
.infcx
963+
.inner
964+
.borrow_mut()
965+
.const_unification_table()
966+
.unioned(self.target_vid, vid)
967+
{
963968
return Err(TypeError::CyclicConst(c));
964969
}
965970

966-
let var_value = variable_table.probe_value(vid);
971+
let var_value =
972+
self.infcx.inner.borrow_mut().const_unification_table().probe_value(vid);
967973
match var_value.val {
968974
ConstVariableValue::Known { value: u } => self.consts(u, u),
969975
ConstVariableValue::Unknown { universe } => {
970976
if self.for_universe.can_name(universe) {
971977
Ok(c)
972978
} else {
973-
let new_var_id = variable_table.new_key(ConstVarValue {
974-
origin: var_value.origin,
975-
val: ConstVariableValue::Unknown { universe: self.for_universe },
976-
});
979+
let new_var_id =
980+
self.infcx.inner.borrow_mut().const_unification_table().new_key(
981+
ConstVarValue {
982+
origin: var_value.origin,
983+
val: ConstVariableValue::Unknown {
984+
universe: self.for_universe,
985+
},
986+
},
987+
);
977988
Ok(self.tcx().mk_const_var(new_var_id, c.ty))
978989
}
979990
}

compiler/rustc_middle/src/query/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,13 @@ rustc_queries! {
687687
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
688688
}
689689

690-
/// The signature of functions.
690+
/// Computes the signature of the function.
691691
query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
692692
desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
693693
separate_provide_extern
694694
}
695695

696+
/// Performs lint checking for the module.
696697
query lint_mod(key: LocalDefId) -> () {
697698
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
698699
}
@@ -702,6 +703,7 @@ rustc_queries! {
702703
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
703704
}
704705

706+
/// Checks for uses of unstable APIs in the module.
705707
query check_mod_unstable_api_usage(key: LocalDefId) -> () {
706708
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
707709
}
@@ -928,6 +930,7 @@ rustc_queries! {
928930
desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
929931
}
930932

933+
/// Generates a MIR body for the shim.
931934
query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
932935
storage(ArenaCacheSelector<'tcx>)
933936
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
@@ -946,11 +949,13 @@ rustc_queries! {
946949
separate_provide_extern
947950
}
948951

952+
/// Gets the span for the definition.
949953
query def_span(def_id: DefId) -> Span {
950954
desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
951955
separate_provide_extern
952956
}
953957

958+
/// Gets the span for the identifier of the definition.
954959
query def_ident_span(def_id: DefId) -> Option<Span> {
955960
desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
956961
separate_provide_extern
@@ -1466,6 +1471,8 @@ rustc_queries! {
14661471
desc { "fetching what a dependency looks like" }
14671472
separate_provide_extern
14681473
}
1474+
1475+
/// Gets the name of the crate.
14691476
query crate_name(_: CrateNum) -> Symbol {
14701477
eval_always
14711478
desc { "fetching what a crate is named" }

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl CheckAttrVisitor<'tcx> {
765765
"not a `use` item",
766766
);
767767
}
768-
err.note("read https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#docno_inlinedocinline for more information")
768+
err.note("read https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#inline-and-no_inline for more information")
769769
.emit();
770770
},
771771
);

compiler/rustc_typeck/src/collect/type_of.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> Subst
292292
// Getting this wrong can lead to ICE and unsoundness, so we assert it here.
293293
for arg in substs.iter() {
294294
let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS
295-
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE;
295+
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE
296+
| ty::TypeFlags::HAS_ERROR;
296297
assert!(!arg.has_type_flags(!allowed_flags));
297298
}
298299
substs

library/core/src/internal_macros.rs

+71
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ macro_rules! forward_ref_unop {
55
forward_ref_unop!(impl $imp, $method for $t,
66
#[stable(feature = "rust1", since = "1.0.0")]);
77
};
8+
(impl const $imp:ident, $method:ident for $t:ty) => {
9+
forward_ref_unop!(impl const $imp, $method for $t,
10+
#[stable(feature = "rust1", since = "1.0.0")]);
11+
};
12+
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
13+
(impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
14+
#[$attr]
15+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
16+
impl const $imp for &$t {
17+
type Output = <$t as $imp>::Output;
18+
19+
#[inline]
20+
fn $method(self) -> <$t as $imp>::Output {
21+
$imp::$method(*self)
22+
}
23+
}
24+
};
825
(impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
926
#[$attr]
1027
impl $imp for &$t {
@@ -25,6 +42,45 @@ macro_rules! forward_ref_binop {
2542
forward_ref_binop!(impl $imp, $method for $t, $u,
2643
#[stable(feature = "rust1", since = "1.0.0")]);
2744
};
45+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
46+
forward_ref_binop!(impl const $imp, $method for $t, $u,
47+
#[stable(feature = "rust1", since = "1.0.0")]);
48+
};
49+
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
50+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
51+
#[$attr]
52+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
53+
impl<'a> const $imp<$u> for &'a $t {
54+
type Output = <$t as $imp<$u>>::Output;
55+
56+
#[inline]
57+
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
58+
$imp::$method(*self, other)
59+
}
60+
}
61+
62+
#[$attr]
63+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
64+
impl const $imp<&$u> for $t {
65+
type Output = <$t as $imp<$u>>::Output;
66+
67+
#[inline]
68+
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
69+
$imp::$method(self, *other)
70+
}
71+
}
72+
73+
#[$attr]
74+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
75+
impl const $imp<&$u> for &$t {
76+
type Output = <$t as $imp<$u>>::Output;
77+
78+
#[inline]
79+
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
80+
$imp::$method(*self, *other)
81+
}
82+
}
83+
};
2884
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
2985
#[$attr]
3086
impl<'a> $imp<$u> for &'a $t {
@@ -65,6 +121,21 @@ macro_rules! forward_ref_op_assign {
65121
forward_ref_op_assign!(impl $imp, $method for $t, $u,
66122
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
67123
};
124+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
125+
forward_ref_op_assign!(impl const $imp, $method for $t, $u,
126+
#[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
127+
};
128+
// Equivalent to the non-const version, with the addition of `rustc_const_unstable`
129+
(impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
130+
#[$attr]
131+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
132+
impl const $imp<&$u> for $t {
133+
#[inline]
134+
fn $method(&mut self, other: &$u) {
135+
$imp::$method(self, *other);
136+
}
137+
}
138+
};
68139
(impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
69140
#[$attr]
70141
impl $imp<&$u> for $t {

library/core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#![feature(const_caller_location)]
106106
#![feature(const_cell_into_inner)]
107107
#![feature(const_discriminant)]
108+
#![cfg_attr(not(bootstrap), feature(const_eval_select))]
108109
#![feature(const_float_bits_conv)]
109110
#![feature(const_float_classify)]
110111
#![feature(const_fmt_arguments_new)]
@@ -117,6 +118,7 @@
117118
#![feature(const_maybe_uninit_as_ptr)]
118119
#![feature(const_maybe_uninit_assume_init)]
119120
#![feature(const_num_from_num)]
121+
#![feature(const_ops)]
120122
#![feature(const_option)]
121123
#![feature(const_pin)]
122124
#![feature(const_replace)]

library/core/src/num/nonzero.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ macro_rules! nonzero_integers {
9292
}
9393

9494
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
95-
impl BitOr for $Ty {
95+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
96+
impl const BitOr for $Ty {
9697
type Output = Self;
9798
#[inline]
9899
fn bitor(self, rhs: Self) -> Self::Output {
@@ -103,7 +104,8 @@ macro_rules! nonzero_integers {
103104
}
104105

105106
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
106-
impl BitOr<$Int> for $Ty {
107+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
108+
impl const BitOr<$Int> for $Ty {
107109
type Output = Self;
108110
#[inline]
109111
fn bitor(self, rhs: $Int) -> Self::Output {
@@ -115,7 +117,8 @@ macro_rules! nonzero_integers {
115117
}
116118

117119
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
118-
impl BitOr<$Ty> for $Int {
120+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
121+
impl const BitOr<$Ty> for $Int {
119122
type Output = $Ty;
120123
#[inline]
121124
fn bitor(self, rhs: $Ty) -> Self::Output {
@@ -127,15 +130,17 @@ macro_rules! nonzero_integers {
127130
}
128131

129132
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
130-
impl BitOrAssign for $Ty {
133+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
134+
impl const BitOrAssign for $Ty {
131135
#[inline]
132136
fn bitor_assign(&mut self, rhs: Self) {
133137
*self = *self | rhs;
134138
}
135139
}
136140

137141
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
138-
impl BitOrAssign<$Int> for $Ty {
142+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
143+
impl const BitOrAssign<$Int> for $Ty {
139144
#[inline]
140145
fn bitor_assign(&mut self, rhs: $Int) {
141146
*self = *self | rhs;
@@ -257,7 +262,8 @@ macro_rules! nonzero_integers_div {
257262
( $( $Ty: ident($Int: ty); )+ ) => {
258263
$(
259264
#[stable(feature = "nonzero_div", since = "1.51.0")]
260-
impl Div<$Ty> for $Int {
265+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
266+
impl const Div<$Ty> for $Int {
261267
type Output = $Int;
262268
/// This operation rounds towards zero,
263269
/// truncating any fractional part of the exact result, and cannot panic.
@@ -270,7 +276,8 @@ macro_rules! nonzero_integers_div {
270276
}
271277

272278
#[stable(feature = "nonzero_div", since = "1.51.0")]
273-
impl Rem<$Ty> for $Int {
279+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
280+
impl const Rem<$Ty> for $Int {
274281
type Output = $Int;
275282
/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
276283
#[inline]

0 commit comments

Comments
 (0)