Skip to content
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

Rollup of 7 pull requests #83690

Closed
wants to merge 15 commits into from
Closed
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
32 changes: 26 additions & 6 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub struct InferenceDiagnosticsData {
pub struct InferenceDiagnosticsParentData {
pub prefix: &'static str,
pub name: String,
pub def_id: DefId,
}

pub enum UnderspecifiedArgKind {
Expand Down Expand Up @@ -328,6 +329,7 @@ impl InferenceDiagnosticsParentData {
Some(InferenceDiagnosticsParentData {
prefix: tcx.def_kind(parent_def_id).descr(parent_def_id),
name: parent_name,
def_id: parent_def_id,
})
}
}
Expand Down Expand Up @@ -754,12 +756,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) =
(&arg_data.kind, &arg_data.parent)
{
err.span_suggestion_verbose(
span,
"consider specifying the const argument",
format!("{}::<{}>", parent_data.name, arg_data.name),
Applicability::MaybeIncorrect,
);
let has_impl_trait =
self.tcx.generics_of(parent_data.def_id).params.iter().any(|param| {
matches!(
param.kind,
ty::GenericParamDefKind::Type {
synthetic: Some(
hir::SyntheticTyParamKind::ImplTrait
| hir::SyntheticTyParamKind::FromAttr,
),
..
}
)
});

// (#83606): Do not emit a suggestion if the parent has an `impl Trait`
// as an argument otherwise it will cause the E0282 error.
if !has_impl_trait {
err.span_suggestion_verbose(
span,
"consider specifying the const argument",
format!("{}::<{}>", parent_data.name, arg_data.name),
Applicability::MaybeIncorrect,
);
}
}

err.span_label(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::fmt;

use super::InferCtxtPrivExt;
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use rustc_middle::ty::print::with_no_trimmed_paths;

#[derive(Debug)]
pub enum GeneratorInteriorOrUpvar {
Expand Down Expand Up @@ -440,7 +441,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
{
// Missing generic type parameter bound.
let param_name = self_ty.to_string();
let constraint = trait_ref.print_only_trait_path().to_string();
let constraint =
with_no_trimmed_paths(|| trait_ref.print_only_trait_path().to_string());
if suggest_constraining_type_param(
self.tcx,
generics,
Expand Down
27 changes: 17 additions & 10 deletions library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,18 @@ mod fn_keyword {}
/// # fn code() { }
/// # let iterator = 0..2;
/// {
/// let mut _iter = std::iter::IntoIterator::into_iter(iterator);
/// loop {
/// match _iter.next() {
/// Some(loop_variable) => {
/// code()
/// },
/// None => break,
/// }
/// }
/// let result = match IntoIterator::into_iter(iterator) {
/// mut iter => loop {
/// let next;
/// match iter.next() {
/// Some(val) => next = val,
/// None => break,
/// };
/// let loop_variable = next;
/// let () = { code(); };
/// },
/// };
/// result
/// }
/// ```
///
Expand Down Expand Up @@ -1310,7 +1313,11 @@ mod return_keyword {}
/// [Reference]: ../reference/items/associated-items.html#methods
mod self_keyword {}

#[doc(keyword = "Self")]
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we can remove the
// three next lines and put back: `#[doc(keyword = "Self")]`.
#[doc(alias = "Self")]
#[allow(rustc::existing_doc_keyword)]
#[doc(keyword = "SelfTy")]
//
/// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
/// definition.
Expand Down
64 changes: 32 additions & 32 deletions library/std/src/prelude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,53 @@
//! The current version of the prelude (version 1) lives in
//! [`std::prelude::v1`], and re-exports the following:
//!
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}:
//! * <code>[std::marker]::{[Copy], [Send], [Sized], [Sync], [Unpin]}</code>,
//! marker traits that indicate fundamental properties of types.
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: various
//! * <code>[std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}</code>, various
//! operations for both destructors and overloading `()`.
//! * [`std::mem`]::[`drop`][`mem::drop`]: a convenience function for explicitly
//! * <code>[std::mem]::[drop][mem::drop]</code>, a convenience function for explicitly
//! dropping a value.
//! * [`std::boxed`]::[`Box`]: a way to allocate values on the heap.
//! * [`std::borrow`]::[`ToOwned`]: the conversion trait that defines
//! * <code>[std::boxed]::[Box]</code>, a way to allocate values on the heap.
//! * <code>[std::borrow]::[ToOwned]</code>, the conversion trait that defines
//! [`to_owned`], the generic method for creating an owned type from a
//! borrowed type.
//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines
//! [`clone`][`Clone::clone`], the method for producing a copy of a value.
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the
//! * <code>[std::clone]::[Clone]</code>, the ubiquitous trait that defines
//! [`clone`][Clone::clone], the method for producing a copy of a value.
//! * <code>[std::cmp]::{[PartialEq], [PartialOrd], [Eq], [Ord]}</code>, the
//! comparison traits, which implement the comparison operators and are often
//! seen in trait bounds.
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: generic
//! * <code>[std::convert]::{[AsRef], [AsMut], [Into], [From]}</code>, generic
//! conversions, used by savvy API authors to create overloaded methods.
//! * [`std::default`]::[`Default`], types that have default values.
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`],
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various
//! * <code>[std::default]::[Default]</code>, types that have default values.
//! * <code>[std::iter]::{[Iterator], [Extend], [IntoIterator], [DoubleEndedIterator], [ExactSizeIterator]}</code>,
//! iterators of various
//! kinds.
//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a
//! * <code>[std::option]::[Option]::{[self][Option], [Some], [None]}</code>, a
//! type which expresses the presence or absence of a value. This type is so
//! commonly used, its variants are also exported.
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: a type
//! * <code>[std::result]::[Result]::{[self][Result], [Ok], [Err]}</code>, a type
//! for functions that may succeed or fail. Like [`Option`], its variants are
//! exported as well.
//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings.
//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated vector.
//! * <code>[std::string]::{[String], [ToString]}</code>, heap-allocated strings.
//! * <code>[std::vec]::[Vec]</code>, a growable, heap-allocated vector.
//!
//! [`mem::drop`]: crate::mem::drop
//! [`std::borrow`]: crate::borrow
//! [`std::boxed`]: crate::boxed
//! [`std::clone`]: crate::clone
//! [`std::cmp`]: crate::cmp
//! [`std::convert`]: crate::convert
//! [`std::default`]: crate::default
//! [`std::iter`]: crate::iter
//! [`std::marker`]: crate::marker
//! [`std::mem`]: crate::mem
//! [`std::ops`]: crate::ops
//! [`std::option`]: crate::option
//! [mem::drop]: crate::mem::drop
//! [std::borrow]: crate::borrow
//! [std::boxed]: crate::boxed
//! [std::clone]: crate::clone
//! [std::cmp]: crate::cmp
//! [std::convert]: crate::convert
//! [std::default]: crate::default
//! [std::iter]: crate::iter
//! [std::marker]: crate::marker
//! [std::mem]: crate::mem
//! [std::ops]: crate::ops
//! [std::option]: crate::option
//! [`std::prelude::v1`]: v1
//! [`std::result`]: crate::result
//! [`std::slice`]: crate::slice
//! [`std::string`]: crate::string
//! [`std::vec`]: mod@crate::vec
//! [std::result]: crate::result
//! [std::slice]: crate::slice
//! [std::string]: crate::string
//! [std::vec]: mod@crate::vec
//! [`to_owned`]: crate::borrow::ToOwned::to_owned
//! [book-closures]: ../../book/ch13-01-closures.html
//! [book-dtor]: ../../book/ch15-03-drop.html
Expand Down
26 changes: 13 additions & 13 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ impl Step for Linkcheck {
/// documentation to ensure we don't have a bunch of dead ones.
fn run(self, builder: &Builder<'_>) {
let host = self.host;
let hosts = &builder.hosts;
let targets = &builder.targets;

// if we have different hosts and targets, some things may be built for
// the host (e.g. rustc) and others for the target (e.g. std). The
// documentation built for each will contain broken links to
// docs built for the other platform (e.g. rustc linking to cargo)
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
panic!(
"Linkcheck currently does not support builds with different hosts and targets.
You can skip linkcheck with --exclude src/tools/linkchecker"
);
}

builder.info(&format!("Linkcheck ({})", host));

Expand All @@ -123,19 +136,6 @@ impl Step for Linkcheck {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
let run = run.path("src/tools/linkchecker");
let hosts = &builder.hosts;
let targets = &builder.targets;

// if we have different hosts and targets, some things may be built for
// the host (e.g. rustc) and others for the target (e.g. std). The
// documentation built for each will contain broken links to
// docs built for the other platform (e.g. rustc linking to cargo)
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
panic!(
"Linkcheck currently does not support builds with different hosts and targets.
You can skip linkcheck with --exclude src/tools/linkchecker"
);
}
run.default_condition(builder.config.docs)
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/associated-types/defaults-suitability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ LL | type Bar: Clone = Vec<T>;
= note: required because of the requirements on the impl of `Clone` for `Vec<T>`
help: consider restricting type parameter `T`
|
LL | trait Foo<T: Clone> {
| ^^^^^^^
LL | trait Foo<T: std::clone::Clone> {
| ^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `(): Foo<Self>` is not satisfied
--> $DIR/defaults-suitability.rs:34:5
Expand Down Expand Up @@ -99,8 +99,8 @@ LL | type Baz = T;
|
help: consider further restricting type parameter `T`
|
LL | Self::Baz: Clone, T: Clone
| ^^^^^^^^^^
LL | Self::Baz: Clone, T: std::clone::Clone
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 8 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | copy::<dyn Setup<From=T>>(t)
|
help: consider restricting type parameter `T`
|
LL | pub fn copy_any<T: Copy>(t: &T) -> T {
| ^^^^^^
LL | pub fn copy_any<T: std::marker::Copy>(t: &T) -> T {
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | type Assoc = T;
|
help: consider restricting type parameter `T`
|
LL | impl<T: Copy> Complete for T {
| ^^^^^^
LL | impl<T: std::marker::Copy> Complete for T {
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issue-70818.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | async { (ty, ty1) }
| ^^^ has type `U` which is not `Send`
help: consider restricting type parameter `U`
|
LL | fn foo<T: Send, U: Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
| ^^^^^^
LL | fn foo<T: Send, U: std::marker::Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/bad/bad-method-typaram-kind.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ LL | 1.bar::<T>();
|
help: consider further restricting this bound
|
LL | fn foo<T:'static + Send>() {
| ^^^^^^
LL | fn foo<T:'static + std::marker::Send>() {
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/bound-suggestions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ use std::fmt::Debug;
// Rustfix should add this, or use `std::fmt::Debug` instead.

#[allow(dead_code)]
fn test_impl(t: impl Sized + Debug) {
fn test_impl(t: impl Sized + std::fmt::Debug) {
println!("{:?}", t);
//~^ ERROR doesn't implement
}

#[allow(dead_code)]
fn test_no_bounds<T: Debug>(t: T) {
fn test_no_bounds<T: std::fmt::Debug>(t: T) {
println!("{:?}", t);
//~^ ERROR doesn't implement
}

#[allow(dead_code)]
fn test_one_bound<T: Sized + Debug>(t: T) {
fn test_one_bound<T: Sized + std::fmt::Debug>(t: T) {
println!("{:?}", t);
//~^ ERROR doesn't implement
}

#[allow(dead_code)]
fn test_no_bounds_where<X, Y>(x: X, y: Y) where X: std::fmt::Debug, Y: Debug {
fn test_no_bounds_where<X, Y>(x: X, y: Y) where X: std::fmt::Debug, Y: std::fmt::Debug {
println!("{:?} {:?}", x, y);
//~^ ERROR doesn't implement
}

#[allow(dead_code)]
fn test_one_bound_where<X>(x: X) where X: Sized + Debug {
fn test_one_bound_where<X>(x: X) where X: Sized + std::fmt::Debug {
println!("{:?}", x);
//~^ ERROR doesn't implement
}

#[allow(dead_code)]
fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: Debug {
fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: std::fmt::Debug {
println!("{:?}", x);
//~^ ERROR doesn't implement
}
Expand Down
Loading