Skip to content

Commit

Permalink
Auto merge of rust-lang#110012 - matthiaskrgr:rollup-sgmm5xv, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Apr 6, 2023
2 parents f5b8f44 + 3473f73 commit de74dab
Show file tree
Hide file tree
Showing 23 changed files with 348 additions and 108 deletions.
39 changes: 34 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, IsSuggestable, Ty};
use rustc_session::Session;
use rustc_span::symbol::{kw, Ident};
use rustc_span::{self, sym, Span};
use rustc_span::{self, sym, BytePos, Span};
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};

use std::iter;
Expand Down Expand Up @@ -894,8 +894,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

let mut errors = errors.into_iter().peekable();
let mut only_extras_so_far = errors
.peek()
.map_or(false, |first| matches!(first, Error::Extra(arg_idx) if arg_idx.index() == 0));
let mut suggestions = vec![];
while let Some(error) = errors.next() {
only_extras_so_far &= matches!(error, Error::Extra(_));

match error {
Error::Invalid(provided_idx, expected_idx, compatibility) => {
let (formal_ty, expected_ty) = formal_and_expected_inputs[expected_idx];
Expand Down Expand Up @@ -941,10 +946,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if arg_idx.index() > 0
&& let Some((_, prev)) = provided_arg_tys
.get(ProvidedIdx::from_usize(arg_idx.index() - 1)
) {
// Include previous comma
span = prev.shrink_to_hi().to(span);
}
) {
// Include previous comma
span = prev.shrink_to_hi().to(span);
}

// Is last argument for deletion in a row starting from the 0-th argument?
// Then delete the next comma, so we are not left with `f(, ...)`
//
// fn f() {}
// - f(0, 1,)
// + f()
if only_extras_so_far
&& errors
.peek()
.map_or(true, |next_error| !matches!(next_error, Error::Extra(_)))
{
let next = provided_arg_tys
.get(arg_idx + 1)
.map(|&(_, sp)| sp)
.unwrap_or_else(|| {
// Subtract one to move before `)`
call_expr.span.with_lo(call_expr.span.hi() - BytePos(1))
});

// Include next comma
span = span.until(next);
}

suggestions.push((span, String::new()));

suggestion_text = match suggestion_text {
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
emit_i8(i8);

emit_bool(bool);
emit_f64(f64);
emit_f32(f32);
emit_char(char);
emit_str(&str);
emit_raw_bytes(&[u8]);
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,6 @@ macro_rules! implement_ty_decoder {
read_isize -> isize;

read_bool -> bool;
read_f64 -> f64;
read_f32 -> f32;
read_char -> char;
read_str -> &str;
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_query_impl/src/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,6 @@ impl<'a, 'tcx> Encoder for CacheEncoder<'a, 'tcx> {
emit_i8(i8);

emit_bool(bool);
emit_f64(f64);
emit_f32(f32);
emit_char(char);
emit_str(&str);
emit_raw_bytes(&[u8]);
Expand Down
36 changes: 0 additions & 36 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,6 @@ impl Encoder for MemEncoder {
self.emit_u8(if v { 1 } else { 0 });
}

#[inline]
fn emit_f64(&mut self, v: f64) {
let as_u64: u64 = v.to_bits();
self.emit_u64(as_u64);
}

#[inline]
fn emit_f32(&mut self, v: f32) {
let as_u32: u32 = v.to_bits();
self.emit_u32(as_u32);
}

#[inline]
fn emit_char(&mut self, v: char) {
self.emit_u32(v as u32);
Expand Down Expand Up @@ -500,18 +488,6 @@ impl Encoder for FileEncoder {
self.emit_u8(if v { 1 } else { 0 });
}

#[inline]
fn emit_f64(&mut self, v: f64) {
let as_u64: u64 = v.to_bits();
self.emit_u64(as_u64);
}

#[inline]
fn emit_f32(&mut self, v: f32) {
let as_u32: u32 = v.to_bits();
self.emit_u32(as_u32);
}

#[inline]
fn emit_char(&mut self, v: char) {
self.emit_u32(v as u32);
Expand Down Expand Up @@ -642,18 +618,6 @@ impl<'a> Decoder for MemDecoder<'a> {
value != 0
}

#[inline]
fn read_f64(&mut self) -> f64 {
let bits = self.read_u64();
f64::from_bits(bits)
}

#[inline]
fn read_f32(&mut self) -> f32 {
let bits = self.read_u32();
f32::from_bits(bits)
}

#[inline]
fn read_char(&mut self) -> char {
let bits = self.read_u32();
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_serialize/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ use std::sync::Arc;
/// be processed or ignored, whichever is appropriate. Then they should provide
/// a `finish` method that finishes up encoding. If the encoder is fallible,
/// `finish` should return a `Result` that indicates success or failure.
///
/// This current does not support `f32` nor `f64`, as they're not needed in any
/// serialized data structures. That could be changed, but consider whether it
/// really makes sense to store floating-point values at all.
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
pub trait Encoder {
// Primitive types:
fn emit_usize(&mut self, v: usize);
Expand All @@ -37,8 +42,6 @@ pub trait Encoder {
fn emit_i16(&mut self, v: i16);
fn emit_i8(&mut self, v: i8);
fn emit_bool(&mut self, v: bool);
fn emit_f64(&mut self, v: f64);
fn emit_f32(&mut self, v: f32);
fn emit_char(&mut self, v: char);
fn emit_str(&mut self, v: &str);
fn emit_raw_bytes(&mut self, s: &[u8]);
Expand All @@ -58,6 +61,11 @@ pub trait Encoder {
// top-level invocation would also just panic on failure. Switching to
// infallibility made things faster and lots of code a little simpler and more
// concise.
///
/// This current does not support `f32` nor `f64`, as they're not needed in any
/// serialized data structures. That could be changed, but consider whether it
/// really makes sense to store floating-point values at all.
/// (If you need it, revert <https://github.com/rust-lang/rust/pull/109984>.)
pub trait Decoder {
// Primitive types:
fn read_usize(&mut self) -> usize;
Expand All @@ -73,8 +81,6 @@ pub trait Decoder {
fn read_i16(&mut self) -> i16;
fn read_i8(&mut self) -> i8;
fn read_bool(&mut self) -> bool;
fn read_f64(&mut self) -> f64;
fn read_f32(&mut self) -> f32;
fn read_char(&mut self) -> char;
fn read_str(&mut self) -> &str;
fn read_raw_bytes(&mut self, len: usize) -> &[u8];
Expand Down Expand Up @@ -143,8 +149,6 @@ direct_serialize_impls! {
i64 emit_i64 read_i64,
i128 emit_i128 read_i128,

f32 emit_f32 read_f32,
f64 emit_f64 read_f64,
bool emit_bool read_bool,
char emit_char read_char
}
Expand Down
32 changes: 4 additions & 28 deletions compiler/rustc_serialize/tests/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ struct Struct {

l: char,
m: String,
n: f32,
o: f64,
p: bool,
q: Option<u32>,
}
Expand Down Expand Up @@ -119,24 +117,6 @@ fn test_bool() {
check_round_trip(vec![false, true, true, false, false]);
}

#[test]
fn test_f32() {
let mut vec = vec![];
for i in -100..100 {
vec.push((i as f32) / 3.0);
}
check_round_trip(vec);
}

#[test]
fn test_f64() {
let mut vec = vec![];
for i in -100..100 {
vec.push((i as f64) / 3.0);
}
check_round_trip(vec);
}

#[test]
fn test_char() {
let vec = vec!['a', 'b', 'c', 'd', 'A', 'X', ' ', '#', 'Ö', 'Ä', 'µ', '€'];
Expand Down Expand Up @@ -200,8 +180,6 @@ fn test_struct() {

l: 'x',
m: "abc".to_string(),
n: 20.5,
o: 21.5,
p: false,
q: None,
}]);
Expand All @@ -222,8 +200,6 @@ fn test_struct() {

l: 'y',
m: "def".to_string(),
n: -20.5,
o: -21.5,
p: true,
q: Some(1234567),
}]);
Expand All @@ -232,15 +208,15 @@ fn test_struct() {
#[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
enum Enum {
Variant1,
Variant2(usize, f32),
Variant2(usize, u32),
Variant3 { a: i32, b: char, c: bool },
}

#[test]
fn test_enum() {
check_round_trip(vec![
Enum::Variant1,
Enum::Variant2(1, 2.5),
Enum::Variant2(1, 25),
Enum::Variant3 { a: 3, b: 'b', c: false },
Enum::Variant3 { a: -4, b: 'f', c: true },
]);
Expand Down Expand Up @@ -269,8 +245,8 @@ fn test_hash_map() {

#[test]
fn test_tuples() {
check_round_trip(vec![('x', (), false, 0.5f32)]);
check_round_trip(vec![(9i8, 10u16, 1.5f64)]);
check_round_trip(vec![('x', (), false, 5u32)]);
check_round_trip(vec![(9i8, 10u16, 15i64)]);
check_round_trip(vec![(-12i16, 11u8, 12usize)]);
check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]);
check_round_trip(vec![(String::new(), "some string".to_string())]);
Expand Down
32 changes: 29 additions & 3 deletions compiler/rustc_span/src/edit_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ pub fn find_best_match_for_name(
fn find_best_match_for_name_impl(
use_substring_score: bool,
candidates: &[Symbol],
lookup: Symbol,
lookup_symbol: Symbol,
dist: Option<usize>,
) -> Option<Symbol> {
let lookup = lookup.as_str();
let lookup = lookup_symbol.as_str();
let lookup_uppercase = lookup.to_uppercase();

// Priority of matches:
Expand All @@ -190,6 +190,8 @@ fn find_best_match_for_name_impl(

let mut dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
let mut best = None;
// store the candidates with the same distance, only for `use_substring_score` current.
let mut next_candidates = vec![];
for c in candidates {
match if use_substring_score {
edit_distance_with_substrings(lookup, c.as_str(), dist)
Expand All @@ -198,12 +200,36 @@ fn find_best_match_for_name_impl(
} {
Some(0) => return Some(*c),
Some(d) => {
dist = d - 1;
if use_substring_score {
if d < dist {
dist = d;
next_candidates.clear();
} else {
// `d == dist` here, we need to store the candidates with the same distance
// so we won't decrease the distance in the next loop.
}
next_candidates.push(*c);
} else {
dist = d - 1;
}
best = Some(*c);
}
None => {}
}
}

// We have a tie among several candidates, try to select the best among them ignoring substrings.
// For example, the candidates list `force_capture`, `capture`, and user inputed `forced_capture`,
// we select `force_capture` with a extra round of edit distance calculation.
if next_candidates.len() > 1 {
debug_assert!(use_substring_score);
best = find_best_match_for_name_impl(
false,
&next_candidates,
lookup_symbol,
Some(lookup.len()),
);
}
if best.is_some() {
return best;
}
Expand Down
Loading

0 comments on commit de74dab

Please sign in to comment.