Skip to content

Commit 77ec48f

Browse files
committed
Auto merge of #142644 - jhpratt:rollup-f2jed9t, r=jhpratt
Rollup of 14 pull requests Successful merges: - #141574 (impl `Default` for `array::IntoIter`) - #141608 (Add support for repetition to `proc_macro::quote`) - #142100 (rustdoc: make srcIndex no longer a global variable) - #142371 (avoid `&mut P<T>` in `visit_expr` etc methods) - #142517 (Windows: Use anonymous pipes in Command) - #142520 (alloc: less static mut + some cleanup) - #142588 (Generic ctx imprv) - #142605 (Don't unwrap in enzyme builds in case of missing llvm-config) - #142608 (Refresh module-level docs for `rustc_target::spec`) - #142618 (Lint about `console` calls in rustdoc JS) - #142620 (Remove a panicking branch in `BorrowedCursor::advance`) - #142631 (Dont suggest remove semi inside macro expansion for redundant semi lint) - #142632 (Update cargo) - #142635 (Temporarily add back -Zwasm-c-abi=spec) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 27eb269 + 3ec1451 commit 77ec48f

Some content is hidden

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

52 files changed

+908
-386
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_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_codegen_llvm/src/builder/autodiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn match_args_from_caller_to_enzyme<'ll>(
114114
let mul = unsafe {
115115
llvm::LLVMBuildMul(
116116
builder.llbuilder,
117-
cx.get_const_i64(elem_bytes_size),
117+
cx.get_const_int(cx.type_i64(), elem_bytes_size),
118118
next_outer_arg,
119119
UNNAMED,
120120
)
@@ -385,7 +385,7 @@ fn generate_enzyme_call<'ll>(
385385
if attrs.width > 1 {
386386
let enzyme_width = cx.create_metadata("enzyme_width".to_string()).unwrap();
387387
args.push(cx.get_metadata_value(enzyme_width));
388-
args.push(cx.get_const_i64(attrs.width as u64));
388+
args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
389389
}
390390

391391
let has_sret = has_sret(outer_fn);

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericCx<'ll, CX> {
9999
type DIVariable = &'ll llvm::debuginfo::DIVariable;
100100
}
101101

102-
impl<'ll> CodegenCx<'ll, '_> {
102+
impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
103103
pub(crate) fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
104104
let len = u64::try_from(elts.len()).expect("LLVMConstArray2 elements len overflow");
105105
unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) }
106106
}
107107

108108
pub(crate) fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
109-
bytes_in_context(self.llcx, bytes)
109+
bytes_in_context(self.llcx(), bytes)
110110
}
111111

112112
pub(crate) fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,8 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
679679
llvm::LLVMMetadataAsValue(self.llcx(), metadata)
680680
}
681681

682-
// FIXME(autodiff): We should split `ConstCodegenMethods` to pull the reusable parts
683-
// onto a trait that is also implemented for GenericCx.
684-
pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value {
685-
let ty = unsafe { llvm::LLVMInt64TypeInContext(self.llcx()) };
686-
unsafe { llvm::LLVMConstInt(ty, n, llvm::False) }
682+
pub(crate) fn get_const_int(&self, ty: &'ll Type, val: u64) -> &'ll Value {
683+
unsafe { llvm::LLVMConstInt(ty, val, llvm::False) }
687684
}
688685

689686
pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> {

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
}

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ lint_redundant_semicolons =
738738
[true] semicolons
739739
*[false] semicolon
740740
}
741-
.suggestion = remove {$multiple ->
741+
742+
lint_redundant_semicolons_suggestion = remove {$multiple_semicolons ->
742743
[true] these semicolons
743744
*[false] this semicolon
744745
}

compiler/rustc_lint/src/lints.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,16 @@ pub(crate) struct PassByValueDiag {
15381538
#[diag(lint_redundant_semicolons)]
15391539
pub(crate) struct RedundantSemicolonsDiag {
15401540
pub multiple: bool,
1541-
#[suggestion(code = "", applicability = "maybe-incorrect")]
1542-
pub suggestion: Span,
1541+
#[subdiagnostic]
1542+
pub suggestion: Option<RedundantSemicolonsSuggestion>,
1543+
}
1544+
1545+
#[derive(Subdiagnostic)]
1546+
#[suggestion(lint_redundant_semicolons_suggestion, code = "", applicability = "maybe-incorrect")]
1547+
pub(crate) struct RedundantSemicolonsSuggestion {
1548+
pub multiple_semicolons: bool,
1549+
#[primary_span]
1550+
pub span: Span,
15431551
}
15441552

15451553
// traits.rs

compiler/rustc_lint/src/redundant_semicolon.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::{Block, StmtKind};
22
use rustc_session::{declare_lint, declare_lint_pass};
33
use rustc_span::Span;
44

5-
use crate::lints::RedundantSemicolonsDiag;
5+
use crate::lints::{RedundantSemicolonsDiag, RedundantSemicolonsSuggestion};
66
use crate::{EarlyContext, EarlyLintPass, LintContext};
77

88
declare_lint! {
@@ -44,16 +44,21 @@ impl EarlyLintPass for RedundantSemicolons {
4444

4545
fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
4646
if let Some((span, multiple)) = seq.take() {
47-
// FIXME: Find a better way of ignoring the trailing
48-
// semicolon from macro expansion
4947
if span == rustc_span::DUMMY_SP {
5048
return;
5149
}
5250

51+
// Ignore redundant semicolons inside macro expansion.(issue #142143)
52+
let suggestion = if span.from_expansion() {
53+
None
54+
} else {
55+
Some(RedundantSemicolonsSuggestion { multiple_semicolons: multiple, span })
56+
};
57+
5358
cx.emit_span_lint(
5459
REDUNDANT_SEMICOLONS,
5560
span,
56-
RedundantSemicolonsDiag { multiple, suggestion: span },
61+
RedundantSemicolonsDiag { multiple, suggestion },
5762
);
5863
}
5964
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,7 @@ impl<'a> CondChecker<'a> {
40874087
}
40884088

40894089
impl MutVisitor for CondChecker<'_> {
4090-
fn visit_expr(&mut self, e: &mut P<Expr>) {
4090+
fn visit_expr(&mut self, e: &mut Expr) {
40914091
self.depth += 1;
40924092
use ForbiddenLetReason::*;
40934093

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ impl<'a> Parser<'a> {
10941094
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
10951095
struct AddMut(bool);
10961096
impl MutVisitor for AddMut {
1097-
fn visit_pat(&mut self, pat: &mut P<Pat>) {
1097+
fn visit_pat(&mut self, pat: &mut Pat) {
10981098
if let PatKind::Ident(BindingMode(ByRef::No, m @ Mutability::Not), ..) =
10991099
&mut pat.kind
11001100
{

0 commit comments

Comments
 (0)