Skip to content

Commit 65b44b0

Browse files
committed
Auto merge of rust-lang#83692 - Dylan-DPC:rollup-2a2m3jy, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#80720 (Make documentation of which items the prelude exports more readable.) - rust-lang#83654 (Do not emit a suggestion that causes the E0632 error) - rust-lang#83671 (Add a regression test for issue-75801) - rust-lang#83678 (Fix Self keyword doc URL conflict on case insensitive file systems (until definitely fixed on rustdoc)) - rust-lang#83680 (Update for loop desugaring docs) - rust-lang#83683 (bootstrap: don't complain about linkcheck if it is excluded) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 74874a6 + 7a587f0 commit 65b44b0

File tree

9 files changed

+153
-61
lines changed

9 files changed

+153
-61
lines changed

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

+26-6
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ pub struct InferenceDiagnosticsData {
287287
pub struct InferenceDiagnosticsParentData {
288288
pub prefix: &'static str,
289289
pub name: String,
290+
pub def_id: DefId,
290291
}
291292

292293
pub enum UnderspecifiedArgKind {
@@ -328,6 +329,7 @@ impl InferenceDiagnosticsParentData {
328329
Some(InferenceDiagnosticsParentData {
329330
prefix: tcx.def_kind(parent_def_id).descr(parent_def_id),
330331
name: parent_name,
332+
def_id: parent_def_id,
331333
})
332334
}
333335
}
@@ -754,12 +756,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
754756
if let (UnderspecifiedArgKind::Const { .. }, Some(parent_data)) =
755757
(&arg_data.kind, &arg_data.parent)
756758
{
757-
err.span_suggestion_verbose(
758-
span,
759-
"consider specifying the const argument",
760-
format!("{}::<{}>", parent_data.name, arg_data.name),
761-
Applicability::MaybeIncorrect,
762-
);
759+
let has_impl_trait =
760+
self.tcx.generics_of(parent_data.def_id).params.iter().any(|param| {
761+
matches!(
762+
param.kind,
763+
ty::GenericParamDefKind::Type {
764+
synthetic: Some(
765+
hir::SyntheticTyParamKind::ImplTrait
766+
| hir::SyntheticTyParamKind::FromAttr,
767+
),
768+
..
769+
}
770+
)
771+
});
772+
773+
// (#83606): Do not emit a suggestion if the parent has an `impl Trait`
774+
// as an argument otherwise it will cause the E0282 error.
775+
if !has_impl_trait {
776+
err.span_suggestion_verbose(
777+
span,
778+
"consider specifying the const argument",
779+
format!("{}::<{}>", parent_data.name, arg_data.name),
780+
Applicability::MaybeIncorrect,
781+
);
782+
}
763783
}
764784

765785
err.span_label(

library/std/src/keyword_docs.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,18 @@ mod fn_keyword {}
547547
/// # fn code() { }
548548
/// # let iterator = 0..2;
549549
/// {
550-
/// let mut _iter = std::iter::IntoIterator::into_iter(iterator);
551-
/// loop {
552-
/// match _iter.next() {
553-
/// Some(loop_variable) => {
554-
/// code()
555-
/// },
556-
/// None => break,
557-
/// }
558-
/// }
550+
/// let result = match IntoIterator::into_iter(iterator) {
551+
/// mut iter => loop {
552+
/// let next;
553+
/// match iter.next() {
554+
/// Some(val) => next = val,
555+
/// None => break,
556+
/// };
557+
/// let loop_variable = next;
558+
/// let () = { code(); };
559+
/// },
560+
/// };
561+
/// result
559562
/// }
560563
/// ```
561564
///
@@ -1310,7 +1313,11 @@ mod return_keyword {}
13101313
/// [Reference]: ../reference/items/associated-items.html#methods
13111314
mod self_keyword {}
13121315

1313-
#[doc(keyword = "Self")]
1316+
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we can remove the
1317+
// three next lines and put back: `#[doc(keyword = "Self")]`.
1318+
#[doc(alias = "Self")]
1319+
#[allow(rustc::existing_doc_keyword)]
1320+
#[doc(keyword = "SelfTy")]
13141321
//
13151322
/// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
13161323
/// definition.

library/std/src/prelude/mod.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,53 @@
2828
//! The current version of the prelude (version 1) lives in
2929
//! [`std::prelude::v1`], and re-exports the following:
3030
//!
31-
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}:
31+
//! * <code>[std::marker]::{[Copy], [Send], [Sized], [Sync], [Unpin]}</code>,
3232
//! marker traits that indicate fundamental properties of types.
33-
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: various
33+
//! * <code>[std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}</code>, various
3434
//! operations for both destructors and overloading `()`.
35-
//! * [`std::mem`]::[`drop`][`mem::drop`]: a convenience function for explicitly
35+
//! * <code>[std::mem]::[drop][mem::drop]</code>, a convenience function for explicitly
3636
//! dropping a value.
37-
//! * [`std::boxed`]::[`Box`]: a way to allocate values on the heap.
38-
//! * [`std::borrow`]::[`ToOwned`]: the conversion trait that defines
37+
//! * <code>[std::boxed]::[Box]</code>, a way to allocate values on the heap.
38+
//! * <code>[std::borrow]::[ToOwned]</code>, the conversion trait that defines
3939
//! [`to_owned`], the generic method for creating an owned type from a
4040
//! borrowed type.
41-
//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines
42-
//! [`clone`][`Clone::clone`], the method for producing a copy of a value.
43-
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the
41+
//! * <code>[std::clone]::[Clone]</code>, the ubiquitous trait that defines
42+
//! [`clone`][Clone::clone], the method for producing a copy of a value.
43+
//! * <code>[std::cmp]::{[PartialEq], [PartialOrd], [Eq], [Ord]}</code>, the
4444
//! comparison traits, which implement the comparison operators and are often
4545
//! seen in trait bounds.
46-
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: generic
46+
//! * <code>[std::convert]::{[AsRef], [AsMut], [Into], [From]}</code>, generic
4747
//! conversions, used by savvy API authors to create overloaded methods.
48-
//! * [`std::default`]::[`Default`], types that have default values.
49-
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`],
50-
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various
48+
//! * <code>[std::default]::[Default]</code>, types that have default values.
49+
//! * <code>[std::iter]::{[Iterator], [Extend], [IntoIterator], [DoubleEndedIterator], [ExactSizeIterator]}</code>,
50+
//! iterators of various
5151
//! kinds.
52-
//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a
52+
//! * <code>[std::option]::[Option]::{[self][Option], [Some], [None]}</code>, a
5353
//! type which expresses the presence or absence of a value. This type is so
5454
//! commonly used, its variants are also exported.
55-
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: a type
55+
//! * <code>[std::result]::[Result]::{[self][Result], [Ok], [Err]}</code>, a type
5656
//! for functions that may succeed or fail. Like [`Option`], its variants are
5757
//! exported as well.
58-
//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings.
59-
//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated vector.
58+
//! * <code>[std::string]::{[String], [ToString]}</code>, heap-allocated strings.
59+
//! * <code>[std::vec]::[Vec]</code>, a growable, heap-allocated vector.
6060
//!
61-
//! [`mem::drop`]: crate::mem::drop
62-
//! [`std::borrow`]: crate::borrow
63-
//! [`std::boxed`]: crate::boxed
64-
//! [`std::clone`]: crate::clone
65-
//! [`std::cmp`]: crate::cmp
66-
//! [`std::convert`]: crate::convert
67-
//! [`std::default`]: crate::default
68-
//! [`std::iter`]: crate::iter
69-
//! [`std::marker`]: crate::marker
70-
//! [`std::mem`]: crate::mem
71-
//! [`std::ops`]: crate::ops
72-
//! [`std::option`]: crate::option
61+
//! [mem::drop]: crate::mem::drop
62+
//! [std::borrow]: crate::borrow
63+
//! [std::boxed]: crate::boxed
64+
//! [std::clone]: crate::clone
65+
//! [std::cmp]: crate::cmp
66+
//! [std::convert]: crate::convert
67+
//! [std::default]: crate::default
68+
//! [std::iter]: crate::iter
69+
//! [std::marker]: crate::marker
70+
//! [std::mem]: crate::mem
71+
//! [std::ops]: crate::ops
72+
//! [std::option]: crate::option
7373
//! [`std::prelude::v1`]: v1
74-
//! [`std::result`]: crate::result
75-
//! [`std::slice`]: crate::slice
76-
//! [`std::string`]: crate::string
77-
//! [`std::vec`]: mod@crate::vec
74+
//! [std::result]: crate::result
75+
//! [std::slice]: crate::slice
76+
//! [std::string]: crate::string
77+
//! [std::vec]: mod@crate::vec
7878
//! [`to_owned`]: crate::borrow::ToOwned::to_owned
7979
//! [book-closures]: ../../book/ch13-01-closures.html
8080
//! [book-dtor]: ../../book/ch15-03-drop.html

src/bootstrap/test.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ impl Step for Linkcheck {
108108
/// documentation to ensure we don't have a bunch of dead ones.
109109
fn run(self, builder: &Builder<'_>) {
110110
let host = self.host;
111+
let hosts = &builder.hosts;
112+
let targets = &builder.targets;
113+
114+
// if we have different hosts and targets, some things may be built for
115+
// the host (e.g. rustc) and others for the target (e.g. std). The
116+
// documentation built for each will contain broken links to
117+
// docs built for the other platform (e.g. rustc linking to cargo)
118+
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
119+
panic!(
120+
"Linkcheck currently does not support builds with different hosts and targets.
121+
You can skip linkcheck with --exclude src/tools/linkchecker"
122+
);
123+
}
111124

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

@@ -123,19 +136,6 @@ impl Step for Linkcheck {
123136
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
124137
let builder = run.builder;
125138
let run = run.path("src/tools/linkchecker");
126-
let hosts = &builder.hosts;
127-
let targets = &builder.targets;
128-
129-
// if we have different hosts and targets, some things may be built for
130-
// the host (e.g. rustc) and others for the target (e.g. std). The
131-
// documentation built for each will contain broken links to
132-
// docs built for the other platform (e.g. rustc linking to cargo)
133-
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
134-
panic!(
135-
"Linkcheck currently does not support builds with different hosts and targets.
136-
You can skip linkcheck with --exclude src/tools/linkchecker"
137-
);
138-
}
139139
run.default_condition(builder.config.docs)
140140
}
141141

src/test/ui/inference/issue-83606.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #83606.
2+
3+
fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
4+
[0; N]
5+
}
6+
7+
fn main() {
8+
let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
9+
//~^ ERROR: type annotations needed for `[usize; _]`
10+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed for `[usize; _]`
2+
--> $DIR/issue-83606.rs:8:13
3+
|
4+
LL | let _ = foo("foo"); //<- Do not suggest `foo::<N>("foo");`!
5+
| - ^^^ cannot infer the value of const parameter `N` declared on the function `foo`
6+
| |
7+
| consider giving this pattern the explicit type `[usize; _]`, where the type parameter `N` is specified
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro_attribute]
11+
pub fn foo(_args: TokenStream, item: TokenStream) -> TokenStream {
12+
item
13+
}

src/test/ui/proc-macro/issue-75801.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// aux-build: issue-75801.rs
2+
3+
// Regression test for #75801.
4+
5+
#[macro_use]
6+
extern crate issue_75801;
7+
8+
macro_rules! foo {
9+
($arg:expr) => {
10+
#[foo]
11+
fn bar() {
12+
let _bar: u32 = $arg;
13+
}
14+
};
15+
}
16+
17+
foo!("baz"); //~ ERROR: mismatched types [E0308]
18+
19+
fn main() {}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-75801.rs:17:6
3+
|
4+
LL | let _bar: u32 = $arg;
5+
| --- expected due to this
6+
...
7+
LL | foo!("baz");
8+
| ^^^^^ expected `u32`, found `&str`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)