Skip to content

Commit 536020c

Browse files
committed
Auto merge of #97224 - matthiaskrgr:rollup-it5nw68, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #97109 (Fix misleading `cannot infer type for type parameter` error) - #97187 (Reverse condition in Vec::retain_mut doctest) - #97201 (Fix typo) - #97203 (Minor tweaks to rustc book summary formatting.) - #97208 (Do not emit the lint `unused_attributes` for *inherent* `#[doc(hidden)]` associated items) - #97215 (Add complexity estimation of iterating over HashSet and HashMap) - #97220 (Add regression test for#81827) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b5caa5a + 6c0c7f1 commit 536020c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+312
-40
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+23
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
866866
}
867867
}
868868

869+
self.report_ambiguous_type_parameter(&mut err, arg);
869870
err.span_label(
870871
span,
871872
arg_data.cannot_infer_msg(use_diag.filter(|d| d.applies_to(span))),
@@ -933,6 +934,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
933934
}
934935
}
935936

937+
fn report_ambiguous_type_parameter(&self, err: &mut Diagnostic, arg: GenericArg<'tcx>) {
938+
if let GenericArgKind::Type(ty) = arg.unpack()
939+
&& let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind()
940+
{
941+
let mut inner = self.inner.borrow_mut();
942+
let ty_vars = &inner.type_variables();
943+
let var_origin = ty_vars.var_origin(ty_vid);
944+
if let TypeVariableOriginKind::TypeParameterDefinition(_, Some(def_id)) =
945+
var_origin.kind
946+
&& let Some(parent_def_id) = self.tcx.parent(def_id).as_local()
947+
&& let Some(node) = self.tcx.hir().find_by_def_id(parent_def_id)
948+
{
949+
match node {
950+
hir::Node::Item(item) if matches!(item.kind, hir::ItemKind::Impl(_) | hir::ItemKind::Fn(..)) => (),
951+
hir::Node::ImplItem(impl_item) if matches!(impl_item.kind, hir::ImplItemKind::Fn(..)) => (),
952+
_ => return,
953+
}
954+
err.span_help(self.tcx.def_span(def_id), "type parameter declared here");
955+
}
956+
}
957+
}
958+
936959
pub fn need_type_info_err_in_generator(
937960
&self,
938961
kind: hir::GeneratorKind,

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl CheckAttrVisitor<'_> {
832832
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
833833
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
834834

835-
if Target::from_item(containing_item) == Target::Impl {
835+
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = containing_item.kind {
836836
let meta_items = attr.meta_item_list().unwrap();
837837

838838
let (span, replacement_span) = if meta_items.len() == 1 {

library/alloc/src/vec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1470,11 +1470,11 @@ impl<T, A: Allocator> Vec<T, A> {
14701470
///
14711471
/// ```
14721472
/// let mut vec = vec![1, 2, 3, 4];
1473-
/// vec.retain_mut(|x| if *x > 3 {
1474-
/// false
1475-
/// } else {
1473+
/// vec.retain_mut(|x| if *x <= 3 {
14761474
/// *x += 1;
14771475
/// true
1476+
/// } else {
1477+
/// false
14781478
/// });
14791479
/// assert_eq!(vec, [2, 3, 4]);
14801480
/// ```

library/std/src/collections/hash/map.rs

+40
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ impl<K, V, S> HashMap<K, V, S> {
344344
/// println!("{key}");
345345
/// }
346346
/// ```
347+
///
348+
/// # Performance
349+
///
350+
/// In the current implementation, iterating over keys takes O(capacity) time
351+
/// instead of O(len) because it internally visits empty buckets too.
347352
#[stable(feature = "rust1", since = "1.0.0")]
348353
pub fn keys(&self) -> Keys<'_, K, V> {
349354
Keys { inner: self.iter() }
@@ -370,6 +375,11 @@ impl<K, V, S> HashMap<K, V, S> {
370375
/// vec.sort_unstable();
371376
/// assert_eq!(vec, ["a", "b", "c"]);
372377
/// ```
378+
///
379+
/// # Performance
380+
///
381+
/// In the current implementation, iterating over keys takes O(capacity) time
382+
/// instead of O(len) because it internally visits empty buckets too.
373383
#[inline]
374384
#[rustc_lint_query_instability]
375385
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
@@ -395,6 +405,11 @@ impl<K, V, S> HashMap<K, V, S> {
395405
/// println!("{val}");
396406
/// }
397407
/// ```
408+
///
409+
/// # Performance
410+
///
411+
/// In the current implementation, iterating over values takes O(capacity) time
412+
/// instead of O(len) because it internally visits empty buckets too.
398413
#[stable(feature = "rust1", since = "1.0.0")]
399414
pub fn values(&self) -> Values<'_, K, V> {
400415
Values { inner: self.iter() }
@@ -422,6 +437,11 @@ impl<K, V, S> HashMap<K, V, S> {
422437
/// println!("{val}");
423438
/// }
424439
/// ```
440+
///
441+
/// # Performance
442+
///
443+
/// In the current implementation, iterating over values takes O(capacity) time
444+
/// instead of O(len) because it internally visits empty buckets too.
425445
#[stable(feature = "map_values_mut", since = "1.10.0")]
426446
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
427447
ValuesMut { inner: self.iter_mut() }
@@ -448,6 +468,11 @@ impl<K, V, S> HashMap<K, V, S> {
448468
/// vec.sort_unstable();
449469
/// assert_eq!(vec, [1, 2, 3]);
450470
/// ```
471+
///
472+
/// # Performance
473+
///
474+
/// In the current implementation, iterating over values takes O(capacity) time
475+
/// instead of O(len) because it internally visits empty buckets too.
451476
#[inline]
452477
#[rustc_lint_query_instability]
453478
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
@@ -473,6 +498,11 @@ impl<K, V, S> HashMap<K, V, S> {
473498
/// println!("key: {key} val: {val}");
474499
/// }
475500
/// ```
501+
///
502+
/// # Performance
503+
///
504+
/// In the current implementation, iterating over map takes O(capacity) time
505+
/// instead of O(len) because it internally visits empty buckets too.
476506
#[rustc_lint_query_instability]
477507
#[stable(feature = "rust1", since = "1.0.0")]
478508
pub fn iter(&self) -> Iter<'_, K, V> {
@@ -503,6 +533,11 @@ impl<K, V, S> HashMap<K, V, S> {
503533
/// println!("key: {key} val: {val}");
504534
/// }
505535
/// ```
536+
///
537+
/// # Performance
538+
///
539+
/// In the current implementation, iterating over map takes O(capacity) time
540+
/// instead of O(len) because it internally visits empty buckets too.
506541
#[rustc_lint_query_instability]
507542
#[stable(feature = "rust1", since = "1.0.0")]
508543
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
@@ -633,6 +668,11 @@ impl<K, V, S> HashMap<K, V, S> {
633668
/// map.retain(|&k, _| k % 2 == 0);
634669
/// assert_eq!(map.len(), 4);
635670
/// ```
671+
///
672+
/// # Performance
673+
///
674+
/// In the current implementation, this operation takes O(capacity) time
675+
/// instead of O(len) because it internally visits empty buckets too.
636676
#[inline]
637677
#[rustc_lint_query_instability]
638678
#[stable(feature = "retain_hash_collection", since = "1.18.0")]

library/std/src/collections/hash/set.rs

+10
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ impl<T, S> HashSet<T, S> {
184184
/// println!("{x}");
185185
/// }
186186
/// ```
187+
///
188+
/// # Performance
189+
///
190+
/// In the current implementation, iterating over set takes O(capacity) time
191+
/// instead of O(len) because it internally visits empty buckets too.
187192
#[inline]
188193
#[rustc_lint_query_instability]
189194
#[stable(feature = "rust1", since = "1.0.0")]
@@ -312,6 +317,11 @@ impl<T, S> HashSet<T, S> {
312317
/// set.retain(|&k| k % 2 == 0);
313318
/// assert_eq!(set.len(), 3);
314319
/// ```
320+
///
321+
/// # Performance
322+
///
323+
/// In the current implementation, this operation takes O(capacity) time
324+
/// instead of O(len) because it internally visits empty buckets too.
315325
#[rustc_lint_query_instability]
316326
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
317327
pub fn retain<F>(&mut self, f: F)

src/doc/rustc/src/SUMMARY.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# The Rustc Book
22

33
- [What is rustc?](what-is-rustc.md)
4-
- [Command-line arguments](command-line-arguments.md)
4+
- [Command-line Arguments](command-line-arguments.md)
5+
- [Codegen Options](codegen-options/index.md)
56
- [Lints](lints/index.md)
6-
- [Lint levels](lints/levels.md)
7+
- [Lint Levels](lints/levels.md)
78
- [Lint Groups](lints/groups.md)
8-
- [Lint listing](lints/listing/index.md)
9-
- [Allowed-by-default lints](lints/listing/allowed-by-default.md)
10-
- [Warn-by-default lints](lints/listing/warn-by-default.md)
11-
- [Deny-by-default lints](lints/listing/deny-by-default.md)
12-
- [Codegen options](codegen-options/index.md)
9+
- [Lint Listing](lints/listing/index.md)
10+
- [Allowed-by-default Lints](lints/listing/allowed-by-default.md)
11+
- [Warn-by-default Lints](lints/listing/warn-by-default.md)
12+
- [Deny-by-default Lints](lints/listing/deny-by-default.md)
1313
- [JSON Output](json.md)
1414
- [Tests](tests/index.md)
1515
- [Platform Support](platform-support.md)
16-
- [Template for target-specific documentation](platform-support/TEMPLATE.md)
16+
- [Target Tier Policy](target-tier-policy.md)
17+
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
1718
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1819
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
1920
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
@@ -25,13 +26,12 @@
2526
- [*-unknown-openbsd](platform-support/openbsd.md)
2627
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
2728
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
28-
- [Target Tier Policy](target-tier-policy.md)
2929
- [Targets](targets/index.md)
3030
- [Built-in Targets](targets/built-in.md)
3131
- [Custom Targets](targets/custom.md)
3232
- [Known Issues](targets/known-issues.md)
3333
- [Profile-guided Optimization](profile-guided-optimization.md)
3434
- [Instrumentation-based Code Coverage](instrument-coverage.md)
35-
- [Linker-plugin based LTO](linker-plugin-lto.md)
35+
- [Linker-plugin-based LTO](linker-plugin-lto.md)
3636
- [Exploit Mitigations](exploit-mitigations.md)
3737
- [Contributing to `rustc`](contributing.md)

src/doc/rustc/src/codegen-options/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Codegen options
1+
# Codegen Options
22

33
All of these options are passed to `rustc` via the `-C` flag, short for "codegen." You can see
44
a version of this list for your exact compiler by running `rustc -C help`.

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Command-line arguments
1+
# Command-line Arguments
22

33
Here's a list of command-line arguments to `rustc` and what they do.
44

src/doc/rustc/src/instrument-coverage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `instrument-coverage`
1+
# Instrumentation-based Code Coverage
22

33
## Introduction
44

src/doc/rustc/src/linker-plugin-lto.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Linker-plugin-LTO
1+
# Linker-plugin-based LTO
22

33
The `-C linker-plugin-lto` flag allows for deferring the LTO optimization
44
to the actual linking step, which in turn allows for performing

src/doc/rustc/src/lints/levels.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lint levels
1+
# Lint Levels
22

33
In `rustc`, lints are divided into five *levels*:
44

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Allowed-by-default lints
1+
# Allowed-by-default Lints
22

33
This file is auto-generated by the lint-docs script.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Deny-by-default lints
1+
# Deny-by-default Lints
22

33
This file is auto-generated by the lint-docs script.

src/doc/rustc/src/lints/listing/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lint listing
1+
# Lint Listing
22

33
This section lists out all of the lints, grouped by their default lint levels.
44

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Warn-by-default lints
1+
# Warn-by-default Lints
22

33
This file is auto-generated by the lint-docs script.

src/doc/rustc/src/platform-support/pc-windows-gnullvm.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Windows targets similar to `*-pc-windows-gnu` but using UCRT as the runtime and various LLVM tools/libraries instead of GCC/Binutils.
66

7-
Target triples avaiable so far:
7+
Target triples available so far:
88
- `aarch64-pc-windows-gnullvm`
99
- `x86_64-pc-windows-gnullvm`
1010

@@ -26,7 +26,7 @@ Like with any other Windows target created binaries are in PE format.
2626
## Building the target
2727

2828
For cross-compilation I recommend using [llvm-mingw](https://github.com/mstorsjo/llvm-mingw) toolchain, one change that seems necessary beside configuring corss compilers is disabling experimental `m86k` target. Otherwise LLVM build fails with `multiple definition ...` errors.
29-
Native bootstrapping builds require rather fragile hacks until host artifacts are avaiable so I won't describe them here.
29+
Native bootstrapping builds require rather fragile hacks until host artifacts are available so I won't describe them here.
3030

3131
## Building Rust programs
3232

src/doc/rustc/src/profile-guided-optimization.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Profile Guided Optimization
1+
# Profile-guided Optimization
22

33
`rustc` supports doing profile-guided optimization (PGO).
44
This chapter describes what PGO is, what it is good for, and how it can be used.

src/test/ui/const-generics/issues/issue-83249.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ LL | let _ = foo([0; 1]);
55
| - ^^^ cannot infer type for type parameter `T` declared on the function `foo`
66
| |
77
| consider giving this pattern a type
8+
|
9+
help: type parameter declared here
10+
--> $DIR/issue-83249.rs:12:8
11+
|
12+
LL | fn foo<T: Foo>(_: [u8; T::N]) -> T {
13+
| ^
814

915
error: aborting due to previous error
1016

src/test/ui/consts/issue-64662.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ error[E0282]: type annotations needed
33
|
44
LL | A = foo(),
55
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
6+
|
7+
help: type parameter declared here
8+
--> $DIR/issue-64662.rs:6:14
9+
|
10+
LL | const fn foo<T>() -> isize {
11+
| ^
612

713
error[E0282]: type annotations needed
814
--> $DIR/issue-64662.rs:3:9
915
|
1016
LL | B = foo(),
1117
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
18+
|
19+
help: type parameter declared here
20+
--> $DIR/issue-64662.rs:6:14
21+
|
22+
LL | const fn foo<T>() -> isize {
23+
| ^
1224

1325
error: aborting due to 2 previous errors
1426

src/test/ui/error-codes/E0401.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ error[E0282]: type annotations needed
3737
|
3838
LL | bfnr(x);
3939
| ^^^^ cannot infer type for type parameter `U` declared on the function `bfnr`
40+
|
41+
help: type parameter declared here
42+
--> $DIR/E0401.rs:4:13
43+
|
44+
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
45+
| ^
4046

4147
error: aborting due to 4 previous errors
4248

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::collections::HashMap;
2+
3+
trait Store<K, V> {
4+
fn get_raw(&self, key: &K) -> Option<()>;
5+
}
6+
7+
struct InMemoryStore;
8+
9+
impl<K> Store<String, HashMap<K, String>> for InMemoryStore {
10+
fn get_raw(&self, key: &String) -> Option<()> {
11+
None
12+
}
13+
}
14+
15+
fn main() {
16+
InMemoryStore.get_raw(&String::default()); //~ ERROR type annotations needed
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/ambiguous_type_parameter.rs:16:19
3+
|
4+
LL | InMemoryStore.get_raw(&String::default());
5+
| ^^^^^^^ cannot infer type for type parameter `K`
6+
|
7+
help: type parameter declared here
8+
--> $DIR/ambiguous_type_parameter.rs:9:6
9+
|
10+
LL | impl<K> Store<String, HashMap<K, String>> for InMemoryStore {
11+
| ^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)