Skip to content

Rollup of 10 pull requests #142614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8713973
std: simplify `NonNull` variance documentation
xizheyin Jun 3, 2025
5f0dd44
avoid `&mut P<T>` in `visit_expr` etc methods
fee1-dead Jun 11, 2025
810d99e
Prepare `rustc-dev` component un-remapping in the compiler
Urgau Jun 10, 2025
268fbfe
Un-remap `rustc-dev` component paths
Urgau Jun 11, 2025
a16b49b
Manually invalidate caches in SimplifyCfg.
cjgillot Jun 15, 2025
0e1db54
Windows: Use anonymous pipes in Command
ChrisDenton Jun 14, 2025
32c0cb0
Add union with default field values case test
jieyouxu Jun 16, 2025
a2d9687
Add comment.
cjgillot Jun 16, 2025
718df66
Two changes: Have BorrowError & BorrowMutError derive Debug and add
nealsid Jun 14, 2025
2fca05a
Rename BorrowFlag type to BorrowCounter
nealsid Jun 14, 2025
994794a
Handle same-crate macro for borrowck semicolon suggestion
Urgau Jun 16, 2025
2dd9cc1
Reject union default field values
jieyouxu Jun 16, 2025
1dbedaf
Refine run-make test ignores due to unpredictable `i686-pc-windows-gn…
jieyouxu Jun 16, 2025
aa8c6f8
Don't match on platform-specific directory not found message
jieyouxu Jun 17, 2025
0348a4a
Make performance of String::insert_str more precise
hkBst Mar 15, 2025
679a1a7
Rollup merge of #138538 - hkBst:patch-4, r=tgross35
workingjubilee Jun 17, 2025
be6b529
Rollup merge of #141946 - xizheyin:141933, r=jhpratt
workingjubilee Jun 17, 2025
4c48468
Rollup merge of #142216 - nealsid:refcell-logging, r=tgross35
workingjubilee Jun 17, 2025
0ab7ae0
Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petr…
workingjubilee Jun 17, 2025
e39823f
Rollup merge of #142377 - Urgau:unremap-rustc-dev, r=jieyouxu
workingjubilee Jun 17, 2025
532edf5
Rollup merge of #142517 - ChrisDenton:anon-pipe, r=Mark-Simulacrum
workingjubilee Jun 17, 2025
540f68e
Rollup merge of #142542 - cjgillot:invalidate-simplify-cfg, r=SparrowLii
workingjubilee Jun 17, 2025
ac8a2cb
Rollup merge of #142563 - jieyouxu:no-more-i686-mingw, r=mati865
workingjubilee Jun 17, 2025
0945b2b
Rollup merge of #142570 - jieyouxu:disunion, r=estebank
workingjubilee Jun 17, 2025
c79a6c0
Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease
workingjubilee Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ impl Pat {
}
}

impl From<P<Pat>> for Pat {
fn from(value: P<Pat>) -> Self {
*value
}
}

/// A single field in a struct pattern.
///
/// Patterns like the fields of `Foo { x, ref y, ref mut z }`
Expand Down Expand Up @@ -1553,17 +1559,23 @@ impl Expr {
)
}

/// Creates a dummy `P<Expr>`.
/// Creates a dummy `Expr`.
///
/// Should only be used when it will be replaced afterwards or as a return value when an error was encountered.
pub fn dummy() -> P<Expr> {
P(Expr {
pub fn dummy() -> Expr {
Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Dummy,
span: DUMMY_SP,
attrs: ThinVec::new(),
tokens: None,
})
}
}
}

impl From<P<Expr>> for Expr {
fn from(value: P<Expr>) -> Self {
*value
}
}

Expand Down Expand Up @@ -2374,6 +2386,12 @@ impl Clone for Ty {
}
}

impl From<P<Ty>> for Ty {
fn from(value: P<Ty>) -> Self {
*value
}
}

impl Ty {
pub fn peel_refs(&self) -> &Self {
let mut final_ty = self;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ pub trait MutVisitor: Sized + MutVisitorResult<Result = ()> {
walk_flat_map_arm(self, arm)
}

fn visit_pat(&mut self, p: &mut P<Pat>) {
fn visit_pat(&mut self, p: &mut Pat) {
walk_pat(self, p);
}

fn visit_anon_const(&mut self, c: &mut AnonConst) {
walk_anon_const(self, c);
}

fn visit_expr(&mut self, e: &mut P<Expr>) {
fn visit_expr(&mut self, e: &mut Expr) {
walk_expr(self, e);
}

Expand All @@ -194,7 +194,7 @@ pub trait MutVisitor: Sized + MutVisitorResult<Result = ()> {
walk_generic_arg(self, arg);
}

fn visit_ty(&mut self, t: &mut P<Ty>) {
fn visit_ty(&mut self, t: &mut Ty) {
walk_ty(self, t);
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ ast_lowering_underscore_expr_lhs_assign =
in expressions, `_` can only be used on the left-hand side of an assignment
.label = `_` not allowed here
ast_lowering_union_default_field_values = unions cannot have default field values
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
using both label and output operands for inline assembly is unstable
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,10 @@ pub(crate) struct UseConstGenericArg {
#[suggestion_part(code = "{other_args}")]
pub call_args: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_union_default_field_values)]
pub(crate) struct UnionWithDefault {
#[primary_span]
pub span: Span,
}
42 changes: 32 additions & 10 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tracing::instrument;

use super::errors::{
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
UnionWithDefault,
};
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
Expand Down Expand Up @@ -316,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.arena.alloc_from_iter(
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
enum_definition.variants.iter().map(|x| this.lower_variant(i, x)),
)
},
);
Expand All @@ -328,7 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, struct_def),
|this| this.lower_variant_data(hir_id, i, struct_def),
);
hir::ItemKind::Struct(ident, generics, struct_def)
}
Expand All @@ -338,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, vdata),
|this| this.lower_variant_data(hir_id, i, vdata),
);
hir::ItemKind::Union(ident, generics, vdata)
}
Expand Down Expand Up @@ -714,13 +715,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
let hir_id = self.lower_node_id(v.id);
self.lower_attrs(hir_id, &v.attrs, v.span);
hir::Variant {
hir_id,
def_id: self.local_def_id(v.id),
data: self.lower_variant_data(hir_id, &v.data),
data: self.lower_variant_data(hir_id, item_kind, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const_to_anon_const(e)),
ident: self.lower_ident(v.ident),
span: self.lower_span(v.span),
Expand All @@ -730,15 +731,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_variant_data(
&mut self,
parent_id: hir::HirId,
item_kind: &ItemKind,
vdata: &VariantData,
) -> hir::VariantData<'hir> {
match vdata {
VariantData::Struct { fields, recovered } => hir::VariantData::Struct {
fields: self
VariantData::Struct { fields, recovered } => {
let fields = self
.arena
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
recovered: *recovered,
},
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f)));

if let ItemKind::Union(..) = item_kind {
for field in &fields[..] {
if let Some(default) = field.default {
// Unions cannot derive `Default`, and it's not clear how to use default
// field values of unions if that was supported. Therefore, blanket reject
// trying to use field values with unions.
if self.tcx.features().default_field_values() {
self.dcx().emit_err(UnionWithDefault { span: default.span });
} else {
let _ = self.dcx().span_delayed_bug(
default.span,
"expected union default field values feature gate error but none \
was produced",
);
}
}
}
}

hir::VariantData::Struct { fields, recovered: *recovered }
}
VariantData::Tuple(fields, id) => {
let ctor_id = self.lower_node_id(*id);
self.alias_attrs(ctor_id, parent_id);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
}
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
let sp = info
.span
.find_ancestor_in_same_ctxt(local_decl.source_info.span)
.unwrap_or(info.span);
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
if info.tail_result_is_ignored {
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl CfgEval<'_> {

impl MutVisitor for CfgEval<'_> {
#[instrument(level = "trace", skip(self))]
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
fn visit_expr(&mut self, expr: &mut ast::Expr) {
self.0.configure_expr(expr, false);
mut_visit::walk_expr(self, expr);
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ast::HasAttrs;
use ast::ptr::P;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::visit::BoundKind;
use rustc_ast::{
Expand Down Expand Up @@ -378,11 +377,11 @@ struct TypeSubstitution<'a> {
}

impl<'a> ast::mut_visit::MutVisitor for TypeSubstitution<'a> {
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
fn visit_ty(&mut self, ty: &mut ast::Ty) {
if let Some(name) = ty.kind.is_simple_path()
&& name == self.from_name
{
**ty = self.to_ty.clone();
*ty = self.to_ty.clone();
self.rewritten = true;
} else {
ast::mut_visit::walk_ty(self, ty);
Expand Down
35 changes: 18 additions & 17 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ impl InvocationCollectorNode for ast::Crate {
}
}

impl InvocationCollectorNode for P<ast::Ty> {
impl InvocationCollectorNode for ast::Ty {
type OutputTy = P<ast::Ty>;
const KIND: AstFragmentKind = AstFragmentKind::Ty;
fn to_annotatable(self) -> Annotatable {
Expand All @@ -1791,7 +1791,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
}
}

impl InvocationCollectorNode for P<ast::Pat> {
impl InvocationCollectorNode for ast::Pat {
type OutputTy = P<ast::Pat>;
const KIND: AstFragmentKind = AstFragmentKind::Pat;
fn to_annotatable(self) -> Annotatable {
Expand All @@ -1814,11 +1814,11 @@ impl InvocationCollectorNode for P<ast::Pat> {
}
}

impl InvocationCollectorNode for P<ast::Expr> {
impl InvocationCollectorNode for ast::Expr {
type OutputTy = P<ast::Expr>;
const KIND: AstFragmentKind = AstFragmentKind::Expr;
fn to_annotatable(self) -> Annotatable {
Annotatable::Expr(self)
Annotatable::Expr(P(self))
}
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
fragment.make_expr()
Expand Down Expand Up @@ -1955,37 +1955,37 @@ impl DummyAstNode for ast::Crate {
}
}

impl DummyAstNode for P<ast::Ty> {
impl DummyAstNode for ast::Ty {
fn dummy() -> Self {
P(ast::Ty {
ast::Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Dummy,
span: Default::default(),
tokens: Default::default(),
})
}
}
}

impl DummyAstNode for P<ast::Pat> {
impl DummyAstNode for ast::Pat {
fn dummy() -> Self {
P(ast::Pat {
ast::Pat {
id: DUMMY_NODE_ID,
kind: PatKind::Wild,
span: Default::default(),
tokens: Default::default(),
})
}
}
}

impl DummyAstNode for P<ast::Expr> {
impl DummyAstNode for ast::Expr {
fn dummy() -> Self {
ast::Expr::dummy()
}
}

impl DummyAstNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag> {
fn dummy() -> Self {
AstNodeWrapper::new(ast::Expr::dummy(), MethodReceiverTag)
AstNodeWrapper::new(P(ast::Expr::dummy()), MethodReceiverTag)
}
}

Expand Down Expand Up @@ -2272,7 +2272,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
}
}

fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
fn visit_node<Node: InvocationCollectorNode<OutputTy: Into<Node>> + DummyAstNode>(
&mut self,
node: &mut Node,
) {
Expand All @@ -2297,14 +2297,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
*node = self
.collect_attr((attr, pos, derives), n.to_annotatable(), Node::KIND)
.make_ast::<Node>()
.into()
}
},
None if node.is_mac_call() => {
let n = mem::replace(node, Node::dummy());
let (mac, attrs, _) = n.take_mac_call();
self.check_attributes(&attrs, &mac);

*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>()
*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>().into()
}
None if node.delegation().is_some() => unreachable!(),
None => {
Expand Down Expand Up @@ -2414,15 +2415,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
self.visit_node(node)
}

fn visit_ty(&mut self, node: &mut P<ast::Ty>) {
fn visit_ty(&mut self, node: &mut ast::Ty) {
self.visit_node(node)
}

fn visit_pat(&mut self, node: &mut P<ast::Pat>) {
fn visit_pat(&mut self, node: &mut ast::Pat) {
self.visit_node(node)
}

fn visit_expr(&mut self, node: &mut P<ast::Expr>) {
fn visit_expr(&mut self, node: &mut ast::Expr) {
// FIXME: Feature gating is performed inconsistently between `Expr` and `OptExpr`.
if let Some(attr) = node.attrs.first() {
self.cfg().maybe_emit_expr_attr_err(attr);
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ impl MutVisitor for PlaceholderExpander {
}
}

fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
fn visit_expr(&mut self, expr: &mut ast::Expr) {
match expr.kind {
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
ast::ExprKind::MacCall(_) => *expr = *self.remove(expr.id).make_expr(),
_ => walk_expr(self, expr),
}
}
Expand Down Expand Up @@ -399,16 +399,16 @@ impl MutVisitor for PlaceholderExpander {
stmts
}

fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
fn visit_pat(&mut self, pat: &mut ast::Pat) {
match pat.kind {
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
ast::PatKind::MacCall(_) => *pat = *self.remove(pat.id).make_pat(),
_ => walk_pat(self, pat),
}
}

fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
fn visit_ty(&mut self, ty: &mut ast::Ty) {
match ty.kind {
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
ast::TyKind::MacCall(_) => *ty = *self.remove(ty.id).make_ty(),
_ => walk_ty(self, ty),
}
}
Expand Down
Loading