1
Fork 0

Auto merge of #83692 - Dylan-DPC:rollup-2a2m3jy, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #80720 (Make documentation of which items the prelude exports more readable.)
 - #83654 (Do not emit a suggestion that causes the E0632 error)
 - #83671 (Add a regression test for issue-75801)
 - #83678 (Fix Self keyword doc URL conflict on case insensitive file systems (until definitely fixed on rustdoc))
 - #83680 (Update for loop desugaring docs)
 - #83683 (bootstrap: don't complain about linkcheck if it is excluded)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-03-30 23:47:51 +00:00
commit 65b44b0320
9 changed files with 153 additions and 61 deletions

View file

@ -287,6 +287,7 @@ pub struct InferenceDiagnosticsData {
pub struct InferenceDiagnosticsParentData { pub struct InferenceDiagnosticsParentData {
pub prefix: &'static str, pub prefix: &'static str,
pub name: String, pub name: String,
pub def_id: DefId,
} }
pub enum UnderspecifiedArgKind { pub enum UnderspecifiedArgKind {
@ -328,6 +329,7 @@ impl InferenceDiagnosticsParentData {
Some(InferenceDiagnosticsParentData { Some(InferenceDiagnosticsParentData {
prefix: tcx.def_kind(parent_def_id).descr(parent_def_id), prefix: tcx.def_kind(parent_def_id).descr(parent_def_id),
name: parent_name, name: parent_name,
def_id: parent_def_id,
}) })
} }
} }
@ -754,12 +756,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) = if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) =
(&arg_data.kind, &arg_data.parent) (&arg_data.kind, &arg_data.parent)
{ {
err.span_suggestion_verbose( let has_impl_trait =
span, self.tcx.generics_of(parent_data.def_id).params.iter().any(|param| {
"consider specifying the const argument", matches!(
format!("{}::<{}>", parent_data.name, arg_data.name), param.kind,
Applicability::MaybeIncorrect, 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( err.span_label(

View file

@ -547,15 +547,18 @@ mod fn_keyword {}
/// # fn code() { } /// # fn code() { }
/// # let iterator = 0..2; /// # let iterator = 0..2;
/// { /// {
/// let mut _iter = std::iter::IntoIterator::into_iter(iterator); /// let result = match IntoIterator::into_iter(iterator) {
/// loop { /// mut iter => loop {
/// match _iter.next() { /// let next;
/// Some(loop_variable) => { /// match iter.next() {
/// code() /// Some(val) => next = val,
/// }, /// None => break,
/// None => break, /// };
/// } /// let loop_variable = next;
/// } /// let () = { code(); };
/// },
/// };
/// result
/// } /// }
/// ``` /// ```
/// ///
@ -1310,7 +1313,11 @@ mod return_keyword {}
/// [Reference]: ../reference/items/associated-items.html#methods /// [Reference]: ../reference/items/associated-items.html#methods
mod self_keyword {} 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 /// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
/// definition. /// definition.

View file

@ -28,53 +28,53 @@
//! The current version of the prelude (version 1) lives in //! The current version of the prelude (version 1) lives in
//! [`std::prelude::v1`], and re-exports the following: //! [`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. //! 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 `()`. //! 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. //! dropping a value.
//! * [`std::boxed`]::[`Box`]: a way to allocate values on the heap. //! * <code>[std::boxed]::[Box]</code>, a way to allocate values on the heap.
//! * [`std::borrow`]::[`ToOwned`]: the conversion trait that defines //! * <code>[std::borrow]::[ToOwned]</code>, the conversion trait that defines
//! [`to_owned`], the generic method for creating an owned type from a //! [`to_owned`], the generic method for creating an owned type from a
//! borrowed type. //! borrowed type.
//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines //! * <code>[std::clone]::[Clone]</code>, the ubiquitous trait that defines
//! [`clone`][`Clone::clone`], the method for producing a copy of a value. //! [`clone`][Clone::clone], the method for producing a copy of a value.
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the //! * <code>[std::cmp]::{[PartialEq], [PartialOrd], [Eq], [Ord]}</code>, the
//! comparison traits, which implement the comparison operators and are often //! comparison traits, which implement the comparison operators and are often
//! seen in trait bounds. //! 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. //! conversions, used by savvy API authors to create overloaded methods.
//! * [`std::default`]::[`Default`], types that have default values. //! * <code>[std::default]::[Default]</code>, types that have default values.
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`], //! * <code>[std::iter]::{[Iterator], [Extend], [IntoIterator], [DoubleEndedIterator], [ExactSizeIterator]}</code>,
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various //! iterators of various
//! kinds. //! 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 //! type which expresses the presence or absence of a value. This type is so
//! commonly used, its variants are also exported. //! 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 //! for functions that may succeed or fail. Like [`Option`], its variants are
//! exported as well. //! exported as well.
//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings. //! * <code>[std::string]::{[String], [ToString]}</code>, heap-allocated strings.
//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated vector. //! * <code>[std::vec]::[Vec]</code>, a growable, heap-allocated vector.
//! //!
//! [`mem::drop`]: crate::mem::drop //! [mem::drop]: crate::mem::drop
//! [`std::borrow`]: crate::borrow //! [std::borrow]: crate::borrow
//! [`std::boxed`]: crate::boxed //! [std::boxed]: crate::boxed
//! [`std::clone`]: crate::clone //! [std::clone]: crate::clone
//! [`std::cmp`]: crate::cmp //! [std::cmp]: crate::cmp
//! [`std::convert`]: crate::convert //! [std::convert]: crate::convert
//! [`std::default`]: crate::default //! [std::default]: crate::default
//! [`std::iter`]: crate::iter //! [std::iter]: crate::iter
//! [`std::marker`]: crate::marker //! [std::marker]: crate::marker
//! [`std::mem`]: crate::mem //! [std::mem]: crate::mem
//! [`std::ops`]: crate::ops //! [std::ops]: crate::ops
//! [`std::option`]: crate::option //! [std::option]: crate::option
//! [`std::prelude::v1`]: v1 //! [`std::prelude::v1`]: v1
//! [`std::result`]: crate::result //! [std::result]: crate::result
//! [`std::slice`]: crate::slice //! [std::slice]: crate::slice
//! [`std::string`]: crate::string //! [std::string]: crate::string
//! [`std::vec`]: mod@crate::vec //! [std::vec]: mod@crate::vec
//! [`to_owned`]: crate::borrow::ToOwned::to_owned //! [`to_owned`]: crate::borrow::ToOwned::to_owned
//! [book-closures]: ../../book/ch13-01-closures.html //! [book-closures]: ../../book/ch13-01-closures.html
//! [book-dtor]: ../../book/ch15-03-drop.html //! [book-dtor]: ../../book/ch15-03-drop.html

View file

@ -108,6 +108,19 @@ impl Step for Linkcheck {
/// documentation to ensure we don't have a bunch of dead ones. /// documentation to ensure we don't have a bunch of dead ones.
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let host = self.host; 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)); builder.info(&format!("Linkcheck ({})", host));
@ -123,19 +136,6 @@ impl Step for Linkcheck {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder; let builder = run.builder;
let run = run.path("src/tools/linkchecker"); 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) run.default_condition(builder.config.docs)
} }

View file

@ -0,0 +1,10 @@
// Regression test for #83606.
fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
[0; N]
}
fn main() {
let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
//~^ ERROR: type annotations needed for `[usize; _]`
}

View file

@ -0,0 +1,11 @@
error[E0282]: type annotations needed for `[usize; _]`
--> $DIR/issue-83606.rs:8:13
|
LL | let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
| - ^^^ cannot infer the value of const parameter `N` declared on the function `foo`
| |
| consider giving this pattern the explicit type `[usize; _]`, where the type parameter `N` is specified
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.

View file

@ -0,0 +1,13 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn foo(_args: TokenStream, item: TokenStream) -> TokenStream {
item
}

View file

@ -0,0 +1,19 @@
// aux-build: issue-75801.rs
// Regression test for #75801.
#[macro_use]
extern crate issue_75801;
macro_rules! foo {
($arg:expr) => {
#[foo]
fn bar() {
let _bar: u32 = $arg;
}
};
}
foo!("baz"); //~ ERROR: mismatched types [E0308]
fn main() {}

View file

@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/issue-75801.rs:17:6
|
LL | let _bar: u32 = $arg;
| --- expected due to this
...
LL | foo!("baz");
| ^^^^^ expected `u32`, found `&str`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.