From 76756ccb3ab1f06a034878d6cb50672f5c8d1331 Mon Sep 17 00:00:00 2001 From: Benjamin Herr Date: Wed, 23 Mar 2022 00:03:13 -0700 Subject: [PATCH 01/29] bootstrap.py: nixos check in /etc/os-release with quotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per https://www.freedesktop.org/software/systemd/man/os-release.html, > Variable assignment values must be enclosed in double or single quotes > if they include spaces, semicolons or other special characters outside > of A–Z, a–z, 0–9. (Assignments that do not include these special > characters may be enclosed in quotes too, but this is optional.) So, past `ID=nixos`, let's also check for `ID='nixos'` and `ID="nixos"`. One of these is necessary between nixos/nixpkgs#162168 and nixos/nixpkgs#164068, but this seems more correct either way. --- src/bootstrap/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 71b8f3c4553bc..0b6bdf474195d 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -678,7 +678,7 @@ def fix_bin_or_dylib(self, fname): # The latter one does not exist on NixOS when using tmpfs as root. try: with open("/etc/os-release", "r") as f: - if not any(line.strip() == "ID=nixos" for line in f): + if not any(l.strip() in ["ID=nixos", "ID='nixos'", 'ID="nixos"'] for l in f): return except FileNotFoundError: return From 064a55952eaa0fddb01aa52740707f3e0d4c7e23 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 29 Mar 2022 16:08:10 -0500 Subject: [PATCH 02/29] Fix `x doc --stage 0 compiler` Eric figured out the fix to this almost 2 years ago, I just didn't read his comment carefully enough at the timme. The issue was that fake rustc and fake rustdoc were inconsistent about when they passed `--sysroot` to the real compiler. Change them to consistently only pass it when `--target` is present. --- src/bootstrap/bin/rustdoc.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index ad3800834b07c..4bba2eb450744 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -15,6 +15,10 @@ fn main() { let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set"); let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"); + // Detect whether or not we're a build script depending on whether --target + // is passed (a bit janky...) + let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str()); + use std::str::FromStr; let verbose = match env::var("RUSTC_VERBOSE") { @@ -26,10 +30,18 @@ fn main() { dylib_path.insert(0, PathBuf::from(libdir.clone())); let mut cmd = Command::new(rustdoc); - cmd.args(&args) - .arg("--sysroot") - .arg(&sysroot) - .env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); + + if target.is_some() { + // The stage0 compiler has a special sysroot distinct from what we + // actually downloaded, so we just always pass the `--sysroot` option, + // unless one is already set. + if !args.iter().any(|arg| arg == "--sysroot") { + cmd.arg("--sysroot").arg(&sysroot); + } + } + + cmd.args(&args); + cmd.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); // Force all crates compiled by this compiler to (a) be unstable and (b) // allow the `rustc_private` feature to link to other unstable crates From bf2c3b0455ba0e7d747f271383ee8ceabd9b6392 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Apr 2022 15:17:55 +0200 Subject: [PATCH 03/29] Fix ICE in rustdoc intra doc links when trying to get traits in scope for a private module --- src/librustdoc/lib.rs | 8 +++++++- src/librustdoc/passes/collect_intra_doc_links/early.rs | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index f59222b780d3e..1d7a790bdb786 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -771,6 +771,7 @@ fn main_options(options: config::Options) -> MainResult { let externs = options.externs.clone(); let render_options = options.render_options.clone(); let scrape_examples_options = options.scrape_examples_options.clone(); + let document_private = options.render_options.document_private; let config = core::create_config(options); interface::create_compiler_and_run(config, |compiler| { @@ -791,7 +792,12 @@ fn main_options(options: config::Options) -> MainResult { let (resolver, resolver_caches) = { let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); let resolver_caches = resolver.borrow_mut().access(|resolver| { - collect_intra_doc_links::early_resolve_intra_doc_links(resolver, krate, externs) + collect_intra_doc_links::early_resolve_intra_doc_links( + resolver, + krate, + externs, + document_private, + ) }); (resolver.clone(), resolver_caches) }; diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index 75e952c5122b8..d712ec8aa6ab7 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -22,6 +22,7 @@ crate fn early_resolve_intra_doc_links( resolver: &mut Resolver<'_>, krate: &ast::Crate, externs: Externs, + document_private_items: bool, ) -> ResolverCaches { let mut loader = IntraLinkCrateLoader { resolver, @@ -30,6 +31,7 @@ crate fn early_resolve_intra_doc_links( traits_in_scope: Default::default(), all_traits: Default::default(), all_trait_impls: Default::default(), + document_private_items, }; // Because of the `crate::` prefix, any doc comment can reference @@ -66,6 +68,7 @@ struct IntraLinkCrateLoader<'r, 'ra> { traits_in_scope: DefIdMap>, all_traits: Vec, all_trait_impls: Vec, + document_private_items: bool, } impl IntraLinkCrateLoader<'_, '_> { @@ -175,7 +178,7 @@ impl IntraLinkCrateLoader<'_, '_> { } for child in self.resolver.module_children_or_reexports(module_id) { - if child.vis == Visibility::Public { + if child.vis == Visibility::Public || self.document_private_items { if let Some(def_id) = child.res.opt_def_id() { self.add_traits_in_parent_scope(def_id); } From 50cc0fa8abd0279608ce3434a5a3fe34dee62a70 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Apr 2022 15:18:28 +0200 Subject: [PATCH 04/29] Add test to ensure rustdoc does not panic on intra doc link pass --- src/test/rustdoc/issue-95633.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/test/rustdoc/issue-95633.rs diff --git a/src/test/rustdoc/issue-95633.rs b/src/test/rustdoc/issue-95633.rs new file mode 100644 index 0000000000000..a71d0a0373187 --- /dev/null +++ b/src/test/rustdoc/issue-95633.rs @@ -0,0 +1,7 @@ +// compile-flags: --document-private-items + +// This ensures that no ICE is triggered when rustdoc is run on this code. + +mod stdlib { + pub (crate) use std::i8; +} From a8877cf73823351cee2a871bd5387628054fabea Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 2 Apr 2022 15:27:14 -0700 Subject: [PATCH 05/29] Handle reporting invariance of fn pointer --- .../src/diagnostics/region_errors.rs | 11 +++++++++++ src/test/ui/nll/issue-95272.rs | 17 +++++++++++++++++ src/test/ui/nll/issue-95272.stderr | 17 +++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/test/ui/nll/issue-95272.rs create mode 100644 src/test/ui/nll/issue-95272.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index e63450a1f58aa..3e7999b43abac 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -358,6 +358,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); (desc, note) } + ty::FnDef(def_id, _) => { + let name = self.infcx.tcx.item_name(*def_id); + let identity_substs = + InternalSubsts::identity_for_item(self.infcx.tcx, *def_id); + let desc = format!("a function pointer to `{name}`"); + let note = format!( + "the function `{name}` is invariant over the parameter `{}`", + identity_substs[param_index as usize] + ); + (desc, note) + } _ => panic!("Unexpected type {:?}", ty), }; diag.note(&format!("requirement occurs because of {desc}",)); diff --git a/src/test/ui/nll/issue-95272.rs b/src/test/ui/nll/issue-95272.rs new file mode 100644 index 0000000000000..5b5308fb8c2ba --- /dev/null +++ b/src/test/ui/nll/issue-95272.rs @@ -0,0 +1,17 @@ +#![feature(nll)] + +use std::cell::Cell; + +fn check<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) +where + 'a: 'b, +{ +} + +fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) { + let f = check; + //~^ ERROR lifetime may not live long enough + f(x, y); +} + +fn main() {} diff --git a/src/test/ui/nll/issue-95272.stderr b/src/test/ui/nll/issue-95272.stderr new file mode 100644 index 0000000000000..41346a4c699c1 --- /dev/null +++ b/src/test/ui/nll/issue-95272.stderr @@ -0,0 +1,17 @@ +error: lifetime may not live long enough + --> $DIR/issue-95272.rs:12:13 + | +LL | fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let f = check; + | ^^^^^ assignment requires that `'a` must outlive `'b` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of a function pointer to `check` + = note: the function `check` is invariant over the parameter `'a` + = help: see for more information about variance + +error: aborting due to previous error + From 2a129d4fa5c8150035ef40689860c29740a9e36d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 2 Apr 2022 15:32:39 -0700 Subject: [PATCH 06/29] Format invariance notes with backticks --- .../src/diagnostics/region_errors.rs | 8 +-- ...ect-fn-ret-invariant.krisskross.nll.stderr | 8 +-- ...project-fn-ret-invariant.oneuse.nll.stderr | 8 +-- ...ject-fn-ret-invariant.transmute.nll.stderr | 4 +- src/test/ui/c-variadic/variadic-ffi-4.stderr | 32 +++++----- ...ubtype.free_inv_x_vs_free_inv_y.nll.stderr | 8 +-- .../match/match-ref-mut-invariance.nll.stderr | 2 +- .../match-ref-mut-let-invariance.nll.stderr | 2 +- ...oximated-shorter-to-static-no-bound.stderr | 4 +- ...mated-shorter-to-static-wrong-bound.stderr | 4 +- .../nll/type-check-pointer-coercions.stderr | 4 +- .../nll/type-check-pointer-comparisons.stderr | 12 ++-- .../ui/nll/where_clauses_in_structs.stderr | 4 +- ...nvariant-static-error-reporting.nll.stderr | 4 +- ...time-bounds-on-fns-where-clause.nll.stderr | 2 +- ...time-bounds-on-fns-where-clause.nll.stderr | 2 +- ...hod-type-parameters-cross-crate.nll.stderr | 4 +- ...hod-type-parameters-trait-bound.nll.stderr | 4 +- ...ns-infer-invariance-due-to-decl.nll.stderr | 4 +- ...-invariance-due-to-mutability-3.nll.stderr | 4 +- ...-invariance-due-to-mutability-4.nll.stderr | 4 +- .../regions-infer-not-param.nll.stderr | 8 +-- .../regions-lifetime-bounds-on-fns.nll.stderr | 2 +- .../regions-trait-object-subtyping.nll.stderr | 4 +- ...nce-invariant-use-contravariant.nll.stderr | 4 +- ...ariance-invariant-use-covariant.nll.stderr | 4 +- .../variance-btree-invariant-types.nll.stderr | 64 +++++++++---------- .../variance-cell-is-invariant.nll.stderr | 4 +- ...variance-use-invariant-struct-1.nll.stderr | 8 +-- 29 files changed, 113 insertions(+), 113 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 3e7999b43abac..1798c525f6d6c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -330,14 +330,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ty::RawPtr(ty_mut) => { assert_eq!(ty_mut.mutbl, rustc_hir::Mutability::Mut); ( - format!("a mutable pointer to {}", ty_mut.ty), + format!("a mutable pointer to `{}`", ty_mut.ty), "mutable pointers are invariant over their type parameter".to_string(), ) } ty::Ref(_, inner_ty, mutbl) => { assert_eq!(*mutbl, rustc_hir::Mutability::Mut); ( - format!("a mutable reference to {}", inner_ty), + format!("a mutable reference to `{}`", inner_ty), "mutable references are invariant over their type parameter" .to_string(), ) @@ -351,10 +351,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let adt_desc = adt.descr(); let desc = format!( - "the type {ty}, which makes the generic argument {generic_arg} invariant" + "the type `{ty}`, which makes the generic argument `{generic_arg}` invariant" ); let note = format!( - "the {adt_desc} {base_ty} is invariant over the parameter {base_generic_arg}" + "the {adt_desc} `{base_ty}` is invariant over the parameter `{base_generic_arg}`" ); (desc, note) } diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.krisskross.nll.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant.krisskross.nll.stderr index 01f800811abbb..55532d6b9b3fa 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.krisskross.nll.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.krisskross.nll.stderr @@ -10,8 +10,8 @@ LL | (a, b) | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of the type Type<'_>, which makes the generic argument '_ invariant - = note: the struct Type<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Type<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: lifetime may not live long enough @@ -26,8 +26,8 @@ LL | (a, b) | ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of the type Type<'_>, which makes the generic argument '_ invariant - = note: the struct Type<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Type<'a>` is invariant over the parameter `'a` = help: see for more information about variance help: `'a` and `'b` must be the same: replace one with the other diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.nll.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.nll.stderr index e925a424c37e1..fd9eb05473af8 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.nll.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.nll.stderr @@ -10,8 +10,8 @@ LL | let a = bar(f, x); | ^^^^^^^^^ argument requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of the type Type<'_>, which makes the generic argument '_ invariant - = note: the struct Type<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Type<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: lifetime may not live long enough @@ -26,8 +26,8 @@ LL | let b = bar(f, y); | ^^^^^^^^^ argument requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of the type Type<'_>, which makes the generic argument '_ invariant - = note: the struct Type<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Type<'a>` is invariant over the parameter `'a` = help: see for more information about variance help: `'a` and `'b` must be the same: replace one with the other diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr index 0457f142e19d5..5a7ead729498d 100644 --- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr +++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.transmute.nll.stderr @@ -7,8 +7,8 @@ LL | fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> { LL | bar(foo, x) | ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` | - = note: requirement occurs because of the type Type<'_>, which makes the generic argument '_ invariant - = note: the struct Type<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Type<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr index ff4da5251a9b2..6f8e53298ace2 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.stderr @@ -8,8 +8,8 @@ LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f LL | ap | ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -22,8 +22,8 @@ LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f LL | ap | ^^ function was supposed to return data with lifetime `'f` but it is returning data with lifetime `'1` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -34,8 +34,8 @@ LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'stati LL | ap | ^^ returning this value requires that `'1` must outlive `'static` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -57,8 +57,8 @@ LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut LL | *ap0 = ap1; | ^^^^ assignment requires that `'1` must outlive `'2` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -71,8 +71,8 @@ LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut LL | *ap0 = ap1; | ^^^^ assignment requires that `'2` must outlive `'1` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -85,7 +85,7 @@ LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` | - = note: requirement occurs because of a mutable reference to VaListImpl<'_> + = note: requirement occurs because of a mutable reference to `VaListImpl<'_>` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -99,7 +99,7 @@ LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1` | - = note: requirement occurs because of a mutable reference to VaListImpl<'_> + = note: requirement occurs because of a mutable reference to `VaListImpl<'_>` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -127,8 +127,8 @@ LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut LL | *ap0 = ap1.clone(); | ^^^^^^^^^^^ argument requires that `'1` must outlive `'2` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: lifetime may not live long enough @@ -141,8 +141,8 @@ LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut LL | *ap0 = ap1.clone(); | ^^^^^^^^^^^ argument requires that `'2` must outlive `'1` | - = note: requirement occurs because of the type VaListImpl<'_>, which makes the generic argument '_ invariant - = note: the struct VaListImpl<'f> is invariant over the parameter 'f + = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant + = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f` = help: see for more information about variance error: aborting due to 11 previous errors diff --git a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.nll.stderr b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.nll.stderr index b4c54d52e5c75..f5db68e8be140 100644 --- a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.nll.stderr +++ b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.nll.stderr @@ -13,8 +13,8 @@ LL | | fn(Inv<'y>)) } | |______________- in this macro invocation | = help: consider adding the following bound: `'x: 'y` - = note: requirement occurs because of the type Inv<'_>, which makes the generic argument '_ invariant - = note: the struct Inv<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Inv<'a>` is invariant over the parameter `'a` = help: see for more information about variance = note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -33,8 +33,8 @@ LL | | fn(Inv<'y>)) } | |______________- in this macro invocation | = help: consider adding the following bound: `'x: 'y` - = note: requirement occurs because of the type Inv<'_>, which makes the generic argument '_ invariant - = note: the struct Inv<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Inv<'a>` is invariant over the parameter `'a` = help: see for more information about variance = note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/match/match-ref-mut-invariance.nll.stderr b/src/test/ui/match/match-ref-mut-invariance.nll.stderr index c8a7876dc54c2..3b7e53cd52724 100644 --- a/src/test/ui/match/match-ref-mut-invariance.nll.stderr +++ b/src/test/ui/match/match-ref-mut-invariance.nll.stderr @@ -9,7 +9,7 @@ LL | match self.0 { ref mut x => x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance diff --git a/src/test/ui/match/match-ref-mut-let-invariance.nll.stderr b/src/test/ui/match/match-ref-mut-let-invariance.nll.stderr index 11ddf1487dd7a..f4d1cea670ba6 100644 --- a/src/test/ui/match/match-ref-mut-let-invariance.nll.stderr +++ b/src/test/ui/match/match-ref-mut-let-invariance.nll.stderr @@ -10,7 +10,7 @@ LL | x | ^ associated function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index cf563072dff60..ec2c220b6b8a0 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -52,8 +52,8 @@ LL | | }); | |______`cell_a` escapes the function body here | argument requires that `'a` must outlive `'static` | - = note: requirement occurs because of the type Cell<&'_#10r u32>, which makes the generic argument &'_#10r u32 invariant - = note: the struct Cell is invariant over the parameter T + = note: requirement occurs because of the type `Cell<&'_#10r u32>`, which makes the generic argument `&'_#10r u32` invariant + = note: the struct `Cell` is invariant over the parameter `T` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 453f6801d7e6b..234212c88767a 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -52,8 +52,8 @@ LL | | }); | |______`cell_a` escapes the function body here | argument requires that `'a` must outlive `'static` | - = note: requirement occurs because of the type Cell<&'_#11r u32>, which makes the generic argument &'_#11r u32 invariant - = note: the struct Cell is invariant over the parameter T + = note: requirement occurs because of the type `Cell<&'_#11r u32>`, which makes the generic argument `&'_#11r u32` invariant + = note: the struct `Cell` is invariant over the parameter `T` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/nll/type-check-pointer-coercions.stderr b/src/test/ui/nll/type-check-pointer-coercions.stderr index b392c2007d398..24b07cabbac56 100644 --- a/src/test/ui/nll/type-check-pointer-coercions.stderr +++ b/src/test/ui/nll/type-check-pointer-coercions.stderr @@ -34,7 +34,7 @@ LL | x | ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable pointer to &i32 + = note: requirement occurs because of a mutable pointer to `&i32` = note: mutable pointers are invariant over their type parameter = help: see for more information about variance @@ -50,7 +50,7 @@ LL | x | ^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable pointer to &i32 + = note: requirement occurs because of a mutable pointer to `&i32` = note: mutable pointers are invariant over their type parameter = help: see for more information about variance diff --git a/src/test/ui/nll/type-check-pointer-comparisons.stderr b/src/test/ui/nll/type-check-pointer-comparisons.stderr index b488af820b86d..8c88b2290395c 100644 --- a/src/test/ui/nll/type-check-pointer-comparisons.stderr +++ b/src/test/ui/nll/type-check-pointer-comparisons.stderr @@ -9,7 +9,7 @@ LL | x == y; | ^ requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -24,7 +24,7 @@ LL | x == y; | ^ requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -41,7 +41,7 @@ LL | x == y; | ^ requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable pointer to &i32 + = note: requirement occurs because of a mutable pointer to `&i32` = note: mutable pointers are invariant over their type parameter = help: see for more information about variance @@ -56,7 +56,7 @@ LL | x == y; | ^ requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable pointer to &i32 + = note: requirement occurs because of a mutable pointer to `&i32` = note: mutable pointers are invariant over their type parameter = help: see for more information about variance @@ -73,7 +73,7 @@ LL | f == g; | ^ requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -88,7 +88,7 @@ LL | f == g; | ^ requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to &i32 + = note: requirement occurs because of a mutable reference to `&i32` = note: mutable references are invariant over their type parameter = help: see for more information about variance diff --git a/src/test/ui/nll/where_clauses_in_structs.stderr b/src/test/ui/nll/where_clauses_in_structs.stderr index 952667d518d58..b88c90e8f5416 100644 --- a/src/test/ui/nll/where_clauses_in_structs.stderr +++ b/src/test/ui/nll/where_clauses_in_structs.stderr @@ -9,8 +9,8 @@ LL | Foo { x, y }; | ^ this usage requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of the type Cell<&u32>, which makes the generic argument &u32 invariant - = note: the struct Cell is invariant over the parameter T + = note: requirement occurs because of the type `Cell<&u32>`, which makes the generic argument `&u32` invariant + = note: the struct `Cell` is invariant over the parameter `T` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr index 376534bf573d2..6e7eb734a50ea 100644 --- a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr +++ b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr @@ -12,8 +12,8 @@ LL | x.unwrap() | `x` escapes the function body here | argument requires that `'a` must outlive `'static` | - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error 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 a64ad46ef462b..233a040491c66 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 @@ -23,7 +23,7 @@ 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: 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 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 ce5e7d0172308..00119743acd78 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 @@ -23,7 +23,7 @@ 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: 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 diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters-cross-crate.nll.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters-cross-crate.nll.stderr index 32f3080ea3714..6193bf02f6d0d 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters-cross-crate.nll.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters-cross-crate.nll.stderr @@ -10,8 +10,8 @@ LL | a.bigger_region(b) | ^^^^^^^^^^^^^^^^^^ argument requires that `'y` must outlive `'x` | = help: consider adding the following bound: `'y: 'x` - = note: requirement occurs because of the type Inv<'_>, which makes the generic argument '_ invariant - = note: the struct Inv<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Inv<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr index 246b6483c21a8..0e0086be9ea8d 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr @@ -10,8 +10,8 @@ LL | f.method(b); | ^^^^^^^^^^^ argument requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of the type Inv<'_>, which makes the generic argument '_ invariant - = note: the struct Inv<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Inv<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-decl.nll.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-decl.nll.stderr index fede5f2d7795f..c8c7808e06c5f 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-decl.nll.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-decl.nll.stderr @@ -6,8 +6,8 @@ LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { LL | b_isize | ^^^^^^^ returning this value requires that `'r` must outlive `'static` | - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.nll.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.nll.stderr index 8f5f366745352..1165011c1f4fc 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.nll.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.nll.stderr @@ -6,8 +6,8 @@ LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { LL | b_isize | ^^^^^^^ returning this value requires that `'r` must outlive `'static` | - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.nll.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.nll.stderr index 8079fb0ef0d7e..f3973a93bad84 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.nll.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.nll.stderr @@ -6,8 +6,8 @@ LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { LL | b_isize | ^^^^^^^ returning this value requires that `'r` must outlive `'static` | - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-infer-not-param.nll.stderr b/src/test/ui/regions/regions-infer-not-param.nll.stderr index 3183aee23d936..f4875e49c3da4 100644 --- a/src/test/ui/regions/regions-infer-not-param.nll.stderr +++ b/src/test/ui/regions/regions-infer-not-param.nll.stderr @@ -17,8 +17,8 @@ LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | lifetime `'a` defined here | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of the type Indirect2<'_>, which makes the generic argument '_ invariant - = note: the struct Indirect2<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Indirect2<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Indirect2<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: lifetime may not live long enough @@ -30,8 +30,8 @@ LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | lifetime `'a` defined here | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of the type Indirect2<'_>, which makes the generic argument '_ invariant - = note: the struct Indirect2<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Indirect2<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Indirect2<'a>` is invariant over the parameter `'a` = help: see for more information about variance help: `'b` and `'a` must be the same: replace one with the other 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 cae692ad2f6fa..ee3dcef1cb5c4 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 @@ -23,7 +23,7 @@ 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: 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 diff --git a/src/test/ui/regions/regions-trait-object-subtyping.nll.stderr b/src/test/ui/regions/regions-trait-object-subtyping.nll.stderr index 26f0fcae638d0..1b3a116d508fa 100644 --- a/src/test/ui/regions/regions-trait-object-subtyping.nll.stderr +++ b/src/test/ui/regions/regions-trait-object-subtyping.nll.stderr @@ -10,7 +10,7 @@ LL | x | ^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` - = note: requirement occurs because of a mutable reference to dyn Dummy + = note: requirement occurs because of a mutable reference to `dyn Dummy` = note: mutable references are invariant over their type parameter = help: see for more information about variance @@ -26,7 +26,7 @@ LL | x | ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` | = help: consider adding the following bound: `'b: 'a` - = note: requirement occurs because of a mutable reference to dyn Dummy + = note: requirement occurs because of a mutable reference to `dyn Dummy` = note: mutable references are invariant over their type parameter = help: see for more information about variance diff --git a/src/test/ui/regions/regions-variance-invariant-use-contravariant.nll.stderr b/src/test/ui/regions/regions-variance-invariant-use-contravariant.nll.stderr index 8e8ca8e47cce8..b35a2cb905dc3 100644 --- a/src/test/ui/regions/regions-variance-invariant-use-contravariant.nll.stderr +++ b/src/test/ui/regions/regions-variance-invariant-use-contravariant.nll.stderr @@ -10,8 +10,8 @@ LL | let _: Invariant<'short> = c; | ^^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long` | = help: consider adding the following bound: `'short: 'long` - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/regions/regions-variance-invariant-use-covariant.nll.stderr b/src/test/ui/regions/regions-variance-invariant-use-covariant.nll.stderr index f9a3d727f7af9..761e78d179e41 100644 --- a/src/test/ui/regions/regions-variance-invariant-use-covariant.nll.stderr +++ b/src/test/ui/regions/regions-variance-invariant-use-covariant.nll.stderr @@ -7,8 +7,8 @@ LL | fn use_<'b>(c: Invariant<'b>) { LL | let _: Invariant<'static> = c; | ^^^^^^^^^^^^^^^^^^ type annotation requires that `'b` must outlive `'static` | - = note: requirement occurs because of the type Invariant<'_>, which makes the generic argument '_ invariant - = note: the struct Invariant<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/variance/variance-btree-invariant-types.nll.stderr b/src/test/ui/variance/variance-btree-invariant-types.nll.stderr index 867d9f8238a96..0d9815cf788a1 100644 --- a/src/test/ui/variance/variance-btree-invariant-types.nll.stderr +++ b/src/test/ui/variance/variance-btree-invariant-types.nll.stderr @@ -6,8 +6,8 @@ LL | fn iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, & LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::IterMut<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::IterMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::IterMut<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::IterMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -18,8 +18,8 @@ LL | fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, ( LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::IterMut<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::IterMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::IterMut<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::IterMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -30,8 +30,8 @@ LL | fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, & LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::IterMut<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::IterMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::IterMut<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::IterMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -42,8 +42,8 @@ LL | fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, ( LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::IterMut<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::IterMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::IterMut<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::IterMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -54,8 +54,8 @@ LL | fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type RangeMut<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct RangeMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `RangeMut<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `RangeMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -66,8 +66,8 @@ LL | fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type RangeMut<'_, (), &()>, which makes the generic argument () invariant - = note: the struct RangeMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `RangeMut<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `RangeMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -78,8 +78,8 @@ LL | fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type RangeMut<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct RangeMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `RangeMut<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `RangeMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -90,8 +90,8 @@ LL | fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type RangeMut<'_, (), &()>, which makes the generic argument () invariant - = note: the struct RangeMut<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `RangeMut<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `RangeMut<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -103,8 +103,8 @@ LL | -> OccupiedEntry<'a, &'new (), ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::OccupiedEntry<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::OccupiedEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::OccupiedEntry<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::OccupiedEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -116,8 +116,8 @@ LL | -> OccupiedEntry<'a, (), &'new ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::OccupiedEntry<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::OccupiedEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::OccupiedEntry<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::OccupiedEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -129,8 +129,8 @@ LL | -> OccupiedEntry<'a, &'static (), ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::OccupiedEntry<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::OccupiedEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::OccupiedEntry<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::OccupiedEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -142,8 +142,8 @@ LL | -> OccupiedEntry<'a, (), &'static ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::OccupiedEntry<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::OccupiedEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::OccupiedEntry<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::OccupiedEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -155,8 +155,8 @@ LL | -> VacantEntry<'a, &'new (), ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::VacantEntry<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::VacantEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::VacantEntry<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::VacantEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -168,8 +168,8 @@ LL | -> VacantEntry<'a, (), &'new ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::VacantEntry<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::VacantEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::VacantEntry<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::VacantEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -181,8 +181,8 @@ LL | -> VacantEntry<'a, &'static (), ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::VacantEntry<'_, &(), ()>, which makes the generic argument &() invariant - = note: the struct std::collections::btree_map::VacantEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::VacantEntry<'_, &(), ()>`, which makes the generic argument `&()` invariant + = note: the struct `std::collections::btree_map::VacantEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: lifetime may not live long enough @@ -194,8 +194,8 @@ LL | -> VacantEntry<'a, (), &'static ()> { LL | v | ^ returning this value requires that `'new` must outlive `'static` | - = note: requirement occurs because of the type std::collections::btree_map::VacantEntry<'_, (), &()>, which makes the generic argument () invariant - = note: the struct std::collections::btree_map::VacantEntry<'a, K, V> is invariant over the parameter K + = note: requirement occurs because of the type `std::collections::btree_map::VacantEntry<'_, (), &()>`, which makes the generic argument `()` invariant + = note: the struct `std::collections::btree_map::VacantEntry<'a, K, V>` is invariant over the parameter `K` = help: see for more information about variance error: aborting due to 16 previous errors diff --git a/src/test/ui/variance/variance-cell-is-invariant.nll.stderr b/src/test/ui/variance/variance-cell-is-invariant.nll.stderr index d6a85680141dc..ab5435d1656d2 100644 --- a/src/test/ui/variance/variance-cell-is-invariant.nll.stderr +++ b/src/test/ui/variance/variance-cell-is-invariant.nll.stderr @@ -10,8 +10,8 @@ LL | let _: Foo<'long> = c; | ^^^^^^^^^^ type annotation requires that `'short` must outlive `'long` | = help: consider adding the following bound: `'short: 'long` - = note: requirement occurs because of the type Foo<'_>, which makes the generic argument '_ invariant - = note: the struct Foo<'a> is invariant over the parameter 'a + = note: requirement occurs because of the type `Foo<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Foo<'a>` is invariant over the parameter `'a` = help: see for more information about variance error: aborting due to previous error diff --git a/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr b/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr index f1df2a88b6bab..600b245c1f7fd 100644 --- a/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr +++ b/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr @@ -10,8 +10,8 @@ LL | v | ^ function was supposed to return data with lifetime `'max` but it is returning data with lifetime `'min` | = help: consider adding the following bound: `'min: 'max` - = note: requirement occurs because of the type SomeStruct<&()>, which makes the generic argument &() invariant - = note: the struct SomeStruct is invariant over the parameter T + = note: requirement occurs because of the type `SomeStruct<&()>`, which makes the generic argument `&()` invariant + = note: the struct `SomeStruct` is invariant over the parameter `T` = help: see for more information about variance error: lifetime may not live long enough @@ -26,8 +26,8 @@ LL | v | ^ function was supposed to return data with lifetime `'max` but it is returning data with lifetime `'min` | = help: consider adding the following bound: `'min: 'max` - = note: requirement occurs because of the type SomeStruct<&()>, which makes the generic argument &() invariant - = note: the struct SomeStruct is invariant over the parameter T + = note: requirement occurs because of the type `SomeStruct<&()>`, which makes the generic argument `&()` invariant + = note: the struct `SomeStruct` is invariant over the parameter `T` = help: see for more information about variance error: aborting due to 2 previous errors From 8c684563a59900d96a4fcadd41e5e92074c13df1 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 23 Mar 2022 07:34:20 +0000 Subject: [PATCH 07/29] errors: introduce `DiagnosticMessage` Introduce a `DiagnosticMessage` type that will enable diagnostic messages to be simple strings or Fluent identifiers. `DiagnosticMessage` is now used in the implementation of the standard `DiagnosticBuilder` APIs. Signed-off-by: David Wood --- compiler/rustc_codegen_ssa/src/back/write.rs | 4 +- .../src/annotate_snippet_emitter_writer.rs | 2 +- compiler/rustc_errors/src/diagnostic.rs | 67 +++++++++++++------ compiler/rustc_errors/src/emitter.rs | 20 +++--- compiler/rustc_errors/src/json.rs | 6 +- compiler/rustc_errors/src/lib.rs | 6 +- compiler/rustc_expand/src/mbe/macro_rules.rs | 9 +-- compiler/rustc_parse/src/parser/item.rs | 3 +- .../src/traits/error_reporting/suggestions.rs | 3 +- .../passes/check_code_block_syntax.rs | 2 +- 10 files changed, 79 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 9417874ffb40b..8aa18b8e37ce2 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1708,13 +1708,13 @@ impl SharedEmitter { impl Emitter for SharedEmitter { fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) { drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { - msg: diag.message(), + msg: diag.message().to_string(), code: diag.code.clone(), lvl: diag.level(), }))); for child in &diag.children { drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic { - msg: child.message(), + msg: child.message().to_string(), code: None, lvl: child.level, }))); diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 5f59eba23f8e9..76c8396cf9179 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -41,7 +41,7 @@ impl Emitter for AnnotateSnippetEmitterWriter { self.emit_messages_default( &diag.level, - diag.message(), + diag.message().to_string(), &diag.code, &primary_span, &children, diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 32c52a6a8a6d9..d31593a132bc8 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -18,6 +18,34 @@ use std::hash::{Hash, Hasher}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub struct SuggestionsDisabled; +/// Abstraction over a message in a diagnostic to support both translatable and non-translatable +/// diagnostic messages. +#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] +pub enum DiagnosticMessage { + /// Non-translatable diagnostic message. + Str(String), + /// Identifier for a Fluent message corresponding to the diagnostic message. + FluentIdentifier(String), +} + +impl DiagnosticMessage { + /// Convert `DiagnosticMessage` to a `&str`. + pub fn as_str(&self) -> &str { + match self { + DiagnosticMessage::Str(msg) => msg, + DiagnosticMessage::FluentIdentifier(..) => unimplemented!(), + } + } + + /// Convert `DiagnosticMessage` to an owned `String`. + pub fn to_string(self) -> String { + match self { + DiagnosticMessage::Str(msg) => msg, + DiagnosticMessage::FluentIdentifier(..) => unimplemented!(), + } + } +} + #[must_use] #[derive(Clone, Debug, Encodable, Decodable)] pub struct Diagnostic { @@ -25,7 +53,7 @@ pub struct Diagnostic { // outside of what methods in this crate themselves allow. crate level: Level, - pub message: Vec<(String, Style)>, + pub message: Vec<(DiagnosticMessage, Style)>, pub code: Option, pub span: MultiSpan, pub children: Vec, @@ -52,7 +80,7 @@ pub enum DiagnosticId { #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct SubDiagnostic { pub level: Level, - pub message: Vec<(String, Style)>, + pub message: Vec<(DiagnosticMessage, Style)>, pub span: MultiSpan, pub render_span: Option, } @@ -112,7 +140,7 @@ impl Diagnostic { pub fn new_with_code(level: Level, code: Option, message: &str) -> Self { Diagnostic { level, - message: vec![(message.to_owned(), Style::NoStyle)], + message: vec![(DiagnosticMessage::Str(message.to_owned()), Style::NoStyle)], code, span: MultiSpan::new(), children: vec![], @@ -465,7 +493,7 @@ impl Diagnostic { .map(|(span, snippet)| SubstitutionPart { snippet, span }) .collect(), }], - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style, applicability, tool_metadata: Default::default(), @@ -493,7 +521,7 @@ impl Diagnostic { .map(|(span, snippet)| SubstitutionPart { snippet, span }) .collect(), }], - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style: SuggestionStyle::CompletelyHidden, applicability, tool_metadata: Default::default(), @@ -548,7 +576,7 @@ impl Diagnostic { substitutions: vec![Substitution { parts: vec![SubstitutionPart { snippet: suggestion, span: sp }], }], - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style, applicability, tool_metadata: Default::default(), @@ -591,7 +619,7 @@ impl Diagnostic { .collect(); self.push_suggestion(CodeSuggestion { substitutions, - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style: SuggestionStyle::ShowCode, applicability, tool_metadata: Default::default(), @@ -616,7 +644,7 @@ impl Diagnostic { .collect(), }) .collect(), - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style: SuggestionStyle::ShowCode, applicability, tool_metadata: Default::default(), @@ -698,7 +726,7 @@ impl Diagnostic { ) { self.push_suggestion(CodeSuggestion { substitutions: vec![], - msg: msg.to_owned(), + msg: DiagnosticMessage::Str(msg.to_owned()), style: SuggestionStyle::CompletelyHidden, applicability, tool_metadata: ToolMetadata::new(tool_metadata), @@ -733,15 +761,15 @@ impl Diagnostic { } pub fn set_primary_message>(&mut self, msg: M) -> &mut Self { - self.message[0] = (msg.into(), Style::NoStyle); + self.message[0] = (DiagnosticMessage::Str(msg.into()), Style::NoStyle); self } - pub fn message(&self) -> String { - self.message.iter().map(|i| i.0.as_str()).collect::() + pub fn message(&self) -> DiagnosticMessage { + DiagnosticMessage::Str(self.message.iter().map(|i| i.0.as_str()).collect::()) } - pub fn styled_message(&self) -> &Vec<(String, Style)> { + pub fn styled_message(&self) -> &Vec<(DiagnosticMessage, Style)> { &self.message } @@ -758,7 +786,7 @@ impl Diagnostic { ) { let sub = SubDiagnostic { level, - message: vec![(message.to_owned(), Style::NoStyle)], + message: vec![(DiagnosticMessage::Str(message.to_owned()), Style::NoStyle)], span, render_span, }; @@ -770,10 +798,11 @@ impl Diagnostic { fn sub_with_highlights( &mut self, level: Level, - message: Vec<(String, Style)>, + mut message: Vec<(String, Style)>, span: MultiSpan, render_span: Option, ) { + let message = message.drain(..).map(|m| (DiagnosticMessage::Str(m.0), m.1)).collect(); let sub = SubDiagnostic { level, message, span, render_span }; self.children.push(sub); } @@ -783,7 +812,7 @@ impl Diagnostic { &self, ) -> ( &Level, - &Vec<(String, Style)>, + &Vec<(DiagnosticMessage, Style)>, &Option, &MultiSpan, &Result, SuggestionsDisabled>, @@ -816,11 +845,11 @@ impl PartialEq for Diagnostic { } impl SubDiagnostic { - pub fn message(&self) -> String { - self.message.iter().map(|i| i.0.as_str()).collect::() + pub fn message(&self) -> DiagnosticMessage { + DiagnosticMessage::Str(self.message.iter().map(|i| i.0.as_str()).collect::()) } - pub fn styled_message(&self) -> &Vec<(String, Style)> { + pub fn styled_message(&self) -> &Vec<(DiagnosticMessage, Style)> { &self.message } } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 93b7201023a49..1f26b002f6a65 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -15,8 +15,8 @@ use rustc_span::{MultiSpan, SourceFile, Span}; use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString}; use crate::styled_buffer::StyledBuffer; use crate::{ - CodeSuggestion, Diagnostic, DiagnosticId, Handler, Level, SubDiagnostic, SubstitutionHighlight, - SuggestionStyle, + CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage, Handler, Level, SubDiagnostic, + SubstitutionHighlight, SuggestionStyle, }; use rustc_lint_defs::pluralize; @@ -236,7 +236,7 @@ pub trait Emitter { // don't display multipart suggestions as labels sugg.substitutions[0].parts.len() == 1 && // don't display long messages as labels - sugg.msg.split_whitespace().count() < 10 && + sugg.msg.as_str().split_whitespace().count() < 10 && // don't display multiline suggestions as labels !sugg.substitutions[0].parts[0].snippet.contains('\n') && ![ @@ -252,12 +252,12 @@ pub trait Emitter { let msg = if substitution.is_empty() || sugg.style.hide_inline() { // This substitution is only removal OR we explicitly don't want to show the // code inline (`hide_inline`). Therefore, we don't show the substitution. - format!("help: {}", sugg.msg) + format!("help: {}", sugg.msg.as_str()) } else { // Show the default suggestion text with the substitution format!( "help: {}{}: `{}`", - sugg.msg, + sugg.msg.as_str(), if self .source_map() .map(|sm| is_case_difference( @@ -333,7 +333,7 @@ pub trait Emitter { children.push(SubDiagnostic { level: Level::Note, - message: vec![(msg, Style::NoStyle)], + message: vec![(DiagnosticMessage::Str(msg), Style::NoStyle)], span: MultiSpan::new(), render_span: None, }); @@ -1176,7 +1176,7 @@ impl EmitterWriter { fn msg_to_buffer( &self, buffer: &mut StyledBuffer, - msg: &[(String, Style)], + msg: &[(DiagnosticMessage, Style)], padding: usize, label: &str, override_style: Option