Skip to content

Commit

Permalink
Auto merge of rust-lang#100274 - Mark-Simulacrum:beta-next, r=Mark-Si…
Browse files Browse the repository at this point in the history
…mulacrum

[beta] 1.64.0 branching

Includes cherry picks of:

* rust-lang#100207
* rust-lang/rust-clippy#9302
* rust-lang/rust@49b1904 (explicit_auto_deref into nursery)
*  Avoid ICE in rustdoc when using Fn bounds rust-lang#100205

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed Aug 9, 2022
2 parents 9bbbf60 + 275ad6b commit 56714e5
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 38 deletions.
3 changes: 3 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ impl Step for RustdocGUI {
.arg("doc")
.arg("--target-dir")
.arg(&out_dir)
.env("RUSTC_BOOTSTRAP", "1")
.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler))
.current_dir(path);
Expand Down Expand Up @@ -1723,6 +1724,8 @@ impl BookTest {

let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
let path = builder.src.join(&self.path);
// Books often have feature-gated example text.
rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
builder.add_rust_test_threads(&mut rustbook_cmd);
builder.info(&format!("Testing rustbook {}", self.path.display()));
Expand Down
2 changes: 1 addition & 1 deletion src/ci/channel
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly
beta
28 changes: 18 additions & 10 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,13 @@ where
fn make_final_bounds(
&self,
ty_to_bounds: FxHashMap<Type, FxHashSet<GenericBound>>,
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)>,
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<GenericBound>>,
) -> Vec<WherePredicate> {
ty_to_bounds
.into_iter()
.flat_map(|(ty, mut bounds)| {
if let Some(data) = ty_to_fn.get(&ty) {
let (poly_trait, output) =
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
if let Some((ref poly_trait, ref output)) = ty_to_fn.get(&ty) {
let mut new_path = poly_trait.trait_.clone();
let last_segment = new_path.segments.pop().expect("segments were empty");

Expand All @@ -374,8 +372,9 @@ where
GenericArgs::Parenthesized { inputs, output } => (inputs, output),
};

let output = output.as_ref().cloned().map(Box::new);
if old_output.is_some() && old_output != output {
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, data.1);
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, output);
}

let new_params = GenericArgs::Parenthesized { inputs: old_input, output };
Expand All @@ -385,7 +384,10 @@ where
.push(PathSegment { name: last_segment.name, args: new_params });

bounds.insert(GenericBound::TraitBound(
PolyTrait { trait_: new_path, generic_params: poly_trait.generic_params },
PolyTrait {
trait_: new_path,
generic_params: poly_trait.generic_params.clone(),
},
hir::TraitBoundModifier::None,
));
}
Expand Down Expand Up @@ -471,7 +473,7 @@ where
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
let mut ty_to_traits: FxHashMap<Type, FxHashSet<Path>> = Default::default();

let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
let mut ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)> = Default::default();

for p in clean_where_predicates {
let (orig_p, p) = (p, p.clean(self.cx));
Expand Down Expand Up @@ -535,8 +537,8 @@ where
if is_fn {
ty_to_fn
.entry(ty.clone())
.and_modify(|e| *e = (Some(poly_trait.clone()), e.1.clone()))
.or_insert(((Some(poly_trait.clone())), None));
.and_modify(|e| *e = (poly_trait.clone(), e.1.clone()))
.or_insert(((poly_trait.clone()), None));

ty_to_bounds.entry(ty.clone()).or_default();
} else {
Expand All @@ -559,7 +561,13 @@ where
.and_modify(|e| {
*e = (e.0.clone(), Some(rhs.ty().unwrap().clone()))
})
.or_insert((None, Some(rhs.ty().unwrap().clone())));
.or_insert((
PolyTrait {
trait_: trait_.clone(),
generic_params: Vec::new(),
},
Some(rhs.ty().unwrap().clone()),
));
continue;
}

Expand Down
37 changes: 32 additions & 5 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub(crate) fn try_inline_glob(
cx: &mut DocContext<'_>,
res: Res,
visited: &mut FxHashSet<DefId>,
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
) -> Option<Vec<clean::Item>> {
let did = res.opt_def_id()?;
if did.is_local() {
Expand All @@ -153,8 +154,17 @@ pub(crate) fn try_inline_glob(

match res {
Res::Def(DefKind::Mod, did) => {
let m = build_module(cx, did, visited);
Some(m.items)
let mut items = build_module_items(cx, did, visited, inlined_names);
items.drain_filter(|item| {
if let Some(name) = item.name {
// If an item with the same type and name already exists,
// it takes priority over the inlined stuff.
!inlined_names.insert((item.type_(), name))
} else {
false
}
});
Some(items)
}
// glob imports on things like enums aren't inlined even for local exports, so just bail
_ => None,
Expand Down Expand Up @@ -517,6 +527,18 @@ fn build_module(
did: DefId,
visited: &mut FxHashSet<DefId>,
) -> clean::Module {
let items = build_module_items(cx, did, visited, &mut FxHashSet::default());

let span = clean::Span::new(cx.tcx.def_span(did));
clean::Module { items, span }
}

fn build_module_items(
cx: &mut DocContext<'_>,
did: DefId,
visited: &mut FxHashSet<DefId>,
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
) -> Vec<clean::Item> {
let mut items = Vec::new();

// If we're re-exporting a re-export it may actually re-export something in
Expand All @@ -526,7 +548,13 @@ fn build_module(
if item.vis.is_public() {
let res = item.res.expect_non_local();
if let Some(def_id) = res.mod_def_id() {
if did == def_id || !visited.insert(def_id) {
// If we're inlining a glob import, it's possible to have
// two distinct modules with the same name. We don't want to
// inline it, or mark any of its contents as visited.
if did == def_id
|| inlined_names.contains(&(ItemType::Module, item.ident.name))
|| !visited.insert(def_id)
{
continue;
}
}
Expand Down Expand Up @@ -563,8 +591,7 @@ fn build_module(
}
}

let span = clean::Span::new(cx.tcx.def_span(did));
clean::Module { items, span }
items
}

pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
Expand Down
27 changes: 11 additions & 16 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
// priority to the not-imported one, so we should, too.
items.extend(self.items.iter().flat_map(|(item, renamed)| {
// First, lower everything other than imports.
if matches!(item.kind, hir::ItemKind::Use(..)) {
if matches!(item.kind, hir::ItemKind::Use(_, hir::UseKind::Glob)) {
return Vec::new();
}
let v = clean_maybe_renamed_item(cx, item, *renamed);
Expand All @@ -84,20 +84,13 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
}));
items.extend(self.items.iter().flat_map(|(item, renamed)| {
// Now we actually lower the imports, skipping everything else.
if !matches!(item.kind, hir::ItemKind::Use(..)) {
return Vec::new();
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
let name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
clean_use_statement(item, name, path, hir::UseKind::Glob, cx, &mut inserted)
} else {
// skip everything else
Vec::new()
}
let mut v = clean_maybe_renamed_item(cx, item, *renamed);
v.drain_filter(|item| {
if let Some(name) = item.name {
// If an item with the same type and name already exists,
// it takes priority over the inlined stuff.
!inserted.insert((item.type_(), name))
} else {
false
}
});
v
}));

// determine if we should display the inner contents or
Expand Down Expand Up @@ -1967,7 +1960,7 @@ fn clean_maybe_renamed_item<'tcx>(
return clean_extern_crate(item, name, orig_name, cx);
}
ItemKind::Use(path, kind) => {
return clean_use_statement(item, name, path, kind, cx);
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
}
_ => unreachable!("not yet converted"),
};
Expand Down Expand Up @@ -2088,6 +2081,7 @@ fn clean_use_statement<'tcx>(
path: &hir::Path<'tcx>,
kind: hir::UseKind,
cx: &mut DocContext<'tcx>,
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
) -> Vec<Item> {
// We need this comparison because some imports (for std types for example)
// are "inserted" as well but directly by the compiler and they should not be
Expand Down Expand Up @@ -2153,7 +2147,8 @@ fn clean_use_statement<'tcx>(
let inner = if kind == hir::UseKind::Glob {
if !denied {
let mut visited = FxHashSet::default();
if let Some(items) = inline::try_inline_glob(cx, path.res, &mut visited) {
if let Some(items) = inline::try_inline_glob(cx, path.res, &mut visited, inlined_names)
{
return items;
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/rustdoc/auxiliary/issue-100204-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![crate_name="first"]

pub mod prelude {
pub use crate::Bot;
}

pub struct Bot;

impl Bot {
pub fn new() -> Bot {
Bot
}
}
21 changes: 21 additions & 0 deletions src/test/rustdoc/fn-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Regression test for #100143

use std::iter::Peekable;

pub struct Span<F: Fn(&i32)> {
inner: Peekable<ConditionalIterator<F>>,
}

pub struct ConditionalIterator<F> {
f: F,
}


// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header in-band"]' 'impl<F: Fn(&i32)> Iterator for ConditionalIterator<F>'
impl<F: Fn(&i32)> Iterator for ConditionalIterator<F> {
type Item = ();

fn next(&mut self) -> Option<Self::Item> {
todo!()
}
}
14 changes: 14 additions & 0 deletions src/test/rustdoc/issue-100204-inline-impl-through-glob-import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// aux-build:issue-100204-aux.rs
// build-aux-docs
// ignore-cross-compile

#![crate_name="second"]

extern crate first;

pub mod prelude {}

// @has first/struct.Bot.html '//h4[@class="code-header"]' 'pub fn new() -> Bot'
// @has second/struct.Bot.html '//h4[@class="code-header"]' 'pub fn new() -> Bot'
#[doc(inline)]
pub use first::*;
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.60.0"]
pub EXPLICIT_AUTO_DEREF,
complexity,
nursery,
"dereferencing when the compiler would automatically dereference"
}

Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(crate_in_macro_def::CRATE_IN_MACRO_DEF),
LintId::of(default::FIELD_REASSIGN_WITH_DEFAULT),
LintId::of(default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY),
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
LintId::of(dereference::NEEDLESS_BORROW),
LintId::of(derivable_impls::DERIVABLE_IMPLS),
LintId::of(derive::DERIVE_HASH_XOR_EQ),
Expand Down Expand Up @@ -144,7 +143,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(matches::MATCH_STR_CASE_MISMATCH),
LintId::of(matches::NEEDLESS_MATCH),
LintId::of(matches::REDUNDANT_PATTERN_MATCHING),
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
LintId::of(matches::SINGLE_MATCH),
LintId::of(matches::WILDCARD_IN_OR_PATTERNS),
LintId::of(mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
LintId::of(bytes_count_to_len::BYTES_COUNT_TO_LEN),
LintId::of(casts::CHAR_LIT_AS_U8),
LintId::of(casts::UNNECESSARY_CAST),
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
LintId::of(derivable_impls::DERIVABLE_IMPLS),
LintId::of(double_parens::DOUBLE_PARENS),
LintId::of(explicit_write::EXPLICIT_WRITE),
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/clippy_lints/src/lib.register_nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
LintId::of(cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(copies::BRANCHES_SHARING_CODE),
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
LintId::of(equatable_if_let::EQUATABLE_IF_LET),
LintId::of(fallible_impl_from::FALLIBLE_IMPL_FROM),
LintId::of(floating_point_arithmetic::IMPRECISE_FLOPS),
LintId::of(floating_point_arithmetic::SUBOPTIMAL_FLOPS),
LintId::of(future_not_send::FUTURE_NOT_SEND),
LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE),
LintId::of(let_if_seq::USELESS_LET_IF_SEQ),
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
LintId::of(methods::ITER_WITH_DRAIN),
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
LintId::of(loops::EMPTY_LOOP),
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
LintId::of(loops::MUT_RANGE_BOUND),
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
LintId::of(methods::NO_EFFECT_REPLACE),
LintId::of(methods::SUSPICIOUS_MAP),
LintId::of(mut_key::MUTABLE_KEY_TYPE),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.60.0"]
pub SIGNIFICANT_DROP_IN_SCRUTINEE,
suspicious,
nursery,
"warns when a temporary of a type with a drop with a significant side-effect might have a surprising lifetime"
}

Expand Down

0 comments on commit 56714e5

Please sign in to comment.