Skip to content

Commit 9ea4d41

Browse files
committed
Auto merge of rust-lang#96414 - Dylan-DPC:rollup-t4ofhoa, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#90312 (Fix some confusing wording and improve slice-search-related docs) - rust-lang#96149 (Remove unused macro rules) - rust-lang#96279 (rustdoc: Remove .woff font files) - rust-lang#96355 (Better handle too many `#` recovery in raw str) - rust-lang#96379 (delay bug when adjusting `NeverToAny` twice during diagnostic code) - rust-lang#96384 (do not consider two extern types to be similar) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ec8619d + f0b2dcc commit 9ea4d41

File tree

33 files changed

+243
-176
lines changed

33 files changed

+243
-176
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

-13
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,6 @@ impl EmissionGuarantee for ! {
255255
/// instead of a `&DiagnosticBuilder<'a>`. This `forward!` macro makes
256256
/// it easy to declare such methods on the builder.
257257
macro_rules! forward {
258-
// Forward pattern for &self -> &Self
259-
(
260-
$(#[$attrs:meta])*
261-
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
262-
) => {
263-
$(#[$attrs])*
264-
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
265-
pub fn $n(&self, $($name: $ty),*) -> &Self {
266-
self.diagnostic.$n($($name),*);
267-
self
268-
}
269-
};
270-
271258
// Forward pattern for &mut self -> &mut Self
272259
(
273260
$(#[$attrs:meta])*

compiler/rustc_middle/src/ty/codec.rs

-3
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ macro_rules! impl_arena_allocatable_decoder {
453453
}
454454
}
455455
};
456-
([$ignore:ident $(, $attrs:ident)*]$args:tt) => {
457-
impl_arena_allocatable_decoder!([$($attrs),*]$args);
458-
};
459456
}
460457

461458
macro_rules! impl_arena_allocatable_decoders {

compiler/rustc_parse/src/parser/diagnostics.rs

+34-9
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,11 @@ impl<'a> Parser<'a> {
431431
return Ok(true);
432432
} else if self.look_ahead(0, |t| {
433433
t == &token::CloseDelim(token::Brace)
434-
|| (
435-
t.can_begin_expr() && t != &token::Semi && t != &token::Pound
436-
// Avoid triggering with too many trailing `#` in raw string.
437-
)
434+
|| (t.can_begin_expr() && t != &token::Semi && t != &token::Pound)
435+
// Avoid triggering with too many trailing `#` in raw string.
436+
|| (sm.is_multiline(
437+
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo())
438+
) && t == &token::Pound)
438439
}) {
439440
// Missing semicolon typo. This is triggered if the next token could either start a
440441
// new statement or is a block close. For example:
@@ -508,7 +509,12 @@ impl<'a> Parser<'a> {
508509
}
509510

510511
if self.check_too_many_raw_str_terminators(&mut err) {
511-
return Err(err);
512+
if expected.contains(&TokenType::Token(token::Semi)) && self.eat(&token::Semi) {
513+
err.emit();
514+
return Ok(true);
515+
} else {
516+
return Err(err);
517+
}
512518
}
513519

514520
if self.prev_token.span == DUMMY_SP {
@@ -538,22 +544,41 @@ impl<'a> Parser<'a> {
538544
}
539545

540546
fn check_too_many_raw_str_terminators(&mut self, err: &mut Diagnostic) -> bool {
547+
let sm = self.sess.source_map();
541548
match (&self.prev_token.kind, &self.token.kind) {
542549
(
543550
TokenKind::Literal(Lit {
544551
kind: LitKind::StrRaw(n_hashes) | LitKind::ByteStrRaw(n_hashes),
545552
..
546553
}),
547554
TokenKind::Pound,
548-
) => {
555+
) if !sm.is_multiline(
556+
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo()),
557+
) =>
558+
{
559+
let n_hashes: u8 = *n_hashes;
549560
err.set_primary_message("too many `#` when terminating raw string");
561+
let str_span = self.prev_token.span;
562+
let mut span = self.token.span;
563+
let mut count = 0;
564+
while self.token.kind == TokenKind::Pound
565+
&& !sm.is_multiline(span.shrink_to_hi().until(self.token.span.shrink_to_lo()))
566+
{
567+
span = span.with_hi(self.token.span.hi());
568+
self.bump();
569+
count += 1;
570+
}
571+
err.set_span(span);
550572
err.span_suggestion(
551-
self.token.span,
552-
"remove the extra `#`",
573+
span,
574+
&format!("remove the extra `#`{}", pluralize!(count)),
553575
String::new(),
554576
Applicability::MachineApplicable,
555577
);
556-
err.note(&format!("the raw string started with {n_hashes} `#`s"));
578+
err.span_label(
579+
str_span,
580+
&format!("this raw string started with {n_hashes} `#`{}", pluralize!(n_hashes)),
581+
);
557582
true
558583
}
559584
_ => false,

compiler/rustc_serialize/src/serialize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ macro_rules! peel {
498498
/// Therefore, the recursion depth is the binary logarithm of the number of
499499
/// tokens to count, and the expanded tree is likewise very small.
500500
macro_rules! count {
501-
() => (0usize);
502501
($one:tt) => (1usize);
503502
($($pairs:tt $_p:tt)*) => (count!($($pairs)*) << 1usize);
504503
($odd:tt $($rest:tt)*) => (count!($($rest)*) | 1usize);

compiler/rustc_target/src/spec/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2249,10 +2249,6 @@ impl ToJson for Target {
22492249
let name = (stringify!($attr)).replace("_", "-");
22502250
d.insert(name, self.$attr.to_json());
22512251
}};
2252-
($attr:ident, $key_name:expr) => {{
2253-
let name = $key_name;
2254-
d.insert(name.into(), self.$attr.to_json());
2255-
}};
22562252
}
22572253

22582254
macro_rules! target_option_val {

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
17271727
} else if cat_a == cat_b {
17281728
match (a.kind(), b.kind()) {
17291729
(ty::Adt(def_a, _), ty::Adt(def_b, _)) => def_a == def_b,
1730+
(ty::Foreign(def_a), ty::Foreign(def_b)) => def_a == def_b,
17301731
// Matching on references results in a lot of unhelpful
17311732
// suggestions, so let's just not do that for now.
17321733
//

compiler/rustc_typeck/src/check/expr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7878
// While we don't allow *arbitrary* coercions here, we *do* allow
7979
// coercions from ! to `expected`.
8080
if ty.is_never() {
81-
assert!(
82-
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
83-
"expression with never type wound up being adjusted"
84-
);
81+
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
82+
self.tcx().sess.delay_span_bug(
83+
expr.span,
84+
"expression with never type wound up being adjusted",
85+
);
86+
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
87+
target.to_owned()
88+
} else {
89+
self.tcx().ty_error()
90+
};
91+
}
92+
8593
let adj_ty = self.next_ty_var(TypeVariableOrigin {
8694
kind: TypeVariableOriginKind::AdjustmentType,
8795
span: expr.span,

library/alloc/src/collections/linked_list.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<T> LinkedList<T> {
645645
/// Returns `true` if the `LinkedList` contains an element equal to the
646646
/// given value.
647647
///
648-
/// This operation should compute in *O*(*n*) time.
648+
/// This operation should compute linearly in *O*(*n*) time.
649649
///
650650
/// # Examples
651651
///
@@ -1569,7 +1569,7 @@ impl<'a, T> CursorMut<'a, T> {
15691569
/// Appends an element to the front of the cursor's parent list. The node
15701570
/// that the cursor points to is unchanged, even if it is the "ghost" node.
15711571
///
1572-
/// This operation should compute in O(1) time.
1572+
/// This operation should compute in *O*(1) time.
15731573
// `push_front` continues to point to "ghost" when it addes a node to mimic
15741574
// the behavior of `insert_before` on an empty list.
15751575
#[unstable(feature = "linked_list_cursors", issue = "58533")]
@@ -1584,7 +1584,7 @@ impl<'a, T> CursorMut<'a, T> {
15841584
/// Appends an element to the back of the cursor's parent list. The node
15851585
/// that the cursor points to is unchanged, even if it is the "ghost" node.
15861586
///
1587-
/// This operation should compute in O(1) time.
1587+
/// This operation should compute in *O*(1) time.
15881588
#[unstable(feature = "linked_list_cursors", issue = "58533")]
15891589
pub fn push_back(&mut self, elt: T) {
15901590
// Safety: We know that `push_back` does not change the position in
@@ -1603,7 +1603,7 @@ impl<'a, T> CursorMut<'a, T> {
16031603
/// unchanged, unless it was pointing to the front element. In that case, it
16041604
/// points to the new front element.
16051605
///
1606-
/// This operation should compute in O(1) time.
1606+
/// This operation should compute in *O*(1) time.
16071607
#[unstable(feature = "linked_list_cursors", issue = "58533")]
16081608
pub fn pop_front(&mut self) -> Option<T> {
16091609
// We can't check if current is empty, we must check the list directly.
@@ -1630,7 +1630,7 @@ impl<'a, T> CursorMut<'a, T> {
16301630
/// unchanged, unless it was pointing to the back element. In that case, it
16311631
/// points to the "ghost" element.
16321632
///
1633-
/// This operation should compute in O(1) time.
1633+
/// This operation should compute in *O*(1) time.
16341634
#[unstable(feature = "linked_list_cursors", issue = "58533")]
16351635
pub fn pop_back(&mut self) -> Option<T> {
16361636
if self.list.is_empty() {

library/alloc/src/collections/vec_deque/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
13421342
/// Returns `true` if the deque contains an element equal to the
13431343
/// given value.
13441344
///
1345+
/// This operation is *O*(*n*).
1346+
///
1347+
/// Note that if you have a sorted `VecDeque`, [`binary_search`] may be faster.
1348+
///
1349+
/// [`binary_search`]: VecDeque::binary_search
1350+
///
13451351
/// # Examples
13461352
///
13471353
/// ```
@@ -2560,7 +2566,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
25602566
}
25612567
}
25622568

2563-
/// Binary searches the sorted deque for a given element.
2569+
/// Binary searches this `VecDeque` for a given element.
2570+
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
25642571
///
25652572
/// If the value is found then [`Result::Ok`] is returned, containing the
25662573
/// index of the matching element. If there are multiple matches, then any
@@ -2570,6 +2577,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
25702577
///
25712578
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
25722579
///
2580+
/// [`contains`]: VecDeque::contains
25732581
/// [`binary_search_by`]: VecDeque::binary_search_by
25742582
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
25752583
/// [`partition_point`]: VecDeque::partition_point
@@ -2614,7 +2622,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
26142622
self.binary_search_by(|e| e.cmp(x))
26152623
}
26162624

2617-
/// Binary searches the sorted deque with a comparator function.
2625+
/// Binary searches this `VecDeque` with a comparator function.
2626+
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
26182627
///
26192628
/// The comparator function should implement an order consistent
26202629
/// with the sort order of the deque, returning an order code that
@@ -2629,6 +2638,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
26292638
///
26302639
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
26312640
///
2641+
/// [`contains`]: VecDeque::contains
26322642
/// [`binary_search`]: VecDeque::binary_search
26332643
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
26342644
/// [`partition_point`]: VecDeque::partition_point
@@ -2667,7 +2677,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
26672677
}
26682678
}
26692679

2670-
/// Binary searches the sorted deque with a key extraction function.
2680+
/// Binary searches this `VecDeque` with a key extraction function.
2681+
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
26712682
///
26722683
/// Assumes that the deque is sorted by the key, for instance with
26732684
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
@@ -2680,6 +2691,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
26802691
///
26812692
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
26822693
///
2694+
/// [`contains`]: VecDeque::contains
26832695
/// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous
26842696
/// [`binary_search`]: VecDeque::binary_search
26852697
/// [`binary_search_by`]: VecDeque::binary_search_by

library/core/src/internal_macros.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// implements the unary operator "op &T"
22
// based on "op T" where T is expected to be `Copy`able
33
macro_rules! forward_ref_unop {
4-
(impl $imp:ident, $method:ident for $t:ty) => {
5-
forward_ref_unop!(impl $imp, $method for $t,
6-
#[stable(feature = "rust1", since = "1.0.0")]);
7-
};
84
(impl const $imp:ident, $method:ident for $t:ty) => {
95
forward_ref_unop!(impl const $imp, $method for $t,
106
#[stable(feature = "rust1", since = "1.0.0")]);
@@ -38,10 +34,6 @@ macro_rules! forward_ref_unop {
3834
// implements binary operators "&T op U", "T op &U", "&T op &U"
3935
// based on "T op U" where T and U are expected to be `Copy`able
4036
macro_rules! forward_ref_binop {
41-
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
42-
forward_ref_binop!(impl $imp, $method for $t, $u,
43-
#[stable(feature = "rust1", since = "1.0.0")]);
44-
};
4537
(impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
4638
forward_ref_binop!(impl const $imp, $method for $t, $u,
4739
#[stable(feature = "rust1", since = "1.0.0")]);
@@ -230,22 +222,6 @@ macro_rules! cfg_if {
230222
}
231223
};
232224

233-
// match if/else chains lacking a final `else`
234-
(
235-
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
236-
$(
237-
else if #[cfg( $e_meta:meta )] { $( $e_tokens:tt )* }
238-
)*
239-
) => {
240-
cfg_if! {
241-
@__items () ;
242-
(( $i_meta ) ( $( $i_tokens )* )) ,
243-
$(
244-
(( $e_meta ) ( $( $e_tokens )* )) ,
245-
)*
246-
}
247-
};
248-
249225
// Internal and recursive macro to emit all the items
250226
//
251227
// Collects all the previous cfgs in a list at the beginning, so they can be

library/core/src/slice/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,12 @@ impl<T> [T] {
21392139

21402140
/// Returns `true` if the slice contains an element with the given value.
21412141
///
2142+
/// This operation is *O*(*n*).
2143+
///
2144+
/// Note that if you have a sorted slice, [`binary_search`] may be faster.
2145+
///
2146+
/// [`binary_search`]: slice::binary_search
2147+
///
21422148
/// # Examples
21432149
///
21442150
/// ```
@@ -2298,7 +2304,8 @@ impl<T> [T] {
22982304
None
22992305
}
23002306

2301-
/// Binary searches this sorted slice for a given element.
2307+
/// Binary searches this slice for a given element.
2308+
/// This behaves similary to [`contains`] if this slice is sorted.
23022309
///
23032310
/// If the value is found then [`Result::Ok`] is returned, containing the
23042311
/// index of the matching element. If there are multiple matches, then any
@@ -2310,6 +2317,7 @@ impl<T> [T] {
23102317
///
23112318
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
23122319
///
2320+
/// [`contains`]: slice::contains
23132321
/// [`binary_search_by`]: slice::binary_search_by
23142322
/// [`binary_search_by_key`]: slice::binary_search_by_key
23152323
/// [`partition_point`]: slice::partition_point
@@ -2349,7 +2357,8 @@ impl<T> [T] {
23492357
self.binary_search_by(|p| p.cmp(x))
23502358
}
23512359

2352-
/// Binary searches this sorted slice with a comparator function.
2360+
/// Binary searches this slice with a comparator function.
2361+
/// This behaves similarly to [`contains`] if this slice is sorted.
23532362
///
23542363
/// The comparator function should implement an order consistent
23552364
/// with the sort order of the underlying slice, returning an
@@ -2366,6 +2375,7 @@ impl<T> [T] {
23662375
///
23672376
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
23682377
///
2378+
/// [`contains`]: slice::contains
23692379
/// [`binary_search`]: slice::binary_search
23702380
/// [`binary_search_by_key`]: slice::binary_search_by_key
23712381
/// [`partition_point`]: slice::partition_point
@@ -2424,7 +2434,8 @@ impl<T> [T] {
24242434
Err(left)
24252435
}
24262436

2427-
/// Binary searches this sorted slice with a key extraction function.
2437+
/// Binary searches this slice with a key extraction function.
2438+
/// This behaves similarly to [`contains`] if this slice is sorted.
24282439
///
24292440
/// Assumes that the slice is sorted by the key, for instance with
24302441
/// [`sort_by_key`] using the same key extraction function.
@@ -2439,6 +2450,7 @@ impl<T> [T] {
24392450
///
24402451
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
24412452
///
2453+
/// [`contains`]: slice::contains
24422454
/// [`sort_by_key`]: slice::sort_by_key
24432455
/// [`binary_search`]: slice::binary_search
24442456
/// [`binary_search_by`]: slice::binary_search_by

library/core/tests/num/ops.rs

-12
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ macro_rules! impls_defined {
4343
}
4444

4545
macro_rules! test_op {
46-
($fn_name:ident, $op:ident::$method:ident($lhs:literal, $rhs:literal), $result:literal, $($t:ty),+) => {
47-
#[test]
48-
fn $fn_name() {
49-
impls_defined!($op, $method($lhs, $rhs), $result, $($t),+);
50-
}
51-
};
52-
($fn_name:ident, $op:ident::$method:ident(&mut $lhs:literal, $rhs:literal), $result:literal, $($t:ty),+) => {
53-
#[test]
54-
fn $fn_name() {
55-
impls_defined!($op, $method(&mut $lhs, $rhs), $result, $($t),+);
56-
}
57-
};
5846
($fn_name:ident, $op:ident::$method:ident($lhs:literal), $result:literal, $($t:ty),+) => {
5947
#[test]
6048
fn $fn_name() {

0 commit comments

Comments
 (0)