Skip to content

Commit de74dab

Browse files
committed
Auto merge of rust-lang#110012 - matthiaskrgr:rollup-sgmm5xv, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#109395 (Fix issue when there are multiple candidates for edit_distance_with_substrings) - rust-lang#109755 (Implement support for `GeneratorWitnessMIR` in new solver) - rust-lang#109782 (Don't leave a comma at the start of argument list when removing arguments) - rust-lang#109977 (rustdoc: avoid including line numbers in Google SERP snippets) - rust-lang#109980 (Derive String's PartialEq implementation) - rust-lang#109984 (Remove f32 & f64 from MemDecoder/MemEncoder) - rust-lang#110004 (add `dont_check_failure_status` option in the compiler test) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f5b8f44 + 3473f73 commit de74dab

File tree

23 files changed

+348
-108
lines changed

23 files changed

+348
-108
lines changed

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+34-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
3131
use rustc_middle::ty::{self, IsSuggestable, Ty};
3232
use rustc_session::Session;
3333
use rustc_span::symbol::{kw, Ident};
34-
use rustc_span::{self, sym, Span};
34+
use rustc_span::{self, sym, BytePos, Span};
3535
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
3636

3737
use std::iter;
@@ -894,8 +894,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
894894
};
895895

896896
let mut errors = errors.into_iter().peekable();
897+
let mut only_extras_so_far = errors
898+
.peek()
899+
.map_or(false, |first| matches!(first, Error::Extra(arg_idx) if arg_idx.index() == 0));
897900
let mut suggestions = vec![];
898901
while let Some(error) = errors.next() {
902+
only_extras_so_far &= matches!(error, Error::Extra(_));
903+
899904
match error {
900905
Error::Invalid(provided_idx, expected_idx, compatibility) => {
901906
let (formal_ty, expected_ty) = formal_and_expected_inputs[expected_idx];
@@ -941,10 +946,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
941946
if arg_idx.index() > 0
942947
&& let Some((_, prev)) = provided_arg_tys
943948
.get(ProvidedIdx::from_usize(arg_idx.index() - 1)
944-
) {
945-
// Include previous comma
946-
span = prev.shrink_to_hi().to(span);
947-
}
949+
) {
950+
// Include previous comma
951+
span = prev.shrink_to_hi().to(span);
952+
}
953+
954+
// Is last argument for deletion in a row starting from the 0-th argument?
955+
// Then delete the next comma, so we are not left with `f(, ...)`
956+
//
957+
// fn f() {}
958+
// - f(0, 1,)
959+
// + f()
960+
if only_extras_so_far
961+
&& errors
962+
.peek()
963+
.map_or(true, |next_error| !matches!(next_error, Error::Extra(_)))
964+
{
965+
let next = provided_arg_tys
966+
.get(arg_idx + 1)
967+
.map(|&(_, sp)| sp)
968+
.unwrap_or_else(|| {
969+
// Subtract one to move before `)`
970+
call_expr.span.with_lo(call_expr.span.hi() - BytePos(1))
971+
});
972+
973+
// Include next comma
974+
span = span.until(next);
975+
}
976+
948977
suggestions.push((span, String::new()));
949978

950979
suggestion_text = match suggestion_text {

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
112112
emit_i8(i8);
113113

114114
emit_bool(bool);
115-
emit_f64(f64);
116-
emit_f32(f32);
117115
emit_char(char);
118116
emit_str(&str);
119117
emit_raw_bytes(&[u8]);

Diff for: compiler/rustc_middle/src/ty/codec.rs

-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ macro_rules! implement_ty_decoder {
511511
read_isize -> isize;
512512

513513
read_bool -> bool;
514-
read_f64 -> f64;
515-
read_f32 -> f32;
516514
read_char -> char;
517515
read_str -> &str;
518516
}

Diff for: compiler/rustc_query_impl/src/on_disk_cache.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,6 @@ impl<'a, 'tcx> Encoder for CacheEncoder<'a, 'tcx> {
10461046
emit_i8(i8);
10471047

10481048
emit_bool(bool);
1049-
emit_f64(f64);
1050-
emit_f32(f32);
10511049
emit_char(char);
10521050
emit_str(&str);
10531051
emit_raw_bytes(&[u8]);

Diff for: compiler/rustc_serialize/src/opaque.rs

-36
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,6 @@ impl Encoder for MemEncoder {
122122
self.emit_u8(if v { 1 } else { 0 });
123123
}
124124

125-
#[inline]
126-
fn emit_f64(&mut self, v: f64) {
127-
let as_u64: u64 = v.to_bits();
128-
self.emit_u64(as_u64);
129-
}
130-
131-
#[inline]
132-
fn emit_f32(&mut self, v: f32) {
133-
let as_u32: u32 = v.to_bits();
134-
self.emit_u32(as_u32);
135-
}
136-
137125
#[inline]
138126
fn emit_char(&mut self, v: char) {
139127
self.emit_u32(v as u32);
@@ -500,18 +488,6 @@ impl Encoder for FileEncoder {
500488
self.emit_u8(if v { 1 } else { 0 });
501489
}
502490

503-
#[inline]
504-
fn emit_f64(&mut self, v: f64) {
505-
let as_u64: u64 = v.to_bits();
506-
self.emit_u64(as_u64);
507-
}
508-
509-
#[inline]
510-
fn emit_f32(&mut self, v: f32) {
511-
let as_u32: u32 = v.to_bits();
512-
self.emit_u32(as_u32);
513-
}
514-
515491
#[inline]
516492
fn emit_char(&mut self, v: char) {
517493
self.emit_u32(v as u32);
@@ -642,18 +618,6 @@ impl<'a> Decoder for MemDecoder<'a> {
642618
value != 0
643619
}
644620

645-
#[inline]
646-
fn read_f64(&mut self) -> f64 {
647-
let bits = self.read_u64();
648-
f64::from_bits(bits)
649-
}
650-
651-
#[inline]
652-
fn read_f32(&mut self) -> f32 {
653-
let bits = self.read_u32();
654-
f32::from_bits(bits)
655-
}
656-
657621
#[inline]
658622
fn read_char(&mut self) -> char {
659623
let bits = self.read_u32();

Diff for: compiler/rustc_serialize/src/serialize.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ use std::sync::Arc;
2222
/// be processed or ignored, whichever is appropriate. Then they should provide
2323
/// a `finish` method that finishes up encoding. If the encoder is fallible,
2424
/// `finish` should return a `Result` that indicates success or failure.
25+
///
26+
/// This current does not support `f32` nor `f64`, as they're not needed in any
27+
/// serialized data structures. That could be changed, but consider whether it
28+
/// really makes sense to store floating-point values at all.
29+
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
2530
pub trait Encoder {
2631
// Primitive types:
2732
fn emit_usize(&mut self, v: usize);
@@ -37,8 +42,6 @@ pub trait Encoder {
3742
fn emit_i16(&mut self, v: i16);
3843
fn emit_i8(&mut self, v: i8);
3944
fn emit_bool(&mut self, v: bool);
40-
fn emit_f64(&mut self, v: f64);
41-
fn emit_f32(&mut self, v: f32);
4245
fn emit_char(&mut self, v: char);
4346
fn emit_str(&mut self, v: &str);
4447
fn emit_raw_bytes(&mut self, s: &[u8]);
@@ -58,6 +61,11 @@ pub trait Encoder {
5861
// top-level invocation would also just panic on failure. Switching to
5962
// infallibility made things faster and lots of code a little simpler and more
6063
// concise.
64+
///
65+
/// This current does not support `f32` nor `f64`, as they're not needed in any
66+
/// serialized data structures. That could be changed, but consider whether it
67+
/// really makes sense to store floating-point values at all.
68+
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
6169
pub trait Decoder {
6270
// Primitive types:
6371
fn read_usize(&mut self) -> usize;
@@ -73,8 +81,6 @@ pub trait Decoder {
7381
fn read_i16(&mut self) -> i16;
7482
fn read_i8(&mut self) -> i8;
7583
fn read_bool(&mut self) -> bool;
76-
fn read_f64(&mut self) -> f64;
77-
fn read_f32(&mut self) -> f32;
7884
fn read_char(&mut self) -> char;
7985
fn read_str(&mut self) -> &str;
8086
fn read_raw_bytes(&mut self, len: usize) -> &[u8];
@@ -143,8 +149,6 @@ direct_serialize_impls! {
143149
i64 emit_i64 read_i64,
144150
i128 emit_i128 read_i128,
145151

146-
f32 emit_f32 read_f32,
147-
f64 emit_f64 read_f64,
148152
bool emit_bool read_bool,
149153
char emit_char read_char
150154
}

Diff for: compiler/rustc_serialize/tests/opaque.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ struct Struct {
2222

2323
l: char,
2424
m: String,
25-
n: f32,
26-
o: f64,
2725
p: bool,
2826
q: Option<u32>,
2927
}
@@ -119,24 +117,6 @@ fn test_bool() {
119117
check_round_trip(vec![false, true, true, false, false]);
120118
}
121119

122-
#[test]
123-
fn test_f32() {
124-
let mut vec = vec![];
125-
for i in -100..100 {
126-
vec.push((i as f32) / 3.0);
127-
}
128-
check_round_trip(vec);
129-
}
130-
131-
#[test]
132-
fn test_f64() {
133-
let mut vec = vec![];
134-
for i in -100..100 {
135-
vec.push((i as f64) / 3.0);
136-
}
137-
check_round_trip(vec);
138-
}
139-
140120
#[test]
141121
fn test_char() {
142122
let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€'];
@@ -200,8 +180,6 @@ fn test_struct() {
200180

201181
l: 'x',
202182
m: "abc".to_string(),
203-
n: 20.5,
204-
o: 21.5,
205183
p: false,
206184
q: None,
207185
}]);
@@ -222,8 +200,6 @@ fn test_struct() {
222200

223201
l: 'y',
224202
m: "def".to_string(),
225-
n: -20.5,
226-
o: -21.5,
227203
p: true,
228204
q: Some(1234567),
229205
}]);
@@ -232,15 +208,15 @@ fn test_struct() {
232208
#[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
233209
enum Enum {
234210
Variant1,
235-
Variant2(usize, f32),
211+
Variant2(usize, u32),
236212
Variant3 { a: i32, b: char, c: bool },
237213
}
238214

239215
#[test]
240216
fn test_enum() {
241217
check_round_trip(vec![
242218
Enum::Variant1,
243-
Enum::Variant2(1, 2.5),
219+
Enum::Variant2(1, 25),
244220
Enum::Variant3 { a: 3, b: 'b', c: false },
245221
Enum::Variant3 { a: -4, b: 'f', c: true },
246222
]);
@@ -269,8 +245,8 @@ fn test_hash_map() {
269245

270246
#[test]
271247
fn test_tuples() {
272-
check_round_trip(vec![('x', (), false, 0.5f32)]);
273-
check_round_trip(vec![(9i8, 10u16, 1.5f64)]);
248+
check_round_trip(vec![('x', (), false, 5u32)]);
249+
check_round_trip(vec![(9i8, 10u16, 15i64)]);
274250
check_round_trip(vec![(-12i16, 11u8, 12usize)]);
275251
check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]);
276252
check_round_trip(vec![(String::new(), "some string".to_string())]);

Diff for: compiler/rustc_span/src/edit_distance.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ pub fn find_best_match_for_name(
174174
fn find_best_match_for_name_impl(
175175
use_substring_score: bool,
176176
candidates: &[Symbol],
177-
lookup: Symbol,
177+
lookup_symbol: Symbol,
178178
dist: Option<usize>,
179179
) -> Option<Symbol> {
180-
let lookup = lookup.as_str();
180+
let lookup = lookup_symbol.as_str();
181181
let lookup_uppercase = lookup.to_uppercase();
182182

183183
// Priority of matches:
@@ -190,6 +190,8 @@ fn find_best_match_for_name_impl(
190190

191191
let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
192192
let mut best = None;
193+
// store the candidates with the same distance, only for `use_substring_score` current.
194+
let mut next_candidates = vec![];
193195
for c in candidates {
194196
match if use_substring_score {
195197
edit_distance_with_substrings(lookup, c.as_str(), dist)
@@ -198,12 +200,36 @@ fn find_best_match_for_name_impl(
198200
} {
199201
Some(0) => return Some(*c),
200202
Some(d) => {
201-
dist = d - 1;
203+
if use_substring_score {
204+
if d < dist {
205+
dist = d;
206+
next_candidates.clear();
207+
} else {
208+
// `d == dist` here, we need to store the candidates with the same distance
209+
// so we won't decrease the distance in the next loop.
210+
}
211+
next_candidates.push(*c);
212+
} else {
213+
dist = d - 1;
214+
}
202215
best = Some(*c);
203216
}
204217
None => {}
205218
}
206219
}
220+
221+
// We have a tie among several candidates, try to select the best among them ignoring substrings.
222+
// For example, the candidates list `force_capture`, `capture`, and user inputed `forced_capture`,
223+
// we select `force_capture` with a extra round of edit distance calculation.
224+
if next_candidates.len() > 1 {
225+
debug_assert!(use_substring_score);
226+
best = find_best_match_for_name_impl(
227+
false,
228+
&next_candidates,
229+
lookup_symbol,
230+
Some(lookup.len()),
231+
);
232+
}
207233
if best.is_some() {
208234
return best;
209235
}

0 commit comments

Comments
 (0)