Skip to content

Commit e8e911a

Browse files
committed
Auto merge of rust-lang#125565 - jhpratt:rollup-vddsp1p, r=jhpratt
Rollup of 7 pull requests Successful merges: - rust-lang#125307 (tidy: stop special-casing tests/ui entry limit) - rust-lang#125375 (Create a triagebot ping group for Rust for Linux) - rust-lang#125433 (A small diagnostic improvement for dropping_copy_types) - rust-lang#125508 (Stop SRoA'ing `DynMetadata` in MIR) - rust-lang#125530 (cleanup dependence of `ExtCtxt` in transcribe when macro expansion) - rust-lang#125544 (Also mention my-self for other check-cfg docs changes) - rust-lang#125546 (Try to not reinstall tools in mingw CI) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd184cc + e459cc4 commit e8e911a

19 files changed

+248
-94
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ fn expand_macro<'cx>(
223223
let arm_span = rhses[i].span();
224224

225225
// rhs has holes ( `$id` and `$(...)` that need filled)
226-
let tts = match transcribe(cx, &named_matches, rhs, rhs_span, transparency) {
226+
let id = cx.current_expansion.id;
227+
let tts = match transcribe(psess, &named_matches, rhs, rhs_span, transparency, id) {
227228
Ok(tts) => tts,
228229
Err(err) => {
229230
let guar = err.emit();

compiler/rustc_expand/src/mbe/transcribe.rs

+29-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::base::ExtCtxt;
21
use crate::errors::{
32
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
43
NoSyntaxVarsExprRepeat, VarStillRepeating,
@@ -9,12 +8,13 @@ use rustc_ast::mut_visit::{self, MutVisitor};
98
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
109
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
1110
use rustc_data_structures::fx::FxHashMap;
12-
use rustc_errors::{pluralize, Diag, PResult};
11+
use rustc_errors::{pluralize, Diag, DiagCtxt, PResult};
1312
use rustc_parse::parser::ParseNtResult;
1413
use rustc_span::hygiene::{LocalExpnId, Transparency};
1514
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
1615
use rustc_span::{with_metavar_spans, Span, SyntaxContext};
1716

17+
use rustc_session::parse::ParseSess;
1818
use smallvec::{smallvec, SmallVec};
1919
use std::mem;
2020

@@ -99,11 +99,12 @@ impl<'a> Iterator for Frame<'a> {
9999
///
100100
/// Along the way, we do some additional error checking.
101101
pub(super) fn transcribe<'a>(
102-
cx: &ExtCtxt<'a>,
102+
psess: &'a ParseSess,
103103
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
104104
src: &mbe::Delimited,
105105
src_span: DelimSpan,
106106
transparency: Transparency,
107+
expand_id: LocalExpnId,
107108
) -> PResult<'a, TokenStream> {
108109
// Nothing for us to transcribe...
109110
if src.tts.is_empty() {
@@ -137,8 +138,9 @@ pub(super) fn transcribe<'a>(
137138
// again, and we are done transcribing.
138139
let mut result: Vec<TokenTree> = Vec::new();
139140
let mut result_stack = Vec::new();
140-
let mut marker = Marker(cx.current_expansion.id, transparency, Default::default());
141+
let mut marker = Marker(expand_id, transparency, Default::default());
141142

143+
let dcx = &psess.dcx;
142144
loop {
143145
// Look at the last frame on the stack.
144146
// If it still has a TokenTree we have not looked at yet, use that tree.
@@ -201,19 +203,17 @@ pub(super) fn transcribe<'a>(
201203
seq @ mbe::TokenTree::Sequence(_, seq_rep) => {
202204
match lockstep_iter_size(seq, interp, &repeats) {
203205
LockstepIterSize::Unconstrained => {
204-
return Err(cx
205-
.dcx()
206-
.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
206+
return Err(dcx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
207207
}
208208

209209
LockstepIterSize::Contradiction(msg) => {
210210
// FIXME: this really ought to be caught at macro definition time... It
211211
// happens when two meta-variables are used in the same repetition in a
212212
// sequence, but they come from different sequence matchers and repeat
213213
// different amounts.
214-
return Err(cx
215-
.dcx()
216-
.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
214+
return Err(
215+
dcx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg })
216+
);
217217
}
218218

219219
LockstepIterSize::Constraint(len, _) => {
@@ -227,9 +227,7 @@ pub(super) fn transcribe<'a>(
227227
// FIXME: this really ought to be caught at macro definition
228228
// time... It happens when the Kleene operator in the matcher and
229229
// the body for the same meta-variable do not match.
230-
return Err(cx
231-
.dcx()
232-
.create_err(MustRepeatOnce { span: sp.entire() }));
230+
return Err(dcx.create_err(MustRepeatOnce { span: sp.entire() }));
233231
}
234232
} else {
235233
// 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -274,7 +272,7 @@ pub(super) fn transcribe<'a>(
274272
MatchedSingle(ParseNtResult::Tt(tt)) => {
275273
// `tt`s are emitted into the output stream directly as "raw tokens",
276274
// without wrapping them into groups.
277-
maybe_use_metavar_location(cx, &stack, sp, tt, &mut marker)
275+
maybe_use_metavar_location(psess, &stack, sp, tt, &mut marker)
278276
}
279277
MatchedSingle(ParseNtResult::Ident(ident, is_raw)) => {
280278
marker.visit_span(&mut sp);
@@ -295,7 +293,7 @@ pub(super) fn transcribe<'a>(
295293
}
296294
MatchedSeq(..) => {
297295
// We were unable to descend far enough. This is an error.
298-
return Err(cx.dcx().create_err(VarStillRepeating { span: sp, ident }));
296+
return Err(dcx.create_err(VarStillRepeating { span: sp, ident }));
299297
}
300298
};
301299
result.push(tt)
@@ -314,7 +312,7 @@ pub(super) fn transcribe<'a>(
314312

315313
// Replace meta-variable expressions with the result of their expansion.
316314
mbe::TokenTree::MetaVarExpr(sp, expr) => {
317-
transcribe_metavar_expr(cx, expr, interp, &mut marker, &repeats, &mut result, sp)?;
315+
transcribe_metavar_expr(dcx, expr, interp, &mut marker, &repeats, &mut result, sp)?;
318316
}
319317

320318
// If we are entering a new delimiter, we push its contents to the `stack` to be
@@ -374,7 +372,7 @@ pub(super) fn transcribe<'a>(
374372
/// combine with each other and not with tokens outside of the sequence.
375373
/// - The metavariable span comes from a different crate, then we prefer the more local span.
376374
fn maybe_use_metavar_location(
377-
cx: &ExtCtxt<'_>,
375+
psess: &ParseSess,
378376
stack: &[Frame<'_>],
379377
mut metavar_span: Span,
380378
orig_tt: &TokenTree,
@@ -412,7 +410,7 @@ fn maybe_use_metavar_location(
412410
&& insert(mspans, dspan.entire(), metavar_span)
413411
}),
414412
};
415-
if no_collision || cx.source_map().is_imported(metavar_span) {
413+
if no_collision || psess.source_map().is_imported(metavar_span) {
416414
return orig_tt.clone();
417415
}
418416

@@ -573,7 +571,7 @@ fn lockstep_iter_size(
573571
/// * `[ $( ${count(foo, 1)} ),* ]` will return an error because `${count(foo, 1)}` is
574572
/// declared inside a single repetition and the index `1` implies two nested repetitions.
575573
fn count_repetitions<'a>(
576-
cx: &ExtCtxt<'a>,
574+
dcx: &'a DiagCtxt,
577575
depth_user: usize,
578576
mut matched: &NamedMatch,
579577
repeats: &[(usize, usize)],
@@ -610,7 +608,7 @@ fn count_repetitions<'a>(
610608
.and_then(|el| el.checked_sub(repeats.len()))
611609
.unwrap_or_default();
612610
if depth_user > depth_max {
613-
return Err(out_of_bounds_err(cx, depth_max + 1, sp.entire(), "count"));
611+
return Err(out_of_bounds_err(dcx, depth_max + 1, sp.entire(), "count"));
614612
}
615613

616614
// `repeats` records all of the nested levels at which we are currently
@@ -626,15 +624,15 @@ fn count_repetitions<'a>(
626624
}
627625

628626
if let MatchedSingle(_) = matched {
629-
return Err(cx.dcx().create_err(CountRepetitionMisplaced { span: sp.entire() }));
627+
return Err(dcx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
630628
}
631629

632630
count(depth_user, depth_max, matched)
633631
}
634632

635633
/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]
636634
fn matched_from_ident<'ctx, 'interp, 'rslt>(
637-
cx: &ExtCtxt<'ctx>,
635+
dcx: &'ctx DiagCtxt,
638636
ident: Ident,
639637
interp: &'interp FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
640638
) -> PResult<'ctx, &'rslt NamedMatch>
@@ -643,12 +641,12 @@ where
643641
{
644642
let span = ident.span;
645643
let key = MacroRulesNormalizedIdent::new(ident);
646-
interp.get(&key).ok_or_else(|| cx.dcx().create_err(MetaVarExprUnrecognizedVar { span, key }))
644+
interp.get(&key).ok_or_else(|| dcx.create_err(MetaVarExprUnrecognizedVar { span, key }))
647645
}
648646

649647
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
650648
/// example, index(999999) in an repetition of only three elements.
651-
fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) -> Diag<'a> {
649+
fn out_of_bounds_err<'a>(dcx: &'a DiagCtxt, max: usize, span: Span, ty: &str) -> Diag<'a> {
652650
let msg = if max == 0 {
653651
format!(
654652
"meta-variable expression `{ty}` with depth parameter \
@@ -660,11 +658,11 @@ fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) ->
660658
must be less than {max}"
661659
)
662660
};
663-
cx.dcx().struct_span_err(span, msg)
661+
dcx.struct_span_err(span, msg)
664662
}
665663

666664
fn transcribe_metavar_expr<'a>(
667-
cx: &ExtCtxt<'a>,
665+
dcx: &'a DiagCtxt,
668666
expr: &MetaVarExpr,
669667
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
670668
marker: &mut Marker,
@@ -679,8 +677,8 @@ fn transcribe_metavar_expr<'a>(
679677
};
680678
match *expr {
681679
MetaVarExpr::Count(original_ident, depth) => {
682-
let matched = matched_from_ident(cx, original_ident, interp)?;
683-
let count = count_repetitions(cx, depth, matched, repeats, sp)?;
680+
let matched = matched_from_ident(dcx, original_ident, interp)?;
681+
let count = count_repetitions(dcx, depth, matched, repeats, sp)?;
684682
let tt = TokenTree::token_alone(
685683
TokenKind::lit(token::Integer, sym::integer(count), None),
686684
visited_span(),
@@ -689,7 +687,7 @@ fn transcribe_metavar_expr<'a>(
689687
}
690688
MetaVarExpr::Ignore(original_ident) => {
691689
// Used to ensure that `original_ident` is present in the LHS
692-
let _ = matched_from_ident(cx, original_ident, interp)?;
690+
let _ = matched_from_ident(dcx, original_ident, interp)?;
693691
}
694692
MetaVarExpr::Index(depth) => match repeats.iter().nth_back(depth) {
695693
Some((index, _)) => {
@@ -698,7 +696,7 @@ fn transcribe_metavar_expr<'a>(
698696
visited_span(),
699697
));
700698
}
701-
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "index")),
699+
None => return Err(out_of_bounds_err(dcx, repeats.len(), sp.entire(), "index")),
702700
},
703701
MetaVarExpr::Len(depth) => match repeats.iter().nth_back(depth) {
704702
Some((_, length)) => {
@@ -707,7 +705,7 @@ fn transcribe_metavar_expr<'a>(
707705
visited_span(),
708706
));
709707
}
710-
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "len")),
708+
None => return Err(out_of_bounds_err(dcx, repeats.len(), sp.entire(), "len")),
711709
},
712710
}
713711
Ok(())

compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ lint_drop_trait_constraints =
233233
lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
234234
.label = argument has type `{$arg_ty}`
235235
.note = use `let _ = ...` to ignore the expression or result
236+
.suggestion = use `let _ = ...` to ignore the expression or result
236237
237238
lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
238239
.label = argument has type `{$arg_ty}`

compiler/rustc_lint/src/drop_forget_useless.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use rustc_hir::{Arm, Expr, ExprKind, Node};
1+
use rustc_hir::{Arm, Expr, ExprKind, Node, StmtKind};
22
use rustc_middle::ty;
33
use rustc_session::{declare_lint, declare_lint_pass};
44
use rustc_span::sym;
55

66
use crate::{
77
lints::{
8-
DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
9-
UndroppedManuallyDropsSuggestion,
8+
DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag,
9+
UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion,
1010
},
1111
LateContext, LateLintPass, LintContext,
1212
};
@@ -164,10 +164,23 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
164164
);
165165
}
166166
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
167+
let sugg = if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
168+
&& let Node::Stmt(stmt) = node
169+
&& let StmtKind::Semi(e) = stmt.kind
170+
&& e.hir_id == expr.hir_id
171+
{
172+
DropCopySuggestion::Suggestion {
173+
start_span: expr.span.shrink_to_lo().until(arg.span),
174+
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
175+
}
176+
} else {
177+
DropCopySuggestion::Note
178+
};
179+
167180
cx.emit_span_lint(
168181
DROPPING_COPY_TYPES,
169182
expr.span,
170-
DropCopyDiag { arg_ty, label: arg.span },
183+
DropCopyDiag { arg_ty, label: arg.span, sugg },
171184
);
172185
}
173186
sym::mem_forget if is_copy => {

compiler/rustc_lint/src/lints.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,25 @@ pub struct DropRefDiag<'a> {
677677

678678
#[derive(LintDiagnostic)]
679679
#[diag(lint_dropping_copy_types)]
680-
#[note]
681680
pub struct DropCopyDiag<'a> {
682681
pub arg_ty: Ty<'a>,
683682
#[label]
684683
pub label: Span,
684+
#[subdiagnostic]
685+
pub sugg: DropCopySuggestion,
686+
}
687+
688+
#[derive(Subdiagnostic)]
689+
pub enum DropCopySuggestion {
690+
#[note(lint_note)]
691+
Note,
692+
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
693+
Suggestion {
694+
#[suggestion_part(code = "let _ = ")]
695+
start_span: Span,
696+
#[suggestion_part(code = "")]
697+
end_span: Span,
698+
},
685699
}
686700

687701
#[derive(LintDiagnostic)]

compiler/rustc_mir_transform/src/sroa.rs

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ fn escaping_locals<'tcx>(
7070
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
7171
return true;
7272
}
73+
if Some(def.did()) == tcx.lang_items().dyn_metadata() {
74+
// codegen wants to see the `DynMetadata<T>`,
75+
// not the inner reference-to-opaque-type.
76+
return true;
77+
}
7378
// We already excluded unions and enums, so this ADT must have one variant
7479
let variant = def.variant(FIRST_VARIANT);
7580
if variant.fields.len() > 1 {

src/ci/scripts/install-mingw.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ if isWindows; then
3939
esac
4040

4141
if [[ "${CUSTOM_MINGW:-0}" == 0 ]]; then
42-
pacboy -S --noconfirm toolchain:p
43-
# According to the comment in the Windows part of install-clang.sh, in the future we might
44-
# want to do this instead:
45-
# pacboy -S --noconfirm clang:p ...
42+
pacman -S --noconfirm --needed mingw-w64-$arch-toolchain mingw-w64-$arch-cmake \
43+
mingw-w64-$arch-gcc \
44+
mingw-w64-$arch-python # the python package is actually for python3
45+
ciCommandAddPath "$(ciCheckoutPath)/msys2/mingw${bits}/bin"
4646
else
4747
mingw_dir="mingw${bits}"
4848

src/ci/scripts/install-msys2.sh

+2-34
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ IFS=$'\n\t'
77

88
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
99
if isWindows; then
10+
ciCommandAddPath "c:/msys64/usr/bin"
11+
1012
# Detect the native Python version installed on the agent. On GitHub
1113
# Actions, the C:\hostedtoolcache\windows\Python directory contains a
1214
# subdirectory for each installed Python version.
@@ -24,38 +26,4 @@ if isWindows; then
2426
fi
2527
ciCommandAddPath "C:\\hostedtoolcache\\windows\\Python\\${native_python_version}\\x64"
2628
ciCommandAddPath "C:\\hostedtoolcache\\windows\\Python\\${native_python_version}\\x64\\Scripts"
27-
28-
# Install pacboy for easily installing packages
29-
pacman -S --noconfirm pactoys
30-
31-
# Remove these pre-installed tools so we can't accidentally use them, because we are using the
32-
# MSYS2 setup action versions instead. Because `rm -r`-ing them is slow, we mv them off path
33-
# instead.
34-
# Remove pre-installed version of MSYS2
35-
echo "Cleaning up existing tools in PATH"
36-
notpath="/c/NOT/ON/PATH/"
37-
mkdir --parents "$notpath"
38-
mv -t "$notpath" "/c/msys64/"
39-
# Remove Strawberry Perl, which contains a version of mingw
40-
mv -t "$notpath" "/c/Strawberry/"
41-
# Remove these other copies of mingw, I don't even know where they come from.
42-
mv -t "$notpath" "/c/mingw64/"
43-
mv -t "$notpath" "/c/mingw32/"
44-
echo "Finished cleaning up tools in PATH"
45-
46-
if isKnownToBeMingwBuild; then
47-
# Use the mingw version of CMake for mingw builds.
48-
# However, the MSVC build needs native CMake, as it fails with the mingw one.
49-
# Delete native CMake
50-
rm -r "/c/Program Files/CMake/"
51-
# Install mingw-w64-$arch-cmake
52-
pacboy -S --noconfirm cmake:p
53-
54-
# It would be nice to use MSYS's git in MinGW builds so that it's tested and known to
55-
# work. But it makes everything extremely slow, so it's commented out for now.
56-
# # Delete Windows-Git
57-
# rm -r "/c/Program Files/Git/"
58-
# # Install MSYS2 git
59-
# pacman -S --noconfirm git
60-
fi
6129
fi

0 commit comments

Comments
 (0)