Skip to content

Commit 40bb7d1

Browse files
authored
Merge pull request #4236 from RalfJung/rustup
Rustup
2 parents 3a0ef6b + f24ea85 commit 40bb7d1

File tree

314 files changed

+5928
-1508
lines changed

Some content is hidden

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

314 files changed

+5928
-1508
lines changed

Cargo.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ dependencies = [
547547
"termize",
548548
"tokio",
549549
"toml 0.7.8",
550-
"ui_test 0.26.5",
550+
"ui_test 0.29.2",
551551
"walkdir",
552552
]
553553

@@ -2021,7 +2021,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
20212021
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
20222022
dependencies = [
20232023
"cfg-if",
2024-
"windows-targets 0.48.5",
2024+
"windows-targets 0.52.6",
20252025
]
20262026

20272027
[[package]]
@@ -5488,9 +5488,9 @@ dependencies = [
54885488

54895489
[[package]]
54905490
name = "ui_test"
5491-
version = "0.26.5"
5491+
version = "0.28.0"
54925492
source = "registry+https://github.com/rust-lang/crates.io-index"
5493-
checksum = "32ee4c40e5a5f9fa6864ff976473e5d6a6e9884b6ce68b40690d9f87e1994c83"
5493+
checksum = "7484683d60d50ca1d1b6433c3dbf6c5ad71d20387acdcfb16fe79573f3fba576"
54945494
dependencies = [
54955495
"annotate-snippets 0.11.5",
54965496
"anyhow",
@@ -5514,9 +5514,9 @@ dependencies = [
55145514

55155515
[[package]]
55165516
name = "ui_test"
5517-
version = "0.28.0"
5517+
version = "0.29.2"
55185518
source = "registry+https://github.com/rust-lang/crates.io-index"
5519-
checksum = "7484683d60d50ca1d1b6433c3dbf6c5ad71d20387acdcfb16fe79573f3fba576"
5519+
checksum = "1211b1111c752c73b33073d2958072be08825fd97c9ab4d83444da361a06634b"
55205520
dependencies = [
55215521
"annotate-snippets 0.11.5",
55225522
"anyhow",

compiler/rustc_ast_lowering/src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1513,16 +1513,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15131513
}))
15141514
}
15151515

1516-
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
1516+
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
15171517
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1518-
PatKind::Ident(_, ident, _) => self.lower_ident(ident),
1519-
PatKind::Wild => Ident::new(kw::Underscore, self.lower_span(param.pat.span)),
1518+
PatKind::Ident(_, ident, _) => {
1519+
if ident.name != kw::Empty {
1520+
Some(self.lower_ident(ident))
1521+
} else {
1522+
None
1523+
}
1524+
}
1525+
PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
15201526
_ => {
15211527
self.dcx().span_delayed_bug(
15221528
param.pat.span,
15231529
"non-ident/wild param pat must trigger an error",
15241530
);
1525-
Ident::new(kw::Empty, self.lower_span(param.pat.span))
1531+
None
15261532
}
15271533
}))
15281534
}

compiler/rustc_ast_passes/src/ast_validation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ impl<'a> AstValidator<'a> {
336336
sym::allow,
337337
sym::cfg,
338338
sym::cfg_attr,
339+
sym::cfg_attr_trace,
339340
sym::deny,
340341
sym::expect,
341342
sym::forbid,

compiler/rustc_ast_pretty/src/pprust/state.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
578578
let mut printed = false;
579579
for attr in attrs {
580580
if attr.style == kind {
581-
self.print_attribute_inline(attr, is_inline);
582-
if is_inline {
583-
self.nbsp();
581+
if self.print_attribute_inline(attr, is_inline) {
582+
if is_inline {
583+
self.nbsp();
584+
}
585+
printed = true;
584586
}
585-
printed = true;
586587
}
587588
}
588589
if printed && trailing_hardbreak && !is_inline {
@@ -591,7 +592,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
591592
printed
592593
}
593594

594-
fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) {
595+
fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> bool {
596+
if attr.has_name(sym::cfg_attr_trace) {
597+
// It's not a valid identifier, so avoid printing it
598+
// to keep the printed code reasonably parse-able.
599+
return false;
600+
}
595601
if !is_inline {
596602
self.hardbreak_if_not_bol();
597603
}
@@ -610,6 +616,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
610616
self.hardbreak()
611617
}
612618
}
619+
true
613620
}
614621

615622
fn print_attr_item(&mut self, item: &ast::AttrItem, span: Span) {
@@ -2047,7 +2054,7 @@ impl<'a> State<'a> {
20472054
}
20482055

20492056
fn print_attribute(&mut self, attr: &ast::Attribute) {
2050-
self.print_attribute_inline(attr, false)
2057+
self.print_attribute_inline(attr, false);
20512058
}
20522059

20532060
fn print_meta_list_item(&mut self, item: &ast::MetaItemInner) {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2514,12 +2514,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
25142514
let ty::Tuple(params) = tupled_params.kind() else { return };
25152515

25162516
// Find the first argument with a matching type, get its name
2517-
let Some((_, this_name)) =
2518-
params.iter().zip(tcx.hir_body_param_names(closure.body)).find(|(param_ty, name)| {
2517+
let Some(this_name) = params.iter().zip(tcx.hir_body_param_names(closure.body)).find_map(
2518+
|(param_ty, name)| {
25192519
// FIXME: also support deref for stuff like `Rc` arguments
2520-
param_ty.peel_refs() == local_ty && name != &Ident::empty()
2521-
})
2522-
else {
2520+
if param_ty.peel_refs() == local_ty { name } else { None }
2521+
},
2522+
) else {
25232523
return;
25242524
};
25252525

@@ -3787,7 +3787,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
37873787
method_args,
37883788
*fn_span,
37893789
call_source.from_hir_call(),
3790-
Some(self.infcx.tcx.fn_arg_names(method_did)[0]),
3790+
self.infcx.tcx.fn_arg_names(method_did)[0],
37913791
)
37923792
{
37933793
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10291029
method_args,
10301030
*fn_span,
10311031
call_source.from_hir_call(),
1032-
Some(self.infcx.tcx.fn_arg_names(method_did)[0]),
1032+
self.infcx.tcx.fn_arg_names(method_did)[0],
10331033
);
10341034

10351035
return FnSelfUse {

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub(crate) struct CoverageSpan {
146146
#[derive(Clone, Debug, Default)]
147147
pub(crate) struct Regions {
148148
pub(crate) code_regions: Vec<CodeRegion>,
149+
pub(crate) expansion_regions: Vec<ExpansionRegion>,
149150
pub(crate) branch_regions: Vec<BranchRegion>,
150151
pub(crate) mcdc_branch_regions: Vec<MCDCBranchRegion>,
151152
pub(crate) mcdc_decision_regions: Vec<MCDCDecisionRegion>,
@@ -154,10 +155,16 @@ pub(crate) struct Regions {
154155
impl Regions {
155156
/// Returns true if none of this structure's tables contain any regions.
156157
pub(crate) fn has_no_regions(&self) -> bool {
157-
let Self { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
158-
self;
158+
let Self {
159+
code_regions,
160+
expansion_regions,
161+
branch_regions,
162+
mcdc_branch_regions,
163+
mcdc_decision_regions,
164+
} = self;
159165

160166
code_regions.is_empty()
167+
&& expansion_regions.is_empty()
161168
&& branch_regions.is_empty()
162169
&& mcdc_branch_regions.is_empty()
163170
&& mcdc_decision_regions.is_empty()
@@ -172,6 +179,14 @@ pub(crate) struct CodeRegion {
172179
pub(crate) counter: Counter,
173180
}
174181

182+
/// Must match the layout of `LLVMRustCoverageExpansionRegion`.
183+
#[derive(Clone, Debug)]
184+
#[repr(C)]
185+
pub(crate) struct ExpansionRegion {
186+
pub(crate) cov_span: CoverageSpan,
187+
pub(crate) expanded_file_id: u32,
188+
}
189+
175190
/// Must match the layout of `LLVMRustCoverageBranchRegion`.
176191
#[derive(Clone, Debug)]
177192
#[repr(C)]

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ pub(crate) fn write_function_mappings_to_buffer(
6363
expressions: &[ffi::CounterExpression],
6464
regions: &ffi::Regions,
6565
) -> Vec<u8> {
66-
let ffi::Regions { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
67-
regions;
66+
let ffi::Regions {
67+
code_regions,
68+
expansion_regions,
69+
branch_regions,
70+
mcdc_branch_regions,
71+
mcdc_decision_regions,
72+
} = regions;
73+
74+
// SAFETY:
75+
// - All types are FFI-compatible and have matching representations in Rust/C++.
76+
// - For pointer/length pairs, the pointer and length come from the same vector or slice.
77+
// - C++ code does not retain any pointers after the call returns.
6878
llvm::build_byte_buffer(|buffer| unsafe {
6979
llvm::LLVMRustCoverageWriteFunctionMappingsToBuffer(
7080
virtual_file_mapping.as_ptr(),
@@ -73,6 +83,8 @@ pub(crate) fn write_function_mappings_to_buffer(
7383
expressions.len(),
7484
code_regions.as_ptr(),
7585
code_regions.len(),
86+
expansion_regions.as_ptr(),
87+
expansion_regions.len(),
7688
branch_regions.as_ptr(),
7789
branch_regions.len(),
7890
mcdc_branch_regions.as_ptr(),

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,22 @@ fn fill_region_tables<'tcx>(
120120
// Associate that global file ID with a local file ID for this function.
121121
let local_file_id = covfun.virtual_file_mapping.local_id_for_global(global_file_id);
122122

123-
let ffi::Regions { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
124-
&mut covfun.regions;
125-
126-
let make_cov_span =
127-
|span: Span| spans::make_coverage_span(local_file_id, source_map, &source_file, span);
123+
// In rare cases, _all_ of a function's spans are discarded, and coverage
124+
// codegen needs to handle that gracefully to avoid #133606.
125+
// It's hard for tests to trigger this organically, so instead we set
126+
// `-Zcoverage-options=discard-all-spans-in-codegen` to force it to occur.
128127
let discard_all = tcx.sess.coverage_discard_all_spans_in_codegen();
128+
let make_coords = |span: Span| {
129+
if discard_all { None } else { spans::make_coords(source_map, &source_file, span) }
130+
};
131+
132+
let ffi::Regions {
133+
code_regions,
134+
expansion_regions: _, // FIXME(Zalathar): Fill out support for expansion regions
135+
branch_regions,
136+
mcdc_branch_regions,
137+
mcdc_decision_regions,
138+
} = &mut covfun.regions;
129139

130140
// For each counter/region pair in this function+file, convert it to a
131141
// form suitable for FFI.
@@ -140,17 +150,8 @@ fn fill_region_tables<'tcx>(
140150
ffi::Counter::from_term(term)
141151
};
142152

143-
// Convert the `Span` into coordinates that we can pass to LLVM, or
144-
// discard the span if conversion fails. In rare, cases _all_ of a
145-
// function's spans are discarded, and the rest of coverage codegen
146-
// needs to handle that gracefully to avoid a repeat of #133606.
147-
// We don't have a good test case for triggering that organically, so
148-
// instead we set `-Zcoverage-options=discard-all-spans-in-codegen`
149-
// to force it to occur.
150-
let Some(cov_span) = make_cov_span(span) else { continue };
151-
if discard_all {
152-
continue;
153-
}
153+
let Some(coords) = make_coords(span) else { continue };
154+
let cov_span = coords.make_coverage_span(local_file_id);
154155

155156
match *kind {
156157
MappingKind::Code { bcb } => {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs

+31-14
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,40 @@ use tracing::debug;
55
use crate::coverageinfo::ffi;
66
use crate::coverageinfo::mapgen::LocalFileId;
77

8+
/// Line and byte-column coordinates of a source code span within some file.
9+
/// The file itself must be tracked separately.
10+
#[derive(Clone, Copy, Debug)]
11+
pub(crate) struct Coords {
12+
/// 1-based starting line of the source code span.
13+
pub(crate) start_line: u32,
14+
/// 1-based starting column (in bytes) of the source code span.
15+
pub(crate) start_col: u32,
16+
/// 1-based ending line of the source code span.
17+
pub(crate) end_line: u32,
18+
/// 1-based ending column (in bytes) of the source code span. High bit must be unset.
19+
pub(crate) end_col: u32,
20+
}
21+
22+
impl Coords {
23+
/// Attaches a local file ID to these coordinates to produce an `ffi::CoverageSpan`.
24+
pub(crate) fn make_coverage_span(&self, local_file_id: LocalFileId) -> ffi::CoverageSpan {
25+
let &Self { start_line, start_col, end_line, end_col } = self;
26+
let file_id = local_file_id.as_u32();
27+
ffi::CoverageSpan { file_id, start_line, start_col, end_line, end_col }
28+
}
29+
}
30+
831
/// Converts the span into its start line and column, and end line and column.
932
///
1033
/// Line numbers and column numbers are 1-based. Unlike most column numbers emitted by
1134
/// the compiler, these column numbers are denoted in **bytes**, because that's what
1235
/// LLVM's `llvm-cov` tool expects to see in coverage maps.
1336
///
14-
/// Returns `None` if the conversion failed for some reason. This shouldn't happen,
37+
/// Returns `None` if the conversion failed for some reason. This should be uncommon,
1538
/// but it's hard to rule out entirely (especially in the presence of complex macros
1639
/// or other expansions), and if it does happen then skipping a span or function is
1740
/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
18-
pub(crate) fn make_coverage_span(
19-
file_id: LocalFileId,
20-
source_map: &SourceMap,
21-
file: &SourceFile,
22-
span: Span,
23-
) -> Option<ffi::CoverageSpan> {
41+
pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) -> Option<Coords> {
2442
let span = ensure_non_empty_span(source_map, span)?;
2543

2644
let lo = span.lo();
@@ -44,8 +62,7 @@ pub(crate) fn make_coverage_span(
4462
start_line = source_map.doctest_offset_line(&file.name, start_line);
4563
end_line = source_map.doctest_offset_line(&file.name, end_line);
4664

47-
check_coverage_span(ffi::CoverageSpan {
48-
file_id: file_id.as_u32(),
65+
check_coords(Coords {
4966
start_line: start_line as u32,
5067
start_col: start_col as u32,
5168
end_line: end_line as u32,
@@ -80,8 +97,8 @@ fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> {
8097
/// it will immediately exit with a fatal error. To prevent that from happening,
8198
/// discard regions that are improperly ordered, or might be interpreted in a
8299
/// way that makes them improperly ordered.
83-
fn check_coverage_span(cov_span: ffi::CoverageSpan) -> Option<ffi::CoverageSpan> {
84-
let ffi::CoverageSpan { file_id: _, start_line, start_col, end_line, end_col } = cov_span;
100+
fn check_coords(coords: Coords) -> Option<Coords> {
101+
let Coords { start_line, start_col, end_line, end_col } = coords;
85102

86103
// Line/column coordinates are supposed to be 1-based. If we ever emit
87104
// coordinates of 0, `llvm-cov` might misinterpret them.
@@ -94,17 +111,17 @@ fn check_coverage_span(cov_span: ffi::CoverageSpan) -> Option<ffi::CoverageSpan>
94111
let is_ordered = (start_line, start_col) <= (end_line, end_col);
95112

96113
if all_nonzero && end_col_has_high_bit_unset && is_ordered {
97-
Some(cov_span)
114+
Some(coords)
98115
} else {
99116
debug!(
100-
?cov_span,
117+
?coords,
101118
?all_nonzero,
102119
?end_col_has_high_bit_unset,
103120
?is_ordered,
104121
"Skipping source region that would be misinterpreted or rejected by LLVM"
105122
);
106123
// If this happens in a debug build, ICE to make it easier to notice.
107-
debug_assert!(false, "Improper source region: {cov_span:?}");
124+
debug_assert!(false, "Improper source region: {coords:?}");
108125
None
109126
}
110127
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,8 @@ unsafe extern "C" {
20192019
NumExpressions: size_t,
20202020
CodeRegions: *const crate::coverageinfo::ffi::CodeRegion,
20212021
NumCodeRegions: size_t,
2022+
ExpansionRegions: *const crate::coverageinfo::ffi::ExpansionRegion,
2023+
NumExpansionRegions: size_t,
20222024
BranchRegions: *const crate::coverageinfo::ffi::BranchRegion,
20232025
NumBranchRegions: size_t,
20242026
MCDCBranchRegions: *const crate::coverageinfo::ffi::MCDCBranchRegion,

compiler/rustc_const_eval/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const_eval_expected_inbounds_pointer =
9393
}
9494
9595
const_eval_extern_static =
96-
cannot access extern static ({$did})
96+
cannot access extern static `{$did}`
9797
const_eval_extern_type_field = `extern type` field does not have a known offset
9898
9999
const_eval_fn_ptr_call =
@@ -381,7 +381,7 @@ const_eval_thread_local_access =
381381
thread-local statics cannot be accessed at compile-time
382382
383383
const_eval_thread_local_static =
384-
cannot access thread local static ({$did})
384+
cannot access thread local static `{$did}`
385385
const_eval_too_generic =
386386
encountered overly generic constant
387387
const_eval_too_many_caller_args =

0 commit comments

Comments
 (0)