Skip to content

Commit 485a343

Browse files
committed
Auto merge of rust-lang#133442 - matthiaskrgr:rollup-lxtm1uv, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#132605 (CI: increase timeout from 4h to 6h) - rust-lang#133042 (btree: add `{Entry,VacantEntry}::insert_entry`) - rust-lang#133070 (Lexer tweaks) - rust-lang#133134 (Don't use a SyntheticProvider for literally every type) - rust-lang#133411 (the emscripten OS no longer exists on non-wasm targets) - rust-lang#133419 (Added a doc test for std::path::strip_prefix) - rust-lang#133430 (Tweak parameter mismatch explanation to not say `{unknown}`) - rust-lang#133435 (miri: disable test_downgrade_observe test on macOS) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2abf82 + cee0476 commit 485a343

File tree

19 files changed

+302
-197
lines changed

19 files changed

+302
-197
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
defaults:
6666
run:
6767
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
68-
timeout-minutes: 240
68+
timeout-minutes: 360
6969
env:
7070
CI_JOB_NAME: ${{ matrix.image }}
7171
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -2347,9 +2347,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23472347

23482348
let check_for_matched_generics = || {
23492349
if matched_inputs.iter().any(|x| x.is_some())
2350-
&& params_with_generics.iter().any(|x| x.0.is_some())
2350+
&& params_with_generics.iter().any(|x| x.1.is_some())
23512351
{
2352-
for (idx, (generic, _)) in params_with_generics.iter().enumerate() {
2352+
for &(idx, generic, _) in &params_with_generics {
23532353
// Param has to have a generic and be matched to be relevant
23542354
if matched_inputs[idx.into()].is_none() {
23552355
continue;
@@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23622362
for unmatching_idx in idx + 1..params_with_generics.len() {
23632363
if matched_inputs[unmatching_idx.into()].is_none()
23642364
&& let Some(unmatched_idx_param_generic) =
2365-
params_with_generics[unmatching_idx].0
2365+
params_with_generics[unmatching_idx].1
23662366
&& unmatched_idx_param_generic.name.ident()
23672367
== generic.name.ident()
23682368
{
@@ -2377,8 +2377,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23772377

23782378
let check_for_matched_generics = check_for_matched_generics();
23792379

2380-
for (idx, (generic_param, param)) in
2381-
params_with_generics.iter().enumerate().filter(|(idx, _)| {
2380+
for &(idx, generic_param, param) in
2381+
params_with_generics.iter().filter(|&(idx, _, _)| {
23822382
check_for_matched_generics
23832383
|| expected_idx.is_none_or(|expected_idx| expected_idx == *idx)
23842384
})
@@ -2390,8 +2390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23902390

23912391
let other_params_matched: Vec<(usize, &hir::Param<'_>)> = params_with_generics
23922392
.iter()
2393-
.enumerate()
2394-
.filter(|(other_idx, (other_generic_param, _))| {
2393+
.filter(|(other_idx, other_generic_param, _)| {
23952394
if *other_idx == idx {
23962395
return false;
23972396
}
@@ -2410,18 +2409,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24102409
}
24112410
other_generic_param.name.ident() == generic_param.name.ident()
24122411
})
2413-
.map(|(other_idx, (_, other_param))| (other_idx, *other_param))
2412+
.map(|&(other_idx, _, other_param)| (other_idx, other_param))
24142413
.collect();
24152414

24162415
if !other_params_matched.is_empty() {
24172416
let other_param_matched_names: Vec<String> = other_params_matched
24182417
.iter()
2419-
.map(|(_, other_param)| {
2418+
.map(|(idx, other_param)| {
24202419
if let hir::PatKind::Binding(_, _, ident, _) = other_param.pat.kind
24212420
{
24222421
format!("`{ident}`")
24232422
} else {
2424-
"{unknown}".to_string()
2423+
format!("parameter #{}", idx + 1)
24252424
}
24262425
})
24272426
.collect();
@@ -2478,18 +2477,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24782477
{
24792478
let param_idents_matching: Vec<String> = params_with_generics
24802479
.iter()
2481-
.filter(|(generic, _)| {
2480+
.filter(|(_, generic, _)| {
24822481
if let Some(generic) = generic {
24832482
generic.name.ident() == generic_param.name.ident()
24842483
} else {
24852484
false
24862485
}
24872486
})
2488-
.map(|(_, param)| {
2487+
.map(|(idx, _, param)| {
24892488
if let hir::PatKind::Binding(_, _, ident, _) = param.pat.kind {
24902489
format!("`{ident}`")
24912490
} else {
2492-
"{unknown}".to_string()
2491+
format!("parameter #{}", idx + 1)
24932492
}
24942493
})
24952494
.collect();
@@ -2498,8 +2497,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24982497
spans.push_span_label(
24992498
generic_param.span,
25002499
format!(
2501-
"{} all reference this parameter {}",
2500+
"{} {} reference this parameter `{}`",
25022501
display_list_with_comma_and(&param_idents_matching),
2502+
if param_idents_matching.len() == 2 { "both" } else { "all" },
25032503
generic_param.name.ident().name,
25042504
),
25052505
);
@@ -2580,7 +2580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25802580

25812581
if let Some(params_with_generics) = self.get_hir_params_with_generics(def_id, is_method) {
25822582
debug_assert_eq!(params_with_generics.len(), matched_inputs.len());
2583-
for (idx, (generic_param, _)) in params_with_generics.iter().enumerate() {
2583+
for &(idx, generic_param, _) in &params_with_generics {
25842584
if matched_inputs[idx.into()].is_none() {
25852585
continue;
25862586
}
@@ -2594,20 +2594,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25942594
};
25952595

25962596
let mut idxs_matched: Vec<usize> = vec![];
2597-
for (other_idx, (_, _)) in params_with_generics.iter().enumerate().filter(
2598-
|(other_idx, (other_generic_param, _))| {
2599-
if *other_idx == idx {
2597+
for &(other_idx, _, _) in
2598+
params_with_generics.iter().filter(|&&(other_idx, other_generic_param, _)| {
2599+
if other_idx == idx {
26002600
return false;
26012601
}
26022602
let Some(other_generic_param) = other_generic_param else {
26032603
return false;
26042604
};
2605-
if matched_inputs[(*other_idx).into()].is_some() {
2605+
if matched_inputs[other_idx.into()].is_some() {
26062606
return false;
26072607
}
26082608
other_generic_param.name.ident() == generic_param.name.ident()
2609-
},
2610-
) {
2609+
})
2610+
{
26112611
idxs_matched.push(other_idx);
26122612
}
26132613

@@ -2642,7 +2642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26422642
&self,
26432643
def_id: DefId,
26442644
is_method: bool,
2645-
) -> Option<Vec<(Option<&hir::GenericParam<'_>>, &hir::Param<'_>)>> {
2645+
) -> Option<Vec<(usize, Option<&hir::GenericParam<'_>>, &hir::Param<'_>)>> {
26462646
let fn_node = self.tcx.hir().get_if_local(def_id)?;
26472647
let fn_decl = fn_node.fn_decl()?;
26482648

@@ -2685,7 +2685,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26852685
}
26862686

26872687
debug_assert_eq!(params.len(), generic_params.len());
2688-
Some(generic_params.into_iter().zip(params).collect())
2688+
Some(
2689+
generic_params
2690+
.into_iter()
2691+
.zip(params)
2692+
.enumerate()
2693+
.map(|(a, (b, c))| (a, b, c))
2694+
.collect(),
2695+
)
26892696
}
26902697
}
26912698

compiler/rustc_lexer/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -566,19 +566,19 @@ impl Cursor<'_> {
566566

567567
fn c_or_byte_string(
568568
&mut self,
569-
mk_kind: impl FnOnce(bool) -> LiteralKind,
570-
mk_kind_raw: impl FnOnce(Option<u8>) -> LiteralKind,
569+
mk_kind: fn(bool) -> LiteralKind,
570+
mk_kind_raw: fn(Option<u8>) -> LiteralKind,
571571
single_quoted: Option<fn(bool) -> LiteralKind>,
572572
) -> TokenKind {
573573
match (self.first(), self.second(), single_quoted) {
574-
('\'', _, Some(mk_kind)) => {
574+
('\'', _, Some(single_quoted)) => {
575575
self.bump();
576576
let terminated = self.single_quoted_string();
577577
let suffix_start = self.pos_within_token();
578578
if terminated {
579579
self.eat_literal_suffix();
580580
}
581-
let kind = mk_kind(terminated);
581+
let kind = single_quoted(terminated);
582582
Literal { kind, suffix_start }
583583
}
584584
('"', _, _) => {

compiler/rustc_lexer/src/tests.rs

+31-41
Original file line numberDiff line numberDiff line change
@@ -77,61 +77,51 @@ fn test_too_many_hashes() {
7777
check_raw_str(&s2, Err(RawStrError::TooManyDelimiters { found: u32::from(max_count) + 1 }));
7878
}
7979

80+
// https://github.com/rust-lang/rust/issues/70528
8081
#[test]
8182
fn test_valid_shebang() {
82-
// https://github.com/rust-lang/rust/issues/70528
83-
let input = "#!/usr/bin/rustrun\nlet x = 5;";
84-
assert_eq!(strip_shebang(input), Some(18));
85-
}
83+
let input = "#!/bin/bash";
84+
assert_eq!(strip_shebang(input), Some(input.len()));
8685

87-
#[test]
88-
fn test_invalid_shebang_valid_rust_syntax() {
89-
// https://github.com/rust-lang/rust/issues/70528
90-
let input = "#! [bad_attribute]";
86+
let input = "#![attribute]";
9187
assert_eq!(strip_shebang(input), None);
92-
}
9388

94-
#[test]
95-
fn test_shebang_second_line() {
96-
// Because shebangs are interpreted by the kernel, they must be on the first line
97-
let input = "\n#!/bin/bash";
89+
let input = "#! /bin/bash";
90+
assert_eq!(strip_shebang(input), Some(input.len()));
91+
92+
let input = "#! [attribute]";
9893
assert_eq!(strip_shebang(input), None);
99-
}
10094

101-
#[test]
102-
fn test_shebang_space() {
103-
let input = "#! /bin/bash";
95+
let input = "#! /* blah */ /bin/bash";
10496
assert_eq!(strip_shebang(input), Some(input.len()));
105-
}
10697

107-
#[test]
108-
fn test_shebang_empty_shebang() {
109-
let input = "#! \n[attribute(foo)]";
98+
let input = "#! /* blah */ [attribute]";
11099
assert_eq!(strip_shebang(input), None);
111-
}
112100

113-
#[test]
114-
fn test_invalid_shebang_comment() {
115-
let input = "#!//bin/ami/a/comment\n[";
116-
assert_eq!(strip_shebang(input), None)
117-
}
101+
let input = "#! // blah\n/bin/bash";
102+
assert_eq!(strip_shebang(input), Some(10)); // strip up to the newline
118103

119-
#[test]
120-
fn test_invalid_shebang_another_comment() {
121-
let input = "#!/*bin/ami/a/comment*/\n[attribute";
122-
assert_eq!(strip_shebang(input), None)
123-
}
104+
let input = "#! // blah\n[attribute]";
105+
assert_eq!(strip_shebang(input), None);
124106

125-
#[test]
126-
fn test_shebang_valid_rust_after() {
127-
let input = "#!/*bin/ami/a/comment*/\npub fn main() {}";
128-
assert_eq!(strip_shebang(input), Some(23))
129-
}
107+
let input = "#! /* blah\nblah\nblah */ /bin/bash";
108+
assert_eq!(strip_shebang(input), Some(10));
130109

131-
#[test]
132-
fn test_shebang_followed_by_attrib() {
133-
let input = "#!/bin/rust-scripts\n#![allow_unused(true)]";
134-
assert_eq!(strip_shebang(input), Some(19));
110+
let input = "#! /* blah\nblah\nblah */ [attribute]";
111+
assert_eq!(strip_shebang(input), None);
112+
113+
let input = "#!\n/bin/sh";
114+
assert_eq!(strip_shebang(input), Some(2));
115+
116+
let input = "#!\n[attribute]";
117+
assert_eq!(strip_shebang(input), None);
118+
119+
// Because shebangs are interpreted by the kernel, they must be on the first line
120+
let input = "\n#!/bin/bash";
121+
assert_eq!(strip_shebang(input), None);
122+
123+
let input = "\n#![attribute]";
124+
assert_eq!(strip_shebang(input), None);
135125
}
136126

137127
fn check_lexing(src: &str, expect: Expect) {

0 commit comments

Comments
 (0)