Skip to content

Commit d0e1491

Browse files
committed
Auto merge of rust-lang#101074 - JohnTitor:rollup-zwznihq, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#96240 (Stabilize `const_ptr_offset_from`.) - rust-lang#99784 (Make forward compatibility lint deprecated_cfg_attr_crate_type_name deny by default) - rust-lang#100811 (Fix wrong compiletest filters on Windows) - rust-lang#100924 (Smaller improvements of tidy and the unicode generator) - rust-lang#100953 (Update documentation for `write!` and `writeln!`) - rust-lang#101018 (rustdoc: omit start/end tags for empty item description blocks) - rust-lang#101044 (rustdoc: remove unused CSS for `hidden-by-*-hider`) - rust-lang#101046 (rustdoc: remove incorrect CSS selector `.impl-items table td`) - rust-lang#101057 (Merge implementations of HIR fn_decl and fn_sig.) - rust-lang#101062 (rustdoc: remove empty extern_crates and type="text/javascript" on script) - rust-lang#101063 (Merge duplicated CSS rules) Failed merges: - rust-lang#101055 (Use smaller span for suggestions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9845f4c + bd89372 commit d0e1491

File tree

29 files changed

+132
-147
lines changed

29 files changed

+132
-147
lines changed

Diff for: compiler/rustc_hir/src/hir.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,7 @@ impl<'hir> OwnerNode<'hir> {
32163216
}
32173217
}
32183218

3219-
pub fn fn_decl(&self) -> Option<&FnDecl<'hir>> {
3219+
pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
32203220
match self {
32213221
OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
32223222
| OwnerNode::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
@@ -3400,19 +3400,20 @@ impl<'hir> Node<'hir> {
34003400
}
34013401
}
34023402

3403-
pub fn fn_decl(&self) -> Option<&'hir FnDecl<'hir>> {
3403+
pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
34043404
match self {
34053405
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
34063406
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
34073407
| Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl),
3408-
Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
3408+
Node::Expr(Expr { kind: ExprKind::Closure(Closure { fn_decl, .. }), .. })
3409+
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
34093410
Some(fn_decl)
34103411
}
34113412
_ => None,
34123413
}
34133414
}
34143415

3415-
pub fn fn_sig(&self) -> Option<&'hir FnSig<'hir>> {
3416+
pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>> {
34163417
match self {
34173418
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
34183419
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,7 @@ declare_lint! {
30943094
///
30953095
/// ### Example
30963096
///
3097-
/// ```rust
3097+
/// ```rust,compile_fail
30983098
/// #![cfg_attr(debug_assertions, crate_type = "lib")]
30993099
/// ```
31003100
///
@@ -3114,7 +3114,7 @@ declare_lint! {
31143114
/// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
31153115
/// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
31163116
pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3117-
Warn,
3117+
Deny,
31183118
"detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
31193119
@future_incompatible = FutureIncompatibleInfo {
31203120
reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
1717
use rustc_span::Span;
1818
use rustc_target::spec::abi::Abi;
1919

20-
fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
21-
match node {
22-
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
23-
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
24-
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(&sig.decl),
25-
Node::Expr(Expr { kind: ExprKind::Closure(Closure { fn_decl, .. }), .. })
26-
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, ..), .. }) => {
27-
Some(fn_decl)
28-
}
29-
_ => None,
30-
}
31-
}
32-
33-
pub fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
34-
match &node {
35-
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
36-
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
37-
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(sig),
38-
_ => None,
39-
}
40-
}
41-
4220
#[inline]
4321
pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
4422
match node {
@@ -389,15 +367,15 @@ impl<'hir> Map<'hir> {
389367

390368
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
391369
if let Some(node) = self.find(hir_id) {
392-
fn_decl(node)
370+
node.fn_decl()
393371
} else {
394372
bug!("no node for hir_id `{}`", hir_id)
395373
}
396374
}
397375

398376
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
399377
if let Some(node) = self.find(hir_id) {
400-
fn_sig(node)
378+
node.fn_sig()
401379
} else {
402380
bug!("no node for hir_id `{}`", hir_id)
403381
}

Diff for: compiler/rustc_mir_transform/src/coverage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ fn fn_sig_and_body<'tcx>(
541541
// to HIR for it.
542542
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
543543
let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body");
544-
(hir::map::fn_sig(hir_node), tcx.hir().body(fn_body_id))
544+
(hir_node.fn_sig(), tcx.hir().body(fn_body_id))
545545
}
546546

547547
fn get_body_span<'tcx>(

Diff for: compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_errors::{
44
MultiSpan,
55
};
66
use rustc_hir as hir;
7-
use rustc_middle::hir::map::fn_sig;
87
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
98
use rustc_session::Session;
109
use rustc_span::def_id::DefId;
@@ -368,7 +367,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
368367
&self,
369368
num_params_to_take: usize,
370369
) -> String {
371-
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(fn_sig);
370+
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(hir::Node::fn_sig);
372371
let is_used_in_input = |def_id| {
373372
fn_sig.map_or(false, |fn_sig| {
374373
fn_sig.decl.inputs.iter().any(|ty| match ty.kind {

Diff for: library/core/src/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1992,11 +1992,11 @@ extern "rust-intrinsic" {
19921992
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
19931993

19941994
/// See documentation of `<*const T>::offset_from` for details.
1995-
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
1995+
#[rustc_const_stable(feature = "const_ptr_offset_from", since = "1.65.0")]
19961996
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
19971997

19981998
/// See documentation of `<*const T>::sub_ptr` for details.
1999-
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
1999+
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
20002000
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
20012001

20022002
/// See documentation of `<*const T>::guaranteed_eq` for details.

Diff for: library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
#![feature(const_replace)]
131131
#![feature(const_ptr_as_ref)]
132132
#![feature(const_ptr_is_null)]
133-
#![feature(const_ptr_offset_from)]
134133
#![feature(const_ptr_read)]
135134
#![feature(const_ptr_write)]
136135
#![feature(const_raw_ptr_comparison)]

Diff for: library/core/src/macros/mod.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,12 @@ macro_rules! r#try {
457457
///
458458
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
459459
/// implementing either, as objects do not typically implement both. However, the module must
460-
/// import the traits qualified so their names do not conflict:
460+
/// avoid conflict between the trait names, such as by importing them as `_` or otherwise renaming
461+
/// them:
461462
///
462463
/// ```
463-
/// use std::fmt::Write as FmtWrite;
464-
/// use std::io::Write as IoWrite;
464+
/// use std::fmt::Write as _;
465+
/// use std::io::Write as _;
465466
///
466467
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
467468
/// let mut s = String::new();
@@ -474,6 +475,23 @@ macro_rules! r#try {
474475
/// }
475476
/// ```
476477
///
478+
/// If you also need the trait names themselves, such as to implement one or both on your types,
479+
/// import the containing module and then name them with a prefix:
480+
///
481+
/// ```
482+
/// # #![allow(unused_imports)]
483+
/// use std::fmt::{self, Write as _};
484+
/// use std::io::{self, Write as _};
485+
///
486+
/// struct Example;
487+
///
488+
/// impl fmt::Write for Example {
489+
/// fn write_str(&mut self, _s: &str) -> core::fmt::Result {
490+
/// unimplemented!();
491+
/// }
492+
/// }
493+
/// ```
494+
///
477495
/// Note: This macro can be used in `no_std` setups as well.
478496
/// In a `no_std` setup you are responsible for the implementation details of the components.
479497
///
@@ -526,25 +544,6 @@ macro_rules! write {
526544
/// Ok(())
527545
/// }
528546
/// ```
529-
///
530-
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
531-
/// implementing either, as objects do not typically implement both. However, the module must
532-
/// import the traits qualified so their names do not conflict:
533-
///
534-
/// ```
535-
/// use std::fmt::Write as FmtWrite;
536-
/// use std::io::Write as IoWrite;
537-
///
538-
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
539-
/// let mut s = String::new();
540-
/// let mut v = Vec::new();
541-
///
542-
/// writeln!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
543-
/// writeln!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
544-
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
545-
/// Ok(())
546-
/// }
547-
/// ```
548547
#[macro_export]
549548
#[stable(feature = "rust1", since = "1.0.0")]
550549
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")]

Diff for: library/core/src/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<T: ?Sized> *const T {
641641
/// }
642642
/// ```
643643
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
644-
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
644+
#[rustc_const_stable(feature = "const_ptr_offset_from", since = "1.65.0")]
645645
#[inline]
646646
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
647647
pub const unsafe fn offset_from(self, origin: *const T) -> isize

Diff for: library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<T: ?Sized> *mut T {
824824
/// }
825825
/// ```
826826
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
827-
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
827+
#[rustc_const_stable(feature = "const_ptr_offset_from", since = "1.65.0")]
828828
#[inline(always)]
829829
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
830830
pub const unsafe fn offset_from(self, origin: *const T) -> isize

Diff for: src/bootstrap/test.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,15 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15141514

15151515
test_args.append(&mut builder.config.cmd.test_args());
15161516

1517-
cmd.args(&test_args);
1517+
// On Windows, replace forward slashes in test-args by backslashes
1518+
// so the correct filters are passed to libtest
1519+
if cfg!(windows) {
1520+
let test_args_win: Vec<String> =
1521+
test_args.iter().map(|s| s.replace("/", "\\")).collect();
1522+
cmd.args(&test_args_win);
1523+
} else {
1524+
cmd.args(&test_args);
1525+
}
15181526

15191527
if builder.is_verbose() {
15201528
cmd.arg("--verbose");

Diff for: src/librustdoc/html/render/print_item.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,21 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
371371
}
372372
clean::ImportKind::Glob => String::new(),
373373
};
374+
let stab_tags = stab_tags.unwrap_or_default();
375+
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
376+
("", "")
377+
} else {
378+
("<div class=\"item-right docblock-short\">", "</div>")
379+
};
374380
write!(
375381
w,
376382
"<div class=\"item-left {stab}{add}import-item\"{id}>\
377383
<code>{vis}{imp}</code>\
378384
</div>\
379-
<div class=\"item-right docblock-short\">{stab_tags}</div>",
385+
{stab_tags_before}{stab_tags}{stab_tags_after}",
380386
stab = stab.unwrap_or_default(),
381387
vis = myitem.visibility.print_with_space(myitem.item_id, cx),
382388
imp = import.print(cx),
383-
stab_tags = stab_tags.unwrap_or_default(),
384389
);
385390
w.write_str(ITEM_TABLE_ROW_CLOSE);
386391
}
@@ -412,6 +417,12 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
412417

413418
let doc_value = myitem.doc_value().unwrap_or_default();
414419
w.write_str(ITEM_TABLE_ROW_OPEN);
420+
let docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string();
421+
let (docs_before, docs_after) = if docs.is_empty() {
422+
("", "")
423+
} else {
424+
("<div class=\"item-right docblock-short\">", "</div>")
425+
};
415426
write!(
416427
w,
417428
"<div class=\"item-left {stab}{add}module-item\">\
@@ -420,11 +431,10 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
420431
{unsafety_flag}\
421432
{stab_tags}\
422433
</div>\
423-
<div class=\"item-right docblock-short\">{docs}</div>",
434+
{docs_before}{docs}{docs_after}",
424435
name = myitem.name.unwrap(),
425436
visibility_emoji = visibility_emoji,
426437
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
427-
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
428438
class = myitem.type_(),
429439
add = add,
430440
stab = stab.unwrap_or_default(),
@@ -987,7 +997,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
987997
// So C's HTML will have something like this:
988998
//
989999
// ```html
990-
// <script type="text/javascript" src="/implementors/A/trait.Foo.js"
1000+
// <script src="/implementors/A/trait.Foo.js"
9911001
// data-ignore-extern-crates="A,B" async></script>
9921002
// ```
9931003
//
@@ -1013,9 +1023,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
10131023
.map(|cnum| cx.shared.tcx.crate_name(cnum).to_string())
10141024
.collect::<Vec<_>>()
10151025
.join(",");
1026+
let (extern_before, extern_after) =
1027+
if extern_crates.is_empty() { ("", "") } else { (" data-ignore-extern-crates=\"", "\"") };
10161028
write!(
10171029
w,
1018-
"<script type=\"text/javascript\" src=\"{src}\" data-ignore-extern-crates=\"{extern_crates}\" async></script>",
1030+
"<script src=\"{src}\"{extern_before}{extern_crates}{extern_after} async></script>",
10191031
src = js_src_path.finish(),
10201032
);
10211033
}

0 commit comments

Comments
 (0)