Skip to content

Commit 1463688

Browse files
committed
Auto merge of rust-lang#101652 - Dylan-DPC:rollup-f4atky0, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#101578 (remove bound var hack in `resolve`) - rust-lang#101606 (doc: fix minor typo) - rust-lang#101614 (Equate fn outputs when inferring RPITIT hidden types) - rust-lang#101631 (rustdoc: avoid cleaning modules with duplicate names) - rust-lang#101635 (Move `Queries::new` out of the macro) - rust-lang#101641 (Update browser-ui-test version to 0.9.8) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2e44c17 + 7835610 commit 1463688

File tree

18 files changed

+215
-146
lines changed

18 files changed

+215
-146
lines changed

compiler/rustc_data_structures/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cfg_if! {
4848
/// the native atomic types.
4949
/// You should use this type through the `AtomicU64`, `AtomicUsize`, etc, type aliases
5050
/// as it's not intended to be used separately.
51-
#[derive(Debug)]
51+
#[derive(Debug, Default)]
5252
pub struct Atomic<T: Copy>(Cell<T>);
5353

5454
impl<T: Copy> Atomic<T> {

compiler/rustc_middle/src/query/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1202,14 +1202,11 @@ rustc_queries! {
12021202
}
12031203
}
12041204

1205-
query codegen_fulfill_obligation(
1205+
query codegen_select_candidate(
12061206
key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
12071207
) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
12081208
cache_on_disk_if { true }
1209-
desc { |tcx|
1210-
"checking if `{}` fulfills its obligations",
1211-
tcx.def_path_str(key.1.def_id())
1212-
}
1209+
desc { |tcx| "computing candidate for `{}`", key.1 }
12131210
}
12141211

12151212
/// Return all `impl` blocks in the current crate.

compiler/rustc_middle/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub enum MethodViolationCode {
10241024
UndispatchableReceiver(Option<Span>),
10251025
}
10261026

1027-
/// These are the error cases for `codegen_fulfill_obligation`.
1027+
/// These are the error cases for `codegen_select_candidate`.
10281028
#[derive(Copy, Clone, Debug, Hash, HashStable, Encodable, Decodable)]
10291029
pub enum CodegenObligationError {
10301030
/// Ambiguity can happen when monomorphizing during trans

compiler/rustc_monomorphize/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn custom_coerce_unsize_info<'tcx>(
3535
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
3636
});
3737

38-
match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
38+
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
3939
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
4040
impl_def_id,
4141
..

compiler/rustc_query_impl/src/plumbing.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::keys::Key;
66
use crate::{on_disk_cache, Queries};
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
8-
use rustc_data_structures::sync::Lock;
8+
use rustc_data_structures::sync::{AtomicU64, Lock};
99
use rustc_errors::{Diagnostic, Handler};
1010
use rustc_middle::dep_graph::{
1111
self, DepKind, DepKindStruct, DepNode, DepNodeIndex, SerializedDepNodeIndex,
@@ -499,9 +499,28 @@ macro_rules! define_queries {
499499
}
500500
}
501501

502+
use crate::{ExternProviders, OnDiskCache, Providers};
503+
504+
impl<'tcx> Queries<'tcx> {
505+
pub fn new(
506+
local_providers: Providers,
507+
extern_providers: ExternProviders,
508+
on_disk_cache: Option<OnDiskCache<'tcx>>,
509+
) -> Self {
510+
Queries {
511+
local_providers: Box::new(local_providers),
512+
extern_providers: Box::new(extern_providers),
513+
on_disk_cache,
514+
jobs: AtomicU64::new(1),
515+
..Queries::default()
516+
}
517+
}
518+
}
519+
502520
macro_rules! define_queries_struct {
503521
(
504522
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
523+
#[derive(Default)]
505524
pub struct Queries<'tcx> {
506525
local_providers: Box<Providers>,
507526
extern_providers: Box<ExternProviders>,
@@ -514,20 +533,6 @@ macro_rules! define_queries_struct {
514533
}
515534

516535
impl<'tcx> Queries<'tcx> {
517-
pub fn new(
518-
local_providers: Providers,
519-
extern_providers: ExternProviders,
520-
on_disk_cache: Option<OnDiskCache<'tcx>>,
521-
) -> Self {
522-
Queries {
523-
local_providers: Box::new(local_providers),
524-
extern_providers: Box::new(extern_providers),
525-
on_disk_cache,
526-
jobs: AtomicU64::new(1),
527-
$($name: Default::default()),*
528-
}
529-
}
530-
531536
pub(crate) fn try_collect_active_jobs(
532537
&'tcx self,
533538
tcx: TyCtxt<'tcx>,

compiler/rustc_trait_selection/src/traits/codegen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::{self, TyCtxt};
1818
/// obligations *could be* resolved if we wanted to.
1919
///
2020
/// This also expects that `trait_ref` is fully normalized.
21-
pub fn codegen_fulfill_obligation<'tcx>(
21+
pub fn codegen_select_candidate<'tcx>(
2222
tcx: TyCtxt<'tcx>,
2323
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
2424
) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
971971
*providers = ty::query::Providers {
972972
specialization_graph_of: specialize::specialization_graph_provider,
973973
specializes: specialize::specializes,
974-
codegen_fulfill_obligation: codegen::codegen_fulfill_obligation,
974+
codegen_select_candidate: codegen::codegen_select_candidate,
975975
own_existential_vtable_entries,
976976
vtable_entries,
977977
vtable_trait_upcasting_coercion_new_vptr_slot,

compiler/rustc_ty_utils/src/instance.rs

+3-110
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,11 @@ use rustc_hir::def_id::{DefId, LocalDefId};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_middle::traits::CodegenObligationError;
55
use rustc_middle::ty::subst::SubstsRef;
6-
use rustc_middle::ty::{
7-
self, Binder, Instance, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
8-
};
6+
use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitable};
97
use rustc_span::{sym, DUMMY_SP};
108
use rustc_trait_selection::traits;
119
use traits::{translate_substs, Reveal};
1210

13-
use rustc_data_structures::sso::SsoHashSet;
14-
use std::collections::btree_map::Entry;
15-
use std::collections::BTreeMap;
16-
use std::ops::ControlFlow;
17-
18-
// FIXME(#86795): `BoundVarsCollector` here should **NOT** be used
19-
// outside of `resolve_associated_item`. It's just to address #64494,
20-
// #83765, and #85848 which are creating bound types/regions that lose
21-
// their `Binder` *unintentionally*.
22-
// It's ideal to remove `BoundVarsCollector` and just use
23-
// `ty::Binder::*` methods but we use this stopgap until we figure out
24-
// the "real" fix.
25-
struct BoundVarsCollector<'tcx> {
26-
binder_index: ty::DebruijnIndex,
27-
vars: BTreeMap<u32, ty::BoundVariableKind>,
28-
// We may encounter the same variable at different levels of binding, so
29-
// this can't just be `Ty`
30-
visited: SsoHashSet<(ty::DebruijnIndex, Ty<'tcx>)>,
31-
}
32-
33-
impl<'tcx> BoundVarsCollector<'tcx> {
34-
fn new() -> Self {
35-
BoundVarsCollector {
36-
binder_index: ty::INNERMOST,
37-
vars: BTreeMap::new(),
38-
visited: SsoHashSet::default(),
39-
}
40-
}
41-
42-
fn into_vars(self, tcx: TyCtxt<'tcx>) -> &'tcx ty::List<ty::BoundVariableKind> {
43-
let max = self.vars.iter().map(|(k, _)| *k).max().unwrap_or(0);
44-
for i in 0..max {
45-
if let None = self.vars.get(&i) {
46-
panic!("Unknown variable: {:?}", i);
47-
}
48-
}
49-
50-
tcx.mk_bound_variable_kinds(self.vars.into_iter().map(|(_, v)| v))
51-
}
52-
}
53-
54-
impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
55-
type BreakTy = ();
56-
57-
fn visit_binder<T: TypeVisitable<'tcx>>(
58-
&mut self,
59-
t: &Binder<'tcx, T>,
60-
) -> ControlFlow<Self::BreakTy> {
61-
self.binder_index.shift_in(1);
62-
let result = t.super_visit_with(self);
63-
self.binder_index.shift_out(1);
64-
result
65-
}
66-
67-
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
68-
if t.outer_exclusive_binder() < self.binder_index
69-
|| !self.visited.insert((self.binder_index, t))
70-
{
71-
return ControlFlow::CONTINUE;
72-
}
73-
match *t.kind() {
74-
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
75-
match self.vars.entry(bound_ty.var.as_u32()) {
76-
Entry::Vacant(entry) => {
77-
entry.insert(ty::BoundVariableKind::Ty(bound_ty.kind));
78-
}
79-
Entry::Occupied(entry) => match entry.get() {
80-
ty::BoundVariableKind::Ty(_) => {}
81-
_ => bug!("Conflicting bound vars"),
82-
},
83-
}
84-
}
85-
86-
_ => (),
87-
};
88-
89-
t.super_visit_with(self)
90-
}
91-
92-
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
93-
match *r {
94-
ty::ReLateBound(index, br) if index == self.binder_index => {
95-
match self.vars.entry(br.var.as_u32()) {
96-
Entry::Vacant(entry) => {
97-
entry.insert(ty::BoundVariableKind::Region(br.kind));
98-
}
99-
Entry::Occupied(entry) => match entry.get() {
100-
ty::BoundVariableKind::Region(_) => {}
101-
_ => bug!("Conflicting bound vars"),
102-
},
103-
}
104-
}
105-
106-
_ => (),
107-
};
108-
109-
r.super_visit_with(self)
110-
}
111-
}
112-
11311
fn resolve_instance<'tcx>(
11412
tcx: TyCtxt<'tcx>,
11513
key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>,
@@ -201,19 +99,14 @@ fn resolve_associated_item<'tcx>(
20199

202100
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
203101

204-
// See FIXME on `BoundVarsCollector`.
205-
let mut bound_vars_collector = BoundVarsCollector::new();
206-
trait_ref.visit_with(&mut bound_vars_collector);
207-
let trait_binder = ty::Binder::bind_with_vars(trait_ref, bound_vars_collector.into_vars(tcx));
208-
let vtbl = match tcx.codegen_fulfill_obligation((param_env, trait_binder)) {
102+
let vtbl = match tcx.codegen_select_candidate((param_env, ty::Binder::dummy(trait_ref))) {
209103
Ok(vtbl) => vtbl,
210104
Err(CodegenObligationError::Ambiguity) => {
211105
let reported = tcx.sess.delay_span_bug(
212106
tcx.def_span(trait_item_id),
213107
&format!(
214-
"encountered ambiguity selecting `{:?}` during codegen, presuming due to \
108+
"encountered ambiguity selecting `{trait_ref:?}` during codegen, presuming due to \
215109
overflow or prior type error",
216-
trait_binder
217110
),
218111
);
219112
return Err(reported);

compiler/rustc_typeck/src/check/compare_method.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,26 @@ pub(super) fn compare_predicates_and_trait_impl_trait_tys<'tcx>(
295295
// type would be more appropriate. In other places we have a `Vec<Span>`
296296
// corresponding to their `Vec<Predicate>`, but we don't have that here.
297297
// Fixing this would improve the output of test `issue-83765.rs`.
298-
let sub_result = infcx
298+
let mut result = infcx
299299
.at(&cause, param_env)
300300
.sup(trait_fty, impl_fty)
301301
.map(|infer_ok| ocx.register_infer_ok_obligations(infer_ok));
302302

303-
if let Err(terr) = sub_result {
303+
// HACK(RPITIT): #101614. When we are trying to infer the hidden types for
304+
// RPITITs, we need to equate the output tys instead of just subtyping. If
305+
// we just use `sup` above, we'll end up `&'static str <: _#1t`, which causes
306+
// us to infer `_#1t = #'_#2r str`, where `'_#2r` is unconstrained, which gets
307+
// fixed up to `ReEmpty`, and which is certainly not what we want.
308+
if trait_fty.has_infer_types() {
309+
result = result.and_then(|()| {
310+
infcx
311+
.at(&cause, param_env)
312+
.eq(trait_sig.output(), impl_sig.output())
313+
.map(|infer_ok| ocx.register_infer_ok_obligations(infer_ok))
314+
});
315+
}
316+
317+
if let Err(terr) = result {
304318
debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
305319

306320
let (impl_err_span, trait_err_span) =
@@ -445,6 +459,7 @@ pub(super) fn compare_predicates_and_trait_impl_trait_tys<'tcx>(
445459
region
446460
}
447461
});
462+
debug!(%ty);
448463
collected_tys.insert(def_id, ty);
449464
}
450465
Err(err) => {

library/std/src/thread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
//! Threads are able to have associated names for identification purposes. By default, spawned
117117
//! threads are unnamed. To specify a name for a thread, build the thread with [`Builder`] and pass
118118
//! the desired thread name to [`Builder::name`]. To retrieve the thread name from within the
119-
//! thread, use [`Thread::name`]. A couple examples of where the name of a thread gets used:
119+
//! thread, use [`Thread::name`]. A couple of examples where the name of a thread gets used:
120120
//!
121121
//! * If a panic occurs in a named thread, the thread name will be printed in the panic message.
122122
//! * The thread name is provided to the OS where applicable (e.g., `pthread_setname_np` in
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.7
1+
0.9.8

src/librustdoc/clean/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,23 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
5050
let mut inserted = FxHashSet::default();
5151
items.extend(doc.foreigns.iter().map(|(item, renamed)| {
5252
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
53-
if let Some(name) = item.name {
53+
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
5454
inserted.insert((item.type_(), name));
5555
}
5656
item
5757
}));
58-
items.extend(doc.mods.iter().map(|x| {
59-
inserted.insert((ItemType::Module, x.name));
60-
clean_doc_module(x, cx)
58+
items.extend(doc.mods.iter().filter_map(|x| {
59+
if !inserted.insert((ItemType::Module, x.name)) {
60+
return None;
61+
}
62+
let item = clean_doc_module(x, cx);
63+
if item.attrs.lists(sym::doc).has_word(sym::hidden) {
64+
// Hidden modules are stripped at a later stage.
65+
// If a hidden module has the same name as a visible one, we want
66+
// to keep both of them around.
67+
inserted.remove(&(ItemType::Module, x.name));
68+
}
69+
Some(item)
6170
}));
6271

6372
// Split up imports from all other items.
@@ -72,7 +81,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
7281
}
7382
let v = clean_maybe_renamed_item(cx, item, *renamed);
7483
for item in &v {
75-
if let Some(name) = item.name {
84+
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
7685
inserted.insert((item.type_(), name));
7786
}
7887
}

src/librustdoc/visit_ast.rs

+12
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
164164
self.inside_public_path &= self.cx.tcx.visibility(def_id).is_public();
165165
for &i in m.item_ids {
166166
let item = self.cx.tcx.hir().item(i);
167+
if matches!(item.kind, hir::ItemKind::Use(_, hir::UseKind::Glob)) {
168+
continue;
169+
}
167170
self.visit_item(item, None, &mut om);
168171
}
172+
for &i in m.item_ids {
173+
let item = self.cx.tcx.hir().item(i);
174+
// To match the way import precedence works, visit glob imports last.
175+
// Later passes in rustdoc will de-duplicate by name and kind, so if glob-
176+
// imported items appear last, then they'll be the ones that get discarded.
177+
if matches!(item.kind, hir::ItemKind::Use(_, hir::UseKind::Glob)) {
178+
self.visit_item(item, None, &mut om);
179+
}
180+
}
169181
self.inside_public_path = orig_inside_public_path;
170182
om
171183
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://github.com/rust-lang/rust/pull/83872#issuecomment-820101008
2+
#![crate_name="foo"]
3+
4+
mod sub4 {
5+
/// 0
6+
pub const X: usize = 0;
7+
pub mod inner {
8+
pub use super::*;
9+
/// 1
10+
pub const X: usize = 1;
11+
}
12+
}
13+
14+
#[doc(inline)]
15+
pub use sub4::inner::*;
16+
17+
// @has 'foo/index.html'
18+
// @has - '//div[@class="item-right docblock-short"]' '1'
19+
// @!has - '//div[@class="item-right docblock-short"]' '0'
20+
fn main() { assert_eq!(X, 1); }

0 commit comments

Comments
 (0)