Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cefa14b

Browse files
committed
Auto merge of rust-lang#121169 - GuillaumeGomez:rollup-oxk5d5j, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - rust-lang#120777 (Bump Unicode to version 15.1.0, regenerate tables) - rust-lang#120971 (Fix comment in core/src/str/validations.rs) - rust-lang#121095 (Add extra indent spaces for rust-playground link) - rust-lang#121109 (Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2)) - rust-lang#121119 (Make `async Fn` trait kind errors better) - rust-lang#121141 (Fix closure kind docs) - rust-lang#121145 (Update aarch64 target feature docs to match LLVM) - rust-lang#121146 (Only point out non-diverging arms for match suggestions) - rust-lang#121147 (Avoid debug logging entire MIR body) - rust-lang#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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 7 additions & 8 deletions
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

Lines changed: 8 additions & 18 deletions
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

Lines changed: 7 additions & 4 deletions
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,

0 commit comments

Comments
 (0)