From 6f162b3583ce96b2f5569314c89e1738c65d7532 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 21 Jul 2022 19:37:03 -0700 Subject: [PATCH 1/4] Update reference This is in preparation to merge https://github.com/rust-lang/rust/pull/99435 which will require the toolstate to be passing. 1 commits in 9fce337a55ee4a4629205f6094656195cecad231..dd07eda38b15f756d60556b7bd7eed6d8db3eeca 2022-06-22 13:59:28 -0700 to 2022-07-21 19:05:26 -0700 - This reverts commit 151b8196a30b1c00cb422e25f459dd4354043a6a, reversing (rust-lang/reference#1192) --- src/doc/reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/reference b/src/doc/reference index 9fce337a55ee4..dd07eda38b15f 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 9fce337a55ee4a4629205f6094656195cecad231 +Subproject commit dd07eda38b15f756d60556b7bd7eed6d8db3eeca From e6e5bc728900a693de66ebf36788212777947bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 19 Jul 2022 13:30:48 +0200 Subject: [PATCH 2/4] Rollup merge of #99435 - CAD97:revert-dollar-dollar-crate, r=Mark-Simulacrum Revert "Stabilize $$ in Rust 1.63.0" This mechanically reverts commit 9edaa76adce4de737db54194eb13d6c298827b37, the one commit from #95860. https://github.com/rust-lang/rust/issues/99035; the behavior of `$$crate` is potentially unexpected and not ready to be stabilized. https://github.com/rust-lang/rust/pull/99193 attempts to forbid `$$crate` without also destabilizing `$$` more generally. `@rustbot` modify labels +T-compiler +T-lang +P-medium +beta-nominated +relnotes (applying the labels I think are accurate from the issue and alternative partial revert) cc `@Mark-Simulacrum` --- compiler/rustc_expand/src/mbe/quoted.rs | 2 + .../rfc-3086-metavar-expr/allowed-features.rs | 12 ----- ...quired-features.rs => required-feature.rs} | 12 +++++ ...eatures.stderr => required-feature.stderr} | 50 ++++++++++++++++--- 4 files changed, 57 insertions(+), 19 deletions(-) delete mode 100644 src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs rename src/test/ui/macros/rfc-3086-metavar-expr/{required-features.rs => required-feature.rs} (65%) rename src/test/ui/macros/rfc-3086-metavar-expr/{required-features.stderr => required-feature.stderr} (52%) diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index d4b8563a03666..707cb73f097f8 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -234,6 +234,8 @@ fn parse_tree( sess, &Token { kind: token::Dollar, span }, ); + } else { + maybe_emit_macro_metavar_expr_feature(features, sess, span); } TokenTree::token(token::Dollar, span) } diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs b/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs deleted file mode 100644 index c248c46f52cd3..0000000000000 --- a/src/test/ui/macros/rfc-3086-metavar-expr/allowed-features.rs +++ /dev/null @@ -1,12 +0,0 @@ -// check-pass - -macro_rules! dollar_dollar { - () => { - macro_rules! bar { - ( $$( $$any:tt )* ) => { $$( $$any )* }; - } - }; -} - -fn main() { -} diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs b/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs similarity index 65% rename from src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs rename to src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs index cce3e578aeafe..b4fef11f1e29a 100644 --- a/src/test/ui/macros/rfc-3086-metavar-expr/required-features.rs +++ b/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs @@ -5,6 +5,18 @@ macro_rules! count { }; } +macro_rules! dollar_dollar { + () => { + macro_rules! bar { + ( $$( $$any:tt )* ) => { $$( $$any )* }; + //~^ ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + //~| ERROR meta-variable expressions are unstable + } + }; +} + macro_rules! index { ( $( $e:stmt ),* ) => { $( ${ignore(e)} ${index()} )* diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr b/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr similarity index 52% rename from src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr rename to src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr index 5efd3b10442d1..ecf598b104d05 100644 --- a/src/test/ui/macros/rfc-3086-metavar-expr/required-features.stderr +++ b/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr @@ -1,5 +1,5 @@ error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:3:10 + --> $DIR/required-feature.rs:3:10 | LL | ${ count(e) } | ^^^^^^^^^^^^ @@ -8,7 +8,43 @@ LL | ${ count(e) } = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:10:13 + --> $DIR/required-feature.rs:11:16 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:20 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:39 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:11:43 + | +LL | ( $$( $$any:tt )* ) => { $$( $$any )* }; + | ^ + | + = note: see issue #83527 for more information + = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable + +error[E0658]: meta-variable expressions are unstable + --> $DIR/required-feature.rs:22:13 | LL | $( ${ignore(e)} ${index()} )* | ^^^^^^^^^^^ @@ -17,7 +53,7 @@ LL | $( ${ignore(e)} ${index()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:10:26 + --> $DIR/required-feature.rs:22:26 | LL | $( ${ignore(e)} ${index()} )* | ^^^^^^^^^ @@ -26,7 +62,7 @@ LL | $( ${ignore(e)} ${index()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:18:19 + --> $DIR/required-feature.rs:30:19 | LL | 0 $( + 1 ${ignore(i)} )* | ^^^^^^^^^^^ @@ -35,7 +71,7 @@ LL | 0 $( + 1 ${ignore(i)} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:25:13 + --> $DIR/required-feature.rs:37:13 | LL | $( ${ignore(e)} ${length()} )* | ^^^^^^^^^^^ @@ -44,7 +80,7 @@ LL | $( ${ignore(e)} ${length()} )* = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable error[E0658]: meta-variable expressions are unstable - --> $DIR/required-features.rs:25:26 + --> $DIR/required-feature.rs:37:26 | LL | $( ${ignore(e)} ${length()} )* | ^^^^^^^^^^ @@ -52,6 +88,6 @@ LL | $( ${ignore(e)} ${length()} )* = note: see issue #83527 for more information = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable -error: aborting due to 6 previous errors +error: aborting due to 10 previous errors For more information about this error, try `rustc --explain E0658`. From 4766af19d8d1fae347ecb5cd19cbce1162cca4e9 Mon Sep 17 00:00:00 2001 From: Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> Date: Mon, 18 Jul 2022 21:14:46 +0530 Subject: [PATCH 3/4] Rollup merge of #99344 - notriddle:notriddle/multiple-macro-rules-w-same-name, r=GuillaumeGomez rustdoc: avoid inlining items with duplicate `(type, name)` Fixes #99221 --- src/librustdoc/clean/mod.rs | 42 ++++++++++++++++--- src/test/rustdoc/auxiliary/issue-99221-aux.rs | 20 +++++++++ ...tiple-macro-rules-w-same-name-submodule.rs | 19 +++++++++ ...-99221-multiple-macro-rules-w-same-name.rs | 17 ++++++++ ...ssue-99221-multiple-structs-w-same-name.rs | 14 +++++++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc/auxiliary/issue-99221-aux.rs create mode 100644 src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs create mode 100644 src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name.rs create mode 100644 src/test/rustdoc/issue-99221-multiple-structs-w-same-name.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2d84d6562819e..31c99b3b30260 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -57,11 +57,43 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> { .map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)), ); items.extend(self.mods.iter().map(|x| x.clean(cx))); - items.extend( - self.items - .iter() - .flat_map(|(item, renamed)| clean_maybe_renamed_item(cx, item, *renamed)), - ); + + // Split up imports from all other items. + // + // This covers the case where somebody does an import which should pull in an item, + // but there's already an item with the same namespace and same name. Rust gives + // priority to the not-imported one, so we should, too. + let mut inserted = FxHashSet::default(); + items.extend(self.items.iter().flat_map(|(item, renamed)| { + // First, lower everything other than imports. + if matches!(item.kind, hir::ItemKind::Use(..)) { + return Vec::new(); + } + let v = clean_maybe_renamed_item(cx, item, *renamed); + for item in &v { + if let Some(name) = item.name { + inserted.insert((item.type_(), name)); + } + } + v + })); + items.extend(self.items.iter().flat_map(|(item, renamed)| { + // Now we actually lower the imports, skipping everything else. + if !matches!(item.kind, hir::ItemKind::Use(..)) { + return Vec::new(); + } + let mut v = clean_maybe_renamed_item(cx, item, *renamed); + v.drain_filter(|item| { + if let Some(name) = item.name { + // If an item with the same type and name already exists, + // it takes priority over the inlined stuff. + !inserted.insert((item.type_(), name)) + } else { + false + } + }); + v + })); // determine if we should display the inner contents or // the outer `mod` item for the source code. diff --git a/src/test/rustdoc/auxiliary/issue-99221-aux.rs b/src/test/rustdoc/auxiliary/issue-99221-aux.rs new file mode 100644 index 0000000000000..e061e42b29db8 --- /dev/null +++ b/src/test/rustdoc/auxiliary/issue-99221-aux.rs @@ -0,0 +1,20 @@ +pub struct Option; +impl Option { + pub fn unwrap(self) {} +} + +mod macros { + use crate::Option; + /// [`Option::unwrap`] + #[macro_export] + macro_rules! print { + () => () + } +} + +mod structs { + use crate::Option; + /// [`Option::unwrap`] + pub struct Print; +} +pub use structs::Print; diff --git a/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs b/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs new file mode 100644 index 0000000000000..e74881d387dc1 --- /dev/null +++ b/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name-submodule.rs @@ -0,0 +1,19 @@ +// aux-build:issue-99221-aux.rs +// build-aux-docs +// ignore-cross-compile + +#![crate_name = "foo"] + +#[macro_use] +extern crate issue_99221_aux; + +pub use issue_99221_aux::*; + +// @count foo/index.html '//a[@class="macro"]' 1 + +mod inner { + #[macro_export] + macro_rules! print { + () => () + } +} diff --git a/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name.rs b/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name.rs new file mode 100644 index 0000000000000..46d59654b99eb --- /dev/null +++ b/src/test/rustdoc/issue-99221-multiple-macro-rules-w-same-name.rs @@ -0,0 +1,17 @@ +// aux-build:issue-99221-aux.rs +// build-aux-docs +// ignore-cross-compile + +#![crate_name = "foo"] + +#[macro_use] +extern crate issue_99221_aux; + +pub use issue_99221_aux::*; + +// @count foo/index.html '//a[@class="macro"]' 1 + +#[macro_export] +macro_rules! print { + () => () +} diff --git a/src/test/rustdoc/issue-99221-multiple-structs-w-same-name.rs b/src/test/rustdoc/issue-99221-multiple-structs-w-same-name.rs new file mode 100644 index 0000000000000..41e64726a3246 --- /dev/null +++ b/src/test/rustdoc/issue-99221-multiple-structs-w-same-name.rs @@ -0,0 +1,14 @@ +// aux-build:issue-99221-aux.rs +// build-aux-docs +// ignore-cross-compile + +#![crate_name = "foo"] + +#[macro_use] +extern crate issue_99221_aux; + +pub use issue_99221_aux::*; + +// @count foo/index.html '//a[@class="struct"][@title="foo::Print struct"]' 1 + +pub struct Print; From 3c1ef0173d3716c1224696f2d5df435ce30c223a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 17 Jul 2022 20:51:58 -0700 Subject: [PATCH 4/4] beta backport of arg mismatch bugfix --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 8 ++------ .../ui/argument-suggestions/issue-98894.rs | 4 ++++ .../argument-suggestions/issue-98894.stderr | 19 +++++++++++++++++++ .../ui/argument-suggestions/issue-98897.rs | 4 ++++ .../argument-suggestions/issue-98897.stderr | 19 +++++++++++++++++++ src/test/ui/issues/issue-3044.rs | 3 +-- src/test/ui/issues/issue-3044.stderr | 16 ++-------------- 7 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 src/test/ui/argument-suggestions/issue-98894.rs create mode 100644 src/test/ui/argument-suggestions/issue-98894.stderr create mode 100644 src/test/ui/argument-suggestions/issue-98897.rs create mode 100644 src/test/ui/argument-suggestions/issue-98897.stderr diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 2326c4069e483..6633bd5821e54 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -303,12 +303,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let provided_arg: &hir::Expr<'tcx> = &provided_args[input_idx]; let expectation = Expectation::rvalue_hint(self, expected_input_ty); - // FIXME: check that this is safe; I don't believe this commits any of the obligations, but I can't be sure. - // - // I had another method of "soft" type checking before, - // but it was failing to find the type of some expressions (like "") - // so I prodded this method and made it pub(super) so I could call it, and it seems to work well. - let checked_ty = self.check_expr_kind(provided_arg, expectation); + let already_checked_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(provided_arg); + let checked_ty = already_checked_ty.unwrap_or_else(|| self.check_expr(provided_arg)); let coerced_ty = expectation.only_has_type(self).unwrap_or(formal_input_ty); let can_coerce = self.can_coerce(checked_ty, coerced_ty); diff --git a/src/test/ui/argument-suggestions/issue-98894.rs b/src/test/ui/argument-suggestions/issue-98894.rs new file mode 100644 index 0000000000000..c2618a96716a5 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98894.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())(if true {} else {return;}); + //~^ ERROR this function takes 2 arguments but 1 argument was supplied +} diff --git a/src/test/ui/argument-suggestions/issue-98894.stderr b/src/test/ui/argument-suggestions/issue-98894.stderr new file mode 100644 index 0000000000000..0c8b94901e16f --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98894.stderr @@ -0,0 +1,19 @@ +error[E0057]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/issue-98894.rs:2:5 + | +LL | (|_, ()| ())(if true {} else {return;}); + | ^^^^^^^^^^^^--------------------------- an argument of type `()` is missing + | +note: closure defined here + --> $DIR/issue-98894.rs:2:6 + | +LL | (|_, ()| ())(if true {} else {return;}); + | ^^^^^^^ +help: provide the argument + | +LL | (|_, ()| ())(if true {} else {return;}, ()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/issue-98897.rs b/src/test/ui/argument-suggestions/issue-98897.rs new file mode 100644 index 0000000000000..c55f495d69862 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98897.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())([return, ()]); + //~^ ERROR this function takes 2 arguments but 1 argument was supplied +} diff --git a/src/test/ui/argument-suggestions/issue-98897.stderr b/src/test/ui/argument-suggestions/issue-98897.stderr new file mode 100644 index 0000000000000..8f0d98d09e89e --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98897.stderr @@ -0,0 +1,19 @@ +error[E0057]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/issue-98897.rs:2:5 + | +LL | (|_, ()| ())([return, ()]); + | ^^^^^^^^^^^^-------------- an argument of type `()` is missing + | +note: closure defined here + --> $DIR/issue-98897.rs:2:6 + | +LL | (|_, ()| ())([return, ()]); + | ^^^^^^^ +help: provide the argument + | +LL | (|_, ()| ())([return, ()], ()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/issues/issue-3044.rs b/src/test/ui/issues/issue-3044.rs index 7363cae8370ab..81d76a90eb0ac 100644 --- a/src/test/ui/issues/issue-3044.rs +++ b/src/test/ui/issues/issue-3044.rs @@ -2,6 +2,5 @@ fn main() { let needlesArr: Vec = vec!['a', 'f']; needlesArr.iter().fold(|x, y| { }); - //~^^ ERROR mismatched types - //~| ERROR this function takes 2 arguments but 1 argument was supplied + //~^^ ERROR this function takes 2 arguments but 1 argument was supplied } diff --git a/src/test/ui/issues/issue-3044.stderr b/src/test/ui/issues/issue-3044.stderr index 6dbe6b59391e3..34c4c113e16c7 100644 --- a/src/test/ui/issues/issue-3044.stderr +++ b/src/test/ui/issues/issue-3044.stderr @@ -1,14 +1,3 @@ -error[E0308]: mismatched types - --> $DIR/issue-3044.rs:3:35 - | -LL | needlesArr.iter().fold(|x, y| { - | ___________________________________^ -LL | | }); - | |_____^ expected closure, found `()` - | - = note: expected closure `[closure@$DIR/issue-3044.rs:3:28: 4:6]` - found unit type `()` - error[E0061]: this function takes 2 arguments but 1 argument was supplied --> $DIR/issue-3044.rs:3:23 | @@ -28,7 +17,6 @@ LL ~ needlesArr.iter().fold(|x, y| { LL ~ }, /* value */); | -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0061, E0308. -For more information about an error, try `rustc --explain E0061`. +For more information about this error, try `rustc --explain E0061`.