Skip to content

Commit cefa14b

Browse files
committed
Auto merge of #121169 - GuillaumeGomez:rollup-oxk5d5j, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - #120777 (Bump Unicode to version 15.1.0, regenerate tables) - #120971 (Fix comment in core/src/str/validations.rs) - #121095 (Add extra indent spaces for rust-playground link) - #121109 (Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2)) - #121119 (Make `async Fn` trait kind errors better) - #121141 (Fix closure kind docs) - #121145 (Update aarch64 target feature docs to match LLVM) - #121146 (Only point out non-diverging arms for match suggestions) - #121147 (Avoid debug logging entire MIR body) - #121155 (doc: add note about panicking examples for strict_overflow_ops) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a447249 + 2a216bb commit cefa14b

File tree

43 files changed

+482
-154
lines changed

Some content is hidden

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

43 files changed

+482
-154
lines changed

compiler/rustc_ast/src/ast.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,12 @@ pub enum TyKind {
21362136
ImplicitSelf,
21372137
/// A macro in the type position.
21382138
MacCall(P<MacCall>),
2139-
/// Placeholder for a kind that has failed to be defined.
2140-
Err,
21412139
/// Placeholder for a `va_list`.
21422140
CVarArgs,
2141+
/// Sometimes we need a dummy value when no error has occurred.
2142+
Dummy,
2143+
/// Placeholder for a kind that has failed to be defined.
2144+
Err(ErrorGuaranteed),
21432145
}
21442146

21452147
impl TyKind {

compiler/rustc_ast/src/mut_visit.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
481481
let Ty { id, kind, span, tokens } = ty.deref_mut();
482482
vis.visit_id(id);
483483
match kind {
484-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never | TyKind::CVarArgs => {}
484+
TyKind::Infer
485+
| TyKind::ImplicitSelf
486+
| TyKind::Err(_)
487+
| TyKind::Dummy
488+
| TyKind::Never
489+
| TyKind::CVarArgs => {}
485490
TyKind::Slice(ty) => vis.visit_ty(ty),
486491
TyKind::Ptr(mt) => vis.visit_mt(mt),
487492
TyKind::Ref(lt, mt) => {
@@ -1649,7 +1654,7 @@ impl DummyAstNode for Ty {
16491654
fn dummy() -> Self {
16501655
Ty {
16511656
id: DUMMY_NODE_ID,
1652-
kind: TyKind::Err,
1657+
kind: TyKind::Dummy,
16531658
span: Default::default(),
16541659
tokens: Default::default(),
16551660
}

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
447447
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
448448
}
449449
TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
450-
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
450+
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {}
451451
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
452452
TyKind::Never | TyKind::CVarArgs => {}
453453
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {

compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12861286
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12871287
let kind = match &t.kind {
12881288
TyKind::Infer => hir::TyKind::Infer,
1289-
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
1289+
TyKind::Err(guar) => hir::TyKind::Err(*guar),
12901290
// Lower the anonymous structs or unions in a nested lowering context.
12911291
//
12921292
// ```
@@ -1504,6 +1504,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15041504
);
15051505
hir::TyKind::Err(guar)
15061506
}
1507+
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
15071508
};
15081509

15091510
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }

compiler/rustc_ast_passes/src/ast_validation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
881881
&item.vis,
882882
errors::VisibilityNotPermittedNote::TraitImpl,
883883
);
884-
if let TyKind::Err = self_ty.kind {
884+
// njn: use Dummy here
885+
if let TyKind::Err(_) = self_ty.kind {
885886
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
886887
}
887888
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,16 @@ impl<'a> State<'a> {
10481048
ast::TyKind::Infer => {
10491049
self.word("_");
10501050
}
1051-
ast::TyKind::Err => {
1051+
ast::TyKind::Err(_) => {
10521052
self.popen();
10531053
self.word("/*ERROR*/");
10541054
self.pclose();
10551055
}
1056+
ast::TyKind::Dummy => {
1057+
self.popen();
1058+
self.word("/*DUMMY*/");
1059+
self.pclose();
1060+
}
10561061
ast::TyKind::ImplicitSelf => {
10571062
self.word("Self");
10581063
}

compiler/rustc_expand/src/base.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,13 @@ impl DummyResult {
567567
}
568568

569569
/// A plain dummy type.
570-
pub fn raw_ty(sp: Span, is_error: bool) -> P<ast::Ty> {
570+
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
571+
// FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some
572+
// values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not
573+
// support, so we use an empty tuple instead.
571574
P(ast::Ty {
572575
id: ast::DUMMY_NODE_ID,
573-
kind: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(ThinVec::new()) },
576+
kind: ast::TyKind::Tup(ThinVec::new()),
574577
span: sp,
575578
tokens: None,
576579
})
@@ -611,7 +614,7 @@ impl MacResult for DummyResult {
611614
}
612615

613616
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
614-
Some(DummyResult::raw_ty(self.span, self.is_error))
617+
Some(DummyResult::raw_ty(self.span))
615618
}
616619

617620
fn make_arms(self: Box<DummyResult>) -> Option<SmallVec<[ast::Arm; 1]>> {

compiler/rustc_hir_typeck/src/_match.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7979
CoerceMany::with_coercion_sites(coerce_first, arms)
8080
};
8181

82-
let mut other_arms = vec![]; // Used only for diagnostics.
82+
let mut prior_non_diverging_arms = vec![]; // Used only for diagnostics.
8383
let mut prior_arm = None;
8484
for arm in arms {
8585
if let Some(e) = &arm.guard {
@@ -118,9 +118,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
118118
prior_arm_ty,
119119
prior_arm_span,
120120
scrut_span: scrut.span,
121-
scrut_hir_id: scrut.hir_id,
122121
source: match_src,
123-
prior_arms: other_arms.clone(),
122+
prior_non_diverging_arms: prior_non_diverging_arms.clone(),
124123
opt_suggest_box_span,
125124
})),
126125
),
@@ -142,16 +141,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
142141
false,
143142
);
144143

145-
other_arms.push(arm_span);
146-
if other_arms.len() > 5 {
147-
other_arms.remove(0);
148-
}
149-
150144
if !arm_ty.is_never() {
151145
// When a match arm has type `!`, then it doesn't influence the expected type for
152146
// the following arm. If all of the prior arms are `!`, then the influence comes
153147
// from elsewhere and we shouldn't point to any previous arm.
154148
prior_arm = Some((arm_block_id, arm_ty, arm_span));
149+
150+
prior_non_diverging_arms.push(arm_span);
151+
if prior_non_diverging_arms.len() > 5 {
152+
prior_non_diverging_arms.remove(0);
153+
}
155154
}
156155
}
157156

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
777777
prior_arm_span,
778778
prior_arm_ty,
779779
source,
780-
ref prior_arms,
780+
ref prior_non_diverging_arms,
781781
opt_suggest_box_span,
782782
scrut_span,
783-
scrut_hir_id,
784783
..
785784
}) => match source {
786785
hir::MatchSource::TryDesugar(scrut_hir_id) => {
@@ -817,12 +816,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
817816
});
818817
let source_map = self.tcx.sess.source_map();
819818
let mut any_multiline_arm = source_map.is_multiline(arm_span);
820-
if prior_arms.len() <= 4 {
821-
for sp in prior_arms {
819+
if prior_non_diverging_arms.len() <= 4 {
820+
for sp in prior_non_diverging_arms {
822821
any_multiline_arm |= source_map.is_multiline(*sp);
823822
err.span_label(*sp, format!("this is found to be of type `{t}`"));
824823
}
825-
} else if let Some(sp) = prior_arms.last() {
824+
} else if let Some(sp) = prior_non_diverging_arms.last() {
826825
any_multiline_arm |= source_map.is_multiline(*sp);
827826
err.span_label(
828827
*sp,
@@ -848,24 +847,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
848847
) {
849848
err.subdiagnostic(subdiag);
850849
}
851-
if let hir::Node::Expr(m) = self.tcx.parent_hir_node(scrut_hir_id)
852-
&& let hir::Node::Stmt(stmt) = self.tcx.parent_hir_node(m.hir_id)
853-
&& let hir::StmtKind::Expr(_) = stmt.kind
854-
{
855-
err.span_suggestion_verbose(
856-
stmt.span.shrink_to_hi(),
857-
"consider using a semicolon here, but this will discard any values \
858-
in the match arms",
859-
";",
860-
Applicability::MaybeIncorrect,
861-
);
862-
}
863850
if let Some(ret_sp) = opt_suggest_box_span {
864851
// Get return type span and point to it.
865852
self.suggest_boxing_for_return_impl_trait(
866853
err,
867854
ret_sp,
868-
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
855+
prior_non_diverging_arms
856+
.iter()
857+
.chain(std::iter::once(&arm_span))
858+
.copied(),
869859
);
870860
}
871861
}

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
203203
})
204204
}
205205
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
206-
prior_arms,
206+
prior_non_diverging_arms,
207207
..
208208
}) => {
209-
if let [.., arm_span] = &prior_arms[..] {
209+
if let [.., arm_span] = &prior_non_diverging_arms[..] {
210210
Some(ConsiderAddingAwait::BothFuturesSugg {
211211
first: arm_span.shrink_to_hi(),
212212
second: exp_span.shrink_to_hi(),
@@ -234,11 +234,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
234234
Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() })
235235
}
236236
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
237-
ref prior_arms,
237+
ref prior_non_diverging_arms,
238238
..
239239
}) => Some({
240240
ConsiderAddingAwait::FutureSuggMultiple {
241-
spans: prior_arms.iter().map(|arm| arm.shrink_to_hi()).collect(),
241+
spans: prior_non_diverging_arms
242+
.iter()
243+
.map(|arm| arm.shrink_to_hi())
244+
.collect(),
242245
}
243246
}),
244247
_ => None,

compiler/rustc_middle/src/traits/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,8 @@ pub struct MatchExpressionArmCause<'tcx> {
569569
pub prior_arm_ty: Ty<'tcx>,
570570
pub prior_arm_span: Span,
571571
pub scrut_span: Span,
572-
pub scrut_hir_id: hir::HirId,
573572
pub source: hir::MatchSource,
574-
pub prior_arms: Vec<Span>,
573+
pub prior_non_diverging_arms: Vec<Span>,
575574
pub opt_suggest_box_span: Option<Span>,
576575
}
577576

compiler/rustc_middle/src/ty/sty.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -2363,28 +2363,42 @@ impl<'tcx> Ty<'tcx> {
23632363
}
23642364

23652365
/// When we create a closure, we record its kind (i.e., what trait
2366-
/// it implements) into its `ClosureArgs` using a type
2366+
/// it implements, constrained by how it uses its borrows) into its
2367+
/// [`ty::ClosureArgs`] or [`ty::CoroutineClosureArgs`] using a type
23672368
/// parameter. This is kind of a phantom type, except that the
23682369
/// most convenient thing for us to are the integral types. This
23692370
/// function converts such a special type into the closure
2370-
/// kind. To go the other way, use `closure_kind.to_ty(tcx)`.
2371+
/// kind. To go the other way, use [`Ty::from_closure_kind`].
23712372
///
23722373
/// Note that during type checking, we use an inference variable
23732374
/// to represent the closure kind, because it has not yet been
23742375
/// inferred. Once upvar inference (in `rustc_hir_analysis/src/check/upvar.rs`)
2375-
/// is complete, that type variable will be unified.
2376+
/// is complete, that type variable will be unified with one of
2377+
/// the integral types.
23762378
///
2377-
/// To be noted that you can use [`ClosureArgs::kind()`] or [`CoroutineClosureArgs::kind()`]
2378-
/// to get the same information, which you can get by calling [`GenericArgs::as_closure()`]
2379-
/// or [`GenericArgs::as_coroutine_closure()`], depending on the type of the closure.
2379+
/// ```rust,ignore (snippet of compiler code)
2380+
/// if let TyKind::Closure(def_id, args) = closure_ty.kind()
2381+
/// && let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
2382+
/// {
2383+
/// println!("{closure_kind:?}");
2384+
/// } else if let TyKind::CoroutineClosure(def_id, args) = closure_ty.kind()
2385+
/// && let Some(closure_kind) = args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
2386+
/// {
2387+
/// println!("{closure_kind:?}");
2388+
/// }
2389+
/// ```
23802390
///
2381-
/// Otherwise, this method can be used as follows:
2391+
/// After upvar analysis, you should instead use [`ClosureArgs::kind()`]
2392+
/// or [`CoroutineClosureArgs::kind()`] to assert that the `ClosureKind`
2393+
/// has been constrained instead of manually calling this method.
23822394
///
23832395
/// ```rust,ignore (snippet of compiler code)
2384-
/// let TyKind::Closure(def_id, [closure_fn_kind_ty, ..]) = closure_ty.kind()
2385-
/// && let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind()
2396+
/// if let TyKind::Closure(def_id, args) = closure_ty.kind()
2397+
/// {
2398+
/// println!("{:?}", args.as_closure().kind());
2399+
/// } else if let TyKind::CoroutineClosure(def_id, args) = closure_ty.kind()
23862400
/// {
2387-
/// // your code
2401+
/// println!("{:?}", args.as_coroutine_closure().kind());
23882402
/// }
23892403
/// ```
23902404
pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
@@ -2406,7 +2420,8 @@ impl<'tcx> Ty<'tcx> {
24062420
}
24072421
}
24082422

2409-
/// Inverse of [`Ty::to_opt_closure_kind`].
2423+
/// Inverse of [`Ty::to_opt_closure_kind`]. See docs on that method
2424+
/// for explanation of the relationship between `Ty` and [`ty::ClosureKind`].
24102425
pub fn from_closure_kind(tcx: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Ty<'tcx> {
24112426
match kind {
24122427
ty::ClosureKind::Fn => tcx.types.i8,

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
653653
debug!("about to call mir_drops_elaborated...");
654654
let body = tcx.mir_drops_elaborated_and_const_checked(did).steal();
655655
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
656-
debug!("body: {:#?}", body);
657656

658657
if body.tainted_by_errors.is_some() {
659658
return body;

compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads {
1515
}
1616

1717
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
18-
debug!("remove_noop_landing_pads({:?})", body);
18+
let def_id = body.source.def_id();
19+
debug!(?def_id);
1920
self.remove_nop_landing_pads(body)
2021
}
2122
}
@@ -81,8 +82,6 @@ impl RemoveNoopLandingPads {
8182
}
8283

8384
fn remove_nop_landing_pads(&self, body: &mut Body<'_>) {
84-
debug!("body: {:#?}", body);
85-
8685
// Skip the pass if there are no blocks with a resume terminator.
8786
let has_resume = body
8887
.basic_blocks

0 commit comments

Comments
 (0)