Skip to content

Commit 444a85a

Browse files
committed
Auto merge of #86379 - JohnTitor:rollup-mkz9x36, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #85870 (Allow whitespace in dump_mir filter) - #86104 (Fix span calculation in format strings) - #86140 (Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`) - #86141 (Link reference in `dyn` keyword documentation) - #86260 (Open trait implementations' toggles by default.) - #86339 (Mention #79078 on compatibility notes of 1.52) - #86341 (Stop returning a value from `report_assert_as_lint`) - #86353 (Remove `projection_ty_from_predicates`) - #86361 (Add missing backslashes to prevent unwanted newlines in rustdoc HTML) - #86372 (Typo correction: s/is/its) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a85f584 + 27d5426 commit 444a85a

File tree

19 files changed

+136
-63
lines changed

19 files changed

+136
-63
lines changed

RELEASES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ Compatibility Notes
306306
- [Rustc now catches more cases of `pub_use_of_private_extern_crate`][80763]
307307
- [Changes in how proc macros handle whitespace may lead to panics when used
308308
with older `proc-macro-hack` versions. A `cargo update` should be sufficient to fix this in all cases.][84136]
309+
- [Turn `#[derive]` into a regular macro attribute][79078]
309310

310311
[84136]: https://github.com/rust-lang/rust/issues/84136
311312
[80763]: https://github.com/rust-lang/rust/pull/80763
@@ -332,6 +333,7 @@ Compatibility Notes
332333
[78429]: https://github.com/rust-lang/rust/pull/78429
333334
[82733]: https://github.com/rust-lang/rust/pull/82733
334335
[82594]: https://github.com/rust-lang/rust/pull/82594
336+
[79078]: https://github.com/rust-lang/rust/pull/79078
335337
[cargo/9181]: https://github.com/rust-lang/cargo/pull/9181
336338
[`char::MAX`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.MAX
337339
[`char::REPLACEMENT_CHARACTER`]: https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.REPLACEMENT_CHARACTER

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ pub fn expand_preparsed_format_args(
939939

940940
let msg = "format argument must be a string literal";
941941
let fmt_sp = efmt.span;
942+
let efmt_kind_is_lit: bool = matches!(efmt.kind, ast::ExprKind::Lit(_));
942943
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
943944
Ok(mut fmt) if append_newline => {
944945
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
@@ -989,7 +990,19 @@ pub fn expand_preparsed_format_args(
989990

990991
if !parser.errors.is_empty() {
991992
let err = parser.errors.remove(0);
992-
let sp = fmt_span.from_inner(err.span);
993+
let sp = if efmt_kind_is_lit {
994+
fmt_span.from_inner(err.span)
995+
} else {
996+
// The format string could be another macro invocation, e.g.:
997+
// format!(concat!("abc", "{}"), 4);
998+
// However, `err.span` is an inner span relative to the *result* of
999+
// the macro invocation, which is why we would get a nonsensical
1000+
// result calling `fmt_span.from_inner(err.span)` as above, and
1001+
// might even end up inside a multibyte character (issue #86085).
1002+
// Therefore, we conservatively report the error for the entire
1003+
// argument span here.
1004+
fmt_span
1005+
};
9931006
let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", err.description));
9941007
e.span_label(sp, err.label + " in format string");
9951008
if let Some(note) = err.note {

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
285285
// required that their size stay the same, but we don't want to change
286286
// it inadvertently. This assert just ensures we're aware of any change.
287287
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
288-
static_assert_size!(DepNode, 18);
288+
static_assert_size!(DepNode, 17);
289289

290290
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
291291
static_assert_size!(DepNode, 24);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ rustc_queries! {
191191
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
192192
}
193193

194-
query projection_ty_from_predicates(key: (DefId, DefId)) -> Option<ty::ProjectionTy<'tcx>> {
195-
desc { |tcx| "finding projection type inside predicates of `{}`", tcx.def_path_str(key.0) }
196-
}
197-
198194
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLib>> {
199195
desc { "looking up the native libraries of a linked crate" }
200196
}

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
528528
source_info: SourceInfo,
529529
message: &'static str,
530530
panic: AssertKind<impl std::fmt::Debug>,
531-
) -> Option<()> {
532-
let lint_root = self.lint_root(source_info)?;
533-
self.tcx.struct_span_lint_hir(lint, lint_root, source_info.span, |lint| {
534-
let mut err = lint.build(message);
535-
err.span_label(source_info.span, format!("{:?}", panic));
536-
err.emit()
537-
});
538-
None
531+
) {
532+
if let Some(lint_root) = self.lint_root(source_info) {
533+
self.tcx.struct_span_lint_hir(lint, lint_root, source_info.span, |lint| {
534+
let mut err = lint.build(message);
535+
err.span_label(source_info.span, format!("{:?}", panic));
536+
err.emit()
537+
});
538+
}
539539
}
540540

541541
fn check_unary_op(
@@ -557,7 +557,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
557557
source_info,
558558
"this arithmetic operation will overflow",
559559
AssertKind::OverflowNeg(val.to_const_int()),
560-
)?;
560+
);
561+
return None;
561562
}
562563

563564
Some(())
@@ -602,7 +603,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
602603
},
603604
r.to_const_int(),
604605
),
605-
)?;
606+
);
607+
return None;
606608
}
607609
}
608610

@@ -617,7 +619,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
617619
source_info,
618620
"this arithmetic operation will overflow",
619621
AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()),
620-
)?;
622+
);
623+
return None;
621624
}
622625
}
623626
Some(())

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) ->
9999
});
100100
filters.split('|').any(|or_filter| {
101101
or_filter.split('&').all(|and_filter| {
102-
and_filter == "all" || pass_name.contains(and_filter) || node_path.contains(and_filter)
102+
let and_filter_trimmed = and_filter.trim();
103+
and_filter_trimmed == "all"
104+
|| pass_name.contains(and_filter_trimmed)
105+
|| node_path.contains(and_filter_trimmed)
103106
})
104107
})
105108
}

compiler/rustc_typeck/src/collect.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub fn provide(providers: &mut Providers) {
7777
generics_of,
7878
predicates_of,
7979
predicates_defined_on,
80-
projection_ty_from_predicates,
8180
explicit_predicates_of,
8281
super_predicates_of,
8382
super_predicates_that_define_assoc_type,
@@ -2352,29 +2351,6 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
23522351
}
23532352
}
23542353

2355-
fn projection_ty_from_predicates(
2356-
tcx: TyCtxt<'tcx>,
2357-
key: (
2358-
// ty_def_id
2359-
DefId,
2360-
// def_id of `N` in `<T as Trait>::N`
2361-
DefId,
2362-
),
2363-
) -> Option<ty::ProjectionTy<'tcx>> {
2364-
let (ty_def_id, item_def_id) = key;
2365-
let mut projection_ty = None;
2366-
for (predicate, _) in tcx.predicates_of(ty_def_id).predicates {
2367-
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder()
2368-
{
2369-
if item_def_id == projection_predicate.projection_ty.item_def_id {
2370-
projection_ty = Some(projection_predicate.projection_ty);
2371-
break;
2372-
}
2373-
}
2374-
}
2375-
projection_ty
2376-
}
2377-
23782354
/// Converts a specific `GenericBound` from the AST into a set of
23792355
/// predicates that apply to the self type. A vector is returned
23802356
/// because this can be anywhere from zero predicates (`T: ?Sized` adds no

library/alloc/src/vec/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,23 @@ impl<T: Clone, A: Allocator + Clone> Clone for Vec<T, A> {
24072407
}
24082408
}
24092409

2410+
/// The hash of a vector is the same as that of the corresponding slice,
2411+
/// as required by the `core::borrow::Borrow` implementation.
2412+
///
2413+
/// ```
2414+
/// use std::hash::{BuildHasher, Hash, Hasher};
2415+
///
2416+
/// fn hash_of(x: impl Hash, b: &impl BuildHasher) -> u64 {
2417+
/// let mut h = b.build_hasher();
2418+
/// x.hash(&mut h);
2419+
/// h.finish()
2420+
/// }
2421+
///
2422+
/// let b = std::collections::hash_map::RandomState::new();
2423+
/// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09];
2424+
/// let s: &[u8] = &[0xa8, 0x3c, 0x09];
2425+
/// assert_eq!(hash_of(v, &b), hash_of(s, &b));
2426+
/// ```
24102427
#[stable(feature = "rust1", since = "1.0.0")]
24112428
impl<T: Hash, A: Allocator> Hash for Vec<T, A> {
24122429
#[inline]

library/core/src/array/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
139139
}
140140
}
141141

142+
/// The hash of an array is the same as that of the corresponding slice,
143+
/// as required by the `Borrow` implementation.
144+
///
145+
/// ```
146+
/// use std::hash::{BuildHasher, Hash, Hasher};
147+
///
148+
/// fn hash_of(x: impl Hash, b: &impl BuildHasher) -> u64 {
149+
/// let mut h = b.build_hasher();
150+
/// x.hash(&mut h);
151+
/// h.finish()
152+
/// }
153+
///
154+
/// let b = std::collections::hash_map::RandomState::new();
155+
/// let a: [u8; 3] = [0xa8, 0x3c, 0x09];
156+
/// let s: &[u8] = &[0xa8, 0x3c, 0x09];
157+
/// assert_eq!(hash_of(a, &b), hash_of(s, &b));
158+
/// ```
142159
#[stable(feature = "rust1", since = "1.0.0")]
143160
impl<T: Hash, const N: usize> Hash for [T; N] {
144161
fn hash<H: hash::Hasher>(&self, state: &mut H) {

library/core/src/ptr/non_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<T: ?Sized> NonNull<T> {
194194
}
195195
}
196196

197-
/// Decompose a (possibly wide) pointer into is address and metadata components.
197+
/// Decompose a (possibly wide) pointer into its address and metadata components.
198198
///
199199
/// The pointer can be later reconstructed with [`NonNull::from_raw_parts`].
200200
#[unstable(feature = "ptr_metadata", issue = "81513")]

0 commit comments

Comments
 (0)