Skip to content

Commit

Permalink
Auto merge of rust-lang#121169 - GuillaumeGomez:rollup-oxk5d5j, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

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
  • Loading branch information
bors committed Feb 16, 2024
2 parents a447249 + 2a216bb commit cefa14b
Show file tree
Hide file tree
Showing 43 changed files with 482 additions and 154 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2136,10 +2136,12 @@ pub enum TyKind {
ImplicitSelf,
/// A macro in the type position.
MacCall(P<MacCall>),
/// Placeholder for a kind that has failed to be defined.
Err,
/// Placeholder for a `va_list`.
CVarArgs,
/// Sometimes we need a dummy value when no error has occurred.
Dummy,
/// Placeholder for a kind that has failed to be defined.
Err(ErrorGuaranteed),
}

impl TyKind {
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,12 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
let Ty { id, kind, span, tokens } = ty.deref_mut();
vis.visit_id(id);
match kind {
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never | TyKind::CVarArgs => {}
TyKind::Infer
| TyKind::ImplicitSelf
| TyKind::Err(_)
| TyKind::Dummy
| TyKind::Never
| TyKind::CVarArgs => {}
TyKind::Slice(ty) => vis.visit_ty(ty),
TyKind::Ptr(mt) => vis.visit_mt(mt),
TyKind::Ref(lt, mt) => {
Expand Down Expand Up @@ -1649,7 +1654,7 @@ impl DummyAstNode for Ty {
fn dummy() -> Self {
Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Err,
kind: TyKind::Dummy,
span: Default::default(),
tokens: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
}
TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Err(_) => {}
TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
TyKind::Never | TyKind::CVarArgs => {}
TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
let kind = match &t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
TyKind::Err(guar) => hir::TyKind::Err(*guar),
// Lower the anonymous structs or unions in a nested lowering context.
//
// ```
Expand Down Expand Up @@ -1504,6 +1504,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
);
hir::TyKind::Err(guar)
}
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
};

hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
&item.vis,
errors::VisibilityNotPermittedNote::TraitImpl,
);
if let TyKind::Err = self_ty.kind {
// njn: use Dummy here
if let TyKind::Err(_) = self_ty.kind {
this.dcx().emit_err(errors::ObsoleteAuto { span: item.span });
}
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,16 @@ impl<'a> State<'a> {
ast::TyKind::Infer => {
self.word("_");
}
ast::TyKind::Err => {
ast::TyKind::Err(_) => {
self.popen();
self.word("/*ERROR*/");
self.pclose();
}
ast::TyKind::Dummy => {
self.popen();
self.word("/*DUMMY*/");
self.pclose();
}
ast::TyKind::ImplicitSelf => {
self.word("Self");
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,13 @@ impl DummyResult {
}

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

fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
Some(DummyResult::raw_ty(self.span, self.is_error))
Some(DummyResult::raw_ty(self.span))
}

fn make_arms(self: Box<DummyResult>) -> Option<SmallVec<[ast::Arm; 1]>> {
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
CoerceMany::with_coercion_sites(coerce_first, arms)
};

let mut other_arms = vec![]; // Used only for diagnostics.
let mut prior_non_diverging_arms = vec![]; // Used only for diagnostics.
let mut prior_arm = None;
for arm in arms {
if let Some(e) = &arm.guard {
Expand Down Expand Up @@ -118,9 +118,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
prior_arm_ty,
prior_arm_span,
scrut_span: scrut.span,
scrut_hir_id: scrut.hir_id,
source: match_src,
prior_arms: other_arms.clone(),
prior_non_diverging_arms: prior_non_diverging_arms.clone(),
opt_suggest_box_span,
})),
),
Expand All @@ -142,16 +141,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false,
);

other_arms.push(arm_span);
if other_arms.len() > 5 {
other_arms.remove(0);
}

if !arm_ty.is_never() {
// When a match arm has type `!`, then it doesn't influence the expected type for
// the following arm. If all of the prior arms are `!`, then the influence comes
// from elsewhere and we shouldn't point to any previous arm.
prior_arm = Some((arm_block_id, arm_ty, arm_span));

prior_non_diverging_arms.push(arm_span);
if prior_non_diverging_arms.len() > 5 {
prior_non_diverging_arms.remove(0);
}
}
}

Expand Down
26 changes: 8 additions & 18 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
prior_arm_span,
prior_arm_ty,
source,
ref prior_arms,
ref prior_non_diverging_arms,
opt_suggest_box_span,
scrut_span,
scrut_hir_id,
..
}) => match source {
hir::MatchSource::TryDesugar(scrut_hir_id) => {
Expand Down Expand Up @@ -817,12 +816,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
});
let source_map = self.tcx.sess.source_map();
let mut any_multiline_arm = source_map.is_multiline(arm_span);
if prior_arms.len() <= 4 {
for sp in prior_arms {
if prior_non_diverging_arms.len() <= 4 {
for sp in prior_non_diverging_arms {
any_multiline_arm |= source_map.is_multiline(*sp);
err.span_label(*sp, format!("this is found to be of type `{t}`"));
}
} else if let Some(sp) = prior_arms.last() {
} else if let Some(sp) = prior_non_diverging_arms.last() {
any_multiline_arm |= source_map.is_multiline(*sp);
err.span_label(
*sp,
Expand All @@ -848,24 +847,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) {
err.subdiagnostic(subdiag);
}
if let hir::Node::Expr(m) = self.tcx.parent_hir_node(scrut_hir_id)
&& let hir::Node::Stmt(stmt) = self.tcx.parent_hir_node(m.hir_id)
&& let hir::StmtKind::Expr(_) = stmt.kind
{
err.span_suggestion_verbose(
stmt.span.shrink_to_hi(),
"consider using a semicolon here, but this will discard any values \
in the match arms",
";",
Applicability::MaybeIncorrect,
);
}
if let Some(ret_sp) = opt_suggest_box_span {
// Get return type span and point to it.
self.suggest_boxing_for_return_impl_trait(
err,
ret_sp,
prior_arms.iter().chain(std::iter::once(&arm_span)).copied(),
prior_non_diverging_arms
.iter()
.chain(std::iter::once(&arm_span))
.copied(),
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_infer/src/infer/error_reporting/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
})
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
prior_arms,
prior_non_diverging_arms,
..
}) => {
if let [.., arm_span] = &prior_arms[..] {
if let [.., arm_span] = &prior_non_diverging_arms[..] {
Some(ConsiderAddingAwait::BothFuturesSugg {
first: arm_span.shrink_to_hi(),
second: exp_span.shrink_to_hi(),
Expand Down Expand Up @@ -234,11 +234,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() })
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
ref prior_arms,
ref prior_non_diverging_arms,
..
}) => Some({
ConsiderAddingAwait::FutureSuggMultiple {
spans: prior_arms.iter().map(|arm| arm.shrink_to_hi()).collect(),
spans: prior_non_diverging_arms
.iter()
.map(|arm| arm.shrink_to_hi())
.collect(),
}
}),
_ => None,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,8 @@ pub struct MatchExpressionArmCause<'tcx> {
pub prior_arm_ty: Ty<'tcx>,
pub prior_arm_span: Span,
pub scrut_span: Span,
pub scrut_hir_id: hir::HirId,
pub source: hir::MatchSource,
pub prior_arms: Vec<Span>,
pub prior_non_diverging_arms: Vec<Span>,
pub opt_suggest_box_span: Option<Span>,
}

Expand Down
37 changes: 26 additions & 11 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2363,28 +2363,42 @@ impl<'tcx> Ty<'tcx> {
}

/// When we create a closure, we record its kind (i.e., what trait
/// it implements) into its `ClosureArgs` using a type
/// it implements, constrained by how it uses its borrows) into its
/// [`ty::ClosureArgs`] or [`ty::CoroutineClosureArgs`] using a type
/// parameter. This is kind of a phantom type, except that the
/// most convenient thing for us to are the integral types. This
/// function converts such a special type into the closure
/// kind. To go the other way, use `closure_kind.to_ty(tcx)`.
/// kind. To go the other way, use [`Ty::from_closure_kind`].
///
/// Note that during type checking, we use an inference variable
/// to represent the closure kind, because it has not yet been
/// inferred. Once upvar inference (in `rustc_hir_analysis/src/check/upvar.rs`)
/// is complete, that type variable will be unified.
/// is complete, that type variable will be unified with one of
/// the integral types.
///
/// To be noted that you can use [`ClosureArgs::kind()`] or [`CoroutineClosureArgs::kind()`]
/// to get the same information, which you can get by calling [`GenericArgs::as_closure()`]
/// or [`GenericArgs::as_coroutine_closure()`], depending on the type of the closure.
/// ```rust,ignore (snippet of compiler code)
/// if let TyKind::Closure(def_id, args) = closure_ty.kind()
/// && let Some(closure_kind) = args.as_closure().kind_ty().to_opt_closure_kind()
/// {
/// println!("{closure_kind:?}");
/// } else if let TyKind::CoroutineClosure(def_id, args) = closure_ty.kind()
/// && let Some(closure_kind) = args.as_coroutine_closure().kind_ty().to_opt_closure_kind()
/// {
/// println!("{closure_kind:?}");
/// }
/// ```
///
/// Otherwise, this method can be used as follows:
/// After upvar analysis, you should instead use [`ClosureArgs::kind()`]
/// or [`CoroutineClosureArgs::kind()`] to assert that the `ClosureKind`
/// has been constrained instead of manually calling this method.
///
/// ```rust,ignore (snippet of compiler code)
/// let TyKind::Closure(def_id, [closure_fn_kind_ty, ..]) = closure_ty.kind()
/// && let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind()
/// if let TyKind::Closure(def_id, args) = closure_ty.kind()
/// {
/// println!("{:?}", args.as_closure().kind());
/// } else if let TyKind::CoroutineClosure(def_id, args) = closure_ty.kind()
/// {
/// // your code
/// println!("{:?}", args.as_coroutine_closure().kind());
/// }
/// ```
pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
Expand All @@ -2406,7 +2420,8 @@ impl<'tcx> Ty<'tcx> {
}
}

/// Inverse of [`Ty::to_opt_closure_kind`].
/// Inverse of [`Ty::to_opt_closure_kind`]. See docs on that method
/// for explanation of the relationship between `Ty` and [`ty::ClosureKind`].
pub fn from_closure_kind(tcx: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Ty<'tcx> {
match kind {
ty::ClosureKind::Fn => tcx.types.i8,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
debug!("about to call mir_drops_elaborated...");
let body = tcx.mir_drops_elaborated_and_const_checked(did).steal();
let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
debug!("body: {:#?}", body);

if body.tainted_by_errors.is_some() {
return body;
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ impl<'tcx> MirPass<'tcx> for RemoveNoopLandingPads {
}

fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!("remove_noop_landing_pads({:?})", body);
let def_id = body.source.def_id();
debug!(?def_id);
self.remove_nop_landing_pads(body)
}
}
Expand Down Expand Up @@ -81,8 +82,6 @@ impl RemoveNoopLandingPads {
}

fn remove_nop_landing_pads(&self, body: &mut Body<'_>) {
debug!("body: {:#?}", body);

// Skip the pass if there are no blocks with a resume terminator.
let has_resume = body
.basic_blocks
Expand Down
Loading

0 comments on commit cefa14b

Please sign in to comment.