Skip to content

Commit 8769c26

Browse files
committed
Auto merge of #115960 - GuillaumeGomez:rollup-8tky3qu, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #112725 (rustdoc-search: add support for type parameters) - #114941 (Don't resolve generic impls that may be shadowed by dyn built-in impls) - #115625 (Explain HRTB + infer limitations of old solver) - #115839 (Bump libc to 0.2.148) - #115924 (Don't complain on a single non-exhaustive 1-ZST) - #115946 (panic when encountering an illegal cpumask in thread::available_parallelism) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ae9c330 + 57f1f91 commit 8769c26

39 files changed

+1605
-488
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2142,9 +2142,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21422142

21432143
[[package]]
21442144
name = "libc"
2145-
version = "0.2.147"
2145+
version = "0.2.148"
21462146
source = "registry+https://github.com/rust-lang/crates.io-index"
2147-
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
2147+
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
21482148
dependencies = [
21492149
"rustc-std-workspace-core",
21502150
]

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -1201,25 +1201,35 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
12011201
);
12021202
return;
12031203
}
1204-
for (span, _trivial, non_exhaustive) in field_infos {
1205-
if let Some((descr, def_id, args, non_exhaustive)) = non_exhaustive {
1206-
tcx.struct_span_lint_hir(
1207-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
1208-
tcx.hir().local_def_id_to_hir_id(adt.did().expect_local()),
1209-
span,
1210-
"zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types",
1211-
|lint| {
1212-
let note = if non_exhaustive {
1213-
"is marked with `#[non_exhaustive]`"
1214-
} else {
1215-
"contains private fields"
1216-
};
1217-
let field_ty = tcx.def_path_str_with_args(def_id, args);
1218-
lint
1219-
.note(format!("this {descr} contains `{field_ty}`, which {note}, \
1220-
and makes it not a breaking change to become non-zero-sized in the future."))
1221-
},
1222-
)
1204+
let mut prev_non_exhaustive_1zst = false;
1205+
for (span, _trivial, non_exhaustive_1zst) in field_infos {
1206+
if let Some((descr, def_id, args, non_exhaustive)) = non_exhaustive_1zst {
1207+
// If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts.
1208+
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
1209+
if non_trivial_count > 0 || prev_non_exhaustive_1zst {
1210+
tcx.struct_span_lint_hir(
1211+
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
1212+
tcx.hir().local_def_id_to_hir_id(adt.did().expect_local()),
1213+
span,
1214+
"zero-sized fields in `repr(transparent)` cannot \
1215+
contain external non-exhaustive types",
1216+
|lint| {
1217+
let note = if non_exhaustive {
1218+
"is marked with `#[non_exhaustive]`"
1219+
} else {
1220+
"contains private fields"
1221+
};
1222+
let field_ty = tcx.def_path_str_with_args(def_id, args);
1223+
lint.note(format!(
1224+
"this {descr} contains `{field_ty}`, which {note}, \
1225+
and makes it not a breaking change to become \
1226+
non-zero-sized in the future."
1227+
))
1228+
},
1229+
)
1230+
} else {
1231+
prev_non_exhaustive_1zst = true;
1232+
}
12231233
}
12241234
}
12251235
}

Diff for: compiler/rustc_middle/src/ty/sty.rs

+27
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,33 @@ impl<'tcx> Ty<'tcx> {
29452945
_ => false,
29462946
}
29472947
}
2948+
2949+
pub fn is_known_rigid(self) -> bool {
2950+
match self.kind() {
2951+
Bool
2952+
| Char
2953+
| Int(_)
2954+
| Uint(_)
2955+
| Float(_)
2956+
| Adt(_, _)
2957+
| Foreign(_)
2958+
| Str
2959+
| Array(_, _)
2960+
| Slice(_)
2961+
| RawPtr(_)
2962+
| Ref(_, _, _)
2963+
| FnDef(_, _)
2964+
| FnPtr(_)
2965+
| Dynamic(_, _, _)
2966+
| Closure(_, _)
2967+
| Generator(_, _, _)
2968+
| GeneratorWitness(_)
2969+
| GeneratorWitnessMIR(_, _)
2970+
| Never
2971+
| Tuple(_) => true,
2972+
Error(_) | Infer(_) | Alias(_, _) | Param(_) | Bound(_, _) | Placeholder(_) => false,
2973+
}
2974+
}
29482975
}
29492976

29502977
/// Extra information about why we ended up with a particular variance.

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
986986
}
987987
}
988988

989+
self.explain_hrtb_projection(&mut err, trait_predicate, obligation.param_env, &obligation.cause);
990+
989991
// Return early if the trait is Debug or Display and the invocation
990992
// originates within a standard library macro, because the output
991993
// is otherwise overwhelming and unhelpful (see #85844 for an

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+73
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ pub trait TypeErrCtxtExt<'tcx> {
406406
candidate_impls: &[ImplCandidate<'tcx>],
407407
span: Span,
408408
);
409+
410+
fn explain_hrtb_projection(
411+
&self,
412+
diag: &mut Diagnostic,
413+
pred: ty::PolyTraitPredicate<'tcx>,
414+
param_env: ty::ParamEnv<'tcx>,
415+
cause: &ObligationCause<'tcx>,
416+
);
409417
}
410418

411419
fn predicate_constraint(generics: &hir::Generics<'_>, pred: ty::Predicate<'_>) -> (Span, String) {
@@ -4027,6 +4035,71 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
40274035
}
40284036
}
40294037
}
4038+
4039+
fn explain_hrtb_projection(
4040+
&self,
4041+
diag: &mut Diagnostic,
4042+
pred: ty::PolyTraitPredicate<'tcx>,
4043+
param_env: ty::ParamEnv<'tcx>,
4044+
cause: &ObligationCause<'tcx>,
4045+
) {
4046+
if pred.skip_binder().has_escaping_bound_vars() && pred.skip_binder().has_non_region_infer()
4047+
{
4048+
self.probe(|_| {
4049+
let ocx = ObligationCtxt::new(self);
4050+
let pred = self.instantiate_binder_with_placeholders(pred);
4051+
let pred = ocx.normalize(&ObligationCause::dummy(), param_env, pred);
4052+
ocx.register_obligation(Obligation::new(
4053+
self.tcx,
4054+
ObligationCause::dummy(),
4055+
param_env,
4056+
pred,
4057+
));
4058+
if !ocx.select_where_possible().is_empty() {
4059+
// encountered errors.
4060+
return;
4061+
}
4062+
4063+
if let ObligationCauseCode::FunctionArgumentObligation {
4064+
call_hir_id,
4065+
arg_hir_id,
4066+
parent_code: _,
4067+
} = cause.code()
4068+
{
4069+
let arg_span = self.tcx.hir().span(*arg_hir_id);
4070+
let mut sp: MultiSpan = arg_span.into();
4071+
4072+
sp.push_span_label(
4073+
arg_span,
4074+
"the trait solver is unable to infer the \
4075+
generic types that should be inferred from this argument",
4076+
);
4077+
sp.push_span_label(
4078+
self.tcx.hir().span(*call_hir_id),
4079+
"add turbofish arguments to this call to \
4080+
specify the types manually, even if it's redundant",
4081+
);
4082+
diag.span_note(
4083+
sp,
4084+
"this is a known limitation of the trait solver that \
4085+
will be lifted in the future",
4086+
);
4087+
} else {
4088+
let mut sp: MultiSpan = cause.span.into();
4089+
sp.push_span_label(
4090+
cause.span,
4091+
"try adding turbofish arguments to this expression to \
4092+
specify the types manually, even if it's redundant",
4093+
);
4094+
diag.span_note(
4095+
sp,
4096+
"this is a known limitation of the trait solver that \
4097+
will be lifted in the future",
4098+
);
4099+
}
4100+
});
4101+
}
4102+
}
40304103
}
40314104

40324105
/// Add a hint to add a missing borrow or remove an unnecessary one.

Diff for: compiler/rustc_ty_utils/src/instance.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,34 @@ fn resolve_associated_item<'tcx>(
141141
false
142142
}
143143
};
144-
145144
if !eligible {
146145
return Ok(None);
147146
}
148147

148+
// HACK: We may have overlapping `dyn Trait` built-in impls and
149+
// user-provided blanket impls. Detect that case here, and return
150+
// ambiguity.
151+
//
152+
// This should not affect totally monomorphized contexts, only
153+
// resolve calls that happen polymorphically, such as the mir-inliner
154+
// and const-prop (and also some lints).
155+
let self_ty = rcvr_args.type_at(0);
156+
if !self_ty.is_known_rigid() {
157+
let predicates = tcx
158+
.predicates_of(impl_data.impl_def_id)
159+
.instantiate(tcx, impl_data.args)
160+
.predicates;
161+
let sized_def_id = tcx.lang_items().sized_trait();
162+
// If we find a `Self: Sized` bound on the item, then we know
163+
// that `dyn Trait` can certainly never apply here.
164+
if !predicates.into_iter().filter_map(ty::Clause::as_trait_clause).any(|clause| {
165+
Some(clause.def_id()) == sized_def_id
166+
&& clause.skip_binder().self_ty() == self_ty
167+
}) {
168+
return Ok(None);
169+
}
170+
}
171+
149172
// Any final impl is required to define all associated items.
150173
if !leaf_def.item.defaultness(tcx).has_value() {
151174
let guard = tcx.sess.delay_span_bug(

Diff for: library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
libc = { version = "0.2.146", default-features = false, features = ['rustc-dep-of-std'], public = true }
20+
libc = { version = "0.2.148", default-features = false, features = ['rustc-dep-of-std'], public = true }
2121
compiler_builtins = { version = "0.1.100" }
2222
profiler_builtins = { path = "../profiler_builtins", optional = true }
2323
unwind = { path = "../unwind" }

Diff for: library/std/src/sys/unix/thread.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ pub fn available_parallelism() -> io::Result<NonZeroUsize> {
324324
if libc::sched_getaffinity(0, mem::size_of::<libc::cpu_set_t>(), &mut set) == 0 {
325325
let count = libc::CPU_COUNT(&set) as usize;
326326
let count = count.min(quota);
327-
// SAFETY: affinity mask can't be empty and the quota gets clamped to a minimum of 1
328-
return Ok(NonZeroUsize::new_unchecked(count));
327+
// reported to occur on MIPS kernels older than our minimum supported kernel version for those targets
328+
let count = NonZeroUsize::new(count)
329+
.expect("CPU count must be > 0. This may be a bug in sched_getaffinity(); try upgrading the kernel.");
330+
return Ok(count);
329331
}
330332
}
331333
}

Diff for: src/doc/rustdoc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Command-line arguments](command-line-arguments.md)
55
- [How to read rustdoc output](how-to-read-rustdoc.md)
66
- [In-doc settings](read-documentation/in-doc-settings.md)
7+
- [Search](read-documentation/search.md)
78
- [How to write documentation](how-to-write-documentation.md)
89
- [What to include (and exclude)](write-documentation/what-to-include.md)
910
- [The `#[doc]` attribute](write-documentation/the-doc-attribute.md)

Diff for: src/doc/rustdoc/src/how-to-read-rustdoc.md

+5-50
Original file line numberDiff line numberDiff line change
@@ -75,56 +75,11 @@ or the current item whose documentation is being displayed.
7575
## The Theme Picker and Search Interface
7676

7777
When viewing `rustdoc`'s output in a browser with JavaScript enabled,
78-
a dynamic interface appears at the top of the page composed of the search
79-
interface, help screen, and options.
80-
81-
### The Search Interface
82-
83-
Typing in the search bar instantly searches the available documentation for
84-
the string entered with a fuzzy matching algorithm that is tolerant of minor
85-
typos.
86-
87-
By default, the search results given are "In Names",
88-
meaning that the fuzzy match is made against the names of items.
89-
Matching names are shown on the left, and the first few words of their
90-
descriptions are given on the right.
91-
By clicking an item, you will navigate to its particular documentation.
92-
93-
There are two other sets of results, shown as tabs in the search results pane.
94-
"In Parameters" shows matches for the string in the types of parameters to
95-
functions, and "In Return Types" shows matches in the return types of functions.
96-
Both are very useful when looking for a function whose name you can't quite
97-
bring to mind when you know the type you have or want.
98-
99-
Names in the search interface can be prefixed with an item type followed by a
100-
colon (such as `mod:`) to restrict the results to just that kind of item. Also,
101-
searching for `println!` will search for a macro named `println`, just like
102-
searching for `macro:println` does.
103-
104-
Function signature searches can query generics, wrapped in angle brackets, and
105-
traits are normalized like types in the search engine. For example, a function
106-
with the signature `fn my_function<I: Iterator<Item=u32>>(input: I) -> usize`
107-
can be matched with the following queries:
108-
109-
* `Iterator<u32> -> usize`
110-
* `trait:Iterator<primitive:u32> -> primitive:usize`
111-
* `Iterator -> usize`
112-
113-
Generics and function parameters are order-agnostic, but sensitive to nesting
114-
and number of matches. For example, a function with the signature
115-
`fn read_all(&mut self: impl Read) -> Result<Vec<u8>, Error>`
116-
will match these queries:
117-
118-
* `Read -> Result<Vec<u8>, Error>`
119-
* `Read -> Result<Error, Vec>`
120-
* `Read -> Result<Vec<u8>>`
121-
122-
But it *does not* match `Result<Vec, u8>` or `Result<u8<Vec>>`.
123-
124-
Function signature searches also support arrays and slices. The explicit name
125-
`primitive:slice<u8>` and `primitive:array<u8>` can be used to match a slice
126-
or array of bytes, while square brackets `[u8]` will match either one. Empty
127-
square brackets, `[]`, will match any slice regardless of what it contains.
78+
a dynamic interface appears at the top of the page composed of the [search]
79+
interface, help screen, and [options].
80+
81+
[options]: read-documentation/in-doc-settings.html
82+
[search]: read-documentation/search.md
12883

12984
Paths are supported as well, you can look for `Vec::new` or `Option::Some` or
13085
even `module::module_child::another_child::struct::field`. Whitespace characters

0 commit comments

Comments
 (0)