Skip to content

Commit c11207e

Browse files
committed
Auto merge of #99764 - matthiaskrgr:rollup-fawyb3m, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #99235 (rustdoc: Add support for `#[rustc_must_implement_one_of]`) - #99716 (remove useless mut from examples) - #99724 (Fix some broken link fragments.) - #99729 (Remove unused tuple fields) - #99757 (Make `transmute_copy` docs read better) - #99758 (remove useless `#[allow]` in a test) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c9b3183 + 8e5bc06 commit c11207e

File tree

18 files changed

+66
-50
lines changed

18 files changed

+66
-50
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -2412,9 +2412,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24122412
#[derive(Debug)]
24132413
enum SubOrigin<'hir> {
24142414
GAT(&'hir hir::Generics<'hir>),
2415-
Impl(&'hir hir::Generics<'hir>),
2416-
Trait(&'hir hir::Generics<'hir>),
2417-
Fn(&'hir hir::Generics<'hir>),
2415+
Impl,
2416+
Trait,
2417+
Fn,
24182418
Unknown,
24192419
}
24202420
let sub_origin = 'origin: {
@@ -2429,34 +2429,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24292429
kind: hir::ImplItemKind::TyAlias(..),
24302430
generics,
24312431
..
2432-
}) => SubOrigin::GAT(generics),
2433-
Node::ImplItem(hir::ImplItem {
2434-
kind: hir::ImplItemKind::Fn(..),
2435-
generics,
2436-
..
2437-
}) => SubOrigin::Fn(generics),
2438-
Node::TraitItem(hir::TraitItem {
2432+
})
2433+
| Node::TraitItem(hir::TraitItem {
24392434
kind: hir::TraitItemKind::Type(..),
24402435
generics,
24412436
..
24422437
}) => SubOrigin::GAT(generics),
2443-
Node::TraitItem(hir::TraitItem {
2444-
kind: hir::TraitItemKind::Fn(..),
2445-
generics,
2438+
Node::ImplItem(hir::ImplItem {
2439+
kind: hir::ImplItemKind::Fn(..),
24462440
..
2447-
}) => SubOrigin::Fn(generics),
2448-
Node::Item(hir::Item {
2449-
kind: hir::ItemKind::Trait(_, _, generics, _, _),
2441+
})
2442+
| Node::TraitItem(hir::TraitItem {
2443+
kind: hir::TraitItemKind::Fn(..),
24502444
..
2451-
}) => SubOrigin::Trait(generics),
2445+
})
2446+
| Node::Item(hir::Item {
2447+
kind: hir::ItemKind::Fn(..), ..
2448+
}) => SubOrigin::Fn,
24522449
Node::Item(hir::Item {
2453-
kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
2450+
kind: hir::ItemKind::Trait(..),
24542451
..
2455-
}) => SubOrigin::Impl(generics),
2452+
}) => SubOrigin::Trait,
24562453
Node::Item(hir::Item {
2457-
kind: hir::ItemKind::Fn(_, generics, _),
2458-
..
2459-
}) => SubOrigin::Fn(generics),
2454+
kind: hir::ItemKind::Impl(..), ..
2455+
}) => SubOrigin::Impl,
24602456
_ => continue,
24612457
};
24622458
}

compiler/rustc_resolve/src/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
524524
let crate_root = self.r.resolve_crate_root(source.ident);
525525
let crate_name = match crate_root.kind {
526526
ModuleKind::Def(.., name) => name,
527-
ModuleKind::Block(..) => unreachable!(),
527+
ModuleKind::Block => unreachable!(),
528528
};
529529
// HACK(eddyb) unclear how good this is, but keeping `$crate`
530530
// in `source` breaks `src/test/ui/imports/import-crate-var.rs`,
@@ -936,7 +936,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
936936
if self.block_needs_anonymous_module(block) {
937937
let module = self.r.new_module(
938938
Some(parent),
939-
ModuleKind::Block(block.id),
939+
ModuleKind::Block,
940940
expansion.to_expn_id(),
941941
block.span,
942942
parent.no_implicit_prelude,

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'a> Resolver<'a> {
163163

164164
let container = match parent.kind {
165165
ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()),
166-
ModuleKind::Block(..) => "block",
166+
ModuleKind::Block => "block",
167167
};
168168

169169
let old_noun = match old_binding.is_import() {

compiler/rustc_resolve/src/ident.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a> Resolver<'a> {
218218
return Some((self.expn_def_scope(ctxt.remove_mark()), None));
219219
}
220220

221-
if let ModuleKind::Block(..) = module.kind {
221+
if let ModuleKind::Block = module.kind {
222222
return Some((module.parent.unwrap().nearest_item_scope(), None));
223223
}
224224

@@ -333,7 +333,7 @@ impl<'a> Resolver<'a> {
333333
};
334334

335335
match module.kind {
336-
ModuleKind::Block(..) => {} // We can see through blocks
336+
ModuleKind::Block => {} // We can see through blocks
337337
_ => break,
338338
}
339339

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
14441444
// Items from this module
14451445
self.r.add_module_candidates(module, &mut names, &filter_fn);
14461446

1447-
if let ModuleKind::Block(..) = module.kind {
1447+
if let ModuleKind::Block = module.kind {
14481448
// We can see through blocks
14491449
} else {
14501450
// Items from the prelude

compiler/rustc_resolve/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ enum ModuleKind {
437437
/// f(); // Resolves to (1)
438438
/// }
439439
/// ```
440-
Block(NodeId),
440+
Block,
441441
/// Any module with a name.
442442
///
443443
/// This could be:
@@ -454,7 +454,7 @@ impl ModuleKind {
454454
/// Get name of the module.
455455
pub fn name(&self) -> Option<Symbol> {
456456
match self {
457-
ModuleKind::Block(..) => None,
457+
ModuleKind::Block => None,
458458
ModuleKind::Def(.., name) => Some(*name),
459459
}
460460
}
@@ -530,7 +530,7 @@ impl<'a> ModuleData<'a> {
530530
) -> Self {
531531
let is_foreign = match kind {
532532
ModuleKind::Def(_, def_id, _) => !def_id.is_local(),
533-
ModuleKind::Block(_) => false,
533+
ModuleKind::Block => false,
534534
};
535535
ModuleData {
536536
parent,

library/core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ pub fn copy<T: Copy>(x: &T) -> T {
10001000
///
10011001
/// This function will unsafely assume the pointer `src` is valid for [`size_of::<U>`][size_of]
10021002
/// bytes by transmuting `&T` to `&U` and then reading the `&U` (except that this is done in a way
1003-
/// that is correct even when `&U` makes stricter alignment requirements than `&T`). It will also
1003+
/// that is correct even when `&U` has stricter alignment requirements than `&T`). It will also
10041004
/// unsafely create a copy of the contained value instead of moving out of `src`.
10051005
///
10061006
/// It is not a compile-time error if `T` and `U` have different sizes, but it

library/std/src/io/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ pub trait Read {
898898
/// use std::fs::File;
899899
///
900900
/// fn main() -> io::Result<()> {
901-
/// let mut f = File::open("foo.txt")?;
901+
/// let f = File::open("foo.txt")?;
902902
///
903903
/// for byte in f.bytes() {
904904
/// println!("{}", byte.unwrap());
@@ -932,8 +932,8 @@ pub trait Read {
932932
/// use std::fs::File;
933933
///
934934
/// fn main() -> io::Result<()> {
935-
/// let mut f1 = File::open("foo.txt")?;
936-
/// let mut f2 = File::open("bar.txt")?;
935+
/// let f1 = File::open("foo.txt")?;
936+
/// let f2 = File::open("bar.txt")?;
937937
///
938938
/// let mut handle = f1.chain(f2);
939939
/// let mut buffer = String::new();
@@ -973,7 +973,7 @@ pub trait Read {
973973
/// use std::fs::File;
974974
///
975975
/// fn main() -> io::Result<()> {
976-
/// let mut f = File::open("foo.txt")?;
976+
/// let f = File::open("foo.txt")?;
977977
/// let mut buffer = [0; 5];
978978
///
979979
/// // read at most five bytes

src/doc/rustdoc/src/deprecated-features.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ change in any release.
1010

1111
In the past the most common use case for customizing passes was to omit the `strip-private` pass.
1212
You can do this more easily, and without risk of the pass being changed, by passing
13-
[`--document-private-items`](./unstable-features.md#--document-private-items).
13+
[`--document-private-items`](command-line-arguments.md#--document-private-items-show-items-that-are-not-public).

src/doc/rustdoc/src/unstable-features.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ Note that the third item is the crate root, which in this case is undocumented.
466466
and is also accepted on stable toolchains.
467467

468468
It can also be used with `--show-coverage`. Take a look at its
469-
[documentation](#--show-coverage-get-statistics-about-code-documentation-coverage) for more
469+
[documentation](#--show-coverage-calculate-the-percentage-of-items-with-documentation) for more
470470
information.
471471

472472
### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests

src/librustdoc/clean/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ fn clean_maybe_renamed_item<'tcx>(
19931993
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
19941994
let items =
19951995
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
1996+
19961997
TraitItem(Trait {
19971998
def_id,
19981999
items,

src/librustdoc/html/render/print_item.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use clean::AttributesExt;
22

3-
use std::cmp::Ordering;
4-
use std::fmt;
5-
use std::rc::Rc;
6-
73
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
84
use rustc_hir as hir;
95
use rustc_hir::def::CtorKind;
@@ -15,6 +11,9 @@ use rustc_middle::ty::{Adt, TyCtxt};
1511
use rustc_span::hygiene::MacroKind;
1612
use rustc_span::symbol::{kw, sym, Symbol};
1713
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
14+
use std::cmp::Ordering;
15+
use std::fmt;
16+
use std::rc::Rc;
1817

1918
use super::{
2019
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
@@ -37,6 +36,7 @@ use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3736
use crate::html::url_parts_builder::UrlPartsBuilder;
3837

3938
use askama::Template;
39+
use itertools::Itertools;
4040

4141
const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
4242
const ITEM_TABLE_CLOSE: &str = "</div>";
@@ -539,6 +539,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
539539
let count_types = required_types.len() + provided_types.len();
540540
let count_consts = required_consts.len() + provided_consts.len();
541541
let count_methods = required_methods.len() + provided_methods.len();
542+
let must_implement_one_of_functions =
543+
cx.tcx().trait_def(t.def_id).must_implement_one_of.clone();
542544

543545
// Output the trait definition
544546
wrap_into_docblock(w, |w| {
@@ -784,13 +786,22 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
784786
}
785787

786788
// Output the documentation for each function individually
787-
if !required_methods.is_empty() {
789+
if !required_methods.is_empty() || must_implement_one_of_functions.is_some() {
788790
write_small_section_header(
789791
w,
790792
"required-methods",
791793
"Required Methods",
792794
"<div class=\"methods\">",
793795
);
796+
797+
if let Some(list) = must_implement_one_of_functions.as_deref() {
798+
write!(
799+
w,
800+
"<div class=\"stab must_implement\">At least one of the `{}` methods is required.</div>",
801+
list.iter().join("`, `")
802+
);
803+
}
804+
794805
for m in required_methods {
795806
trait_item(w, cx, m, it);
796807
}

src/librustdoc/html/static/css/themes/ayu.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ details.rustdoc-toggle > summary::before {
205205

206206
/* Created this empty rule to satisfy the theme checks. */
207207
.stab.empty-impl {}
208+
.stab.must_implement {}
208209

209210
.stab.unstable,
210211
.stab.deprecated,
211212
.stab.portability,
212-
.stab.empty-impl {
213+
.stab.empty-impl,
214+
.stab.must_implement {
213215
color: #c5c5c5;
214216
background: #314559 !important;
215217
border-style: none !important;

src/librustdoc/html/static/css/themes/dark.css

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ details.rustdoc-toggle > summary::before {
180180
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
181181
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
182182
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
183+
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
183184
.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
184185
.stab.portability > code { background: none; }
185186

src/librustdoc/html/static/css/themes/light.css

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ details.rustdoc-toggle > summary::before {
163163
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
164164
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
165165
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
166+
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; }
166167
.stab.portability { background: #F3DFFF; border-color: #b07bdb; }
167168
.stab.portability > code { background: none; }
168169

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_name = "c"]
2+
#![feature(rustc_attrs)]
3+
4+
#[rustc_must_implement_one_of(a, b)]
5+
// @matches c/trait.Trait.html '//*[@class="stab must_implement"]' \
6+
// 'At least one of the `a`, `b` methods is required.$'
7+
pub trait Trait {
8+
fn a() {}
9+
fn b() {}
10+
}

src/test/ui/issues/issue-30371.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-pass
22
#![allow(unreachable_code)]
3-
#![allow(unused_mut)] // rust-lang/rust#54586
43
#![deny(unused_variables)]
54

65
fn main() {

src/tools/linkchecker/main.rs

-5
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,6 @@ impl Checker {
348348
return;
349349
}
350350

351-
// These appear to be broken in mdbook right now?
352-
if fragment.starts_with('-') {
353-
return;
354-
}
355-
356351
parse_ids(&mut target_ids.borrow_mut(), &pretty_path, target_source, report);
357352

358353
if target_ids.borrow().contains(*fragment) {

0 commit comments

Comments
 (0)