Skip to content

Commit b28d30e

Browse files
committed
Auto merge of rust-lang#105378 - matthiaskrgr:rollup-fjeorw5, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#104898 (Put all cached values into a central struct instead of just the stable hash) - rust-lang#105004 (Fix `emit_unused_delims_expr` ICE) - rust-lang#105174 (Suggest removing struct field from destructive binding only in shorthand scenario) - rust-lang#105250 (Replace usage of `ResumeTy` in async lowering with `Context`) - rust-lang#105286 (Add -Z maximal-hir-to-mir-coverage flag) - rust-lang#105320 (rustdoc: simplify CSS selectors on top-doc and non-exhaustive toggles) - rust-lang#105349 (Point at args in associated const fn pointers) - rust-lang#105362 (Cleanup macro-expanded code in `rustc_type_ir`) - rust-lang#105370 (Remove outdated syntax from trait alias pretty printing) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e60fbaf + 97008a2 commit b28d30e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+658
-750
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+36-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::def::Res;
1616
use rustc_hir::definitions::DefPathData;
1717
use rustc_session::errors::report_lit_error;
1818
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
19-
use rustc_span::symbol::{sym, Ident};
19+
use rustc_span::symbol::{kw, sym, Ident};
2020
use rustc_span::DUMMY_SP;
2121
use thin_vec::thin_vec;
2222

@@ -594,14 +594,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
594594
) -> hir::ExprKind<'hir> {
595595
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
596596

597-
// Resume argument type: `ResumeTy`
598-
let unstable_span =
599-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
600-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
597+
// Resume argument type, which should be `&mut Context<'_>`.
598+
// NOTE: Using the `'static` lifetime here is technically cheating.
599+
// The `Future::poll` argument really is `&'a mut Context<'b>`, but we cannot
600+
// express the fact that we are not storing it across yield-points yet,
601+
// and we would thus run into lifetime errors.
602+
// See <https://github.com/rust-lang/rust/issues/68923>.
603+
// Our lowering makes sure we are not mis-using the `_task_context` input type
604+
// in the sense that we are indeed not using it across yield points. We
605+
// get a fresh `&mut Context` for each resume / call of `Future::poll`.
606+
// This "cheating" was previously done with a `ResumeTy` that contained a raw
607+
// pointer, and a `get_context` accessor that pulled the `Context` lifetimes
608+
// out of thin air.
609+
let context_lifetime_ident = Ident::with_dummy_span(kw::StaticLifetime);
610+
let context_lifetime = self.arena.alloc(hir::Lifetime {
611+
hir_id: self.next_id(),
612+
ident: context_lifetime_ident,
613+
res: hir::LifetimeName::Static,
614+
});
615+
let context_path =
616+
hir::QPath::LangItem(hir::LangItem::Context, self.lower_span(span), None);
617+
let context_ty = hir::MutTy {
618+
ty: self.arena.alloc(hir::Ty {
619+
hir_id: self.next_id(),
620+
kind: hir::TyKind::Path(context_path),
621+
span: self.lower_span(span),
622+
}),
623+
mutbl: hir::Mutability::Mut,
624+
};
601625
let input_ty = hir::Ty {
602626
hir_id: self.next_id(),
603-
kind: hir::TyKind::Path(resume_ty),
604-
span: unstable_span,
627+
kind: hir::TyKind::Rptr(context_lifetime, context_ty),
628+
span: self.lower_span(span),
605629
};
606630

607631
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
@@ -659,12 +683,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
659683
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
660684

661685
let hir_id = self.lower_node_id(closure_node_id);
686+
let unstable_span =
687+
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
662688
if track_caller {
663-
let unstable_span = self.mark_span_with_reason(
664-
DesugaringKind::Async,
665-
span,
666-
self.allow_gen_future.clone(),
667-
);
668689
self.lower_attrs(
669690
hir_id,
670691
&[Attribute {
@@ -711,7 +732,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
711732
/// mut __awaitee => loop {
712733
/// match unsafe { ::std::future::Future::poll(
713734
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
714-
/// ::std::future::get_context(task_context),
735+
/// task_context,
715736
/// ) } {
716737
/// ::std::task::Poll::Ready(result) => break result,
717738
/// ::std::task::Poll::Pending => {}
@@ -752,7 +773,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
752773
// unsafe {
753774
// ::std::future::Future::poll(
754775
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
755-
// ::std::future::get_context(task_context),
776+
// task_context,
756777
// )
757778
// }
758779
let poll_expr = {
@@ -770,16 +791,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
770791
arena_vec![self; ref_mut_awaitee],
771792
Some(expr_hir_id),
772793
);
773-
let get_context = self.expr_call_lang_item_fn_mut(
774-
gen_future_span,
775-
hir::LangItem::GetContext,
776-
arena_vec![self; task_context],
777-
Some(expr_hir_id),
778-
);
779794
let call = self.expr_call_lang_item_fn(
780795
span,
781796
hir::LangItem::FuturePoll,
782-
arena_vec![self; new_unchecked, get_context],
797+
arena_vec![self; new_unchecked, task_context],
783798
Some(expr_hir_id),
784799
);
785800
self.arena.alloc(self.expr_unsafe(call))

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,10 @@ impl<'a> State<'a> {
348348
self.head(visibility_qualified(&item.vis, "trait"));
349349
self.print_ident(item.ident);
350350
self.print_generic_params(&generics.params);
351-
let mut real_bounds = Vec::with_capacity(bounds.len());
352-
// FIXME(durka) this seems to be some quite outdated syntax
353-
for b in bounds.iter() {
354-
if let GenericBound::Trait(ptr, ast::TraitBoundModifier::Maybe) = b {
355-
self.space();
356-
self.word_space("for ?");
357-
self.print_trait_ref(&ptr.trait_ref);
358-
} else {
359-
real_bounds.push(b.clone());
360-
}
361-
}
362351
self.nbsp();
363-
if !real_bounds.is_empty() {
352+
if !bounds.is_empty() {
364353
self.word_nbsp("=");
365-
self.print_type_bounds(&real_bounds);
354+
self.print_type_bounds(&bounds);
366355
}
367356
self.print_where_clause(&generics.where_clause);
368357
self.word(";");

compiler/rustc_data_structures/src/intern.rs

-83
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::hash::{Hash, Hasher};
44
use std::ops::Deref;
55
use std::ptr;
66

7-
use crate::fingerprint::Fingerprint;
8-
97
mod private {
108
#[derive(Clone, Copy, Debug)]
119
pub struct PrivateZst;
@@ -110,86 +108,5 @@ where
110108
}
111109
}
112110

113-
/// A helper type that you can wrap round your own type in order to automatically
114-
/// cache the stable hash on creation and not recompute it whenever the stable hash
115-
/// of the type is computed.
116-
/// This is only done in incremental mode. You can also opt out of caching by using
117-
/// StableHash::ZERO for the hash, in which case the hash gets computed each time.
118-
/// This is useful if you have values that you intern but never (can?) use for stable
119-
/// hashing.
120-
#[derive(Copy, Clone)]
121-
pub struct WithStableHash<T> {
122-
pub internee: T,
123-
pub stable_hash: Fingerprint,
124-
}
125-
126-
impl<T: PartialEq> PartialEq for WithStableHash<T> {
127-
#[inline]
128-
fn eq(&self, other: &Self) -> bool {
129-
self.internee.eq(&other.internee)
130-
}
131-
}
132-
133-
impl<T: Eq> Eq for WithStableHash<T> {}
134-
135-
impl<T: Ord> PartialOrd for WithStableHash<T> {
136-
fn partial_cmp(&self, other: &WithStableHash<T>) -> Option<Ordering> {
137-
Some(self.internee.cmp(&other.internee))
138-
}
139-
}
140-
141-
impl<T: Ord> Ord for WithStableHash<T> {
142-
fn cmp(&self, other: &WithStableHash<T>) -> Ordering {
143-
self.internee.cmp(&other.internee)
144-
}
145-
}
146-
147-
impl<T> Deref for WithStableHash<T> {
148-
type Target = T;
149-
150-
#[inline]
151-
fn deref(&self) -> &T {
152-
&self.internee
153-
}
154-
}
155-
156-
impl<T: Hash> Hash for WithStableHash<T> {
157-
#[inline]
158-
fn hash<H: Hasher>(&self, s: &mut H) {
159-
if self.stable_hash != Fingerprint::ZERO {
160-
self.stable_hash.hash(s)
161-
} else {
162-
self.internee.hash(s)
163-
}
164-
}
165-
}
166-
167-
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for WithStableHash<T> {
168-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
169-
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
170-
// No cached hash available. This can only mean that incremental is disabled.
171-
// We don't cache stable hashes in non-incremental mode, because they are used
172-
// so rarely that the performance actually suffers.
173-
174-
// We need to build the hash as if we cached it and then hash that hash, as
175-
// otherwise the hashes will differ between cached and non-cached mode.
176-
let stable_hash: Fingerprint = {
177-
let mut hasher = StableHasher::new();
178-
self.internee.hash_stable(hcx, &mut hasher);
179-
hasher.finish()
180-
};
181-
if cfg!(debug_assertions) && self.stable_hash != Fingerprint::ZERO {
182-
assert_eq!(
183-
stable_hash, self.stable_hash,
184-
"cached stable hash does not match freshly computed stable hash"
185-
);
186-
}
187-
stable_hash.hash_stable(hcx, hasher);
188-
} else {
189-
self.stable_hash.hash_stable(hcx, hasher);
190-
}
191-
}
192-
}
193-
194111
#[cfg(test)]
195112
mod tests;

compiler/rustc_hir/src/lang_items.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,9 @@ language_item_table! {
286286

287287
// FIXME(swatinem): the following lang items are used for async lowering and
288288
// should become obsolete eventually.
289-
ResumeTy, sym::ResumeTy, resume_ty, Target::Struct, GenericRequirement::None;
290289
IdentityFuture, sym::identity_future, identity_future_fn, Target::Fn, GenericRequirement::None;
291-
GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None;
292290

291+
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
293292
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
294293

295294
FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

compiler/rustc_hir_pretty/src/lib.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,8 @@ impl<'a> State<'a> {
695695
self.head("trait");
696696
self.print_ident(item.ident);
697697
self.print_generic_params(generics.params);
698-
let mut real_bounds = Vec::with_capacity(bounds.len());
699-
// FIXME(durka) this seems to be some quite outdated syntax
700-
for b in bounds {
701-
if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
702-
self.space();
703-
self.word_space("for ?");
704-
self.print_trait_ref(&ptr.trait_ref);
705-
} else {
706-
real_bounds.push(b);
707-
}
708-
}
709698
self.nbsp();
710-
self.print_bounds("=", real_bounds);
699+
self.print_bounds("=", bounds);
711700
self.print_where_clause(generics);
712701
self.word(";");
713702
self.end(); // end inner head-block

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1918,15 +1918,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19181918
receiver: Option<&'tcx hir::Expr<'tcx>>,
19191919
args: &'tcx [hir::Expr<'tcx>],
19201920
) -> bool {
1921-
// Do not call `fn_sig` on non-functions.
1922-
if !matches!(
1923-
self.tcx.def_kind(def_id),
1924-
DefKind::Fn | DefKind::AssocFn | DefKind::Variant | DefKind::Ctor(..)
1925-
) {
1921+
let ty = self.tcx.type_of(def_id);
1922+
if !ty.is_fn() {
19261923
return false;
19271924
}
1928-
1929-
let sig = self.tcx.fn_sig(def_id).skip_binder();
1925+
let sig = ty.fn_sig(self.tcx).skip_binder();
19301926
let args_referencing_param: Vec<_> = sig
19311927
.inputs()
19321928
.iter()

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ fn test_unstable_options_tracking_hash() {
747747
tracked!(link_only, true);
748748
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
749749
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
750+
tracked!(maximal_hir_to_mir_coverage, true);
750751
tracked!(merge_functions, Some(MergeFunctions::Disabled));
751752
tracked!(mir_emit_retag, true);
752753
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);

compiler/rustc_lint/src/pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare_tool_lint! {
1010
/// The `rustc_pass_by_value` lint marks a type with `#[rustc_pass_by_value]` requiring it to
1111
/// always be passed by value. This is usually used for types that are thin wrappers around
1212
/// references, so there is no benefit to an extra layer of indirection. (Example: `Ty` which
13-
/// is a reference to an `Interned<TyS>`)
13+
/// is a reference to an `Interned<TyKind>`)
1414
pub rustc::PASS_BY_VALUE,
1515
Warn,
1616
"pass by reference of a type flagged as `#[rustc_pass_by_value]`",

compiler/rustc_lint/src/unused.rs

+26-5
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,34 @@ trait UnusedDelimLint {
633633
left_pos: Option<BytePos>,
634634
right_pos: Option<BytePos>,
635635
) {
636+
// If `value` has `ExprKind::Err`, unused delim lint can be broken.
637+
// For example, the following code caused ICE.
638+
// This is because the `ExprKind::Call` in `value` has `ExprKind::Err` as its argument
639+
// and this leads to wrong spans. #104897
640+
//
641+
// ```
642+
// fn f(){(print!(á
643+
// ```
644+
use rustc_ast::visit::{walk_expr, Visitor};
645+
struct ErrExprVisitor {
646+
has_error: bool,
647+
}
648+
impl<'ast> Visitor<'ast> for ErrExprVisitor {
649+
fn visit_expr(&mut self, expr: &'ast ast::Expr) {
650+
if let ExprKind::Err = expr.kind {
651+
self.has_error = true;
652+
return;
653+
}
654+
walk_expr(self, expr)
655+
}
656+
}
657+
let mut visitor = ErrExprVisitor { has_error: false };
658+
visitor.visit_expr(value);
659+
if visitor.has_error {
660+
return;
661+
}
636662
let spans = match value.kind {
637663
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
638-
if let StmtKind::Expr(expr) = &block.stmts[0].kind
639-
&& let ExprKind::Err = expr.kind
640-
{
641-
return
642-
}
643664
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
644665
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
645666
} else {

compiler/rustc_middle/src/arena.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(rustc::usage_of_ty_tykind)]
2+
13
/// This higher-order macro declares a list of types which can be allocated by `Arena`.
24
///
35
/// Specifying the `decode` modifier will add decode impls for `&T` and `&[T]` where `T` is the type
@@ -89,8 +91,8 @@ macro_rules! arena_types {
8991
[] hir_id_set: rustc_hir::HirIdSet,
9092

9193
// Interned types
92-
[] tys: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::TyS<'tcx>>,
93-
[] predicates: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::PredicateS<'tcx>>,
94+
[] tys: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::TyKind<'tcx>>,
95+
[] predicates: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::PredicateKind<'tcx>>,
9496
[] consts: rustc_middle::ty::ConstS<'tcx>,
9597

9698
// Note that this deliberately duplicates items in the `rustc_hir::arena`,

compiler/rustc_middle/src/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl hash::Hash for Allocation {
103103
/// Interned types generally have an `Outer` type and an `Inner` type, where
104104
/// `Outer` is a newtype around `Interned<Inner>`, and all the operations are
105105
/// done on `Outer`, because all occurrences are interned. E.g. `Ty` is an
106-
/// outer type and `TyS` is its inner type.
106+
/// outer type and `TyKind` is its inner type.
107107
///
108108
/// Here things are different because only const allocations are interned. This
109109
/// means that both the inner type (`Allocation`) and the outer type

0 commit comments

Comments
 (0)