Skip to content

Commit 1b4aa42

Browse files
committed
Auto merge of #142614 - workingjubilee:rollup-g5qf7y3, r=workingjubilee
Rollup of 10 pull requests Successful merges: - #138538 (Make performance description of String::{insert,insert_str,remove} more precise) - #141946 (std: refactor explanation of `NonNull`) - #142216 (Miscellaneous RefCell cleanups) - #142371 (avoid `&mut P<T>` in `visit_expr` etc methods) - #142377 (Try unremapping compiler sources) - #142517 (Windows: Use anonymous pipes in Command) - #142542 (Manually invalidate caches in SimplifyCfg.) - #142563 (Refine run-make test ignores due to unpredictable `i686-pc-windows-gnu` unwind mechanism) - #142570 (Reject union default field values) - #142584 (Handle same-crate macro for borrowck semicolon suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 55d4364 + c79a6c0 commit 1b4aa42

File tree

41 files changed

+699
-452
lines changed

Some content is hidden

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

41 files changed

+699
-452
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,12 @@ impl Pat {
710710
}
711711
}
712712

713+
impl From<P<Pat>> for Pat {
714+
fn from(value: P<Pat>) -> Self {
715+
*value
716+
}
717+
}
718+
713719
/// A single field in a struct pattern.
714720
///
715721
/// Patterns like the fields of `Foo { x, ref y, ref mut z }`
@@ -1553,17 +1559,23 @@ impl Expr {
15531559
)
15541560
}
15551561

1556-
/// Creates a dummy `P<Expr>`.
1562+
/// Creates a dummy `Expr`.
15571563
///
15581564
/// Should only be used when it will be replaced afterwards or as a return value when an error was encountered.
1559-
pub fn dummy() -> P<Expr> {
1560-
P(Expr {
1565+
pub fn dummy() -> Expr {
1566+
Expr {
15611567
id: DUMMY_NODE_ID,
15621568
kind: ExprKind::Dummy,
15631569
span: DUMMY_SP,
15641570
attrs: ThinVec::new(),
15651571
tokens: None,
1566-
})
1572+
}
1573+
}
1574+
}
1575+
1576+
impl From<P<Expr>> for Expr {
1577+
fn from(value: P<Expr>) -> Self {
1578+
*value
15671579
}
15681580
}
15691581

@@ -2374,6 +2386,12 @@ impl Clone for Ty {
23742386
}
23752387
}
23762388

2389+
impl From<P<Ty>> for Ty {
2390+
fn from(value: P<Ty>) -> Self {
2391+
*value
2392+
}
2393+
}
2394+
23772395
impl Ty {
23782396
pub fn peel_refs(&self) -> &Self {
23792397
let mut final_ty = self;

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ pub trait MutVisitor: Sized + MutVisitorResult<Result = ()> {
168168
walk_flat_map_arm(self, arm)
169169
}
170170

171-
fn visit_pat(&mut self, p: &mut P<Pat>) {
171+
fn visit_pat(&mut self, p: &mut Pat) {
172172
walk_pat(self, p);
173173
}
174174

175175
fn visit_anon_const(&mut self, c: &mut AnonConst) {
176176
walk_anon_const(self, c);
177177
}
178178

179-
fn visit_expr(&mut self, e: &mut P<Expr>) {
179+
fn visit_expr(&mut self, e: &mut Expr) {
180180
walk_expr(self, e);
181181
}
182182

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

197-
fn visit_ty(&mut self, t: &mut P<Ty>) {
197+
fn visit_ty(&mut self, t: &mut Ty) {
198198
walk_ty(self, t);
199199
}
200200

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ ast_lowering_underscore_expr_lhs_assign =
179179
in expressions, `_` can only be used on the left-hand side of an assignment
180180
.label = `_` not allowed here
181181
182+
ast_lowering_union_default_field_values = unions cannot have default field values
183+
182184
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
183185
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
184186
using both label and output operands for inline assembly is unstable

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,10 @@ pub(crate) struct UseConstGenericArg {
475475
#[suggestion_part(code = "{other_args}")]
476476
pub call_args: Span,
477477
}
478+
479+
#[derive(Diagnostic)]
480+
#[diag(ast_lowering_union_default_field_values)]
481+
pub(crate) struct UnionWithDefault {
482+
#[primary_span]
483+
pub span: Span,
484+
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tracing::instrument;
1717

1818
use super::errors::{
1919
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
20+
UnionWithDefault,
2021
};
2122
use super::stability::{enabled_names, gate_unstable_abi};
2223
use super::{
@@ -316,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
316317
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
317318
|this| {
318319
this.arena.alloc_from_iter(
319-
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
320+
enum_definition.variants.iter().map(|x| this.lower_variant(i, x)),
320321
)
321322
},
322323
);
@@ -328,7 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
328329
generics,
329330
id,
330331
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
331-
|this| this.lower_variant_data(hir_id, struct_def),
332+
|this| this.lower_variant_data(hir_id, i, struct_def),
332333
);
333334
hir::ItemKind::Struct(ident, generics, struct_def)
334335
}
@@ -338,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
338339
generics,
339340
id,
340341
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
341-
|this| this.lower_variant_data(hir_id, vdata),
342+
|this| this.lower_variant_data(hir_id, i, vdata),
342343
);
343344
hir::ItemKind::Union(ident, generics, vdata)
344345
}
@@ -714,13 +715,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
714715
}
715716
}
716717

717-
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
718+
fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
718719
let hir_id = self.lower_node_id(v.id);
719720
self.lower_attrs(hir_id, &v.attrs, v.span);
720721
hir::Variant {
721722
hir_id,
722723
def_id: self.local_def_id(v.id),
723-
data: self.lower_variant_data(hir_id, &v.data),
724+
data: self.lower_variant_data(hir_id, item_kind, &v.data),
724725
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const_to_anon_const(e)),
725726
ident: self.lower_ident(v.ident),
726727
span: self.lower_span(v.span),
@@ -730,15 +731,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
730731
fn lower_variant_data(
731732
&mut self,
732733
parent_id: hir::HirId,
734+
item_kind: &ItemKind,
733735
vdata: &VariantData,
734736
) -> hir::VariantData<'hir> {
735737
match vdata {
736-
VariantData::Struct { fields, recovered } => hir::VariantData::Struct {
737-
fields: self
738+
VariantData::Struct { fields, recovered } => {
739+
let fields = self
738740
.arena
739-
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
740-
recovered: *recovered,
741-
},
741+
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f)));
742+
743+
if let ItemKind::Union(..) = item_kind {
744+
for field in &fields[..] {
745+
if let Some(default) = field.default {
746+
// Unions cannot derive `Default`, and it's not clear how to use default
747+
// field values of unions if that was supported. Therefore, blanket reject
748+
// trying to use field values with unions.
749+
if self.tcx.features().default_field_values() {
750+
self.dcx().emit_err(UnionWithDefault { span: default.span });
751+
} else {
752+
let _ = self.dcx().span_delayed_bug(
753+
default.span,
754+
"expected union default field values feature gate error but none \
755+
was produced",
756+
);
757+
}
758+
}
759+
}
760+
}
761+
762+
hir::VariantData::Struct { fields, recovered: *recovered }
763+
}
742764
VariantData::Tuple(fields, id) => {
743765
let ctor_id = self.lower_node_id(*id);
744766
self.alias_attrs(ctor_id, parent_id);

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
342342
}
343343
}
344344
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
345-
let sp = info
346-
.span
347-
.find_ancestor_in_same_ctxt(local_decl.source_info.span)
348-
.unwrap_or(info.span);
345+
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
349346
if info.tail_result_is_ignored {
350347
// #85581: If the first mutable borrow's scope contains
351348
// the second borrow, this suggestion isn't helpful.

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CfgEval<'_> {
155155

156156
impl MutVisitor for CfgEval<'_> {
157157
#[instrument(level = "trace", skip(self))]
158-
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
158+
fn visit_expr(&mut self, expr: &mut ast::Expr) {
159159
self.0.configure_expr(expr, false);
160160
mut_visit::walk_expr(self, expr);
161161
}

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use ast::HasAttrs;
2-
use ast::ptr::P;
32
use rustc_ast::mut_visit::MutVisitor;
43
use rustc_ast::visit::BoundKind;
54
use rustc_ast::{
@@ -378,11 +377,11 @@ struct TypeSubstitution<'a> {
378377
}
379378

380379
impl<'a> ast::mut_visit::MutVisitor for TypeSubstitution<'a> {
381-
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
380+
fn visit_ty(&mut self, ty: &mut ast::Ty) {
382381
if let Some(name) = ty.kind.is_simple_path()
383382
&& name == self.from_name
384383
{
385-
**ty = self.to_ty.clone();
384+
*ty = self.to_ty.clone();
386385
self.rewritten = true;
387386
} else {
388387
ast::mut_visit::walk_ty(self, ty);

compiler/rustc_expand/src/expand.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ impl InvocationCollectorNode for ast::Crate {
17681768
}
17691769
}
17701770

1771-
impl InvocationCollectorNode for P<ast::Ty> {
1771+
impl InvocationCollectorNode for ast::Ty {
17721772
type OutputTy = P<ast::Ty>;
17731773
const KIND: AstFragmentKind = AstFragmentKind::Ty;
17741774
fn to_annotatable(self) -> Annotatable {
@@ -1791,7 +1791,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
17911791
}
17921792
}
17931793

1794-
impl InvocationCollectorNode for P<ast::Pat> {
1794+
impl InvocationCollectorNode for ast::Pat {
17951795
type OutputTy = P<ast::Pat>;
17961796
const KIND: AstFragmentKind = AstFragmentKind::Pat;
17971797
fn to_annotatable(self) -> Annotatable {
@@ -1814,11 +1814,11 @@ impl InvocationCollectorNode for P<ast::Pat> {
18141814
}
18151815
}
18161816

1817-
impl InvocationCollectorNode for P<ast::Expr> {
1817+
impl InvocationCollectorNode for ast::Expr {
18181818
type OutputTy = P<ast::Expr>;
18191819
const KIND: AstFragmentKind = AstFragmentKind::Expr;
18201820
fn to_annotatable(self) -> Annotatable {
1821-
Annotatable::Expr(self)
1821+
Annotatable::Expr(P(self))
18221822
}
18231823
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
18241824
fragment.make_expr()
@@ -1955,37 +1955,37 @@ impl DummyAstNode for ast::Crate {
19551955
}
19561956
}
19571957

1958-
impl DummyAstNode for P<ast::Ty> {
1958+
impl DummyAstNode for ast::Ty {
19591959
fn dummy() -> Self {
1960-
P(ast::Ty {
1960+
ast::Ty {
19611961
id: DUMMY_NODE_ID,
19621962
kind: TyKind::Dummy,
19631963
span: Default::default(),
19641964
tokens: Default::default(),
1965-
})
1965+
}
19661966
}
19671967
}
19681968

1969-
impl DummyAstNode for P<ast::Pat> {
1969+
impl DummyAstNode for ast::Pat {
19701970
fn dummy() -> Self {
1971-
P(ast::Pat {
1971+
ast::Pat {
19721972
id: DUMMY_NODE_ID,
19731973
kind: PatKind::Wild,
19741974
span: Default::default(),
19751975
tokens: Default::default(),
1976-
})
1976+
}
19771977
}
19781978
}
19791979

1980-
impl DummyAstNode for P<ast::Expr> {
1980+
impl DummyAstNode for ast::Expr {
19811981
fn dummy() -> Self {
19821982
ast::Expr::dummy()
19831983
}
19841984
}
19851985

19861986
impl DummyAstNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag> {
19871987
fn dummy() -> Self {
1988-
AstNodeWrapper::new(ast::Expr::dummy(), MethodReceiverTag)
1988+
AstNodeWrapper::new(P(ast::Expr::dummy()), MethodReceiverTag)
19891989
}
19901990
}
19911991

@@ -2272,7 +2272,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22722272
}
22732273
}
22742274

2275-
fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
2275+
fn visit_node<Node: InvocationCollectorNode<OutputTy: Into<Node>> + DummyAstNode>(
22762276
&mut self,
22772277
node: &mut Node,
22782278
) {
@@ -2297,14 +2297,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22972297
*node = self
22982298
.collect_attr((attr, pos, derives), n.to_annotatable(), Node::KIND)
22992299
.make_ast::<Node>()
2300+
.into()
23002301
}
23012302
},
23022303
None if node.is_mac_call() => {
23032304
let n = mem::replace(node, Node::dummy());
23042305
let (mac, attrs, _) = n.take_mac_call();
23052306
self.check_attributes(&attrs, &mac);
23062307

2307-
*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>()
2308+
*node = self.collect_bang(mac, Node::KIND).make_ast::<Node>().into()
23082309
}
23092310
None if node.delegation().is_some() => unreachable!(),
23102311
None => {
@@ -2414,15 +2415,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
24142415
self.visit_node(node)
24152416
}
24162417

2417-
fn visit_ty(&mut self, node: &mut P<ast::Ty>) {
2418+
fn visit_ty(&mut self, node: &mut ast::Ty) {
24182419
self.visit_node(node)
24192420
}
24202421

2421-
fn visit_pat(&mut self, node: &mut P<ast::Pat>) {
2422+
fn visit_pat(&mut self, node: &mut ast::Pat) {
24222423
self.visit_node(node)
24232424
}
24242425

2425-
fn visit_expr(&mut self, node: &mut P<ast::Expr>) {
2426+
fn visit_expr(&mut self, node: &mut ast::Expr) {
24262427
// FIXME: Feature gating is performed inconsistently between `Expr` and `OptExpr`.
24272428
if let Some(attr) = node.attrs.first() {
24282429
self.cfg().maybe_emit_expr_attr_err(attr);

compiler/rustc_expand/src/placeholders.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ impl MutVisitor for PlaceholderExpander {
332332
}
333333
}
334334

335-
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
335+
fn visit_expr(&mut self, expr: &mut ast::Expr) {
336336
match expr.kind {
337-
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
337+
ast::ExprKind::MacCall(_) => *expr = *self.remove(expr.id).make_expr(),
338338
_ => walk_expr(self, expr),
339339
}
340340
}
@@ -399,16 +399,16 @@ impl MutVisitor for PlaceholderExpander {
399399
stmts
400400
}
401401

402-
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
402+
fn visit_pat(&mut self, pat: &mut ast::Pat) {
403403
match pat.kind {
404-
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
404+
ast::PatKind::MacCall(_) => *pat = *self.remove(pat.id).make_pat(),
405405
_ => walk_pat(self, pat),
406406
}
407407
}
408408

409-
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
409+
fn visit_ty(&mut self, ty: &mut ast::Ty) {
410410
match ty.kind {
411-
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
411+
ast::TyKind::MacCall(_) => *ty = *self.remove(ty.id).make_ty(),
412412
_ => walk_ty(self, ty),
413413
}
414414
}

0 commit comments

Comments
 (0)