Skip to content

Commit 56714e5

Browse files
committed
Auto merge of #100274 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] 1.64.0 branching Includes cherry picks of: * #100207 * rust-lang/rust-clippy#9302 * 49b1904 (explicit_auto_deref into nursery) * Avoid ICE in rustdoc when using Fn bounds #100205 r? `@Mark-Simulacrum`
2 parents 9bbbf60 + 275ad6b commit 56714e5

14 files changed

+117
-38
lines changed

Diff for: src/bootstrap/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ impl Step for RustdocGUI {
10031003
.arg("doc")
10041004
.arg("--target-dir")
10051005
.arg(&out_dir)
1006+
.env("RUSTC_BOOTSTRAP", "1")
10061007
.env("RUSTDOC", builder.rustdoc(self.compiler))
10071008
.env("RUSTC", builder.rustc(self.compiler))
10081009
.current_dir(path);
@@ -1723,6 +1724,8 @@ impl BookTest {
17231724

17241725
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
17251726
let path = builder.src.join(&self.path);
1727+
// Books often have feature-gated example text.
1728+
rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
17261729
rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
17271730
builder.add_rust_test_threads(&mut rustbook_cmd);
17281731
builder.info(&format!("Testing rustbook {}", self.path.display()));

Diff for: src/ci/channel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly
1+
beta

Diff for: src/librustdoc/clean/auto_trait.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,13 @@ where
348348
fn make_final_bounds(
349349
&self,
350350
ty_to_bounds: FxHashMap<Type, FxHashSet<GenericBound>>,
351-
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
351+
ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)>,
352352
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<GenericBound>>,
353353
) -> Vec<WherePredicate> {
354354
ty_to_bounds
355355
.into_iter()
356356
.flat_map(|(ty, mut bounds)| {
357-
if let Some(data) = ty_to_fn.get(&ty) {
358-
let (poly_trait, output) =
359-
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
357+
if let Some((ref poly_trait, ref output)) = ty_to_fn.get(&ty) {
360358
let mut new_path = poly_trait.trait_.clone();
361359
let last_segment = new_path.segments.pop().expect("segments were empty");
362360

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

375+
let output = output.as_ref().cloned().map(Box::new);
377376
if old_output.is_some() && old_output != output {
378-
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, data.1);
377+
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, output);
379378
}
380379

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

387386
bounds.insert(GenericBound::TraitBound(
388-
PolyTrait { trait_: new_path, generic_params: poly_trait.generic_params },
387+
PolyTrait {
388+
trait_: new_path,
389+
generic_params: poly_trait.generic_params.clone(),
390+
},
389391
hir::TraitBoundModifier::None,
390392
));
391393
}
@@ -471,7 +473,7 @@ where
471473
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
472474
let mut ty_to_traits: FxHashMap<Type, FxHashSet<Path>> = Default::default();
473475

474-
let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
476+
let mut ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)> = Default::default();
475477

476478
for p in clean_where_predicates {
477479
let (orig_p, p) = (p, p.clean(self.cx));
@@ -535,8 +537,8 @@ where
535537
if is_fn {
536538
ty_to_fn
537539
.entry(ty.clone())
538-
.and_modify(|e| *e = (Some(poly_trait.clone()), e.1.clone()))
539-
.or_insert(((Some(poly_trait.clone())), None));
540+
.and_modify(|e| *e = (poly_trait.clone(), e.1.clone()))
541+
.or_insert(((poly_trait.clone()), None));
540542

541543
ty_to_bounds.entry(ty.clone()).or_default();
542544
} else {
@@ -559,7 +561,13 @@ where
559561
.and_modify(|e| {
560562
*e = (e.0.clone(), Some(rhs.ty().unwrap().clone()))
561563
})
562-
.or_insert((None, Some(rhs.ty().unwrap().clone())));
564+
.or_insert((
565+
PolyTrait {
566+
trait_: trait_.clone(),
567+
generic_params: Vec::new(),
568+
},
569+
Some(rhs.ty().unwrap().clone()),
570+
));
563571
continue;
564572
}
565573

Diff for: src/librustdoc/clean/inline.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub(crate) fn try_inline_glob(
145145
cx: &mut DocContext<'_>,
146146
res: Res,
147147
visited: &mut FxHashSet<DefId>,
148+
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
148149
) -> Option<Vec<clean::Item>> {
149150
let did = res.opt_def_id()?;
150151
if did.is_local() {
@@ -153,8 +154,17 @@ pub(crate) fn try_inline_glob(
153154

154155
match res {
155156
Res::Def(DefKind::Mod, did) => {
156-
let m = build_module(cx, did, visited);
157-
Some(m.items)
157+
let mut items = build_module_items(cx, did, visited, inlined_names);
158+
items.drain_filter(|item| {
159+
if let Some(name) = item.name {
160+
// If an item with the same type and name already exists,
161+
// it takes priority over the inlined stuff.
162+
!inlined_names.insert((item.type_(), name))
163+
} else {
164+
false
165+
}
166+
});
167+
Some(items)
158168
}
159169
// glob imports on things like enums aren't inlined even for local exports, so just bail
160170
_ => None,
@@ -517,6 +527,18 @@ fn build_module(
517527
did: DefId,
518528
visited: &mut FxHashSet<DefId>,
519529
) -> clean::Module {
530+
let items = build_module_items(cx, did, visited, &mut FxHashSet::default());
531+
532+
let span = clean::Span::new(cx.tcx.def_span(did));
533+
clean::Module { items, span }
534+
}
535+
536+
fn build_module_items(
537+
cx: &mut DocContext<'_>,
538+
did: DefId,
539+
visited: &mut FxHashSet<DefId>,
540+
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
541+
) -> Vec<clean::Item> {
520542
let mut items = Vec::new();
521543

522544
// If we're re-exporting a re-export it may actually re-export something in
@@ -526,7 +548,13 @@ fn build_module(
526548
if item.vis.is_public() {
527549
let res = item.res.expect_non_local();
528550
if let Some(def_id) = res.mod_def_id() {
529-
if did == def_id || !visited.insert(def_id) {
551+
// If we're inlining a glob import, it's possible to have
552+
// two distinct modules with the same name. We don't want to
553+
// inline it, or mark any of its contents as visited.
554+
if did == def_id
555+
|| inlined_names.contains(&(ItemType::Module, item.ident.name))
556+
|| !visited.insert(def_id)
557+
{
530558
continue;
531559
}
532560
}
@@ -563,8 +591,7 @@ fn build_module(
563591
}
564592
}
565593

566-
let span = clean::Span::new(cx.tcx.def_span(did));
567-
clean::Module { items, span }
594+
items
568595
}
569596

570597
pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {

Diff for: src/librustdoc/clean/mod.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
7171
// priority to the not-imported one, so we should, too.
7272
items.extend(self.items.iter().flat_map(|(item, renamed)| {
7373
// First, lower everything other than imports.
74-
if matches!(item.kind, hir::ItemKind::Use(..)) {
74+
if matches!(item.kind, hir::ItemKind::Use(_, hir::UseKind::Glob)) {
7575
return Vec::new();
7676
}
7777
let v = clean_maybe_renamed_item(cx, item, *renamed);
@@ -84,20 +84,13 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
8484
}));
8585
items.extend(self.items.iter().flat_map(|(item, renamed)| {
8686
// Now we actually lower the imports, skipping everything else.
87-
if !matches!(item.kind, hir::ItemKind::Use(..)) {
88-
return Vec::new();
87+
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
88+
let name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
89+
clean_use_statement(item, name, path, hir::UseKind::Glob, cx, &mut inserted)
90+
} else {
91+
// skip everything else
92+
Vec::new()
8993
}
90-
let mut v = clean_maybe_renamed_item(cx, item, *renamed);
91-
v.drain_filter(|item| {
92-
if let Some(name) = item.name {
93-
// If an item with the same type and name already exists,
94-
// it takes priority over the inlined stuff.
95-
!inserted.insert((item.type_(), name))
96-
} else {
97-
false
98-
}
99-
});
100-
v
10194
}));
10295

10396
// determine if we should display the inner contents or
@@ -1967,7 +1960,7 @@ fn clean_maybe_renamed_item<'tcx>(
19671960
return clean_extern_crate(item, name, orig_name, cx);
19681961
}
19691962
ItemKind::Use(path, kind) => {
1970-
return clean_use_statement(item, name, path, kind, cx);
1963+
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
19711964
}
19721965
_ => unreachable!("not yet converted"),
19731966
};
@@ -2088,6 +2081,7 @@ fn clean_use_statement<'tcx>(
20882081
path: &hir::Path<'tcx>,
20892082
kind: hir::UseKind,
20902083
cx: &mut DocContext<'tcx>,
2084+
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
20912085
) -> Vec<Item> {
20922086
// We need this comparison because some imports (for std types for example)
20932087
// are "inserted" as well but directly by the compiler and they should not be
@@ -2153,7 +2147,8 @@ fn clean_use_statement<'tcx>(
21532147
let inner = if kind == hir::UseKind::Glob {
21542148
if !denied {
21552149
let mut visited = FxHashSet::default();
2156-
if let Some(items) = inline::try_inline_glob(cx, path.res, &mut visited) {
2150+
if let Some(items) = inline::try_inline_glob(cx, path.res, &mut visited, inlined_names)
2151+
{
21572152
return items;
21582153
}
21592154
}

Diff for: src/test/rustdoc/auxiliary/issue-100204-aux.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_name="first"]
2+
3+
pub mod prelude {
4+
pub use crate::Bot;
5+
}
6+
7+
pub struct Bot;
8+
9+
impl Bot {
10+
pub fn new() -> Bot {
11+
Bot
12+
}
13+
}

Diff for: src/test/rustdoc/fn-bound.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for #100143
2+
3+
use std::iter::Peekable;
4+
5+
pub struct Span<F: Fn(&i32)> {
6+
inner: Peekable<ConditionalIterator<F>>,
7+
}
8+
9+
pub struct ConditionalIterator<F> {
10+
f: F,
11+
}
12+
13+
14+
// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header in-band"]' 'impl<F: Fn(&i32)> Iterator for ConditionalIterator<F>'
15+
impl<F: Fn(&i32)> Iterator for ConditionalIterator<F> {
16+
type Item = ();
17+
18+
fn next(&mut self) -> Option<Self::Item> {
19+
todo!()
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// aux-build:issue-100204-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name="second"]
6+
7+
extern crate first;
8+
9+
pub mod prelude {}
10+
11+
// @has first/struct.Bot.html '//h4[@class="code-header"]' 'pub fn new() -> Bot'
12+
// @has second/struct.Bot.html '//h4[@class="code-header"]' 'pub fn new() -> Bot'
13+
#[doc(inline)]
14+
pub use first::*;

Diff for: src/tools/clippy/clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ declare_clippy_lint! {
127127
/// ```
128128
#[clippy::version = "1.60.0"]
129129
pub EXPLICIT_AUTO_DEREF,
130-
complexity,
130+
nursery,
131131
"dereferencing when the compiler would automatically dereference"
132132
}
133133

Diff for: src/tools/clippy/clippy_lints/src/lib.register_all.rs

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
3939
LintId::of(crate_in_macro_def::CRATE_IN_MACRO_DEF),
4040
LintId::of(default::FIELD_REASSIGN_WITH_DEFAULT),
4141
LintId::of(default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY),
42-
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
4342
LintId::of(dereference::NEEDLESS_BORROW),
4443
LintId::of(derivable_impls::DERIVABLE_IMPLS),
4544
LintId::of(derive::DERIVE_HASH_XOR_EQ),
@@ -144,7 +143,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
144143
LintId::of(matches::MATCH_STR_CASE_MISMATCH),
145144
LintId::of(matches::NEEDLESS_MATCH),
146145
LintId::of(matches::REDUNDANT_PATTERN_MATCHING),
147-
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
148146
LintId::of(matches::SINGLE_MATCH),
149147
LintId::of(matches::WILDCARD_IN_OR_PATTERNS),
150148
LintId::of(mem_replace::MEM_REPLACE_OPTION_WITH_NONE),

Diff for: src/tools/clippy/clippy_lints/src/lib.register_complexity.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
99
LintId::of(bytes_count_to_len::BYTES_COUNT_TO_LEN),
1010
LintId::of(casts::CHAR_LIT_AS_U8),
1111
LintId::of(casts::UNNECESSARY_CAST),
12-
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
1312
LintId::of(derivable_impls::DERIVABLE_IMPLS),
1413
LintId::of(double_parens::DOUBLE_PARENS),
1514
LintId::of(explicit_write::EXPLICIT_WRITE),

Diff for: src/tools/clippy/clippy_lints/src/lib.register_nursery.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
66
LintId::of(attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
77
LintId::of(cognitive_complexity::COGNITIVE_COMPLEXITY),
88
LintId::of(copies::BRANCHES_SHARING_CODE),
9+
LintId::of(dereference::EXPLICIT_AUTO_DEREF),
910
LintId::of(equatable_if_let::EQUATABLE_IF_LET),
1011
LintId::of(fallible_impl_from::FALLIBLE_IMPL_FROM),
1112
LintId::of(floating_point_arithmetic::IMPRECISE_FLOPS),
1213
LintId::of(floating_point_arithmetic::SUBOPTIMAL_FLOPS),
1314
LintId::of(future_not_send::FUTURE_NOT_SEND),
1415
LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE),
1516
LintId::of(let_if_seq::USELESS_LET_IF_SEQ),
17+
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
1618
LintId::of(methods::ITER_WITH_DRAIN),
1719
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
1820
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),

Diff for: src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
2222
LintId::of(loops::EMPTY_LOOP),
2323
LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
2424
LintId::of(loops::MUT_RANGE_BOUND),
25-
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
2625
LintId::of(methods::NO_EFFECT_REPLACE),
2726
LintId::of(methods::SUSPICIOUS_MAP),
2827
LintId::of(mut_key::MUTABLE_KEY_TYPE),

Diff for: src/tools/clippy/clippy_lints/src/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ declare_clippy_lint! {
835835
/// ```
836836
#[clippy::version = "1.60.0"]
837837
pub SIGNIFICANT_DROP_IN_SCRUTINEE,
838-
suspicious,
838+
nursery,
839839
"warns when a temporary of a type with a drop with a significant side-effect might have a surprising lifetime"
840840
}
841841

0 commit comments

Comments
 (0)