From 2550069ab30686e1d292c2d08a470082f50c5b27 Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 20 May 2022 10:53:58 -0300 Subject: [PATCH 1/6] Move tests --- src/test/ui/{issues => associated-types}/issue-20825-2.rs | 0 src/test/ui/{issues => associated-types}/issue-20825.rs | 0 src/test/ui/{issues => associated-types}/issue-20825.stderr | 0 src/test/ui/{issues => hygiene}/issue-32922.rs | 0 src/test/ui/{issues => impl-trait}/issue-46959.rs | 0 src/test/ui/{issues => macros}/issue-33185.rs | 0 src/test/ui/{issues => match}/issue-27021.rs | 0 src/test/ui/{issues => pattern}/issue-27320.rs | 0 src/test/ui/{issues => process}/issue-13304.rs | 0 src/test/ui/{issues => save-analysis}/issue-26459.rs | 0 src/test/ui/{issues => save-analysis}/issue-26459.stderr | 0 src/test/ui/{issues => typeck}/auxiliary/issue-36708.rs | 0 src/test/ui/{issues => typeck}/issue-36708.rs | 0 src/test/ui/{issues => typeck}/issue-36708.stderr | 0 src/test/ui/{issues => unsized}/issue-40231-1.rs | 0 src/test/ui/{issues => unsized}/issue-40231-2.rs | 0 src/tools/tidy/src/ui_tests.rs | 4 ++-- 17 files changed, 2 insertions(+), 2 deletions(-) rename src/test/ui/{issues => associated-types}/issue-20825-2.rs (100%) rename src/test/ui/{issues => associated-types}/issue-20825.rs (100%) rename src/test/ui/{issues => associated-types}/issue-20825.stderr (100%) rename src/test/ui/{issues => hygiene}/issue-32922.rs (100%) rename src/test/ui/{issues => impl-trait}/issue-46959.rs (100%) rename src/test/ui/{issues => macros}/issue-33185.rs (100%) rename src/test/ui/{issues => match}/issue-27021.rs (100%) rename src/test/ui/{issues => pattern}/issue-27320.rs (100%) rename src/test/ui/{issues => process}/issue-13304.rs (100%) rename src/test/ui/{issues => save-analysis}/issue-26459.rs (100%) rename src/test/ui/{issues => save-analysis}/issue-26459.stderr (100%) rename src/test/ui/{issues => typeck}/auxiliary/issue-36708.rs (100%) rename src/test/ui/{issues => typeck}/issue-36708.rs (100%) rename src/test/ui/{issues => typeck}/issue-36708.stderr (100%) rename src/test/ui/{issues => unsized}/issue-40231-1.rs (100%) rename src/test/ui/{issues => unsized}/issue-40231-2.rs (100%) diff --git a/src/test/ui/issues/issue-20825-2.rs b/src/test/ui/associated-types/issue-20825-2.rs similarity index 100% rename from src/test/ui/issues/issue-20825-2.rs rename to src/test/ui/associated-types/issue-20825-2.rs diff --git a/src/test/ui/issues/issue-20825.rs b/src/test/ui/associated-types/issue-20825.rs similarity index 100% rename from src/test/ui/issues/issue-20825.rs rename to src/test/ui/associated-types/issue-20825.rs diff --git a/src/test/ui/issues/issue-20825.stderr b/src/test/ui/associated-types/issue-20825.stderr similarity index 100% rename from src/test/ui/issues/issue-20825.stderr rename to src/test/ui/associated-types/issue-20825.stderr diff --git a/src/test/ui/issues/issue-32922.rs b/src/test/ui/hygiene/issue-32922.rs similarity index 100% rename from src/test/ui/issues/issue-32922.rs rename to src/test/ui/hygiene/issue-32922.rs diff --git a/src/test/ui/issues/issue-46959.rs b/src/test/ui/impl-trait/issue-46959.rs similarity index 100% rename from src/test/ui/issues/issue-46959.rs rename to src/test/ui/impl-trait/issue-46959.rs diff --git a/src/test/ui/issues/issue-33185.rs b/src/test/ui/macros/issue-33185.rs similarity index 100% rename from src/test/ui/issues/issue-33185.rs rename to src/test/ui/macros/issue-33185.rs diff --git a/src/test/ui/issues/issue-27021.rs b/src/test/ui/match/issue-27021.rs similarity index 100% rename from src/test/ui/issues/issue-27021.rs rename to src/test/ui/match/issue-27021.rs diff --git a/src/test/ui/issues/issue-27320.rs b/src/test/ui/pattern/issue-27320.rs similarity index 100% rename from src/test/ui/issues/issue-27320.rs rename to src/test/ui/pattern/issue-27320.rs diff --git a/src/test/ui/issues/issue-13304.rs b/src/test/ui/process/issue-13304.rs similarity index 100% rename from src/test/ui/issues/issue-13304.rs rename to src/test/ui/process/issue-13304.rs diff --git a/src/test/ui/issues/issue-26459.rs b/src/test/ui/save-analysis/issue-26459.rs similarity index 100% rename from src/test/ui/issues/issue-26459.rs rename to src/test/ui/save-analysis/issue-26459.rs diff --git a/src/test/ui/issues/issue-26459.stderr b/src/test/ui/save-analysis/issue-26459.stderr similarity index 100% rename from src/test/ui/issues/issue-26459.stderr rename to src/test/ui/save-analysis/issue-26459.stderr diff --git a/src/test/ui/issues/auxiliary/issue-36708.rs b/src/test/ui/typeck/auxiliary/issue-36708.rs similarity index 100% rename from src/test/ui/issues/auxiliary/issue-36708.rs rename to src/test/ui/typeck/auxiliary/issue-36708.rs diff --git a/src/test/ui/issues/issue-36708.rs b/src/test/ui/typeck/issue-36708.rs similarity index 100% rename from src/test/ui/issues/issue-36708.rs rename to src/test/ui/typeck/issue-36708.rs diff --git a/src/test/ui/issues/issue-36708.stderr b/src/test/ui/typeck/issue-36708.stderr similarity index 100% rename from src/test/ui/issues/issue-36708.stderr rename to src/test/ui/typeck/issue-36708.stderr diff --git a/src/test/ui/issues/issue-40231-1.rs b/src/test/ui/unsized/issue-40231-1.rs similarity index 100% rename from src/test/ui/issues/issue-40231-1.rs rename to src/test/ui/unsized/issue-40231-1.rs diff --git a/src/test/ui/issues/issue-40231-2.rs b/src/test/ui/unsized/issue-40231-2.rs similarity index 100% rename from src/test/ui/issues/issue-40231-2.rs rename to src/test/ui/unsized/issue-40231-2.rs diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 5712e84adbc20..cf72dc4bd09a3 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,8 +7,8 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 974; -const ISSUES_ENTRY_LIMIT: usize = 2248; +const ROOT_ENTRY_LIMIT: usize = 971; +const ISSUES_ENTRY_LIMIT: usize = 2234; fn check_entries(path: &Path, bad: &mut bool) { let dirs = walkdir::WalkDir::new(&path.join("test/ui")) From 2e2836ad141104c52f926668f95d906df84325cc Mon Sep 17 00:00:00 2001 From: Proloy Mishra <67726964+pro465@users.noreply.github.com> Date: Sun, 22 May 2022 17:52:04 +0530 Subject: [PATCH 2/6] small change --- library/std/src/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 28e802d07e197..1def9fe097202 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -2108,7 +2108,7 @@ pub fn id() -> u32 { /// A trait for implementing arbitrary return types in the `main` function. /// -/// The C-main function only supports to return integers as return type. +/// The C-main function only supports returning integers. /// So, every type implementing the `Termination` trait has to be converted /// to an integer. /// From b0ea4e74cbcb7e4e42f622cda098b95e583f62d9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 May 2022 08:30:56 -0500 Subject: [PATCH 3/6] Avoid accidentally enabling unstable features in compilers (take 2) This allows rustbuild to control whether crates can use nightly features or not. It also prevents rustbuild from using nightly features itself. --- src/bootstrap/bootstrap.py | 1 - src/bootstrap/doc.rs | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index e38a574ca2310..7a684c89fe31f 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1171,7 +1171,6 @@ def bootstrap(help_triggered): env = os.environ.copy() env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) env["BOOTSTRAP_PYTHON"] = sys.executable - env["RUSTC_BOOTSTRAP"] = '1' if build.rustc_commit is not None: env["BOOTSTRAP_DOWNLOAD_RUSTC"] = '1' run(args, env=env, verbose=build.verbose, is_bootstrap=True) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index fcef784d2d1fa..be6655ddb61d0 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -881,6 +881,10 @@ impl Step for RustcBook { if self.validate { cmd.arg("--validate"); } + if !builder.unstable_features() { + // We need to validate nightly features, even on the stable channel. + cmd.env("RUSTC_BOOTSTRAP", "1"); + } // If the lib directories are in an unusual location (changed in // config.toml), then this needs to explicitly update the dylib search // path. From 1532fd8cd0db93f469e414f9da31ef083a44fcba Mon Sep 17 00:00:00 2001 From: yue4u Date: Sun, 22 May 2022 23:17:44 +0900 Subject: [PATCH 4/6] Quote replace target in bootstrap configure --- src/bootstrap/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 87a130a09827d..2fc036082cba6 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -407,7 +407,7 @@ def set(key, value): configured_targets.append(target) for target in configured_targets: targets[target] = sections['target'][:] - targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", target) + targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target)) def is_number(value): From 751ad4a0e9fc43a9e810cce69d4cef581323e79a Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 May 2022 09:44:23 -0500 Subject: [PATCH 5/6] Disable unstable features in bootstrap tools This statically prevents issues like https://github.com/rust-lang/rust/issues/59264, where tools can only be built with the in-tree compiler and not beta. --- src/bootstrap/builder.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2224bf5f66e90..68d0d685ebb40 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1201,6 +1201,14 @@ impl<'a> Builder<'a> { // this), as well as #63012 which is the tracking issue for this // feature on the rustc side. cargo.arg("-Zbinary-dep-depinfo"); + match mode { + Mode::ToolBootstrap => { + // Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally. + // HACK: because anyhow does feature detection in build.rs, we need to allow the backtrace feature too. + rustflags.arg("-Zallow-features=binary-dep-depinfo,backtrace"); + } + Mode::Std | Mode::Rustc | Mode::ToolStd | Mode::Codegen | Mode::ToolRustc => {} + } cargo.arg("-j").arg(self.jobs().to_string()); // Remove make-related flags to ensure Cargo can correctly set things up From 683a9c8391f73a5fd9b39efd7b1179f6a2264ae2 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Fri, 20 May 2022 02:00:42 -0400 Subject: [PATCH 6/6] Do leak check after function ptr coercion --- .../src/infer/error_reporting/mod.rs | 11 ++- compiler/rustc_middle/src/ty/error.rs | 9 +-- .../rustc_mir_build/src/build/matches/mod.rs | 1 + compiler/rustc_mir_build/src/thir/cx/block.rs | 1 + compiler/rustc_mir_build/src/thir/cx/mod.rs | 1 + compiler/rustc_typeck/src/check/_match.rs | 73 +++++++++++-------- compiler/rustc_typeck/src/check/coercion.rs | 47 ++++++++---- compiler/rustc_typeck/src/check/demand.rs | 18 ++++- .../placeholder-pattern-fail.nll.stderr | 31 +------- .../ui/hrtb/hrtb-exists-forall-fn.nll.stderr | 4 +- ... => old-lub-glb-hr-noteq1.baseleak.stderr} | 5 +- .../old-lub-glb-hr-noteq1.basenoleak.stderr | 21 ++++++ .../old-lub-glb-hr-noteq1.nllleak.stderr | 21 ++++++ ...=> old-lub-glb-hr-noteq1.nllnoleak.stderr} | 2 +- src/test/ui/lub-glb/old-lub-glb-hr-noteq1.rs | 12 ++- ... => old-lub-glb-hr-noteq2.baseleak.stderr} | 5 +- .../old-lub-glb-hr-noteq2.basenoleak.stderr | 21 ++++++ .../old-lub-glb-hr-noteq2.nllleak.stderr | 21 ++++++ src/test/ui/lub-glb/old-lub-glb-hr-noteq2.rs | 22 ++++-- ...ime-bounds-on-fns-where-clause.base.stderr | 6 +- ...time-bounds-on-fns-where-clause.nll.stderr | 46 +----------- ...ion-lifetime-bounds-on-fns-where-clause.rs | 3 - ...ime-bounds-on-fns-where-clause.base.stderr | 8 +- ...time-bounds-on-fns-where-clause.nll.stderr | 55 +------------- ...ple-lifetime-bounds-on-fns-where-clause.rs | 4 - ...n-subtyping-return-static-fail.base.stderr | 11 ++- ...fn-subtyping-return-static-fail.nll.stderr | 13 +++- ...regions-lifetime-bounds-on-fns.base.stderr | 6 +- .../regions-lifetime-bounds-on-fns.nll.stderr | 46 +----------- .../regions/regions-lifetime-bounds-on-fns.rs | 3 - 30 files changed, 271 insertions(+), 256 deletions(-) rename src/test/ui/lub-glb/{old-lub-glb-hr-noteq1.stderr => old-lub-glb-hr-noteq1.baseleak.stderr} (90%) create mode 100644 src/test/ui/lub-glb/old-lub-glb-hr-noteq1.basenoleak.stderr create mode 100644 src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllleak.stderr rename src/test/ui/lub-glb/{old-lub-glb-hr-noteq1.nll.stderr => old-lub-glb-hr-noteq1.nllnoleak.stderr} (89%) rename src/test/ui/lub-glb/{old-lub-glb-hr-noteq2.stderr => old-lub-glb-hr-noteq2.baseleak.stderr} (90%) create mode 100644 src/test/ui/lub-glb/old-lub-glb-hr-noteq2.basenoleak.stderr create mode 100644 src/test/ui/lub-glb/old-lub-glb-hr-noteq2.nllleak.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 02caae7a90a91..11c893a7cb6d9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1442,6 +1442,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// the message in `secondary_span` as the primary label, and apply the message that would /// otherwise be used for the primary label on the `secondary_span` `Span`. This applies on /// E0271, like `src/test/ui/issues/issue-39970.stderr`. + #[tracing::instrument( + level = "debug", + skip(self, diag, secondary_span, swap_secondary_and_primary, force_label) + )] pub fn note_type_err( &self, diag: &mut Diagnostic, @@ -1453,7 +1457,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { force_label: bool, ) { let span = cause.span(self.tcx); - debug!("note_type_err cause={:?} values={:?}, terr={:?}", cause, values, terr); // For some types of errors, expected-found does not make // sense, so just ignore the values we were given. @@ -1621,9 +1624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } }; - // Ignore msg for object safe coercion - // since E0038 message will be printed match terr { + // Ignore msg for object safe coercion + // since E0038 message will be printed TypeError::ObjectUnsafeCoercion(_) => {} _ => { let mut label_or_note = |span: Span, msg: &str| { @@ -1774,6 +1777,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // It reads better to have the error origin as the final // thing. self.note_error_origin(diag, cause, exp_found, terr); + + debug!(?diag); } fn suggest_tuple_pattern( diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index a0fe632f11a07..a6c14ea0de343 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -135,11 +135,10 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ArgCount => write!(f, "incorrect number of function parameters"), FieldMisMatch(adt, field) => write!(f, "field type mismatch: {}.{}", adt, field), RegionsDoesNotOutlive(..) => write!(f, "lifetime mismatch"), - RegionsInsufficientlyPolymorphic(br, _) => write!( - f, - "expected bound lifetime parameter{}, found concrete lifetime", - br_string(br) - ), + // Actually naming the region here is a bit confusing because context is lacking + RegionsInsufficientlyPolymorphic(..) => { + write!(f, "one type is more general than the other") + } RegionsOverlyPolymorphic(br, _) => write!( f, "expected concrete lifetime, found bound lifetime parameter{}", diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 56acf65d9c5aa..9df86c6ada134 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -151,6 +151,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// /// * From each pre-binding block to the next pre-binding block. /// * From each otherwise block to the next pre-binding block. + #[tracing::instrument(level = "debug", skip(self, arms))] pub(crate) fn match_expr( &mut self, destination: Place<'tcx>, diff --git a/compiler/rustc_mir_build/src/thir/cx/block.rs b/compiler/rustc_mir_build/src/thir/cx/block.rs index d0b18ce67c6d8..59750d5d0b88e 100644 --- a/compiler/rustc_mir_build/src/thir/cx/block.rs +++ b/compiler/rustc_mir_build/src/thir/cx/block.rs @@ -75,6 +75,7 @@ impl<'tcx> Cx<'tcx> { }; let mut pattern = self.pattern_from_hir(local.pat); + debug!(?pattern); if let Some(ty) = &local.ty { if let Some(&user_ty) = diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 13b4e90ca09ce..bd17df60cd788 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -98,6 +98,7 @@ impl<'tcx> Cx<'tcx> { } } + #[tracing::instrument(level = "debug", skip(self))] pub(crate) fn pattern_from_hir(&mut self, p: &hir::Pat<'_>) -> Pat<'tcx> { let p = match self.tcx.hir().get(p.hir_id) { Node::Pat(p) | Node::Binding(p) => p, diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 9aff854c80305..3632e14385fe9 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -56,6 +56,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut all_arms_diverge = Diverges::WarnedAlways; let expected = orig_expected.adjust_for_branches(self); + debug!(?expected); let mut coercion = { let coerce_first = match expected { @@ -127,6 +128,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(&arm.body), arm_ty, Some(&mut |err: &mut Diagnostic| { + let Some(ret) = self.ret_type_span else { + return; + }; + let Expectation::IsLast(stmt) = orig_expected else { + return + }; let can_coerce_to_return_ty = match self.ret_coercion.as_ref() { Some(ret_coercion) if self.in_tail_expr => { let ret_ty = ret_coercion.borrow().expected_ty(); @@ -138,38 +145,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => false, }; - if let (Expectation::IsLast(stmt), Some(ret), true) = - (orig_expected, self.ret_type_span, can_coerce_to_return_ty) - { - let semi_span = expr.span.shrink_to_hi().with_hi(stmt.hi()); - let mut ret_span: MultiSpan = semi_span.into(); - ret_span.push_span_label( - expr.span, - "this could be implicitly returned but it is a statement, not a \ - tail expression" - .to_owned(), - ); - ret_span.push_span_label( - ret, - "the `match` arms can conform to this return type".to_owned(), - ); - ret_span.push_span_label( - semi_span, - "the `match` is a statement because of this semicolon, consider \ - removing it" - .to_owned(), - ); - err.span_note( - ret_span, - "you might have meant to return the `match` expression", - ); - err.tool_only_span_suggestion( - semi_span, - "remove this semicolon", - String::new(), - Applicability::MaybeIncorrect, - ); + if !can_coerce_to_return_ty { + return; } + + let semi_span = expr.span.shrink_to_hi().with_hi(stmt.hi()); + let mut ret_span: MultiSpan = semi_span.into(); + ret_span.push_span_label( + expr.span, + "this could be implicitly returned but it is a statement, not a \ + tail expression" + .to_owned(), + ); + ret_span.push_span_label( + ret, + "the `match` arms can conform to this return type".to_owned(), + ); + ret_span.push_span_label( + semi_span, + "the `match` is a statement because of this semicolon, consider \ + removing it" + .to_owned(), + ); + err.span_note( + ret_span, + "you might have meant to return the `match` expression", + ); + err.tool_only_span_suggestion( + semi_span, + "remove this semicolon", + String::new(), + Applicability::MaybeIncorrect, + ); }), false, ); @@ -199,7 +206,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We won't diverge unless the scrutinee or all arms diverge. self.diverges.set(scrut_diverges | all_arms_diverge); - coercion.complete(self) + let match_ty = coercion.complete(self); + debug!(?match_ty); + match_ty } fn get_appropriate_arm_semicolon_removal_span( diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index a17b13d49fd7f..6d540bf7e4f4b 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -737,14 +737,27 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { F: FnOnce(Ty<'tcx>) -> Vec>, G: FnOnce(Ty<'tcx>) -> Vec>, { - if let ty::FnPtr(fn_ty_b) = b.kind() - && let (hir::Unsafety::Normal, hir::Unsafety::Unsafe) = - (fn_ty_a.unsafety(), fn_ty_b.unsafety()) - { - let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a); - return self.unify_and(unsafe_a, b, to_unsafe); - } - self.unify_and(a, b, normal) + self.commit_unconditionally(|snapshot| { + let result = if let ty::FnPtr(fn_ty_b) = b.kind() + && let (hir::Unsafety::Normal, hir::Unsafety::Unsafe) = + (fn_ty_a.unsafety(), fn_ty_b.unsafety()) + { + let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a); + self.unify_and(unsafe_a, b, to_unsafe) + } else { + self.unify_and(a, b, normal) + }; + + // FIXME(#73154): This is a hack. Currently LUB can generate + // unsolvable constraints. Additionally, it returns `a` + // unconditionally, even when the "LUB" is `b`. In the future, we + // want the coerced type to be the actual supertype of these two, + // but for now, we want to just error to ensure we don't lock + // ourselves into a specific behavior with NLL. + self.leak_check(false, snapshot)?; + + result + }) } fn coerce_from_fn_pointer( @@ -1133,8 +1146,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (adjustments, target) = self.register_infer_ok_obligations(ok); self.apply_adjustments(new, adjustments); debug!( - "coercion::try_find_coercion_lub: was able to coerce from previous type {:?} to new type {:?}", - prev_ty, new_ty, + "coercion::try_find_coercion_lub: was able to coerce from new type {:?} to previous type {:?} ({:?})", + new_ty, prev_ty, target ); return Ok(target); } @@ -1190,15 +1203,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } Ok(ok) => { - debug!( - "coercion::try_find_coercion_lub: was able to coerce previous type {:?} to new type {:?}", - prev_ty, new_ty, - ); let (adjustments, target) = self.register_infer_ok_obligations(ok); for expr in exprs { let expr = expr.as_coercion_site(); self.apply_adjustments(expr, adjustments.clone()); } + debug!( + "coercion::try_find_coercion_lub: was able to coerce previous type {:?} to new type {:?} ({:?})", + prev_ty, new_ty, target + ); Ok(target) } } @@ -1430,6 +1443,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { }) }; + debug!(?result); match result { Ok(v) => { self.final_ty = Some(v); @@ -1520,7 +1534,10 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { augment_error(&mut err); } - if let Some(expr) = expression { + let is_insufficiently_polymorphic = + matches!(coercion_error, TypeError::RegionsInsufficientlyPolymorphic(..)); + + if !is_insufficiently_polymorphic && let Some(expr) = expression { fcx.emit_coerce_suggestions( &mut err, expr, diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index ceb57386e300f..d0d2841209a6e 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -129,6 +129,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// N.B., this code relies on `self.diverges` to be accurate. In particular, assignments to `!` /// will be permitted if the diverges flag is currently "always". + #[tracing::instrument(level = "debug", skip(self, expr, expected_ty_expr, allow_two_phase))] pub fn demand_coerce_diag( &self, expr: &hir::Expr<'tcx>, @@ -150,7 +151,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expr_ty = self.resolve_vars_with_obligations(checked_ty); let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e.clone()); - self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr, Some(e)); + let is_insufficiently_polymorphic = + matches!(e, TypeError::RegionsInsufficientlyPolymorphic(..)); + + // FIXME(#73154): For now, we do leak check when coercing function + // pointers in typeck, instead of only during borrowck. This can lead + // to these `RegionsInsufficientlyPolymorphic` errors that aren't helpful. + if !is_insufficiently_polymorphic { + self.emit_coerce_suggestions( + &mut err, + expr, + expr_ty, + expected, + expected_ty_expr, + Some(e), + ); + } (expected, Some(err)) } diff --git a/src/test/ui/hr-subtype/placeholder-pattern-fail.nll.stderr b/src/test/ui/hr-subtype/placeholder-pattern-fail.nll.stderr index 1836249efdb2a..73b0a31736447 100644 --- a/src/test/ui/hr-subtype/placeholder-pattern-fail.nll.stderr +++ b/src/test/ui/hr-subtype/placeholder-pattern-fail.nll.stderr @@ -1,37 +1,12 @@ error[E0308]: mismatched types - --> $DIR/placeholder-pattern-fail.rs:9:12 + --> $DIR/placeholder-pattern-fail.rs:9:47 | LL | let _: for<'a, 'b> fn(Inv<'a>, Inv<'b>) = sub; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other + | ^^^ one type is more general than the other | = note: expected fn pointer `for<'a, 'b> fn(Inv<'a>, Inv<'b>)` found fn pointer `for<'a> fn(Inv<'a>, Inv<'a>)` -error[E0308]: mismatched types - --> $DIR/placeholder-pattern-fail.rs:9:12 - | -LL | let _: for<'a, 'b> fn(Inv<'a>, Inv<'b>) = sub; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other - | - = note: expected fn pointer `for<'a, 'b> fn(Inv<'a>, Inv<'b>)` - found fn pointer `for<'a> fn(Inv<'a>, Inv<'a>)` - -error: lifetime may not live long enough - --> $DIR/placeholder-pattern-fail.rs:14:13 - | -LL | fn simple1<'c>(x: (&'c i32,)) { - | -- lifetime `'c` defined here -LL | let _x: (&'static i32,) = x; - | ^^^^^^^^^^^^^^^ type annotation requires that `'c` must outlive `'static` - -error: lifetime may not live long enough - --> $DIR/placeholder-pattern-fail.rs:19:12 - | -LL | fn simple2<'c>(x: (&'c i32,)) { - | -- lifetime `'c` defined here -LL | let _: (&'static i32,) = x; - | ^^^^^^^^^^^^^^^ type annotation requires that `'c` must outlive `'static` - -error: aborting due to 4 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/hrtb/hrtb-exists-forall-fn.nll.stderr b/src/test/ui/hrtb/hrtb-exists-forall-fn.nll.stderr index 1ee3c67496397..9914783d9767d 100644 --- a/src/test/ui/hrtb/hrtb-exists-forall-fn.nll.stderr +++ b/src/test/ui/hrtb/hrtb-exists-forall-fn.nll.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/hrtb-exists-forall-fn.rs:17:12 + --> $DIR/hrtb-exists-forall-fn.rs:17:34 | LL | let _: for<'b> fn(&'b u32) = foo(); - | ^^^^^^^^^^^^^^^^^^^ one type is more general than the other + | ^^^^^ one type is more general than the other | = note: expected fn pointer `for<'b> fn(&'b u32)` found fn pointer `fn(&u32)` diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.baseleak.stderr similarity index 90% rename from src/test/ui/lub-glb/old-lub-glb-hr-noteq1.stderr rename to src/test/ui/lub-glb/old-lub-glb-hr-noteq1.baseleak.stderr index 305e952d6046b..4448f9326cb94 100644 --- a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.stderr +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.baseleak.stderr @@ -1,5 +1,5 @@ error[E0308]: `match` arms have incompatible types - --> $DIR/old-lub-glb-hr-noteq1.rs:11:14 + --> $DIR/old-lub-glb-hr-noteq1.rs:17:14 | LL | let z = match 22 { | _____________- @@ -7,6 +7,9 @@ LL | | 0 => x, | | - this is found to be of type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` LL | | _ => y, | | ^ one type is more general than the other +LL | | +... | +LL | | LL | | }; | |_____- `match` arms have incompatible types | diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.basenoleak.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.basenoleak.stderr new file mode 100644 index 0000000000000..4448f9326cb94 --- /dev/null +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.basenoleak.stderr @@ -0,0 +1,21 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/old-lub-glb-hr-noteq1.rs:17:14 + | +LL | let z = match 22 { + | _____________- +LL | | 0 => x, + | | - this is found to be of type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` +LL | | _ => y, + | | ^ one type is more general than the other +LL | | +... | +LL | | +LL | | }; + | |_____- `match` arms have incompatible types + | + = note: expected fn pointer `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` + found fn pointer `for<'a> fn(&'a u8, &'a u8) -> &'a u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllleak.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllleak.stderr new file mode 100644 index 0000000000000..4448f9326cb94 --- /dev/null +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllleak.stderr @@ -0,0 +1,21 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/old-lub-glb-hr-noteq1.rs:17:14 + | +LL | let z = match 22 { + | _____________- +LL | | 0 => x, + | | - this is found to be of type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` +LL | | _ => y, + | | ^ one type is more general than the other +LL | | +... | +LL | | +LL | | }; + | |_____- `match` arms have incompatible types + | + = note: expected fn pointer `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` + found fn pointer `for<'a> fn(&'a u8, &'a u8) -> &'a u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nll.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllnoleak.stderr similarity index 89% rename from src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nll.stderr rename to src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllnoleak.stderr index 5ac392914e57b..0d61311350e8c 100644 --- a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nll.stderr +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.nllnoleak.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/old-lub-glb-hr-noteq1.rs:11:14 + --> $DIR/old-lub-glb-hr-noteq1.rs:17:14 | LL | _ => y, | ^ one type is more general than the other diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.rs b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.rs index 918542d471b58..2cf123cce7ffd 100644 --- a/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.rs +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq1.rs @@ -2,13 +2,23 @@ // general than the other. Test the case where the more general type (`x`) is the first // match arm specifically. +// revisions: baseleak basenoleak nllleak nllnoleak +// ignore-compare-mode-nll +//[nllleak] compile-flags: -Zborrowck=mir +//[nllnoleak] compile-flags: -Zborrowck=mir -Zno-leak-check +//[basenoleak] compile-flags:-Zno-leak-check + fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { // The two types above are not equivalent. With the older LUB/GLB // algorithm, this may have worked (I don't remember), but now it // doesn't because we require equality. let z = match 22 { 0 => x, - _ => y, //~ ERROR `match` arms have incompatible types + _ => y, + //[baseleak]~^ ERROR `match` arms have incompatible types + //[nllleak]~^^ ERROR `match` arms have incompatible types + //[basenoleak]~^^^ ERROR `match` arms have incompatible types + //[nllnoleak]~^^^^ ERROR mismatched types }; } diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.baseleak.stderr similarity index 90% rename from src/test/ui/lub-glb/old-lub-glb-hr-noteq2.stderr rename to src/test/ui/lub-glb/old-lub-glb-hr-noteq2.baseleak.stderr index eacbbb8764025..1c9ce115e961e 100644 --- a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.stderr +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.baseleak.stderr @@ -1,5 +1,5 @@ error[E0308]: `match` arms have incompatible types - --> $DIR/old-lub-glb-hr-noteq2.rs:21:14 + --> $DIR/old-lub-glb-hr-noteq2.rs:28:14 | LL | let z = match 22 { | _____________- @@ -7,6 +7,9 @@ LL | | 0 => y, | | - this is found to be of type `for<'a> fn(&'a u8, &'a u8) -> &'a u8` LL | | _ => x, | | ^ one type is more general than the other +LL | | +LL | | +LL | | LL | | }; | |_____- `match` arms have incompatible types | diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.basenoleak.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.basenoleak.stderr new file mode 100644 index 0000000000000..1c9ce115e961e --- /dev/null +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.basenoleak.stderr @@ -0,0 +1,21 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/old-lub-glb-hr-noteq2.rs:28:14 + | +LL | let z = match 22 { + | _____________- +LL | | 0 => y, + | | - this is found to be of type `for<'a> fn(&'a u8, &'a u8) -> &'a u8` +LL | | _ => x, + | | ^ one type is more general than the other +LL | | +LL | | +LL | | +LL | | }; + | |_____- `match` arms have incompatible types + | + = note: expected fn pointer `for<'a> fn(&'a u8, &'a u8) -> &'a u8` + found fn pointer `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.nllleak.stderr b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.nllleak.stderr new file mode 100644 index 0000000000000..1c9ce115e961e --- /dev/null +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.nllleak.stderr @@ -0,0 +1,21 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/old-lub-glb-hr-noteq2.rs:28:14 + | +LL | let z = match 22 { + | _____________- +LL | | 0 => y, + | | - this is found to be of type `for<'a> fn(&'a u8, &'a u8) -> &'a u8` +LL | | _ => x, + | | ^ one type is more general than the other +LL | | +LL | | +LL | | +LL | | }; + | |_____- `match` arms have incompatible types + | + = note: expected fn pointer `for<'a> fn(&'a u8, &'a u8) -> &'a u8` + found fn pointer `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.rs b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.rs index 2aabc0dab1edb..d49b85ce05ef7 100644 --- a/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.rs +++ b/src/test/ui/lub-glb/old-lub-glb-hr-noteq2.rs @@ -2,15 +2,22 @@ // one is more general than the other. Test the case where the more general type // (`x`) is the second match arm specifically. // -// FIXME(#73154) Skip for compare-mode because the pure NLL checker accepts this -// test. (Note that it still errors in old-lub-glb-hr-noteq1.rs). What happens +// FIXME(#73154) Pure NLL checker without leak check accepts this test. +// (Note that it still errors in old-lub-glb-hr-noteq1.rs). What happens // is that, due to the ordering of the match arms, we pick the correct "more // general" fn type, and we ignore the errors from the non-NLL type checker that // requires equality. The NLL type checker only requires a subtyping -// relationship, and that holds. -// +// relationship, and that holds. To unblock landing NLL - and ensure that we can +// choose to make this always in error in the future - we perform the leak check +// after coercing a function pointer. + +// revisions: baseleak basenoleak nllleak nllnoleak // ignore-compare-mode-nll -// ignore-compare-mode-polonius +//[nllleak] compile-flags: -Zborrowck=mir +//[nllnoleak] compile-flags: -Zborrowck=mir -Zno-leak-check +//[basenoleak] compile-flags:-Zno-leak-check + +//[nllnoleak] check-pass fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8) -> &'a u8) { // The two types above are not equivalent. With the older LUB/GLB @@ -18,7 +25,10 @@ fn foo(x: for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8, y: for<'a> fn(&'a u8, &'a u8 // doesn't because we require equality. let z = match 22 { 0 => y, - _ => x, //~ ERROR `match` arms have incompatible types + _ => x, + //[baseleak]~^ ERROR `match` arms have incompatible types + //[nllleak]~^^ ERROR `match` arms have incompatible types + //[basenoleak]~^^^ ERROR `match` arms have incompatible types }; } diff --git a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.base.stderr b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.base.stderr index 2ba4f4f5d9f46..b8b9de627af30 100644 --- a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.base.stderr +++ b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.base.stderr @@ -8,7 +8,7 @@ LL | *x = *y; | ^^ ...but data from `y` flows into `x` here error[E0623]: lifetime mismatch - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:20:7 + --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:19:7 | LL | fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { | --------- --------- these two types are declared with different lifetimes... @@ -17,13 +17,13 @@ LL | a(x, y); | ^ ...but data from `y` flows into `x` here error[E0308]: mismatched types - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:28:43 + --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:26:43 | LL | let _: fn(&mut &isize, &mut &isize) = a; | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` + found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}` error: aborting due to 3 previous errors diff --git a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.nll.stderr b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.nll.stderr index c64309743346d..8a4b313264654 100644 --- a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.nll.stderr +++ b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.nll.stderr @@ -1,50 +1,12 @@ -error: lifetime may not live long enough - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:12:5 - | -LL | fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | // Illegal now because there is no `'b:'a` declaration. -LL | *x = *y; - | ^^^^^^^ assignment requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - -error: lifetime may not live long enough - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:20:5 - | -LL | fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -... -LL | a(x, y); - | ^^^^^^^ argument requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to `&isize` - = note: mutable references are invariant over their type parameter - = help: see for more information about variance - -error[E0308]: mismatched types - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:28:12 - | -LL | let _: fn(&mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other - | - = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` - error[E0308]: mismatched types - --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:28:12 + --> $DIR/region-lifetime-bounds-on-fns-where-clause.rs:26:43 | LL | let _: fn(&mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other + | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` + found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}` -error: aborting due to 4 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.rs b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.rs index ec91d1798083c..61ae1cc3fad6a 100644 --- a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.rs @@ -11,7 +11,6 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //[base]~^ ERROR E0623 - //[nll]~^^ ERROR lifetime may not live long enough } fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { @@ -19,7 +18,6 @@ fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { // related as required. a(x, y); //[base]~^ ERROR lifetime mismatch [E0623] - //[nll]~^^ ERROR lifetime may not live long enough } fn d() { @@ -27,7 +25,6 @@ fn d() { // inconstraints: let _: fn(&mut &isize, &mut &isize) = a; //~^ ERROR mismatched types [E0308] - //[nll]~^^ ERROR mismatched types [E0308] } fn e() { diff --git a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.base.stderr b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.base.stderr index 537a1fb98a50f..062411e6f6890 100644 --- a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.base.stderr +++ b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.base.stderr @@ -8,7 +8,7 @@ LL | *x = *y; | ^^ ...but data from `y` flows into `x` here error[E0623]: lifetime mismatch - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:16:10 + --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:15:10 | LL | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { | --------- --------- @@ -19,7 +19,7 @@ LL | *z = *y; | ^^ ...but data from `y` flows into `z` here error[E0623]: lifetime mismatch - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:22:7 + --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:21:7 | LL | fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { | --------- --------- these two types are declared with different lifetimes... @@ -28,13 +28,13 @@ LL | a(x, y, z); | ^ ...but data from `y` flows into `x` here error[E0308]: mismatched types - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:30:56 + --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:28:56 | LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut &'s isize, &'t0 mut &'t1 isize, &'t2 mut &'t3 isize)` - found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)` + found fn item `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize) {a::<'_, '_, '_>}` error: aborting due to 4 previous errors diff --git a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.nll.stderr b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.nll.stderr index 053078f58df93..f304c69d44b5d 100644 --- a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.nll.stderr +++ b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.nll.stderr @@ -1,59 +1,12 @@ -error: lifetime may not live long enough - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:13:5 - | -LL | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | // Illegal now because there is no `'b:'a` declaration. -LL | *x = *y; - | ^^^^^^^ assignment requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - -error: lifetime may not live long enough - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:22:5 - | -LL | fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -... -LL | a(x, y, z); - | ^^^^^^^^^^ argument requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to `&isize` - = note: mutable references are invariant over their type parameter - = help: see for more information about variance - -error[E0308]: mismatched types - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:30:12 - | -LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other - | - = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut &'s isize, &'t0 mut &'t1 isize, &'t2 mut &'t3 isize)` - found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)` - -error[E0308]: mismatched types - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:30:12 - | -LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other - | - = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut &'s isize, &'t0 mut &'t1 isize, &'t2 mut &'t3 isize)` - found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)` - error[E0308]: mismatched types - --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:30:12 + --> $DIR/region-multiple-lifetime-bounds-on-fns-where-clause.rs:28:56 | LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other + | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut &'s isize, &'t0 mut &'t1 isize, &'t2 mut &'t3 isize)` - found fn pointer `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize)` + found fn item `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize) {a::<'_, '_, '_>}` -error: aborting due to 5 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.rs b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.rs index 8b5c1d47ec61b..da225d842d9b0 100644 --- a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.rs +++ b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.rs @@ -12,7 +12,6 @@ fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //[base]~^ ERROR E0623 - //[nll]~^^ ERROR lifetime may not live long enough *z = *y; //[base]~ ERROR E0623 } @@ -21,7 +20,6 @@ fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) { // related as required. a(x, y, z); //[base]~^ ERROR lifetime mismatch [E0623] - //[nll]~^^ ERROR lifetime may not live long enough } fn d() { @@ -29,8 +27,6 @@ fn d() { // inconstraints: let _: fn(&mut &isize, &mut &isize, &mut &isize) = a; //~^ ERROR E0308 - //[nll]~^^ ERROR mismatched types [E0308] - //[nll]~| ERROR mismatched types [E0308] } fn e() { diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.base.stderr b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.base.stderr index 2182d8f661ff8..4616035870abf 100644 --- a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.base.stderr +++ b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.base.stderr @@ -2,10 +2,17 @@ error[E0308]: mismatched types --> $DIR/regions-fn-subtyping-return-static-fail.rs:52:12 | LL | want_G(baz); - | ^^^ one type is more general than the other + | ------ ^^^ one type is more general than the other + | | + | arguments to this function are incorrect | = note: expected fn pointer `for<'cx> fn(&'cx S) -> &'static S` - found fn pointer `for<'r> fn(&'r S) -> &'r S` + found fn item `for<'r> fn(&'r S) -> &'r S {baz}` +note: function defined here + --> $DIR/regions-fn-subtyping-return-static-fail.rs:24:4 + | +LL | fn want_G(f: G) {} + | ^^^^^^ ---- error: aborting due to previous error diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.nll.stderr b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.nll.stderr index 0bca2cfbefd9f..4616035870abf 100644 --- a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.nll.stderr +++ b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.nll.stderr @@ -1,11 +1,18 @@ error[E0308]: mismatched types - --> $DIR/regions-fn-subtyping-return-static-fail.rs:52:5 + --> $DIR/regions-fn-subtyping-return-static-fail.rs:52:12 | LL | want_G(baz); - | ^^^^^^^^^^^ one type is more general than the other + | ------ ^^^ one type is more general than the other + | | + | arguments to this function are incorrect | = note: expected fn pointer `for<'cx> fn(&'cx S) -> &'static S` - found fn pointer `for<'r> fn(&'r S) -> &'r S` + found fn item `for<'r> fn(&'r S) -> &'r S {baz}` +note: function defined here + --> $DIR/regions-fn-subtyping-return-static-fail.rs:24:4 + | +LL | fn want_G(f: G) {} + | ^^^^^^ ---- error: aborting due to previous error diff --git a/src/test/ui/regions/regions-lifetime-bounds-on-fns.base.stderr b/src/test/ui/regions/regions-lifetime-bounds-on-fns.base.stderr index e57b06aac3927..613e9af90a43f 100644 --- a/src/test/ui/regions/regions-lifetime-bounds-on-fns.base.stderr +++ b/src/test/ui/regions/regions-lifetime-bounds-on-fns.base.stderr @@ -8,7 +8,7 @@ LL | *x = *y; | ^^ ...but data from `y` flows into `x` here error[E0623]: lifetime mismatch - --> $DIR/regions-lifetime-bounds-on-fns.rs:20:7 + --> $DIR/regions-lifetime-bounds-on-fns.rs:19:7 | LL | fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { | --------- --------- these two types are declared with different lifetimes... @@ -17,13 +17,13 @@ LL | a(x, y); | ^ ...but data from `y` flows into `x` here error[E0308]: mismatched types - --> $DIR/regions-lifetime-bounds-on-fns.rs:28:43 + --> $DIR/regions-lifetime-bounds-on-fns.rs:26:43 | LL | let _: fn(&mut &isize, &mut &isize) = a; | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` + found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}` error: aborting due to 3 previous errors diff --git a/src/test/ui/regions/regions-lifetime-bounds-on-fns.nll.stderr b/src/test/ui/regions/regions-lifetime-bounds-on-fns.nll.stderr index 7fe8b4bf57fc1..268a60968b734 100644 --- a/src/test/ui/regions/regions-lifetime-bounds-on-fns.nll.stderr +++ b/src/test/ui/regions/regions-lifetime-bounds-on-fns.nll.stderr @@ -1,50 +1,12 @@ -error: lifetime may not live long enough - --> $DIR/regions-lifetime-bounds-on-fns.rs:12:5 - | -LL | fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | // Illegal now because there is no `'b:'a` declaration. -LL | *x = *y; - | ^^^^^^^ assignment requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - -error: lifetime may not live long enough - --> $DIR/regions-lifetime-bounds-on-fns.rs:20:5 - | -LL | fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -... -LL | a(x, y); - | ^^^^^^^ argument requires that `'b` must outlive `'a` - | - = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to `&isize` - = note: mutable references are invariant over their type parameter - = help: see for more information about variance - -error[E0308]: mismatched types - --> $DIR/regions-lifetime-bounds-on-fns.rs:28:12 - | -LL | let _: fn(&mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other - | - = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` - error[E0308]: mismatched types - --> $DIR/regions-lifetime-bounds-on-fns.rs:28:12 + --> $DIR/regions-lifetime-bounds-on-fns.rs:26:43 | LL | let _: fn(&mut &isize, &mut &isize) = a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other + | ^ one type is more general than the other | = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)` - found fn pointer `for<'r, 's> fn(&'r mut &isize, &'s mut &isize)` + found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}` -error: aborting due to 4 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/regions/regions-lifetime-bounds-on-fns.rs b/src/test/ui/regions/regions-lifetime-bounds-on-fns.rs index 97c08d8ab0e3c..ef5e5cb12ef10 100644 --- a/src/test/ui/regions/regions-lifetime-bounds-on-fns.rs +++ b/src/test/ui/regions/regions-lifetime-bounds-on-fns.rs @@ -11,7 +11,6 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { // Illegal now because there is no `'b:'a` declaration. *x = *y; //[base]~^ ERROR lifetime mismatch [E0623] - //[nll]~^^ ERROR lifetime may not live long enough } fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { @@ -19,7 +18,6 @@ fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) { // related as required. a(x, y); //[base]~^ ERROR lifetime mismatch [E0623] - //[nll]~^^ ERROR lifetime may not live long enough } fn d() { @@ -27,7 +25,6 @@ fn d() { // inconstraints: let _: fn(&mut &isize, &mut &isize) = a; //~^ ERROR mismatched types [E0308] - //[nll]~^^ ERROR mismatched types [E0308] } fn e() {