Skip to content

Rollup of 7 pull requests #97224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

self.report_ambiguous_type_parameter(&mut err, arg);
err.span_label(
span,
arg_data.cannot_infer_msg(use_diag.filter(|d| d.applies_to(span))),
Expand Down Expand Up @@ -933,6 +934,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

fn report_ambiguous_type_parameter(&self, err: &mut Diagnostic, arg: GenericArg<'tcx>) {
if let GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind()
{
let mut inner = self.inner.borrow_mut();
let ty_vars = &inner.type_variables();
let var_origin = ty_vars.var_origin(ty_vid);
if let TypeVariableOriginKind::TypeParameterDefinition(_, Some(def_id)) =
var_origin.kind
&& let Some(parent_def_id) = self.tcx.parent(def_id).as_local()
&& let Some(node) = self.tcx.hir().find_by_def_id(parent_def_id)
{
match node {
hir::Node::Item(item) if matches!(item.kind, hir::ItemKind::Impl(_) | hir::ItemKind::Fn(..)) => (),
hir::Node::ImplItem(impl_item) if matches!(impl_item.kind, hir::ImplItemKind::Fn(..)) => (),
_ => return,
}
err.span_help(self.tcx.def_span(def_id), "type parameter declared here");
}
}
}

pub fn need_type_info_err_in_generator(
&self,
kind: hir::GeneratorKind,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ impl CheckAttrVisitor<'_> {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);

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

let (span, replacement_span) = if meta_items.len() == 1 {
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,11 +1470,11 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.retain_mut(|x| if *x > 3 {
/// false
/// } else {
/// vec.retain_mut(|x| if *x <= 3 {
/// *x += 1;
/// true
/// } else {
/// false
/// });
/// assert_eq!(vec, [2, 3, 4]);
/// ```
Expand Down
40 changes: 40 additions & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// println!("{key}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over keys takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys(&self) -> Keys<'_, K, V> {
Keys { inner: self.iter() }
Expand All @@ -370,6 +375,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// vec.sort_unstable();
/// assert_eq!(vec, ["a", "b", "c"]);
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over keys takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
Expand All @@ -395,6 +405,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// println!("{val}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over values takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values(&self) -> Values<'_, K, V> {
Values { inner: self.iter() }
Expand Down Expand Up @@ -422,6 +437,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// println!("{val}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over values takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[stable(feature = "map_values_mut", since = "1.10.0")]
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
ValuesMut { inner: self.iter_mut() }
Expand All @@ -448,6 +468,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// vec.sort_unstable();
/// assert_eq!(vec, [1, 2, 3]);
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over values takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
Expand All @@ -473,6 +498,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// println!("key: {key} val: {val}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over map takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[rustc_lint_query_instability]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<'_, K, V> {
Expand Down Expand Up @@ -503,6 +533,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// println!("key: {key} val: {val}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over map takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[rustc_lint_query_instability]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
Expand Down Expand Up @@ -633,6 +668,11 @@ impl<K, V, S> HashMap<K, V, S> {
/// map.retain(|&k, _| k % 2 == 0);
/// assert_eq!(map.len(), 4);
/// ```
///
/// # Performance
///
/// In the current implementation, this operation takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ impl<T, S> HashSet<T, S> {
/// println!("{x}");
/// }
/// ```
///
/// # Performance
///
/// In the current implementation, iterating over set takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[inline]
#[rustc_lint_query_instability]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -312,6 +317,11 @@ impl<T, S> HashSet<T, S> {
/// set.retain(|&k| k % 2 == 0);
/// assert_eq!(set.len(), 3);
/// ```
///
/// # Performance
///
/// In the current implementation, this operation takes O(capacity) time
/// instead of O(len) because it internally visits empty buckets too.
#[rustc_lint_query_instability]
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
pub fn retain<F>(&mut self, f: F)
Expand Down
20 changes: 10 additions & 10 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# The Rustc Book

- [What is rustc?](what-is-rustc.md)
- [Command-line arguments](command-line-arguments.md)
- [Command-line Arguments](command-line-arguments.md)
- [Codegen Options](codegen-options/index.md)
- [Lints](lints/index.md)
- [Lint levels](lints/levels.md)
- [Lint Levels](lints/levels.md)
- [Lint Groups](lints/groups.md)
- [Lint listing](lints/listing/index.md)
- [Allowed-by-default lints](lints/listing/allowed-by-default.md)
- [Warn-by-default lints](lints/listing/warn-by-default.md)
- [Deny-by-default lints](lints/listing/deny-by-default.md)
- [Codegen options](codegen-options/index.md)
- [Lint Listing](lints/listing/index.md)
- [Allowed-by-default Lints](lints/listing/allowed-by-default.md)
- [Warn-by-default Lints](lints/listing/warn-by-default.md)
- [Deny-by-default Lints](lints/listing/deny-by-default.md)
- [JSON Output](json.md)
- [Tests](tests/index.md)
- [Platform Support](platform-support.md)
- [Template for target-specific documentation](platform-support/TEMPLATE.md)
- [Target Tier Policy](target-tier-policy.md)
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
Expand All @@ -25,13 +26,12 @@
- [*-unknown-openbsd](platform-support/openbsd.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
- [Target Tier Policy](target-tier-policy.md)
- [Targets](targets/index.md)
- [Built-in Targets](targets/built-in.md)
- [Custom Targets](targets/custom.md)
- [Known Issues](targets/known-issues.md)
- [Profile-guided Optimization](profile-guided-optimization.md)
- [Instrumentation-based Code Coverage](instrument-coverage.md)
- [Linker-plugin based LTO](linker-plugin-lto.md)
- [Linker-plugin-based LTO](linker-plugin-lto.md)
- [Exploit Mitigations](exploit-mitigations.md)
- [Contributing to `rustc`](contributing.md)
2 changes: 1 addition & 1 deletion src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Codegen options
# Codegen Options

All of these options are passed to `rustc` via the `-C` flag, short for "codegen." You can see
a version of this list for your exact compiler by running `rustc -C help`.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Command-line arguments
# Command-line Arguments

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

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/instrument-coverage.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `instrument-coverage`
# Instrumentation-based Code Coverage

## Introduction

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/linker-plugin-lto.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Linker-plugin-LTO
# Linker-plugin-based LTO

The `-C linker-plugin-lto` flag allows for deferring the LTO optimization
to the actual linking step, which in turn allows for performing
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/levels.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lint levels
# Lint Levels

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

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/listing/allowed-by-default.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Allowed-by-default lints
# Allowed-by-default Lints

This file is auto-generated by the lint-docs script.
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Deny-by-default lints
# Deny-by-default Lints

This file is auto-generated by the lint-docs script.
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/listing/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lint listing
# Lint Listing

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

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Warn-by-default lints
# Warn-by-default Lints

This file is auto-generated by the lint-docs script.
4 changes: 2 additions & 2 deletions src/doc/rustc/src/platform-support/pc-windows-gnullvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

Target triples avaiable so far:
Target triples available so far:
- `aarch64-pc-windows-gnullvm`
- `x86_64-pc-windows-gnullvm`

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

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.
Native bootstrapping builds require rather fragile hacks until host artifacts are avaiable so I won't describe them here.
Native bootstrapping builds require rather fragile hacks until host artifacts are available so I won't describe them here.

## Building Rust programs

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/profile-guided-optimization.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Profile Guided Optimization
# Profile-guided Optimization

`rustc` supports doing profile-guided optimization (PGO).
This chapter describes what PGO is, what it is good for, and how it can be used.
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/issues/issue-83249.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ LL | let _ = foo([0; 1]);
| - ^^^ cannot infer type for type parameter `T` declared on the function `foo`
| |
| consider giving this pattern a type
|
help: type parameter declared here
--> $DIR/issue-83249.rs:12:8
|
LL | fn foo<T: Foo>(_: [u8; T::N]) -> T {
| ^

error: aborting due to previous error

Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/consts/issue-64662.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ error[E0282]: type annotations needed
|
LL | A = foo(),
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
|
help: type parameter declared here
--> $DIR/issue-64662.rs:6:14
|
LL | const fn foo<T>() -> isize {
| ^

error[E0282]: type annotations needed
--> $DIR/issue-64662.rs:3:9
|
LL | B = foo(),
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
|
help: type parameter declared here
--> $DIR/issue-64662.rs:6:14
|
LL | const fn foo<T>() -> isize {
| ^

error: aborting due to 2 previous errors

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/error-codes/E0401.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ error[E0282]: type annotations needed
|
LL | bfnr(x);
| ^^^^ cannot infer type for type parameter `U` declared on the function `bfnr`
|
help: type parameter declared here
--> $DIR/E0401.rs:4:13
|
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
| ^

error: aborting due to 4 previous errors

Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/inference/ambiguous_type_parameter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::collections::HashMap;

trait Store<K, V> {
fn get_raw(&self, key: &K) -> Option<()>;
}

struct InMemoryStore;

impl<K> Store<String, HashMap<K, String>> for InMemoryStore {
fn get_raw(&self, key: &String) -> Option<()> {
None
}
}

fn main() {
InMemoryStore.get_raw(&String::default()); //~ ERROR type annotations needed
}
15 changes: 15 additions & 0 deletions src/test/ui/inference/ambiguous_type_parameter.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0282]: type annotations needed
--> $DIR/ambiguous_type_parameter.rs:16:19
|
LL | InMemoryStore.get_raw(&String::default());
| ^^^^^^^ cannot infer type for type parameter `K`
|
help: type parameter declared here
--> $DIR/ambiguous_type_parameter.rs:9:6
|
LL | impl<K> Store<String, HashMap<K, String>> for InMemoryStore {
| ^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
Loading