Skip to content

Commit f2f881b

Browse files
committed
Auto merge of #148075 - cuviper:beta-next, r=cuviper
[beta] backports - Revert constification of `AsRef for Cow` due to inference failure #148011 - Revert constification of `Borrow` and `Deref for Cow` due to inference failure #148016 - Revert "fix: Filter suggestion parts that match existing code" #148043 - Revert "feat: implement `hash_map!` macro" #148049 - fix panic when rustc tries to reduce intermediate filenames len with utf8 #148018 r? cuviper
2 parents 1f25197 + 1e668e0 commit f2f881b

File tree

17 files changed

+174
-115
lines changed

17 files changed

+174
-115
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,11 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
945945
None,
946946
"Span must not be empty and have no suggestion",
947947
);
948+
debug_assert_eq!(
949+
parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
950+
None,
951+
"suggestion must not have overlapping parts",
952+
);
948953

949954
self.push_suggestion(CodeSuggestion {
950955
substitutions: vec![Substitution { parts }],

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@ impl HumanEmitter {
23542354
.sum();
23552355
let underline_start = (span_start_pos + start) as isize + offset;
23562356
let underline_end = (span_start_pos + start + sub_len) as isize + offset;
2357+
assert!(underline_start >= 0 && underline_end >= 0);
23572358
let padding: usize = max_line_num_len + 3;
23582359
for p in underline_start..underline_end {
23592360
if let DisplaySuggestion::Underline = show_code_change

compiler/rustc_errors/src/lib.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,6 @@ impl CodeSuggestion {
381381
// Assumption: all spans are in the same file, and all spans
382382
// are disjoint. Sort in ascending order.
383383
substitution.parts.sort_by_key(|part| part.span.lo());
384-
// Verify the assumption that all spans are disjoint
385-
assert_eq!(
386-
substitution.parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
387-
None,
388-
"all spans must be disjoint",
389-
);
390-
391-
// Account for cases where we are suggesting the same code that's already
392-
// there. This shouldn't happen often, but in some cases for multipart
393-
// suggestions it's much easier to handle it here than in the origin.
394-
substitution.parts.retain(|p| is_different(sm, &p.snippet, p.span));
395384

396385
// Find the bounding span.
397386
let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?;
@@ -481,12 +470,16 @@ impl CodeSuggestion {
481470
_ => 1,
482471
})
483472
.sum();
484-
485-
line_highlight.push(SubstitutionHighlight {
486-
start: (cur_lo.col.0 as isize + acc) as usize,
487-
end: (cur_lo.col.0 as isize + acc + len) as usize,
488-
});
489-
473+
if !is_different(sm, &part.snippet, part.span) {
474+
// Account for cases where we are suggesting the same code that's already
475+
// there. This shouldn't happen often, but in some cases for multipart
476+
// suggestions it's much easier to handle it here than in the origin.
477+
} else {
478+
line_highlight.push(SubstitutionHighlight {
479+
start: (cur_lo.col.0 as isize + acc) as usize,
480+
end: (cur_lo.col.0 as isize + acc + len) as usize,
481+
});
482+
}
490483
buf.push_str(&part.snippet);
491484
let cur_hi = sm.lookup_char_pos(part.span.hi());
492485
// Account for the difference between the width of the current code and the

compiler/rustc_session/src/config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,13 +1207,22 @@ fn maybe_strip_file_name(mut path: PathBuf) -> PathBuf {
12071207
if path.file_name().map_or(0, |name| name.len()) > MAX_FILENAME_LENGTH {
12081208
let filename = path.file_name().unwrap().to_string_lossy();
12091209
let hash_len = 64 / 4; // Hash64 is 64 bits encoded in hex
1210-
let stripped_len = filename.len() - MAX_FILENAME_LENGTH + hash_len;
1210+
let hyphen_len = 1; // the '-' we insert between hash and suffix
1211+
1212+
// number of bytes of suffix we can keep so that "hash-<suffix>" fits
1213+
let allowed_suffix = MAX_FILENAME_LENGTH.saturating_sub(hash_len + hyphen_len);
1214+
1215+
// number of bytes to remove from the start
1216+
let stripped_bytes = filename.len().saturating_sub(allowed_suffix);
1217+
1218+
// ensure we don't cut in a middle of a char
1219+
let split_at = filename.ceil_char_boundary(stripped_bytes);
12111220

12121221
let mut hasher = StableHasher::new();
1213-
filename[..stripped_len].hash(&mut hasher);
1222+
filename[..split_at].hash(&mut hasher);
12141223
let hash = hasher.finish::<Hash64>();
12151224

1216-
path.set_file_name(format!("{:x}-{}", hash, &filename[stripped_len..]));
1225+
path.set_file_name(format!("{:x}-{}", hash, &filename[split_at..]));
12171226
}
12181227
path
12191228
}

compiler/rustc_session/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
3+
#![cfg_attr(bootstrap, feature(round_char_boundary))]
34
#![feature(default_field_values)]
45
#![feature(iter_intersperse)]
56
#![feature(rustc_attrs)]

library/alloc/src/borrow.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ use crate::fmt;
1616
#[cfg(not(no_global_oom_handling))]
1717
use crate::string::String;
1818

19+
// FIXME(inference): const bounds removed due to inference regressions found by crater;
20+
// see https://github.com/rust-lang/rust/issues/147964
21+
// #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1922
#[stable(feature = "rust1", since = "1.0.0")]
20-
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
21-
impl<'a, B: ?Sized> const Borrow<B> for Cow<'a, B>
22-
where
23-
B: ToOwned,
24-
B::Owned: [const] Borrow<B>,
23+
impl<'a, B: ?Sized + ToOwned> Borrow<B> for Cow<'a, B>
24+
// where
25+
// B::Owned: [const] Borrow<B>,
2526
{
2627
fn borrow(&self) -> &B {
2728
&**self
@@ -327,11 +328,13 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
327328
}
328329
}
329330

331+
// FIXME(inference): const bounds removed due to inference regressions found by crater;
332+
// see https://github.com/rust-lang/rust/issues/147964
333+
// #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
330334
#[stable(feature = "rust1", since = "1.0.0")]
331-
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
332-
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
333-
where
334-
B::Owned: [const] Borrow<B>,
335+
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B>
336+
// where
337+
// B::Owned: [const] Borrow<B>,
335338
{
336339
type Target = B;
337340

@@ -441,11 +444,13 @@ where
441444
}
442445
}
443446

447+
// FIXME(inference): const bounds removed due to inference regressions found by crater;
448+
// see https://github.com/rust-lang/rust/issues/147964
449+
// #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
444450
#[stable(feature = "rust1", since = "1.0.0")]
445-
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
446-
impl<T: ?Sized + ToOwned> const AsRef<T> for Cow<'_, T>
447-
where
448-
T::Owned: [const] Borrow<T>,
451+
impl<T: ?Sized + ToOwned> AsRef<T> for Cow<'_, T>
452+
// where
453+
// T::Owned: [const] Borrow<T>,
449454
{
450455
fn as_ref(&self) -> &T {
451456
self

library/std/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@
294294
#![feature(ffi_const)]
295295
#![feature(formatting_options)]
296296
#![feature(funnel_shifts)]
297-
#![feature(hash_map_internals)]
298-
#![feature(hash_map_macro)]
299297
#![feature(if_let_guard)]
300298
#![feature(intra_doc_pointers)]
301299
#![feature(iter_advance_by)]

library/std/src/macros.rs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -379,77 +379,3 @@ macro_rules! dbg {
379379
($($crate::dbg!($val)),+,)
380380
};
381381
}
382-
383-
#[doc(hidden)]
384-
#[macro_export]
385-
#[allow_internal_unstable(hash_map_internals)]
386-
#[unstable(feature = "hash_map_internals", issue = "none")]
387-
macro_rules! repetition_utils {
388-
(@count $($tokens:tt),*) => {{
389-
[$($crate::repetition_utils!(@replace $tokens => ())),*].len()
390-
}};
391-
392-
(@replace $x:tt => $y:tt) => { $y }
393-
}
394-
395-
/// Creates a [`HashMap`] containing the arguments.
396-
///
397-
/// `hash_map!` allows specifying the entries that make
398-
/// up the [`HashMap`] where the key and value are separated by a `=>`.
399-
///
400-
/// The entries are separated by commas with a trailing comma being allowed.
401-
///
402-
/// It is semantically equivalent to using repeated [`HashMap::insert`]
403-
/// on a newly created hashmap.
404-
///
405-
/// `hash_map!` will attempt to avoid repeated reallocations by
406-
/// using [`HashMap::with_capacity`].
407-
///
408-
/// # Examples
409-
///
410-
/// ```rust
411-
/// #![feature(hash_map_macro)]
412-
///
413-
/// let map = hash_map! {
414-
/// "key" => "value",
415-
/// "key1" => "value1"
416-
/// };
417-
///
418-
/// assert_eq!(map.get("key"), Some(&"value"));
419-
/// assert_eq!(map.get("key1"), Some(&"value1"));
420-
/// assert!(map.get("brrrrrrooooommm").is_none());
421-
/// ```
422-
///
423-
/// And with a trailing comma
424-
///
425-
///```rust
426-
/// #![feature(hash_map_macro)]
427-
///
428-
/// let map = hash_map! {
429-
/// "key" => "value", // notice the ,
430-
/// };
431-
///
432-
/// assert_eq!(map.get("key"), Some(&"value"));
433-
/// ```
434-
///
435-
/// The key and value are moved into the HashMap.
436-
///
437-
/// [`HashMap`]: crate::collections::HashMap
438-
/// [`HashMap::insert`]: crate::collections::HashMap::insert
439-
/// [`HashMap::with_capacity`]: crate::collections::HashMap::with_capacity
440-
#[macro_export]
441-
#[allow_internal_unstable(hash_map_internals)]
442-
#[unstable(feature = "hash_map_macro", issue = "144032")]
443-
macro_rules! hash_map {
444-
() => {{
445-
$crate::collections::HashMap::new()
446-
}};
447-
448-
( $( $key:expr => $value:expr ),* $(,)? ) => {{
449-
let mut map = $crate::collections::HashMap::with_capacity(
450-
const { $crate::repetition_utils!(@count $($key),*) }
451-
);
452-
$( map.insert($key, $value); )*
453-
map
454-
}}
455-
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Make sure that a `std` macro `hash_map!` does not cause ambiguity
2+
//! with a local glob import with the same name.
3+
//!
4+
//! See regression https://github.com/rust-lang/rust/issues/147971
5+
6+
mod module {
7+
macro_rules! hash_map {
8+
() => {};
9+
}
10+
pub(crate) use hash_map;
11+
}
12+
13+
use module::*;
14+
15+
fn main() {
16+
hash_map! {}
17+
}

src/tools/clippy/tests/ui/bool_assert_comparison.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,10 @@ LL | assert_eq!(a!(), true);
272272
|
273273
help: replace it with `assert!(..)`
274274
|
275-
LL - assert_eq!(a!(), true);
276-
LL + assert!(a!());
275+
LL | true
276+
...
277+
LL |
278+
LL ~ assert!(a!());
277279
|
278280

279281
error: used `assert_eq!` with a literal bool
@@ -284,8 +286,10 @@ LL | assert_eq!(true, b!());
284286
|
285287
help: replace it with `assert!(..)`
286288
|
287-
LL - assert_eq!(true, b!());
288-
LL + assert!(b!());
289+
LL | true
290+
...
291+
LL |
292+
LL ~ assert!(b!());
289293
|
290294

291295
error: used `debug_assert_eq!` with a literal bool

0 commit comments

Comments
 (0)