Skip to content

Commit 12c5b1e

Browse files
committed
Auto merge of #99586 - ehuss:beta-backports, r=ehuss
[beta] Beta 1.63 backports * Reference: Revert $$ macro_metavar rust-lang/reference#1192 * Revert "Stabilize $$ in Rust 1.63.0" #99435 * rustdoc: avoid inlining items with duplicate `(type, name)` #99344 * Do not call `check_expr` twice in `check_compatible` #99397
2 parents efd3583 + 3c1ef01 commit 12c5b1e

17 files changed

+216
-47
lines changed

compiler/rustc_expand/src/mbe/quoted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ fn parse_tree(
234234
sess,
235235
&Token { kind: token::Dollar, span },
236236
);
237+
} else {
238+
maybe_emit_macro_metavar_expr_feature(features, sess, span);
237239
}
238240
TokenTree::token(token::Dollar, span)
239241
}

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303303

304304
let provided_arg: &hir::Expr<'tcx> = &provided_args[input_idx];
305305
let expectation = Expectation::rvalue_hint(self, expected_input_ty);
306-
// FIXME: check that this is safe; I don't believe this commits any of the obligations, but I can't be sure.
307-
//
308-
// I had another method of "soft" type checking before,
309-
// but it was failing to find the type of some expressions (like "")
310-
// so I prodded this method and made it pub(super) so I could call it, and it seems to work well.
311-
let checked_ty = self.check_expr_kind(provided_arg, expectation);
306+
let already_checked_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(provided_arg);
307+
let checked_ty = already_checked_ty.unwrap_or_else(|| self.check_expr(provided_arg));
312308

313309
let coerced_ty = expectation.only_has_type(self).unwrap_or(formal_input_ty);
314310
let can_coerce = self.can_coerce(checked_ty, coerced_ty);

src/doc/reference

src/librustdoc/clean/mod.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,43 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
5757
.map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)),
5858
);
5959
items.extend(self.mods.iter().map(|x| x.clean(cx)));
60-
items.extend(
61-
self.items
62-
.iter()
63-
.flat_map(|(item, renamed)| clean_maybe_renamed_item(cx, item, *renamed)),
64-
);
60+
61+
// Split up imports from all other items.
62+
//
63+
// This covers the case where somebody does an import which should pull in an item,
64+
// but there's already an item with the same namespace and same name. Rust gives
65+
// priority to the not-imported one, so we should, too.
66+
let mut inserted = FxHashSet::default();
67+
items.extend(self.items.iter().flat_map(|(item, renamed)| {
68+
// First, lower everything other than imports.
69+
if matches!(item.kind, hir::ItemKind::Use(..)) {
70+
return Vec::new();
71+
}
72+
let v = clean_maybe_renamed_item(cx, item, *renamed);
73+
for item in &v {
74+
if let Some(name) = item.name {
75+
inserted.insert((item.type_(), name));
76+
}
77+
}
78+
v
79+
}));
80+
items.extend(self.items.iter().flat_map(|(item, renamed)| {
81+
// Now we actually lower the imports, skipping everything else.
82+
if !matches!(item.kind, hir::ItemKind::Use(..)) {
83+
return Vec::new();
84+
}
85+
let mut v = clean_maybe_renamed_item(cx, item, *renamed);
86+
v.drain_filter(|item| {
87+
if let Some(name) = item.name {
88+
// If an item with the same type and name already exists,
89+
// it takes priority over the inlined stuff.
90+
!inserted.insert((item.type_(), name))
91+
} else {
92+
false
93+
}
94+
});
95+
v
96+
}));
6597

6698
// determine if we should display the inner contents or
6799
// the outer `mod` item for the source code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub struct Option;
2+
impl Option {
3+
pub fn unwrap(self) {}
4+
}
5+
6+
mod macros {
7+
use crate::Option;
8+
/// [`Option::unwrap`]
9+
#[macro_export]
10+
macro_rules! print {
11+
() => ()
12+
}
13+
}
14+
15+
mod structs {
16+
use crate::Option;
17+
/// [`Option::unwrap`]
18+
pub struct Print;
19+
}
20+
pub use structs::Print;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// aux-build:issue-99221-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99221_aux;
9+
10+
pub use issue_99221_aux::*;
11+
12+
// @count foo/index.html '//a[@class="macro"]' 1
13+
14+
mod inner {
15+
#[macro_export]
16+
macro_rules! print {
17+
() => ()
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:issue-99221-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99221_aux;
9+
10+
pub use issue_99221_aux::*;
11+
12+
// @count foo/index.html '//a[@class="macro"]' 1
13+
14+
#[macro_export]
15+
macro_rules! print {
16+
() => ()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// aux-build:issue-99221-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99221_aux;
9+
10+
pub use issue_99221_aux::*;
11+
12+
// @count foo/index.html '//a[@class="struct"][@title="foo::Print struct"]' 1
13+
14+
pub struct Print;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
(|_, ()| ())(if true {} else {return;});
3+
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0057]: this function takes 2 arguments but 1 argument was supplied
2+
--> $DIR/issue-98894.rs:2:5
3+
|
4+
LL | (|_, ()| ())(if true {} else {return;});
5+
| ^^^^^^^^^^^^--------------------------- an argument of type `()` is missing
6+
|
7+
note: closure defined here
8+
--> $DIR/issue-98894.rs:2:6
9+
|
10+
LL | (|_, ()| ())(if true {} else {return;});
11+
| ^^^^^^^
12+
help: provide the argument
13+
|
14+
LL | (|_, ()| ())(if true {} else {return;}, ());
15+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0057`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
(|_, ()| ())([return, ()]);
3+
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0057]: this function takes 2 arguments but 1 argument was supplied
2+
--> $DIR/issue-98897.rs:2:5
3+
|
4+
LL | (|_, ()| ())([return, ()]);
5+
| ^^^^^^^^^^^^-------------- an argument of type `()` is missing
6+
|
7+
note: closure defined here
8+
--> $DIR/issue-98897.rs:2:6
9+
|
10+
LL | (|_, ()| ())([return, ()]);
11+
| ^^^^^^^
12+
help: provide the argument
13+
|
14+
LL | (|_, ()| ())([return, ()], ());
15+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0057`.

src/test/ui/issues/issue-3044.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ fn main() {
22
let needlesArr: Vec<char> = vec!['a', 'f'];
33
needlesArr.iter().fold(|x, y| {
44
});
5-
//~^^ ERROR mismatched types
6-
//~| ERROR this function takes 2 arguments but 1 argument was supplied
5+
//~^^ ERROR this function takes 2 arguments but 1 argument was supplied
76
}

src/test/ui/issues/issue-3044.stderr

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-3044.rs:3:35
3-
|
4-
LL | needlesArr.iter().fold(|x, y| {
5-
| ___________________________________^
6-
LL | | });
7-
| |_____^ expected closure, found `()`
8-
|
9-
= note: expected closure `[closure@$DIR/issue-3044.rs:3:28: 4:6]`
10-
found unit type `()`
11-
121
error[E0061]: this function takes 2 arguments but 1 argument was supplied
132
--> $DIR/issue-3044.rs:3:23
143
|
@@ -28,7 +17,6 @@ LL ~ needlesArr.iter().fold(|x, y| {
2817
LL ~ }, /* value */);
2918
|
3019

31-
error: aborting due to 2 previous errors
20+
error: aborting due to previous error
3221

33-
Some errors have detailed explanations: E0061, E0308.
34-
For more information about an error, try `rustc --explain E0061`.
22+
For more information about this error, try `rustc --explain E0061`.

src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs

-12
This file was deleted.

src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ macro_rules! count {
55
};
66
}
77

8+
macro_rules! dollar_dollar {
9+
() => {
10+
macro_rules! bar {
11+
( $$( $$any:tt )* ) => { $$( $$any )* };
12+
//~^ ERROR meta-variable expressions are unstable
13+
//~| ERROR meta-variable expressions are unstable
14+
//~| ERROR meta-variable expressions are unstable
15+
//~| ERROR meta-variable expressions are unstable
16+
}
17+
};
18+
}
19+
820
macro_rules! index {
921
( $( $e:stmt ),* ) => {
1022
$( ${ignore(e)} ${index()} )*
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: meta-variable expressions are unstable
2-
--> $DIR/required-features.rs:3:10
2+
--> $DIR/required-feature.rs:3:10
33
|
44
LL | ${ count(e) }
55
| ^^^^^^^^^^^^
@@ -8,7 +8,43 @@ LL | ${ count(e) }
88
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
99

1010
error[E0658]: meta-variable expressions are unstable
11-
--> $DIR/required-features.rs:10:13
11+
--> $DIR/required-feature.rs:11:16
12+
|
13+
LL | ( $$( $$any:tt )* ) => { $$( $$any )* };
14+
| ^
15+
|
16+
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
17+
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
18+
19+
error[E0658]: meta-variable expressions are unstable
20+
--> $DIR/required-feature.rs:11:20
21+
|
22+
LL | ( $$( $$any:tt )* ) => { $$( $$any )* };
23+
| ^
24+
|
25+
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
26+
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
27+
28+
error[E0658]: meta-variable expressions are unstable
29+
--> $DIR/required-feature.rs:11:39
30+
|
31+
LL | ( $$( $$any:tt )* ) => { $$( $$any )* };
32+
| ^
33+
|
34+
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
35+
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
36+
37+
error[E0658]: meta-variable expressions are unstable
38+
--> $DIR/required-feature.rs:11:43
39+
|
40+
LL | ( $$( $$any:tt )* ) => { $$( $$any )* };
41+
| ^
42+
|
43+
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
44+
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
45+
46+
error[E0658]: meta-variable expressions are unstable
47+
--> $DIR/required-feature.rs:22:13
1248
|
1349
LL | $( ${ignore(e)} ${index()} )*
1450
| ^^^^^^^^^^^
@@ -17,7 +53,7 @@ LL | $( ${ignore(e)} ${index()} )*
1753
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
1854

1955
error[E0658]: meta-variable expressions are unstable
20-
--> $DIR/required-features.rs:10:26
56+
--> $DIR/required-feature.rs:22:26
2157
|
2258
LL | $( ${ignore(e)} ${index()} )*
2359
| ^^^^^^^^^
@@ -26,7 +62,7 @@ LL | $( ${ignore(e)} ${index()} )*
2662
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
2763

2864
error[E0658]: meta-variable expressions are unstable
29-
--> $DIR/required-features.rs:18:19
65+
--> $DIR/required-feature.rs:30:19
3066
|
3167
LL | 0 $( + 1 ${ignore(i)} )*
3268
| ^^^^^^^^^^^
@@ -35,7 +71,7 @@ LL | 0 $( + 1 ${ignore(i)} )*
3571
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
3672

3773
error[E0658]: meta-variable expressions are unstable
38-
--> $DIR/required-features.rs:25:13
74+
--> $DIR/required-feature.rs:37:13
3975
|
4076
LL | $( ${ignore(e)} ${length()} )*
4177
| ^^^^^^^^^^^
@@ -44,14 +80,14 @@ LL | $( ${ignore(e)} ${length()} )*
4480
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
4581

4682
error[E0658]: meta-variable expressions are unstable
47-
--> $DIR/required-features.rs:25:26
83+
--> $DIR/required-feature.rs:37:26
4884
|
4985
LL | $( ${ignore(e)} ${length()} )*
5086
| ^^^^^^^^^^
5187
|
5288
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
5389
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
5490

55-
error: aborting due to 6 previous errors
91+
error: aborting due to 10 previous errors
5692

5793
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)