Skip to content

Commit bf242bb

Browse files
committed
Auto merge of rust-lang#93795 - JohnTitor:rollup-n0dmsoo, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#93445 (Add From<u8> for ExitCode) - rust-lang#93694 (rustdoc: tweak line spacing and paragraph spacing for accessibility) - rust-lang#93735 (Stabilize int_abs_diff in 1.60.0.) - rust-lang#93746 (Remove defaultness from ImplItem.) - rust-lang#93748 (rustc_query_impl: reduce visibility of some modules/fn's) - rust-lang#93751 (Drop tracking: track borrows of projections) - rust-lang#93781 (update `ty::TyKind` documentation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e1f586c + 7f4486b commit bf242bb

File tree

31 files changed

+246
-173
lines changed

31 files changed

+246
-173
lines changed

compiler/rustc_ast_lowering/src/item.rs

-4
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
894894
AssocItemKind::MacCall(..) => panic!("`TyMac` should have been expanded by now"),
895895
};
896896

897-
// Since `default impl` is not yet implemented, this is always true in impls.
898-
let has_value = true;
899-
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
900897
let hir_id = self.lower_node_id(i.id);
901898
self.lower_attrs(hir_id, &i.attrs);
902899
let item = hir::ImplItem {
903900
def_id: hir_id.expect_owner(),
904901
ident: self.lower_ident(i.ident),
905902
generics,
906903
vis: self.lower_visibility(&i.vis),
907-
defaultness,
908904
kind,
909905
span: self.lower_span(i.span),
910906
};

compiler/rustc_hir/src/hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,6 @@ pub struct ImplItem<'hir> {
21122112
pub ident: Ident,
21132113
pub def_id: LocalDefId,
21142114
pub vis: Visibility<'hir>,
2115-
pub defaultness: Defaultness,
21162115
pub generics: Generics<'hir>,
21172116
pub kind: ImplItemKind<'hir>,
21182117
pub span: Span,
@@ -3310,6 +3309,6 @@ mod size_asserts {
33103309

33113310
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
33123311
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
3313-
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152);
3312+
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
33143313
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
33153314
}

compiler/rustc_hir/src/intravisit.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,10 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
10201020

10211021
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
10221022
// N.B., deliberately force a compilation error if/when new fields are added.
1023-
let ImplItem { def_id: _, ident, ref vis, ref defaultness, ref generics, ref kind, span: _ } =
1024-
*impl_item;
1023+
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span: _ } = *impl_item;
10251024

10261025
visitor.visit_ident(ident);
10271026
visitor.visit_vis(vis);
1028-
visitor.visit_defaultness(defaultness);
10291027
visitor.visit_generics(generics);
10301028
match *kind {
10311029
ImplItemKind::Const(ref ty, body) => {

compiler/rustc_hir/src/stable_hash_impls.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
164164

165165
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
166166
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
167-
let ImplItem { def_id: _, ident, ref vis, defaultness, ref generics, ref kind, span } =
168-
*self;
167+
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span } = *self;
169168

170169
hcx.hash_hir_item_like(|hcx| {
171170
ident.name.hash_stable(hcx, hasher);
172171
vis.hash_stable(hcx, hasher);
173-
defaultness.hash_stable(hcx, hasher);
174172
generics.hash_stable(hcx, hasher);
175173
kind.hash_stable(hcx, hasher);
176174
span.hash_stable(hcx, hasher);

compiler/rustc_hir_pretty/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,6 @@ impl<'a> State<'a> {
923923
self.hardbreak_if_not_bol();
924924
self.maybe_print_comment(ii.span.lo());
925925
self.print_outer_attributes(self.attrs(ii.hir_id()));
926-
self.print_defaultness(ii.defaultness);
927926

928927
match ii.kind {
929928
hir::ImplItemKind::Const(ref ty, expr) => {

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ fn test_debugging_options_tracking_hash() {
730730
tracked!(debug_info_for_profiling, true);
731731
tracked!(debug_macros, true);
732732
tracked!(dep_info_omit_d_target, true);
733+
tracked!(drop_tracking, true);
733734
tracked!(dual_proc_macros, true);
734735
tracked!(fewer_names, Some(true));
735736
tracked!(force_unstable_if_unmarked, true);

compiler/rustc_middle/src/ty/sty.rs

+69-19
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ impl BoundRegionKind {
7474
}
7575
}
7676

77-
/// Defines the kinds of types.
77+
/// Defines the kinds of types used by the type system.
7878
///
79-
/// N.B., if you change this, you'll probably want to change the corresponding
80-
/// AST structure in `rustc_ast/src/ast.rs` as well.
79+
/// Types written by the user start out as [hir::TyKind](rustc_hir::TyKind) and get
80+
/// converted to this representation using `AstConv::ast_ty_to_ty`.
8181
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)]
8282
#[derive(HashStable)]
8383
#[rustc_diagnostic_item = "TyKind"]
@@ -100,10 +100,11 @@ pub enum TyKind<'tcx> {
100100

101101
/// Algebraic data types (ADT). For example: structures, enumerations and unions.
102102
///
103-
/// InternalSubsts here, possibly against intuition, *may* contain `Param`s.
104-
/// That is, even after substitution it is possible that there are type
105-
/// variables. This happens when the `Adt` corresponds to an ADT
106-
/// definition and not a concrete use of it.
103+
/// For example, the type `List<i32>` would be represented using the `AdtDef`
104+
/// for `struct List<T>` and the substs `[i32]`.
105+
///
106+
/// Note that generic parameters in fields only get lazily substituted
107+
/// by using something like `adt_def.all_fields().map(|field| field.ty(tcx, substs))`.
107108
Adt(&'tcx AdtDef, SubstsRef<'tcx>),
108109

109110
/// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
@@ -112,7 +113,7 @@ pub enum TyKind<'tcx> {
112113
/// The pointee of a string slice. Written as `str`.
113114
Str,
114115

115-
/// An array with the given length. Written as `[T; n]`.
116+
/// An array with the given length. Written as `[T; N]`.
116117
Array(Ty<'tcx>, &'tcx ty::Const<'tcx>),
117118

118119
/// The pointee of an array slice. Written as `[T]`.
@@ -126,11 +127,12 @@ pub enum TyKind<'tcx> {
126127
Ref(Region<'tcx>, Ty<'tcx>, hir::Mutability),
127128

128129
/// The anonymous type of a function declaration/definition. Each
129-
/// function has a unique type, which is output (for a function
130-
/// named `foo` returning an `i32`) as `fn() -> i32 {foo}`.
130+
/// function has a unique type.
131131
///
132-
/// For example the type of `bar` here:
132+
/// For the function `fn foo() -> i32 { 3 }` this type would be
133+
/// shown to the user as `fn() -> i32 {foo}`.
133134
///
135+
/// For example the type of `bar` here:
134136
/// ```rust
135137
/// fn foo() -> i32 { 1 }
136138
/// let bar = foo; // bar: fn() -> i32 {foo}
@@ -139,6 +141,9 @@ pub enum TyKind<'tcx> {
139141

140142
/// A pointer to a function. Written as `fn() -> i32`.
141143
///
144+
/// Note that both functions and closures start out as either
145+
/// [FnDef] or [Closure] which can be then be coerced to this variant.
146+
///
142147
/// For example the type of `bar` here:
143148
///
144149
/// ```rust
@@ -150,17 +155,41 @@ pub enum TyKind<'tcx> {
150155
/// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
151156
Dynamic(&'tcx List<Binder<'tcx, ExistentialPredicate<'tcx>>>, ty::Region<'tcx>),
152157

153-
/// The anonymous type of a closure. Used to represent the type of
154-
/// `|a| a`.
155-
/// For the order of the substs see the `ClosureSubsts` type's documentation.
158+
/// The anonymous type of a closure. Used to represent the type of `|a| a`.
159+
///
160+
/// Closure substs contain both the - potentially substituted - generic parameters
161+
/// of its parent and some synthetic parameters. See the documentation for
162+
/// [ClosureSubsts] for more details.
156163
Closure(DefId, SubstsRef<'tcx>),
157164

158165
/// The anonymous type of a generator. Used to represent the type of
159166
/// `|a| yield a`.
167+
///
168+
/// For more info about generator substs, visit the documentation for
169+
/// [GeneratorSubsts].
160170
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
161171

162172
/// A type representing the types stored inside a generator.
163-
/// This should only appear in GeneratorInteriors.
173+
/// This should only appear as part of the [GeneratorSubsts].
174+
///
175+
/// Note that the captured variables for generators are stored separately
176+
/// using a tuple in the same way as for closures.
177+
///
178+
/// Unlike upvars, the witness can reference lifetimes from
179+
/// inside of the generator itself. To deal with them in
180+
/// the type of the generator, we convert them to higher ranked
181+
/// lifetimes bound by the witness itself.
182+
///
183+
/// Looking at the following example, the witness for this generator
184+
/// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
185+
///
186+
/// ```rust
187+
/// |a| {
188+
/// let x = &vec![3];
189+
/// yield a;
190+
/// yield x[0];
191+
/// }
192+
/// ```
164193
GeneratorWitness(Binder<'tcx, &'tcx List<Ty<'tcx>>>),
165194

166195
/// The never type `!`.
@@ -175,23 +204,44 @@ pub enum TyKind<'tcx> {
175204
Projection(ProjectionTy<'tcx>),
176205

177206
/// Opaque (`impl Trait`) type found in a return type.
207+
///
178208
/// The `DefId` comes either from
179209
/// * the `impl Trait` ast::Ty node,
180210
/// * or the `type Foo = impl Trait` declaration
181-
/// The substitutions are for the generics of the function in question.
182-
/// After typeck, the concrete type can be found in the `types` map.
211+
///
212+
/// For RPIT the substitutions are for the generics of the function,
213+
/// while for TAIT it is used for the generic parameters of the alias.
214+
///
215+
/// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type.
183216
Opaque(DefId, SubstsRef<'tcx>),
184217

185218
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
186219
Param(ParamTy),
187220

188-
/// Bound type variable, used only when preparing a trait query.
221+
/// Bound type variable, used to represent the `'a` in `for<'a> fn(&'a ())`.
222+
///
223+
/// For canonical queries, we replace inference variables with bound variables,
224+
/// so e.g. when checking whether `&'_ (): Trait<_>` holds, we canonicalize that to
225+
/// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
226+
/// back to inference variables in a new inference context when inside of the query.
227+
///
228+
/// See the `rustc-dev-guide` for more details about
229+
/// [higher-ranked trait bounds][1] and [canonical queries][2].
230+
///
231+
/// [1]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
232+
/// [2]: https://rustc-dev-guide.rust-lang.org/traits/canonical-queries.html
189233
Bound(ty::DebruijnIndex, BoundTy),
190234

191-
/// A placeholder type - universally quantified higher-ranked type.
235+
/// A placeholder type, used during higher ranked subtyping to instantiate
236+
/// bound variables.
192237
Placeholder(ty::PlaceholderType),
193238

194239
/// A type variable used during type checking.
240+
///
241+
/// Similar to placeholders, inference variables also live in a universe to
242+
/// correctly deal with higher ranked types. Though unlike placeholders,
243+
/// that universe is stored in the `InferCtxt` instead of directly
244+
/// inside of the type.
195245
Infer(InferTy),
196246

197247
/// A placeholder for a type which could not be computed; this is

compiler/rustc_query_impl/src/plumbing.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ macro_rules! define_queries {
299299
}
300300

301301
#[allow(nonstandard_style)]
302-
pub mod queries {
302+
mod queries {
303303
use std::marker::PhantomData;
304304

305305
$(pub struct $name<$tcx> {
@@ -353,7 +353,7 @@ macro_rules! define_queries {
353353
})*
354354

355355
#[allow(nonstandard_style)]
356-
pub mod query_callbacks {
356+
mod query_callbacks {
357357
use super::*;
358358
use rustc_middle::dep_graph::DepNode;
359359
use rustc_middle::ty::query::query_keys;
@@ -402,7 +402,7 @@ macro_rules! define_queries {
402402
}
403403
}
404404

405-
$(pub fn $name()-> DepKindStruct {
405+
$(pub(crate) fn $name()-> DepKindStruct {
406406
let is_anon = is_anon!([$($modifiers)*]);
407407
let is_eval_always = is_eval_always!([$($modifiers)*]);
408408

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ options! {
11731173
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
11741174
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
11751175
(default: no)"),
1176+
drop_tracking: bool = (false, parse_bool, [TRACKED],
1177+
"enables drop tracking in generators (default: no)"),
11761178
dual_proc_macros: bool = (false, parse_bool, [TRACKED],
11771179
"load proc macros for both target and host, but only link to the target (default: no)"),
11781180
dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_typeck/src/check/generator_interior.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ use tracing::debug;
2222

2323
mod drop_ranges;
2424

25-
// FIXME(eholk): This flag is here to give a quick way to disable drop tracking in case we find
26-
// unexpected breakages while it's still new. It should be removed before too long. For example,
27-
// see #93161.
28-
const ENABLE_DROP_TRACKING: bool = false;
29-
3025
struct InteriorVisitor<'a, 'tcx> {
3126
fcx: &'a FnCtxt<'a, 'tcx>,
3227
types: FxIndexSet<ty::GeneratorInteriorTypeCause<'tcx>>,
@@ -82,7 +77,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
8277
yield_data.expr_and_pat_count, self.expr_count, source_span
8378
);
8479

85-
if ENABLE_DROP_TRACKING
80+
if self.fcx.sess().opts.debugging_opts.drop_tracking
8681
&& self
8782
.drop_ranges
8883
.is_dropped_at(hir_id, yield_data.expr_and_pat_count)
@@ -208,7 +203,7 @@ pub fn resolve_interior<'a, 'tcx>(
208203
};
209204
intravisit::walk_body(&mut visitor, body);
210205

211-
// Check that we visited the same amount of expressions and the RegionResolutionVisitor
206+
// Check that we visited the same amount of expressions as the RegionResolutionVisitor
212207
let region_expr_count = visitor.region_scope_tree.body_expr_count(body_id).unwrap();
213208
assert_eq!(region_expr_count, visitor.expr_count);
214209

compiler/rustc_typeck/src/check/generator_interior/drop_ranges.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn compute_drop_ranges<'a, 'tcx>(
3737
def_id: DefId,
3838
body: &'tcx Body<'tcx>,
3939
) -> DropRanges {
40-
if super::ENABLE_DROP_TRACKING {
40+
if fcx.sess().opts.debugging_opts.drop_tracking {
4141
let consumed_borrowed_places = find_consumed_and_borrowed(fcx, def_id, body);
4242

4343
let num_exprs = fcx.tcx.region_scope_tree(def_id).body_expr_count(body.id()).unwrap_or(0);
@@ -116,6 +116,18 @@ impl TrackedValue {
116116
TrackedValue::Variable(hir_id) | TrackedValue::Temporary(hir_id) => *hir_id,
117117
}
118118
}
119+
120+
fn from_place_with_projections_allowed(place_with_id: &PlaceWithHirId<'_>) -> Self {
121+
match place_with_id.place.base {
122+
PlaceBase::Rvalue | PlaceBase::StaticItem => {
123+
TrackedValue::Temporary(place_with_id.hir_id)
124+
}
125+
PlaceBase::Local(hir_id)
126+
| PlaceBase::Upvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id }, .. }) => {
127+
TrackedValue::Variable(hir_id)
128+
}
129+
}
130+
}
119131
}
120132

121133
/// Represents a reason why we might not be able to convert a HirId or Place
@@ -142,15 +154,7 @@ impl TryFrom<&PlaceWithHirId<'_>> for TrackedValue {
142154
return Err(TrackedValueConversionError::PlaceProjectionsNotSupported);
143155
}
144156

145-
match place_with_id.place.base {
146-
PlaceBase::Rvalue | PlaceBase::StaticItem => {
147-
Ok(TrackedValue::Temporary(place_with_id.hir_id))
148-
}
149-
PlaceBase::Local(hir_id)
150-
| PlaceBase::Upvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id }, .. }) => {
151-
Ok(TrackedValue::Variable(hir_id))
152-
}
153-
}
157+
Ok(TrackedValue::from_place_with_projections_allowed(place_with_id))
154158
}
155159
}
156160

compiler/rustc_typeck/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
9696
_diag_expr_id: HirId,
9797
_bk: rustc_middle::ty::BorrowKind,
9898
) {
99-
place_with_id
100-
.try_into()
101-
.map_or(false, |tracked_value| self.places.borrowed.insert(tracked_value));
99+
self.places
100+
.borrowed
101+
.insert(TrackedValue::from_place_with_projections_allowed(place_with_id));
102102
}
103103

104104
fn mutate(

library/core/src/num/int_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2420,14 +2420,14 @@ macro_rules! int_impl {
24202420
/// Basic usage:
24212421
///
24222422
/// ```
2423-
/// #![feature(int_abs_diff)]
24242423
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($UnsignedT), ");")]
24252424
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($UnsignedT), ");")]
24262425
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(80), 180", stringify!($UnsignedT), ");")]
24272426
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(-120), 20", stringify!($UnsignedT), ");")]
24282427
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.abs_diff(", stringify!($SelfT), "::MAX), ", stringify!($UnsignedT), "::MAX);")]
24292428
/// ```
2430-
#[unstable(feature = "int_abs_diff", issue = "89492")]
2429+
#[stable(feature = "int_abs_diff", since = "1.60.0")]
2430+
#[rustc_const_stable(feature = "int_abs_diff", since = "1.60.0")]
24312431
#[must_use = "this returns the result of the operation, \
24322432
without modifying the original"]
24332433
#[inline]

library/core/src/num/uint_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1635,11 +1635,11 @@ macro_rules! uint_impl {
16351635
/// Basic usage:
16361636
///
16371637
/// ```
1638-
/// #![feature(int_abs_diff)]
16391638
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($SelfT), ");")]
16401639
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($SelfT), ");")]
16411640
/// ```
1642-
#[unstable(feature = "int_abs_diff", issue = "89492")]
1641+
#[stable(feature = "int_abs_diff", since = "1.60.0")]
1642+
#[rustc_const_stable(feature = "int_abs_diff", since = "1.60.0")]
16431643
#[must_use = "this returns the result of the operation, \
16441644
without modifying the original"]
16451645
#[inline]

0 commit comments

Comments
 (0)