Skip to content

Commit

Permalink
Auto merge of #99764 - matthiaskrgr:rollup-fawyb3m, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 26, 2022
2 parents c9b3183 + 8e5bc06 commit c11207e
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 50 deletions.
40 changes: 18 additions & 22 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2412,9 +2412,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
#[derive(Debug)]
enum SubOrigin<'hir> {
GAT(&'hir hir::Generics<'hir>),
Impl(&'hir hir::Generics<'hir>),
Trait(&'hir hir::Generics<'hir>),
Fn(&'hir hir::Generics<'hir>),
Impl,
Trait,
Fn,
Unknown,
}
let sub_origin = 'origin: {
Expand All @@ -2429,34 +2429,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
kind: hir::ImplItemKind::TyAlias(..),
generics,
..
}) => SubOrigin::GAT(generics),
Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(..),
generics,
..
}) => SubOrigin::Fn(generics),
Node::TraitItem(hir::TraitItem {
})
| Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(..),
generics,
..
}) => SubOrigin::GAT(generics),
Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(..),
generics,
Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(..),
..
}) => SubOrigin::Fn(generics),
Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, _, generics, _, _),
})
| Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(..),
..
}) => SubOrigin::Trait(generics),
})
| Node::Item(hir::Item {
kind: hir::ItemKind::Fn(..), ..
}) => SubOrigin::Fn,
Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
kind: hir::ItemKind::Trait(..),
..
}) => SubOrigin::Impl(generics),
}) => SubOrigin::Trait,
Node::Item(hir::Item {
kind: hir::ItemKind::Fn(_, generics, _),
..
}) => SubOrigin::Fn(generics),
kind: hir::ItemKind::Impl(..), ..
}) => SubOrigin::Impl,
_ => continue,
};
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let crate_root = self.r.resolve_crate_root(source.ident);
let crate_name = match crate_root.kind {
ModuleKind::Def(.., name) => name,
ModuleKind::Block(..) => unreachable!(),
ModuleKind::Block => unreachable!(),
};
// HACK(eddyb) unclear how good this is, but keeping `$crate`
// in `source` breaks `src/test/ui/imports/import-crate-var.rs`,
Expand Down Expand Up @@ -936,7 +936,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
if self.block_needs_anonymous_module(block) {
let module = self.r.new_module(
Some(parent),
ModuleKind::Block(block.id),
ModuleKind::Block,
expansion.to_expn_id(),
block.span,
parent.no_implicit_prelude,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'a> Resolver<'a> {

let container = match parent.kind {
ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()),
ModuleKind::Block(..) => "block",
ModuleKind::Block => "block",
};

let old_noun = match old_binding.is_import() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'a> Resolver<'a> {
return Some((self.expn_def_scope(ctxt.remove_mark()), None));
}

if let ModuleKind::Block(..) = module.kind {
if let ModuleKind::Block = module.kind {
return Some((module.parent.unwrap().nearest_item_scope(), None));
}

Expand Down Expand Up @@ -333,7 +333,7 @@ impl<'a> Resolver<'a> {
};

match module.kind {
ModuleKind::Block(..) => {} // We can see through blocks
ModuleKind::Block => {} // We can see through blocks
_ => break,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
// Items from this module
self.r.add_module_candidates(module, &mut names, &filter_fn);

if let ModuleKind::Block(..) = module.kind {
if let ModuleKind::Block = module.kind {
// We can see through blocks
} else {
// Items from the prelude
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ enum ModuleKind {
/// f(); // Resolves to (1)
/// }
/// ```
Block(NodeId),
Block,
/// Any module with a name.
///
/// This could be:
Expand All @@ -454,7 +454,7 @@ impl ModuleKind {
/// Get name of the module.
pub fn name(&self) -> Option<Symbol> {
match self {
ModuleKind::Block(..) => None,
ModuleKind::Block => None,
ModuleKind::Def(.., name) => Some(*name),
}
}
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<'a> ModuleData<'a> {
) -> Self {
let is_foreign = match kind {
ModuleKind::Def(_, def_id, _) => !def_id.is_local(),
ModuleKind::Block(_) => false,
ModuleKind::Block => false,
};
ModuleData {
parent,
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ pub fn copy<T: Copy>(x: &T) -> T {
///
/// This function will unsafely assume the pointer `src` is valid for [`size_of::<U>`][size_of]
/// bytes by transmuting `&T` to `&U` and then reading the `&U` (except that this is done in a way
/// that is correct even when `&U` makes stricter alignment requirements than `&T`). It will also
/// that is correct even when `&U` has stricter alignment requirements than `&T`). It will also
/// unsafely create a copy of the contained value instead of moving out of `src`.
///
/// It is not a compile-time error if `T` and `U` have different sizes, but it
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ pub trait Read {
/// use std::fs::File;
///
/// fn main() -> io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let f = File::open("foo.txt")?;
///
/// for byte in f.bytes() {
/// println!("{}", byte.unwrap());
Expand Down Expand Up @@ -932,8 +932,8 @@ pub trait Read {
/// use std::fs::File;
///
/// fn main() -> io::Result<()> {
/// let mut f1 = File::open("foo.txt")?;
/// let mut f2 = File::open("bar.txt")?;
/// let f1 = File::open("foo.txt")?;
/// let f2 = File::open("bar.txt")?;
///
/// let mut handle = f1.chain(f2);
/// let mut buffer = String::new();
Expand Down Expand Up @@ -973,7 +973,7 @@ pub trait Read {
/// use std::fs::File;
///
/// fn main() -> io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let f = File::open("foo.txt")?;
/// let mut buffer = [0; 5];
///
/// // read at most five bytes
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/deprecated-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ change in any release.

In the past the most common use case for customizing passes was to omit the `strip-private` pass.
You can do this more easily, and without risk of the pass being changed, by passing
[`--document-private-items`](./unstable-features.md#--document-private-items).
[`--document-private-items`](command-line-arguments.md#--document-private-items-show-items-that-are-not-public).
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ Note that the third item is the crate root, which in this case is undocumented.
and is also accepted on stable toolchains.

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

### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ fn clean_maybe_renamed_item<'tcx>(
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
let items =
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();

TraitItem(Trait {
def_id,
items,
Expand Down
21 changes: 16 additions & 5 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use clean::AttributesExt;

use std::cmp::Ordering;
use std::fmt;
use std::rc::Rc;

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
use rustc_hir::def::CtorKind;
Expand All @@ -15,6 +11,9 @@ use rustc_middle::ty::{Adt, TyCtxt};
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
use std::cmp::Ordering;
use std::fmt;
use std::rc::Rc;

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

use askama::Template;
use itertools::Itertools;

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

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

// Output the documentation for each function individually
if !required_methods.is_empty() {
if !required_methods.is_empty() || must_implement_one_of_functions.is_some() {
write_small_section_header(
w,
"required-methods",
"Required Methods",
"<div class=\"methods\">",
);

if let Some(list) = must_implement_one_of_functions.as_deref() {
write!(
w,
"<div class=\"stab must_implement\">At least one of the `{}` methods is required.</div>",
list.iter().join("`, `")
);
}

for m in required_methods {
trait_item(w, cx, m, it);
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,13 @@ details.rustdoc-toggle > summary::before {

/* Created this empty rule to satisfy the theme checks. */
.stab.empty-impl {}
.stab.must_implement {}

.stab.unstable,
.stab.deprecated,
.stab.portability,
.stab.empty-impl {
.stab.empty-impl,
.stab.must_implement {
color: #c5c5c5;
background: #314559 !important;
border-style: none !important;
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ details.rustdoc-toggle > summary::before {
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; }
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; }
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; }
.stab.portability > code { background: none; }

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ details.rustdoc-toggle > summary::before {
.stab.empty-impl { background: #FFF5D6; border-color: #FFC600; }
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; }
.stab.must_implement { background: #F3DFFF; border-color: #b07bdb; }
.stab.portability { background: #F3DFFF; border-color: #b07bdb; }
.stab.portability > code { background: none; }

Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc/must_implement_one_of.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name = "c"]
#![feature(rustc_attrs)]

#[rustc_must_implement_one_of(a, b)]
// @matches c/trait.Trait.html '//*[@class="stab must_implement"]' \
// 'At least one of the `a`, `b` methods is required.$'
pub trait Trait {
fn a() {}
fn b() {}
}
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-30371.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass
#![allow(unreachable_code)]
#![allow(unused_mut)] // rust-lang/rust#54586
#![deny(unused_variables)]

fn main() {
Expand Down
5 changes: 0 additions & 5 deletions src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,6 @@ impl Checker {
return;
}

// These appear to be broken in mdbook right now?
if fragment.starts_with('-') {
return;
}

parse_ids(&mut target_ids.borrow_mut(), &pretty_path, target_source, report);

if target_ids.borrow().contains(*fragment) {
Expand Down

0 comments on commit c11207e

Please sign in to comment.