Skip to content

Commit 444a85a

Browse files
committed
Auto merge of rust-lang#86379 - JohnTitor:rollup-mkz9x36, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#85870 (Allow whitespace in dump_mir filter) - rust-lang#86104 (Fix span calculation in format strings) - rust-lang#86140 (Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`) - rust-lang#86141 (Link reference in `dyn` keyword documentation) - rust-lang#86260 (Open trait implementations' toggles by default.) - rust-lang#86339 (Mention rust-lang#79078 on compatibility notes of 1.52) - rust-lang#86341 (Stop returning a value from `report_assert_as_lint`) - rust-lang#86353 (Remove `projection_ty_from_predicates`) - rust-lang#86361 (Add missing backslashes to prevent unwanted newlines in rustdoc HTML) - rust-lang#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

+2
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

+14-1
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

+1-1
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

-4
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

+14-11
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

+4-1
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

-24
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

+17
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

+17
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

+1-1
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")]

library/std/src/keyword_docs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,9 @@ mod await_keyword {}
22562256
/// At run-time, when a method needs to be called on the `dyn Trait`, the vtable is consulted to get
22572257
/// the function pointer and then that function pointer is called.
22582258
///
2259+
/// See the Reference for more information on [trait objects][ref-trait-obj]
2260+
/// and [object safety][ref-obj-safety].
2261+
///
22592262
/// ## Trade-offs
22602263
///
22612264
/// The above indirection is the additional runtime cost of calling a function on a `dyn Trait`.
@@ -2264,9 +2267,9 @@ mod await_keyword {}
22642267
/// However, `dyn Trait` is likely to produce smaller code than `impl Trait` / generic parameters as
22652268
/// the method won't be duplicated for each concrete type.
22662269
///
2267-
/// Read more about `object safety` and [trait object]s.
2268-
///
22692270
/// [trait object]: ../book/ch17-02-trait-objects.html
2271+
/// [ref-trait-obj]: ../reference/types/trait-object.html
2272+
/// [ref-obj-safety]: ../reference/items/traits.html#object-safety
22702273
/// [erased]: https://en.wikipedia.org/wiki/Type_erasure
22712274
mod dyn_keyword {}
22722275

src/librustdoc/html/render/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
488488
.into(),
489489
("auto-hide-large-items", "Auto-hide item contents for large items.", true).into(),
490490
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
491-
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true)
491+
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", false)
492492
.into(),
493493
("auto-collapse-implementors", "Auto-hide implementors of a trait", true).into(),
494494
("go-to-only-result", "Directly go to item in search if there is only one result", false)
@@ -1543,15 +1543,10 @@ fn render_impl(
15431543
}
15441544
}
15451545
if render_mode == RenderMode::Normal {
1546-
let is_implementing_trait = i.inner_impl().trait_.is_some();
15471546
let toggled = !impl_items.is_empty() || !default_impl_items.is_empty();
15481547
if toggled {
15491548
close_tags.insert_str(0, "</details>");
1550-
if is_implementing_trait {
1551-
write!(w, "<details class=\"rustdoc-toggle implementors-toggle\">");
1552-
} else {
1553-
write!(w, "<details class=\"rustdoc-toggle implementors-toggle\" open>");
1554-
}
1549+
write!(w, "<details class=\"rustdoc-toggle implementors-toggle\" open>");
15551550
}
15561551
if toggled {
15571552
write!(w, "<summary>")

src/librustdoc/html/render/print_item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
864864
if fields.peek().is_some() {
865865
write!(
866866
w,
867-
"<h2 id=\"fields\" class=\"fields small-section-header\">
867+
"<h2 id=\"fields\" class=\"fields small-section-header\">\
868868
Fields<a href=\"#fields\" class=\"anchor\"></a></h2>"
869869
);
870870
for (field, ty) in fields {
@@ -953,8 +953,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
953953
if !e.variants.is_empty() {
954954
write!(
955955
w,
956-
"<h2 id=\"variants\" class=\"variants small-section-header\">
957-
Variants{}<a href=\"#variants\" class=\"anchor\"></a></h2>\n",
956+
"<h2 id=\"variants\" class=\"variants small-section-header\">\
957+
Variants{}<a href=\"#variants\" class=\"anchor\"></a></h2>",
958958
document_non_exhaustive_header(it)
959959
);
960960
document_non_exhaustive(w, it);
@@ -1139,7 +1139,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
11391139
if fields.peek().is_some() {
11401140
write!(
11411141
w,
1142-
"<h2 id=\"fields\" class=\"fields small-section-header\">
1142+
"<h2 id=\"fields\" class=\"fields small-section-header\">\
11431143
Fields{}<a href=\"#fields\" class=\"anchor\"></a></h2>",
11441144
document_non_exhaustive_header(it)
11451145
);

src/librustdoc/html/static/main.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -779,25 +779,25 @@ function hideThemeButtonState() {
779779

780780
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
781781
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
782-
var hideImplementations = getSettingValue("auto-hide-trait-implementations") !== "false";
782+
var hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true";
783783
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
784784

785-
function openImplementors(id) {
785+
function setImplementorsTogglesOpen(id, open) {
786786
var list = document.getElementById(id);
787787
if (list !== null) {
788788
onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) {
789-
e.open = true;
789+
e.open = open;
790790
});
791791
}
792792
}
793793

794-
if (!hideImplementations) {
795-
openImplementors("trait-implementations-list");
796-
openImplementors("blanket-implementations-list");
794+
if (hideImplementations) {
795+
setImplementorsTogglesOpen("trait-implementations-list", false);
796+
setImplementorsTogglesOpen("blanket-implementations-list", false);
797797
}
798798

799799
if (!hideImplementors) {
800-
openImplementors("implementors-list");
800+
setImplementorsTogglesOpen("implementors-list", true);
801801
}
802802

803803
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This tests that the "implementations" section on struct/enum pages
2+
// has all the implementations toggled open by default, so users can
3+
// find method names in those implementations with Ctrl-F.
4+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
5+
assert: (".rustdoc-toggle.implementors-toggle", "open", "")

src/test/ui/fmt/format-concat-span.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// If the format string is another macro invocation, rustc would previously
2+
// compute nonsensical spans, such as:
3+
//
4+
// error: invalid format string: unmatched `}` found
5+
// --> test.rs:2:17
6+
// |
7+
// 2 | format!(concat!("abc}"));
8+
// | ^ unmatched `}` in format string
9+
//
10+
// This test checks that this behavior has been fixed.
11+
12+
fn main() {
13+
format!(concat!("abc}"));
14+
//~^ ERROR: invalid format string: unmatched `}` found
15+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: invalid format string: unmatched `}` found
2+
--> $DIR/format-concat-span.rs:13:13
3+
|
4+
LL | format!(concat!("abc}"));
5+
| ^^^^^^^^^^^^^^^ unmatched `}` in format string
6+
|
7+
= note: if you intended to print `}`, you can escape it using `}}`
8+
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: aborting due to previous error
11+

src/test/ui/fmt/issue-86085.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Tests for an ICE with the fuzzed input below.
2+
3+
fn main ( ) {
4+
format ! ( concat ! ( r#"lJ𐏿Æ�.𐏿�"# , "r} {}" ) ) ;
5+
//~^ ERROR: invalid format string: unmatched `}` found
6+
}

src/test/ui/fmt/issue-86085.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: invalid format string: unmatched `}` found
2+
--> $DIR/issue-86085.rs:4:12
3+
|
4+
LL | format ! ( concat ! ( r#"lJ𐏿Æ�.𐏿�"# , "r} {}" ) ) ;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` in format string
6+
|
7+
= note: if you intended to print `}`, you can escape it using `}}`
8+
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)