From 692ae3d9fb55c1f19508e5b3c1aadfdd2cd27431 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 28 Oct 2019 17:07:15 -0400 Subject: [PATCH 01/17] Move has_panic_handler to query --- src/librustc/session/mod.rs | 4 ---- src/librustc/ty/context.rs | 5 +++++ src/librustc_metadata/encoder.rs | 3 +-- src/librustc_typeck/check/mod.rs | 5 ----- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 81f0853201c0..18f0f129d37e 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -156,9 +156,6 @@ pub struct Session { /// Metadata about the allocators for the current crate being compiled. pub has_global_allocator: Once, - /// Metadata about the panic handlers for the current crate being compiled. - pub has_panic_handler: Once, - /// Cap lint level specified by a driver specifically. pub driver_lint_caps: FxHashMap, @@ -1249,7 +1246,6 @@ fn build_session_( print_fuel, jobserver: jobserver::client(), has_global_allocator: Once::new(), - has_panic_handler: Once::new(), driver_lint_caps, trait_methods_not_found: Lock::new(Default::default()), confused_type_with_std_module: Lock::new(Default::default()), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 3d28beefb341..0906d9ebd8e7 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { assert_eq!(cnum, LOCAL_CRATE); attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins) }; + providers.has_panic_handler = |tcx, cnum| { + assert_eq!(cnum, LOCAL_CRATE); + // We want to check if the panic handler was defined in this crate + tcx.lang_items().panic_impl().map_or(false, |did| did.is_local()) + }; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index f2b0cfa53050..de00e9920e68 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> { let attrs = tcx.hir().krate_attrs(); let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator); let has_global_allocator = *tcx.sess.has_global_allocator.get(); - let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false); let root = self.lazy(CrateRoot { name: tcx.crate_name(LOCAL_CRATE), @@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> { panic_strategy: tcx.sess.panic_strategy(), edition: tcx.sess.edition(), has_global_allocator: has_global_allocator, - has_panic_handler: has_panic_handler, + has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE), has_default_lib_allocator: has_default_lib_allocator, plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index), proc_macro_decls_static: if is_proc_macro { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f7132cd868aa..0f53abaaf263 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1267,11 +1267,6 @@ fn check_fn<'a, 'tcx>( if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { - // at this point we don't care if there are duplicate handlers or if the handler has - // the wrong signature as this value we'll be used when writing metadata and that - // only happens if compilation succeeded - fcx.tcx.sess.has_panic_handler.try_set_same(true); - if declared_ret_ty.kind != ty::Never { fcx.tcx.sess.span_err( decl.output.span(), From 6a30ce639f9eeba7d085721d219553635f32c280 Mon Sep 17 00:00:00 2001 From: Dmitry Kadashev Date: Thu, 31 Oct 2019 16:57:29 +0700 Subject: [PATCH 02/17] Add type parameter name to type mismatch error messages Part of #47319. This just adds type parameter name to type mismatch error message, so e.g. the following: ``` expected enum `std::option::Option`, found type parameter ``` becomes ``` expected enum `std::option::Option`, found type parameter `T` ``` --- src/librustc/ty/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 77613b548cfd..4ef6a162c8b6 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -241,7 +241,7 @@ impl<'tcx> ty::TyS<'tcx> { ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), ty::Projection(_) => "associated type".into(), ty::UnnormalizedProjection(_) => "non-normalized associated type".into(), - ty::Param(_) => "type parameter".into(), + ty::Param(p) => format!("type parameter `{}`", p).into(), ty::Opaque(..) => "opaque type".into(), ty::Error => "type error".into(), } From 036f1828041c80842129b28695b60ba31a74403a Mon Sep 17 00:00:00 2001 From: Dmitry Kadashev Date: Thu, 31 Oct 2019 17:20:33 +0700 Subject: [PATCH 03/17] Show type param definitions in type mismatch errors Fixes #47319. Shows the type parameter definition(s) on type mismatch errors so the context is clearer. Pretty much changes the following: ``` LL | bar1(t); | ^ | | | expected enum `std::option::Option`, found type parameter `T` ``` into: ``` LL | fn foo1(t: T) { | - this type parameter LL | bar1(t); | ^ | | | expected enum `std::option::Option`, found type parameter `T` ``` --- src/librustc/infer/error_reporting/mod.rs | 10 +++++++++- src/librustc/ty/error.rs | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index a50cc86862e5..57cb9564f71b 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1190,8 +1190,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } + // In some (most?) cases cause.body_id points to actual body, but in some cases + // it's a actual definition. According to the comments (e.g. in + // librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter + // is relied upon by some other code. This might (or might not) need cleanup. + let body_owner_def_id = match self.tcx.hir().opt_local_def_id(cause.body_id) { + Some(def_id) => def_id, + None => self.tcx.hir().body_owner_def_id(hir::BodyId{hir_id: cause.body_id}), + }; self.check_and_note_conflicting_crates(diag, terr, span); - self.tcx.note_and_explain_type_err(diag, terr, span); + self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id); // It reads better to have the error origin as the final // thing. diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 4ef6a162c8b6..768487fb1626 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -254,6 +254,7 @@ impl<'tcx> TyCtxt<'tcx> { db: &mut DiagnosticBuilder<'_>, err: &TypeError<'tcx>, sp: Span, + body_owner_def_id: DefId, ) { use self::TypeError::*; @@ -288,7 +289,16 @@ impl<'tcx> TyCtxt<'tcx> { ); } }, - (ty::Param(_), ty::Param(_)) => { + (ty::Param(expected), ty::Param(found)) => { + let generics = self.generics_of(body_owner_def_id); + db.span_label( + self.def_span(generics.type_param(expected, self).def_id), + "expected type parameter" + ); + db.span_label( + self.def_span(generics.type_param(found, self).def_id), + "found type parameter" + ); db.note("a type parameter was expected, but a different one was found; \ you might be missing a type parameter or trait bound"); db.note("for more information, visit \ @@ -301,7 +311,12 @@ impl<'tcx> TyCtxt<'tcx> { (ty::Param(_), ty::Projection(_)) | (ty::Projection(_), ty::Param(_)) => { db.note("you might be missing a type parameter or trait bound"); } - (ty::Param(_), _) | (_, ty::Param(_)) => { + (ty::Param(p), _) | (_, ty::Param(p)) => { + let generics = self.generics_of(body_owner_def_id); + db.span_label( + self.def_span(generics.type_param(p, self).def_id), + "this type parameter" + ); db.help("type parameters must be constrained to match other types"); if self.sess.teach(&db.get_code().unwrap()) { db.help("given a type parameter `T` and a method `foo`: From 4e10b75951e5ab7975952826a7591f8eca77e423 Mon Sep 17 00:00:00 2001 From: Dmitry Kadashev Date: Fri, 1 Nov 2019 10:58:37 +0700 Subject: [PATCH 04/17] Update tests Update the tests to reflect changes to how type mismatch errors are reported (two previous commits). --- .../associated-types-issue-20346.stderr | 5 +++- .../reordered-type-param.stderr | 5 +++- .../impl-generic-mismatch-ab.stderr | 6 +++- .../universal-mismatched-type.stderr | 6 ++-- .../universal-two-impl-traits.stderr | 11 +++++-- src/test/ui/issues/issue-13853.stderr | 4 +-- src/test/ui/issues/issue-20225.stderr | 13 ++++++-- src/test/ui/issues/issue-24204.stderr | 2 +- src/test/ui/issues/issue-2951.rs | 2 +- src/test/ui/issues/issue-2951.stderr | 7 ++++- .../ui/mismatched_types/issue-35030.stderr | 7 +++-- .../struct-path-self-type-mismatch.stderr | 15 ++++++++-- src/test/ui/structs/struct-path-self.stderr | 6 ++-- .../enum-variant-generic-args.stderr | 30 +++++++++++++++---- src/test/ui/type/type-parameter-names.rs | 2 +- src/test/ui/type/type-parameter-names.stderr | 7 +++-- .../type/type-params-in-different-spaces-1.rs | 2 +- .../type-params-in-different-spaces-1.stderr | 12 ++++++-- .../type-params-in-different-spaces-3.stderr | 14 ++++++--- 19 files changed, 116 insertions(+), 40 deletions(-) diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index b763b82d540c..f5053f6a1c0c 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -4,8 +4,11 @@ error[E0271]: type mismatch resolving ` as Iterator>::Item == std::op LL | fn is_iterator_of>(_: &I) {} | -------------- ------ required by this bound in `is_iterator_of` ... +LL | fn test_adapter>>(it: I) { + | - this type parameter +... LL | is_iterator_of::, _>(&adapter); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found type parameter `T` | = note: expected type `std::option::Option` found type `T` diff --git a/src/test/ui/compare-method/reordered-type-param.stderr b/src/test/ui/compare-method/reordered-type-param.stderr index 8176e96d6de1..326b84470d62 100644 --- a/src/test/ui/compare-method/reordered-type-param.stderr +++ b/src/test/ui/compare-method/reordered-type-param.stderr @@ -5,7 +5,10 @@ LL | fn b(&self, x: C) -> C; | - type in trait ... LL | fn b(&self, _x: G) -> G { panic!() } - | ^ expected type parameter, found a different type parameter + | - - ^ expected type parameter `F`, found type parameter `G` + | | | + | | found type parameter + | expected type parameter | = note: expected type `fn(&E, F) -> F` found type `fn(&E, G) -> G` diff --git a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr index e4d0a731ebfe..84fc66bb94ce 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -5,7 +5,11 @@ LL | fn foo(&self, a: &A, b: &impl Debug); | -- type in trait ... LL | fn foo(&self, a: &impl Debug, b: &B) { } - | ^^^^^^^^^^^ expected type parameter, found a different type parameter + | - ^---------- + | | || + | | |found type parameter + | | expected type parameter `B`, found type parameter `impl Debug` + | expected type parameter | = note: expected type `fn(&(), &B, &impl Debug)` found type `fn(&(), &impl Debug, &B)` diff --git a/src/test/ui/impl-trait/universal-mismatched-type.stderr b/src/test/ui/impl-trait/universal-mismatched-type.stderr index d92c3f034e5a..ae20a5aa8838 100644 --- a/src/test/ui/impl-trait/universal-mismatched-type.stderr +++ b/src/test/ui/impl-trait/universal-mismatched-type.stderr @@ -2,9 +2,11 @@ error[E0308]: mismatched types --> $DIR/universal-mismatched-type.rs:4:5 | LL | fn foo(x: impl Debug) -> String { - | ------ expected `std::string::String` because of return type + | ---------- ------ expected `std::string::String` because of return type + | | + | this type parameter LL | x - | ^ expected struct `std::string::String`, found type parameter + | ^ expected struct `std::string::String`, found type parameter `impl Debug` | = note: expected type `std::string::String` found type `impl Debug` diff --git a/src/test/ui/impl-trait/universal-two-impl-traits.stderr b/src/test/ui/impl-trait/universal-two-impl-traits.stderr index 98a70f268cf7..f540d319a279 100644 --- a/src/test/ui/impl-trait/universal-two-impl-traits.stderr +++ b/src/test/ui/impl-trait/universal-two-impl-traits.stderr @@ -1,11 +1,16 @@ error[E0308]: mismatched types --> $DIR/universal-two-impl-traits.rs:5:9 | +LL | fn foo(x: impl Debug, y: impl Debug) -> String { + | ---------- ---------- found type parameter + | | + | expected type parameter +LL | let mut a = x; LL | a = y; - | ^ expected type parameter, found a different type parameter + | ^ expected type parameter `impl Debug`, found a different type parameter `impl Debug` | - = note: expected type `impl Debug` (type parameter) - found type `impl Debug` (type parameter) + = note: expected type `impl Debug` (type parameter `impl Debug`) + found type `impl Debug` (type parameter `impl Debug`) = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters diff --git a/src/test/ui/issues/issue-13853.stderr b/src/test/ui/issues/issue-13853.stderr index 3f2d0aa87adc..67721356208c 100644 --- a/src/test/ui/issues/issue-13853.stderr +++ b/src/test/ui/issues/issue-13853.stderr @@ -2,10 +2,10 @@ error[E0308]: mismatched types --> $DIR/issue-13853.rs:14:9 | LL | fn nodes<'a, I: Iterator>(&self) -> I - | - expected `I` because of return type + | - this type parameter - expected `I` because of return type ... LL | self.iter() - | ^^^^^^^^^^^ expected type parameter, found struct `std::slice::Iter` + | ^^^^^^^^^^^ expected type parameter `I`, found struct `std::slice::Iter` | = note: expected type `I` found type `std::slice::Iter<'_, N>` diff --git a/src/test/ui/issues/issue-20225.stderr b/src/test/ui/issues/issue-20225.stderr index 4c464e6d4f68..40093b13edfe 100644 --- a/src/test/ui/issues/issue-20225.stderr +++ b/src/test/ui/issues/issue-20225.stderr @@ -1,8 +1,10 @@ error[E0053]: method `call` has an incompatible type for trait --> $DIR/issue-20225.rs:6:3 | +LL | impl<'a, T> Fn<(&'a T,)> for Foo { + | - this type parameter LL | extern "rust-call" fn call(&self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter `T` | = note: expected type `extern "rust-call" fn(&Foo, (&'a T,))` found type `extern "rust-call" fn(&Foo, (T,))` @@ -12,8 +14,10 @@ LL | extern "rust-call" fn call(&self, (_,): (T,)) {} error[E0053]: method `call_mut` has an incompatible type for trait --> $DIR/issue-20225.rs:12:3 | +LL | impl<'a, T> FnMut<(&'a T,)> for Foo { + | - this type parameter LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter `T` | = note: expected type `extern "rust-call" fn(&mut Foo, (&'a T,))` found type `extern "rust-call" fn(&mut Foo, (T,))` @@ -23,8 +27,11 @@ LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {} error[E0053]: method `call_once` has an incompatible type for trait --> $DIR/issue-20225.rs:20:3 | +LL | impl<'a, T> FnOnce<(&'a T,)> for Foo { + | - this type parameter +... LL | extern "rust-call" fn call_once(self, (_,): (T,)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found type parameter `T` | = note: expected type `extern "rust-call" fn(Foo, (&'a T,))` found type `extern "rust-call" fn(Foo, (T,))` diff --git a/src/test/ui/issues/issue-24204.stderr b/src/test/ui/issues/issue-24204.stderr index 9c53c1b86cea..ace5b5f72fc6 100644 --- a/src/test/ui/issues/issue-24204.stderr +++ b/src/test/ui/issues/issue-24204.stderr @@ -5,7 +5,7 @@ LL | trait Trait: Sized { | ------------------ required by `Trait` ... LL | fn test>(b: i32) -> T where T::A: MultiDispatch { T::new(b) } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found associated type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type | = note: expected type `T` found type `<::A as MultiDispatch>::O` diff --git a/src/test/ui/issues/issue-2951.rs b/src/test/ui/issues/issue-2951.rs index e0ae3ffa6240..cc52dab02459 100644 --- a/src/test/ui/issues/issue-2951.rs +++ b/src/test/ui/issues/issue-2951.rs @@ -4,7 +4,7 @@ fn foo(x: T, y: U) { //~^ ERROR mismatched types //~| expected type `T` //~| found type `U` - //~| expected type parameter, found a different type parameter + //~| expected type parameter `T`, found type parameter `U` } fn main() { diff --git a/src/test/ui/issues/issue-2951.stderr b/src/test/ui/issues/issue-2951.stderr index a6ccc4835fa6..414571752904 100644 --- a/src/test/ui/issues/issue-2951.stderr +++ b/src/test/ui/issues/issue-2951.stderr @@ -1,8 +1,13 @@ error[E0308]: mismatched types --> $DIR/issue-2951.rs:3:10 | +LL | fn foo(x: T, y: U) { + | - - found type parameter + | | + | expected type parameter +LL | let mut xx = x; LL | xx = y; - | ^ expected type parameter, found a different type parameter + | ^ expected type parameter `T`, found type parameter `U` | = note: expected type `T` found type `U` diff --git a/src/test/ui/mismatched_types/issue-35030.stderr b/src/test/ui/mismatched_types/issue-35030.stderr index 4a9afb9d2494..39eca93f88d1 100644 --- a/src/test/ui/mismatched_types/issue-35030.stderr +++ b/src/test/ui/mismatched_types/issue-35030.stderr @@ -1,10 +1,13 @@ error[E0308]: mismatched types --> $DIR/issue-35030.rs:9:14 | +LL | impl Parser for bool { + | ---- this type parameter +LL | fn parse(text: &str) -> Option { LL | Some(true) - | ^^^^ expected type parameter, found bool + | ^^^^ expected type parameter `bool`, found bool | - = note: expected type `bool` (type parameter) + = note: expected type `bool` (type parameter `bool`) found type `bool` (bool) = help: type parameters must be constrained to match other types = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters diff --git a/src/test/ui/structs/struct-path-self-type-mismatch.stderr b/src/test/ui/structs/struct-path-self-type-mismatch.stderr index b905cd1a294c..687d610baf8c 100644 --- a/src/test/ui/structs/struct-path-self-type-mismatch.stderr +++ b/src/test/ui/structs/struct-path-self-type-mismatch.stderr @@ -7,8 +7,13 @@ LL | Self { inner: 1.5f32 }; error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:15:20 | +LL | impl Foo { + | - expected type parameter +LL | fn new(u: U) -> Foo { + | - found type parameter +... LL | inner: u - | ^ expected type parameter, found a different type parameter + | ^ expected type parameter `T`, found type parameter `U` | = note: expected type `T` found type `U` @@ -18,14 +23,18 @@ LL | inner: u error[E0308]: mismatched types --> $DIR/struct-path-self-type-mismatch.rs:13:9 | +LL | impl Foo { + | - found type parameter LL | fn new(u: U) -> Foo { - | ------ expected `Foo` because of return type + | - ------ expected `Foo` because of return type + | | + | expected type parameter LL | / Self { LL | | LL | | inner: u LL | | LL | | } - | |_________^ expected type parameter, found a different type parameter + | |_________^ expected type parameter `U`, found type parameter `T` | = note: expected type `Foo` found type `Foo` diff --git a/src/test/ui/structs/struct-path-self.stderr b/src/test/ui/structs/struct-path-self.stderr index 8c88cacc69e3..693ed35cbc9c 100644 --- a/src/test/ui/structs/struct-path-self.stderr +++ b/src/test/ui/structs/struct-path-self.stderr @@ -1,4 +1,4 @@ -error[E0071]: expected struct, variant or union type, found type parameter +error[E0071]: expected struct, variant or union type, found type parameter `Self` --> $DIR/struct-path-self.rs:5:17 | LL | let s = Self {}; @@ -10,13 +10,13 @@ error[E0109]: type arguments are not allowed for this type LL | let z = Self:: {}; | ^^ type argument not allowed -error[E0071]: expected struct, variant or union type, found type parameter +error[E0071]: expected struct, variant or union type, found type parameter `Self` --> $DIR/struct-path-self.rs:7:17 | LL | let z = Self:: {}; | ^^^^^^^^^^ not a struct -error[E0071]: expected struct, variant or union type, found type parameter +error[E0071]: expected struct, variant or union type, found type parameter `Self` --> $DIR/struct-path-self.rs:11:13 | LL | Self { .. } => {} diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index a0a617fdbbc3..9e44e208f0ee 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -1,8 +1,11 @@ error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:13:25 | +LL | impl Enum { + | - this type parameter +LL | fn ts_variant() { LL | Self::TSVariant(()); - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` @@ -24,8 +27,11 @@ LL | Self::<()>::TSVariant(()); error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:17:31 | +LL | impl Enum { + | - this type parameter +... LL | Self::<()>::TSVariant(()); - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` @@ -47,8 +53,11 @@ LL | Self::<()>::TSVariant::<()>(()); error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:26:29 | +LL | impl Enum { + | - this type parameter +... LL | Self::SVariant { v: () }; - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` @@ -64,8 +73,11 @@ LL | Self::SVariant::<()> { v: () }; error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:28:35 | +LL | impl Enum { + | - this type parameter +... LL | Self::SVariant::<()> { v: () }; - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` @@ -81,8 +93,11 @@ LL | Self::<()>::SVariant { v: () }; error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:31:35 | +LL | impl Enum { + | - this type parameter +... LL | Self::<()>::SVariant { v: () }; - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` @@ -104,8 +119,11 @@ LL | Self::<()>::SVariant::<()> { v: () }; error[E0308]: mismatched types --> $DIR/enum-variant-generic-args.rs:34:41 | +LL | impl Enum { + | - this type parameter +... LL | Self::<()>::SVariant::<()> { v: () }; - | ^^ expected type parameter, found () + | ^^ expected type parameter `T`, found () | = note: expected type `T` found type `()` diff --git a/src/test/ui/type/type-parameter-names.rs b/src/test/ui/type/type-parameter-names.rs index b6b3795d09bf..825766463453 100644 --- a/src/test/ui/type/type-parameter-names.rs +++ b/src/test/ui/type/type-parameter-names.rs @@ -6,7 +6,7 @@ fn foo(x: Foo) -> Bar { //~^ ERROR mismatched types //~| expected type `Bar` //~| found type `Foo` -//~| expected type parameter, found a different type parameter +//~| expected type parameter `Bar`, found type parameter `Foo` } fn main() {} diff --git a/src/test/ui/type/type-parameter-names.stderr b/src/test/ui/type/type-parameter-names.stderr index 3397eec9e050..78d6989a3363 100644 --- a/src/test/ui/type/type-parameter-names.stderr +++ b/src/test/ui/type/type-parameter-names.stderr @@ -2,9 +2,12 @@ error[E0308]: mismatched types --> $DIR/type-parameter-names.rs:5:5 | LL | fn foo(x: Foo) -> Bar { - | --- expected `Bar` because of return type + | --- --- --- expected `Bar` because of return type + | | | + | | expected type parameter + | found type parameter LL | x - | ^ expected type parameter, found a different type parameter + | ^ expected type parameter `Bar`, found type parameter `Foo` | = note: expected type `Bar` found type `Foo` diff --git a/src/test/ui/type/type-params-in-different-spaces-1.rs b/src/test/ui/type/type-params-in-different-spaces-1.rs index 71fb7f380aea..d2dce7006b76 100644 --- a/src/test/ui/type/type-params-in-different-spaces-1.rs +++ b/src/test/ui/type/type-params-in-different-spaces-1.rs @@ -5,7 +5,7 @@ trait BrokenAdd: Copy + Add { *self + rhs //~ ERROR mismatched types //~| expected type `Self` //~| found type `T` - //~| expected type parameter, found a different type parameter + //~| expected type parameter `Self`, found type parameter `T` } } diff --git a/src/test/ui/type/type-params-in-different-spaces-1.stderr b/src/test/ui/type/type-params-in-different-spaces-1.stderr index a10bf4e0b778..d2c6b7304ff3 100644 --- a/src/test/ui/type/type-params-in-different-spaces-1.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-1.stderr @@ -1,8 +1,16 @@ error[E0308]: mismatched types --> $DIR/type-params-in-different-spaces-1.rs:5:17 | -LL | *self + rhs - | ^^^ expected type parameter, found a different type parameter +LL | / trait BrokenAdd: Copy + Add { +LL | | fn broken_add(&self, rhs: T) -> Self { + | | - found type parameter +LL | | *self + rhs + | | ^^^ expected type parameter `Self`, found type parameter `T` +LL | | +... | +LL | | } +LL | | } + | |_- expected type parameter | = note: expected type `Self` found type `T` diff --git a/src/test/ui/type/type-params-in-different-spaces-3.stderr b/src/test/ui/type/type-params-in-different-spaces-3.stderr index 9f0fa5a0ea1f..ec5d6372792b 100644 --- a/src/test/ui/type/type-params-in-different-spaces-3.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-3.stderr @@ -1,10 +1,16 @@ error[E0308]: mismatched types --> $DIR/type-params-in-different-spaces-3.rs:3:9 | -LL | fn test(u: X) -> Self { - | ---- expected `Self` because of return type -LL | u - | ^ expected type parameter, found a different type parameter +LL | / trait Tr : Sized { +LL | | fn test(u: X) -> Self { + | | - ---- expected `Self` because of return type + | | | + | | found type parameter +LL | | u + | | ^ expected type parameter `Self`, found type parameter `X` +LL | | } +LL | | } + | |_- expected type parameter | = note: expected type `Self` found type `X` From 774e60b0c16d234d247978b92db27869d6ab45fa Mon Sep 17 00:00:00 2001 From: Dmitry Kadashev Date: Sat, 2 Nov 2019 14:51:10 +0700 Subject: [PATCH 05/17] Prettify mismatched types error message in a special case Type parameters are referenced in the error message after the previous few commits (using span label). But when the main error message already references the very same type parameter it becomes clumsy. Do not show the additional label in this case as per code review comment by @estebank. Also this contains a small style fix. --- src/librustc/infer/error_reporting/mod.rs | 8 +++---- src/librustc/ty/error.rs | 24 +++++++++---------- .../impl-generic-mismatch-ab.stderr | 6 ++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 57cb9564f71b..3c4db5e0e259 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1194,10 +1194,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // it's a actual definition. According to the comments (e.g. in // librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter // is relied upon by some other code. This might (or might not) need cleanup. - let body_owner_def_id = match self.tcx.hir().opt_local_def_id(cause.body_id) { - Some(def_id) => def_id, - None => self.tcx.hir().body_owner_def_id(hir::BodyId{hir_id: cause.body_id}), - }; + let body_owner_def_id = self.tcx.hir().opt_local_def_id(cause.body_id) + .unwrap_or_else(|| { + self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id }) + }); self.check_and_note_conflicting_crates(diag, terr, span); self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id); diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 768487fb1626..0639a70ed0c4 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -291,14 +291,14 @@ impl<'tcx> TyCtxt<'tcx> { }, (ty::Param(expected), ty::Param(found)) => { let generics = self.generics_of(body_owner_def_id); - db.span_label( - self.def_span(generics.type_param(expected, self).def_id), - "expected type parameter" - ); - db.span_label( - self.def_span(generics.type_param(found, self).def_id), - "found type parameter" - ); + let e_span = self.def_span(generics.type_param(expected, self).def_id); + if !sp.contains(e_span) { + db.span_label(e_span, "expected type parameter"); + } + let f_span = self.def_span(generics.type_param(found, self).def_id); + if !sp.contains(f_span) { + db.span_label(f_span, "found type parameter"); + } db.note("a type parameter was expected, but a different one was found; \ you might be missing a type parameter or trait bound"); db.note("for more information, visit \ @@ -313,10 +313,10 @@ impl<'tcx> TyCtxt<'tcx> { } (ty::Param(p), _) | (_, ty::Param(p)) => { let generics = self.generics_of(body_owner_def_id); - db.span_label( - self.def_span(generics.type_param(p, self).def_id), - "this type parameter" - ); + let p_span = self.def_span(generics.type_param(p, self).def_id); + if !sp.contains(p_span) { + db.span_label(p_span, "this type parameter"); + } db.help("type parameters must be constrained to match other types"); if self.sess.teach(&db.get_code().unwrap()) { db.help("given a type parameter `T` and a method `foo`: diff --git a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr index 84fc66bb94ce..7cb4677a2b19 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -5,10 +5,8 @@ LL | fn foo(&self, a: &A, b: &impl Debug); | -- type in trait ... LL | fn foo(&self, a: &impl Debug, b: &B) { } - | - ^---------- - | | || - | | |found type parameter - | | expected type parameter `B`, found type parameter `impl Debug` + | - ^^^^^^^^^^^ expected type parameter `B`, found type parameter `impl Debug` + | | | expected type parameter | = note: expected type `fn(&(), &B, &impl Debug)` From 90f891d8ae9073623769fac18f00c4f1031fcb59 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 3 Nov 2019 14:58:01 +0300 Subject: [PATCH 06/17] syntax: Avoid span arithmetics for delimiter tokens --- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/tokenstream.rs | 20 ++++------------ src/libsyntax_expand/mbe.rs | 24 ++++++------------- src/libsyntax_expand/mbe/macro_rules.rs | 6 ++--- .../ui/imports/import-prefix-macro-1.stderr | 2 +- src/test/ui/issues/issue-39848.stderr | 2 +- src/test/ui/parser/issue-62973.stderr | 4 ++-- src/test/ui/parser/issue-63135.stderr | 8 +++---- .../parser/macro/macro-doc-comments-2.stderr | 2 +- src/test/ui/parser/missing_right_paren.rs | 3 +++ src/test/ui/parser/missing_right_paren.stderr | 17 +++++++++++++ 11 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 src/test/ui/parser/missing_right_paren.rs create mode 100644 src/test/ui/parser/missing_right_paren.stderr diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6ead1ce811d4..bce36d259ac8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -210,12 +210,12 @@ impl TokenCursor { loop { let tree = if !self.frame.open_delim { self.frame.open_delim = true; - TokenTree::open_tt(self.frame.span.open, self.frame.delim) + TokenTree::open_tt(self.frame.span, self.frame.delim) } else if let Some(tree) = self.frame.tree_cursor.next() { tree } else if !self.frame.close_delim { self.frame.close_delim = true; - TokenTree::close_tt(self.frame.span.close, self.frame.delim) + TokenTree::close_tt(self.frame.span, self.frame.delim) } else if let Some(frame) = self.stack.pop() { self.frame = frame; continue diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 0559f224f1f4..7e0582797c7a 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -15,7 +15,7 @@ use crate::parse::token::{self, DelimToken, Token, TokenKind}; -use syntax_pos::{BytePos, Span, DUMMY_SP}; +use syntax_pos::{Span, DUMMY_SP}; #[cfg(target_arch = "x86_64")] use rustc_data_structures::static_assert_size; use rustc_data_structures::sync::Lrc; @@ -110,23 +110,13 @@ impl TokenTree { } /// Returns the opening delimiter as a token tree. - pub fn open_tt(span: Span, delim: DelimToken) -> TokenTree { - let open_span = if span.is_dummy() { - span - } else { - span.with_hi(span.lo() + BytePos(delim.len() as u32)) - }; - TokenTree::token(token::OpenDelim(delim), open_span) + pub fn open_tt(span: DelimSpan, delim: DelimToken) -> TokenTree { + TokenTree::token(token::OpenDelim(delim), span.open) } /// Returns the closing delimiter as a token tree. - pub fn close_tt(span: Span, delim: DelimToken) -> TokenTree { - let close_span = if span.is_dummy() { - span - } else { - span.with_lo(span.hi() - BytePos(delim.len() as u32)) - }; - TokenTree::token(token::CloseDelim(delim), close_span) + pub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree { + TokenTree::token(token::CloseDelim(delim), span.close) } } diff --git a/src/libsyntax_expand/mbe.rs b/src/libsyntax_expand/mbe.rs index d0f790638efa..06e0cde3ad88 100644 --- a/src/libsyntax_expand/mbe.rs +++ b/src/libsyntax_expand/mbe.rs @@ -13,7 +13,7 @@ use syntax::ast; use syntax::parse::token::{self, Token, TokenKind}; use syntax::tokenstream::{DelimSpan}; -use syntax_pos::{BytePos, Span}; +use syntax_pos::Span; use rustc_data_structures::sync::Lrc; @@ -27,23 +27,13 @@ struct Delimited { impl Delimited { /// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter. - fn open_tt(&self, span: Span) -> TokenTree { - let open_span = if span.is_dummy() { - span - } else { - span.with_hi(span.lo() + BytePos(self.delim.len() as u32)) - }; - TokenTree::token(token::OpenDelim(self.delim), open_span) + fn open_tt(&self, span: DelimSpan) -> TokenTree { + TokenTree::token(token::OpenDelim(self.delim), span.open) } /// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter. - fn close_tt(&self, span: Span) -> TokenTree { - let close_span = if span.is_dummy() { - span - } else { - span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) - }; - TokenTree::token(token::CloseDelim(self.delim), close_span) + fn close_tt(&self, span: DelimSpan) -> TokenTree { + TokenTree::token(token::CloseDelim(self.delim), span.close) } } @@ -138,10 +128,10 @@ impl TokenTree { } (&TokenTree::Delimited(span, ref delimed), _) => { if index == 0 { - return delimed.open_tt(span.open); + return delimed.open_tt(span); } if index == delimed.tts.len() + 1 { - return delimed.close_tt(span.close); + return delimed.close_tt(span); } delimed.tts[index - 1].clone() } diff --git a/src/libsyntax_expand/mbe/macro_rules.rs b/src/libsyntax_expand/mbe/macro_rules.rs index 9a4130b2d8d0..bfdc4c52b5a5 100644 --- a/src/libsyntax_expand/mbe/macro_rules.rs +++ b/src/libsyntax_expand/mbe/macro_rules.rs @@ -566,7 +566,7 @@ impl FirstSets { } TokenTree::Delimited(span, ref delimited) => { build_recur(sets, &delimited.tts[..]); - first.replace_with(delimited.open_tt(span.open)); + first.replace_with(delimited.open_tt(span)); } TokenTree::Sequence(sp, ref seq_rep) => { let subfirst = build_recur(sets, &seq_rep.tts[..]); @@ -628,7 +628,7 @@ impl FirstSets { return first; } TokenTree::Delimited(span, ref delimited) => { - first.add_one(delimited.open_tt(span.open)); + first.add_one(delimited.open_tt(span)); return first; } TokenTree::Sequence(sp, ref seq_rep) => { @@ -826,7 +826,7 @@ fn check_matcher_core( } } TokenTree::Delimited(span, ref d) => { - let my_suffix = TokenSet::singleton(d.close_tt(span.close)); + let my_suffix = TokenSet::singleton(d.close_tt(span)); check_matcher_core(sess, features, attrs, first_sets, &d.tts, &my_suffix); // don't track non NT tokens last.replace_with_irrelevant(); diff --git a/src/test/ui/imports/import-prefix-macro-1.stderr b/src/test/ui/imports/import-prefix-macro-1.stderr index 577f12824716..862a31b44653 100644 --- a/src/test/ui/imports/import-prefix-macro-1.stderr +++ b/src/test/ui/imports/import-prefix-macro-1.stderr @@ -2,7 +2,7 @@ error: expected one of `::`, `;`, or `as`, found `{` --> $DIR/import-prefix-macro-1.rs:11:27 | LL | ($p: path) => (use $p {S, Z}); - | ^ expected one of `::`, `;`, or `as` here + | ^^^^^^ expected one of `::`, `;`, or `as` here ... LL | import! { a::b::c } | ------------------- in this macro invocation diff --git a/src/test/ui/issues/issue-39848.stderr b/src/test/ui/issues/issue-39848.stderr index fa87967432df..47aa8e17a304 100644 --- a/src/test/ui/issues/issue-39848.stderr +++ b/src/test/ui/issues/issue-39848.stderr @@ -2,7 +2,7 @@ error: expected `{`, found `foo` --> $DIR/issue-39848.rs:8:19 | LL | if $tgt.has_$field() {} - | -- - help: try placing this code inside a block: `{ ) }` + | -- -- help: try placing this code inside a block: `{ () }` | | | this `if` statement has a condition, but no block ... diff --git a/src/test/ui/parser/issue-62973.stderr b/src/test/ui/parser/issue-62973.stderr index e73776dc7b46..d22d78b72b9a 100644 --- a/src/test/ui/parser/issue-62973.stderr +++ b/src/test/ui/parser/issue-62973.stderr @@ -34,13 +34,13 @@ LL | ) | error: expected one of `.`, `?`, `{`, or an operator, found `}` - --> $DIR/issue-62973.rs:8:1 + --> $DIR/issue-62973.rs:8:2 | LL | fn p() { match s { v, E { [) {) } | ----- while parsing this match expression LL | LL | - | ^ expected one of `.`, `?`, `{`, or an operator here + | ^ expected one of `.`, `?`, `{`, or an operator here error: incorrect close delimiter: `)` --> $DIR/issue-62973.rs:6:28 diff --git a/src/test/ui/parser/issue-63135.stderr b/src/test/ui/parser/issue-63135.stderr index a077ad454a9d..8e8087978a36 100644 --- a/src/test/ui/parser/issue-63135.stderr +++ b/src/test/ui/parser/issue-63135.stderr @@ -23,16 +23,16 @@ LL | fn i(n{...,f # | `..` must be at the end and cannot have a trailing comma error: expected `[`, found `}` - --> $DIR/issue-63135.rs:3:15 + --> $DIR/issue-63135.rs:3:16 | LL | fn i(n{...,f # - | ^ expected `[` + | ^ expected `[` error: expected one of `:` or `|`, found `)` - --> $DIR/issue-63135.rs:3:15 + --> $DIR/issue-63135.rs:3:16 | LL | fn i(n{...,f # - | ^ expected one of `:` or `|` here + | ^ expected one of `:` or `|` here error: aborting due to 5 previous errors diff --git a/src/test/ui/parser/macro/macro-doc-comments-2.stderr b/src/test/ui/parser/macro/macro-doc-comments-2.stderr index 6abe95192bef..023d1a3e039f 100644 --- a/src/test/ui/parser/macro/macro-doc-comments-2.stderr +++ b/src/test/ui/parser/macro/macro-doc-comments-2.stderr @@ -5,7 +5,7 @@ LL | macro_rules! inner { | ------------------ when calling this macro ... LL | /// Outer - | ^ no rules expected this token in macro call + | ^^^^^^^^^ no rules expected this token in macro call error: aborting due to previous error diff --git a/src/test/ui/parser/missing_right_paren.rs b/src/test/ui/parser/missing_right_paren.rs new file mode 100644 index 000000000000..4f7c5eea1d18 --- /dev/null +++ b/src/test/ui/parser/missing_right_paren.rs @@ -0,0 +1,3 @@ +// ignore-tidy-trailing-newlines +// error-pattern: aborting due to 2 previous errors +fn main((ؼ \ No newline at end of file diff --git a/src/test/ui/parser/missing_right_paren.stderr b/src/test/ui/parser/missing_right_paren.stderr new file mode 100644 index 000000000000..fc75b031e76a --- /dev/null +++ b/src/test/ui/parser/missing_right_paren.stderr @@ -0,0 +1,17 @@ +error: this file contains an un-closed delimiter + --> $DIR/missing_right_paren.rs:3:11 + | +LL | fn main((ؼ + | -- ^ + | || + | |un-closed delimiter + | un-closed delimiter + +error: expected one of `:` or `|`, found `)` + --> $DIR/missing_right_paren.rs:3:11 + | +LL | fn main((ؼ + | ^ expected one of `:` or `|` here + +error: aborting due to 2 previous errors + From d06a4ded13b948a6a5b546514ccc7009097f145a Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Sun, 3 Nov 2019 12:04:01 -0500 Subject: [PATCH 07/17] use silent emitter for rustdoc highlighting pass --- src/librustc_errors/emitter.rs | 8 +++ src/librustc_interface/interface.rs | 14 +---- src/librustdoc/html/highlight.rs | 4 +- src/libsyntax/sess.rs | 8 ++- src/test/rustdoc-ui/invalid-syntax.stderr | 64 ----------------------- 5 files changed, 19 insertions(+), 79 deletions(-) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index b153f0f0e82b..5f74df13fae2 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -424,6 +424,14 @@ impl Emitter for EmitterWriter { } } +/// An emitter that does nothing when emitting a diagnostic. +pub struct SilentEmitter; + +impl Emitter for SilentEmitter { + fn source_map(&self) -> Option<&Lrc> { None } + fn emit_diagnostic(&mut self, _: &Diagnostic) {} +} + /// maximum number of lines we will print for each error; arbitrary. pub const MAX_HIGHLIGHT_LINES: usize = 6; /// maximum number of suggestions to be shown diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index e014e4ed0fdc..4e4d6d982fbc 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -17,10 +17,9 @@ use std::sync::{Arc, Mutex}; use syntax::{self, parse}; use syntax::ast::{self, MetaItemKind}; use syntax::parse::token; -use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap}; +use syntax::source_map::{FileName, FileLoader, SourceMap}; use syntax::sess::ParseSess; use syntax_pos::edition; -use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn}; pub type Result = result::Result; @@ -63,18 +62,9 @@ impl Compiler { /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`. pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option)> { - struct NullEmitter; - impl Emitter for NullEmitter { - fn emit_diagnostic(&mut self, _: &Diagnostic) {} - fn source_map(&self) -> Option<&Lrc> { None } - } - syntax::with_default_globals(move || { let cfg = cfgspecs.into_iter().map(|s| { - - let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let handler = Handler::with_emitter(false, None, Box::new(NullEmitter)); - let sess = ParseSess::with_span_handler(handler, cm); + let sess = ParseSess::with_silent_emitter(); let filename = FileName::cfg_spec_source_code(&s); let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string()); diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 30c9453a643d..88ba13f2796a 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -11,7 +11,7 @@ use std::fmt::Display; use std::io; use std::io::prelude::*; -use syntax::source_map::{SourceMap, FilePathMapping}; +use syntax::source_map::SourceMap; use syntax::parse::lexer; use syntax::parse::token::{self, Token}; use syntax::sess::ParseSess; @@ -33,7 +33,7 @@ pub fn render_with_highlighting( class, tooltip).unwrap(); } - let sess = ParseSess::new(FilePathMapping::empty()); + let sess = ParseSess::with_silent_emitter(); let fm = sess.source_map().new_source_file( FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned(), diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 28a0868d5dd1..2251c3961db2 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -6,7 +6,7 @@ use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId}; use crate::source_map::{SourceMap, FilePathMapping}; use crate::feature_gate::UnstableFeatures; -use errors::{Applicability, Handler, ColorConfig, DiagnosticBuilder}; +use errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock, Once}; use syntax_pos::{Symbol, Span, MultiSpan}; @@ -104,6 +104,12 @@ impl ParseSess { } } + pub fn with_silent_emitter() -> Self { + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); + let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter)); + ParseSess::with_span_handler(handler, cm) + } + #[inline] pub fn source_map(&self) -> &SourceMap { &self.source_map diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr index 8ec4338e13f9..84c10028fd1f 100644 --- a/src/test/rustdoc-ui/invalid-syntax.stderr +++ b/src/test/rustdoc-ui/invalid-syntax.stderr @@ -222,67 +222,3 @@ warning: could not parse code block as Rust code LL | /// \____/ | ^^^^^^ -error: unknown start of token: \ - --> :1:1 - | -1 | \____/ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: ` - --> :1:1 - | -1 | ``` - | ^ - | -help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not - | -1 | '`` - | ^ - -error: unknown start of token: \ - --> :2:1 - | -2 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: ` - --> :3:30 - | -3 | | ^^^^^^ did you mean `baz::foobar`? - | ^ - | -help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not - | -3 | | ^^^^^^ did you mean 'baz::foobar`? - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ - | ^ - From b4dde363446e29005331b9ac295d07d12c89d458 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 4 Nov 2019 12:28:13 +0100 Subject: [PATCH 08/17] let caller of check_ptr_access_align control the error message --- src/librustc_mir/interpret/memory.rs | 10 ++++++---- src/librustc_mir/interpret/validity.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index d113ee33162d..47b918248330 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { align: Align, ) -> InterpResult<'tcx, Option>> { let align = if M::CHECK_ALIGN { Some(align) } else { None }; - self.check_ptr_access_align(sptr, size, align) + self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest) } /// Like `check_ptr_access`, but *definitely* checks alignment when `align` - /// is `Some` (overriding `M::CHECK_ALIGN`). - pub(super) fn check_ptr_access_align( + /// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control + /// the error message for the out-of-bounds case. + pub fn check_ptr_access_align( &self, sptr: Scalar, size: Size, align: Option, + msg: CheckInAllocMsg, ) -> InterpResult<'tcx, Option>> { fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> { if offset % align.bytes() == 0 { @@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // It is sufficient to check this for the end pointer. The addition // checks for overflow. let end_ptr = ptr.offset(size, self)?; - end_ptr.check_inbounds_alloc(allocation_size, CheckInAllocMsg::MemoryAccessTest)?; + end_ptr.check_inbounds_alloc(allocation_size, msg)?; // Test align. Check this last; if both bounds and alignment are violated // we want the error to be about the bounds. if let Some(align) = align { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 3444fb60f333..82b8b28d72b7 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet; use std::hash::Hash; use super::{ - GlobalAlloc, InterpResult, + GlobalAlloc, InterpResult, CheckInAllocMsg, Scalar, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy, }; @@ -424,7 +424,12 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> // alignment should take attributes into account). .unwrap_or_else(|| (layout.size, layout.align.abi)); let ptr: Option<_> = match - self.ecx.memory.check_ptr_access_align(ptr, size, Some(align)) + self.ecx.memory.check_ptr_access_align( + ptr, + size, + Some(align), + CheckInAllocMsg::InboundsTest, + ) { Ok(ptr) => ptr, Err(err) => { From 3bbfc7320ba0f23541f94a84cf5281a210a546cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 4 Nov 2019 16:19:55 -0800 Subject: [PATCH 09/17] Detect `::` -> `:` typo when involving turbofish --- src/libsyntax/parse/parser/diagnostics.rs | 3 ++- src/libsyntax/parse/parser/stmt.rs | 1 + .../type-ascription-instead-of-path-2.rs | 5 +++++ .../type-ascription-instead-of-path-2.stderr | 13 +++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/type-ascription-instead-of-path-2.rs create mode 100644 src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr diff --git a/src/libsyntax/parse/parser/diagnostics.rs b/src/libsyntax/parse/parser/diagnostics.rs index ab2b4519cb72..ad479e6278b7 100644 --- a/src/libsyntax/parse/parser/diagnostics.rs +++ b/src/libsyntax/parse/parser/diagnostics.rs @@ -354,7 +354,7 @@ impl<'a> Parser<'a> { } pub fn maybe_annotate_with_ascription( - &self, + &mut self, err: &mut DiagnosticBuilder<'_>, maybe_expected_semicolon: bool, ) { @@ -395,6 +395,7 @@ impl<'a> Parser<'a> { err.note("for more information, see \ https://github.com/rust-lang/rust/issues/23416"); } + self.last_type_ascription = None; } } diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index 4f51fefe66fb..12c530f3cbba 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -397,6 +397,7 @@ impl<'a> Parser<'a> { } let stmt = match self.parse_full_stmt(false) { Err(mut err) => { + self.maybe_annotate_with_ascription(&mut err, false); err.emit(); self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); Some(Stmt { diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs b/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs new file mode 100644 index 000000000000..220fd1eebda4 --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs @@ -0,0 +1,5 @@ +fn main() -> Result<(), ()> { + vec![Ok(2)].into_iter().collect:,_>>()?; + //~^ ERROR expected `::`, found `(` + Ok(()) +} diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr b/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr new file mode 100644 index 000000000000..191c4f631c45 --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr @@ -0,0 +1,13 @@ +error: expected `::`, found `(` + --> $DIR/type-ascription-instead-of-path-2.rs:2:55 + | +LL | vec![Ok(2)].into_iter().collect:,_>>()?; + | - ^ expected `::` + | | + | tried to parse a type due to this type ascription + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: aborting due to previous error + From f28126ee1bebc4b4216f9ffb8f375e59983da65d Mon Sep 17 00:00:00 2001 From: Youngsuk Kim Date: Tue, 5 Nov 2019 00:35:18 -0500 Subject: [PATCH 10/17] Fix typo in explanation of `E0080` Handling issue #66105 in Rust repo. `evaluate an constant expression` to `evaluate a constant expression` --- src/librustc/error_codes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index 3e35add9616b..f5ff92e69bc7 100644 --- a/src/librustc/error_codes.rs +++ b/src/librustc/error_codes.rs @@ -335,7 +335,7 @@ This works because `Box` is a pointer, so its size is well-known. "##, E0080: r##" -This error indicates that the compiler was unable to sensibly evaluate an +This error indicates that the compiler was unable to sensibly evaluate a constant expression that had to be evaluated. Attempting to divide by 0 or causing integer overflow are two ways to induce this error. For example: From 7d7fbcb3015521412ab17a814680cd1d9bb6cde9 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 28 Oct 2019 12:40:12 +0100 Subject: [PATCH 11/17] Remove `PartialEq` and `Eq` from the `SpecialDerives`. --- src/librustc/hir/lowering/item.rs | 9 +-------- src/librustc_resolve/lib.rs | 2 -- src/libsyntax/expand/mod.rs | 2 -- src/libsyntax_ext/deriving/cmp/eq.rs | 3 --- src/libsyntax_ext/deriving/cmp/partial_eq.rs | 3 --- 5 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 9da87090c79b..f1b999cdd6f0 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -18,7 +18,6 @@ use smallvec::SmallVec; use syntax::attr; use syntax::ast::*; use syntax::visit::{self, Visitor}; -use syntax::expand::SpecialDerives; use syntax::source_map::{respan, DesugaringKind, Spanned}; use syntax::symbol::{kw, sym}; use syntax_pos::Span; @@ -227,13 +226,7 @@ impl LoweringContext<'_> { pub fn lower_item(&mut self, i: &Item) -> Option { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); - let mut attrs = self.lower_attrs_extendable(&i.attrs); - if self.resolver.has_derives(i.id, SpecialDerives::PARTIAL_EQ | SpecialDerives::EQ) { - // Add `#[structural_match]` if the item derived both `PartialEq` and `Eq`. - let ident = Ident::new(sym::structural_match, i.span); - attrs.push(attr::mk_attr_outer(attr::mk_word_item(ident))); - } - let attrs = attrs.into(); + let attrs = self.lower_attrs(&i.attrs); if let ItemKind::MacroDef(ref def) = i.kind { if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b45eb356bdbd..ca4505445582 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -937,8 +937,6 @@ pub struct Resolver<'a> { /// Some built-in derives mark items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. - /// FIXME: Find a way for `PartialEq` and `Eq` to emulate `#[structural_match]` - /// by marking the produced impls rather than the original items. special_derives: FxHashMap, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. diff --git a/src/libsyntax/expand/mod.rs b/src/libsyntax/expand/mod.rs index 038f60287bef..357295081970 100644 --- a/src/libsyntax/expand/mod.rs +++ b/src/libsyntax/expand/mod.rs @@ -9,8 +9,6 @@ bitflags::bitflags! { /// Built-in derives that need some extra tracking beyond the usual macro functionality. #[derive(Default)] pub struct SpecialDerives: u8 { - const PARTIAL_EQ = 1 << 0; - const EQ = 1 << 1; const COPY = 1 << 2; } } diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index eddf8eea1db3..41189de7fa21 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{self, Ident, Expr, MetaItem, GenericArg}; -use syntax::expand::SpecialDerives; use syntax::ptr::P; use syntax::symbol::{sym, Symbol}; use syntax_expand::base::{Annotatable, ExtCtxt}; @@ -14,8 +13,6 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::EQ); - let inline = cx.meta_word(span, sym::inline); let hidden = syntax::attr::mk_nested_word_item(Ident::new(sym::hidden, span)); let doc = syntax::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]); diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 2e2be91de8a4..19562e350ddb 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{BinOpKind, Expr, MetaItem}; -use syntax::expand::SpecialDerives; use syntax::ptr::P; use syntax::symbol::sym; use syntax_expand::base::{Annotatable, ExtCtxt}; @@ -14,8 +13,6 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::PARTIAL_EQ); - // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_op(cx: &mut ExtCtxt<'_>, From 0dfe0ed8e1b2b8596a8cabee0afdae23e343ee69 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 30 Oct 2019 11:13:00 +0100 Subject: [PATCH 12/17] Review feedback: Remove more stuff! Simplify simplify simplify! --- src/librustc/hir/lowering.rs | 3 --- src/librustc_resolve/lib.rs | 17 +++-------------- src/librustc_resolve/macros.rs | 9 ++++----- src/libsyntax/expand/mod.rs | 8 -------- src/libsyntax_expand/base.rs | 5 ++--- src/libsyntax_expand/expand.rs | 2 +- src/libsyntax_ext/deriving/clone.rs | 3 +-- src/libsyntax_ext/deriving/generic/mod.rs | 7 ++----- 8 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6b6032516ca7..c6acdf53de30 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -65,7 +65,6 @@ use syntax::ast; use syntax::ptr::P as AstP; use syntax::ast::*; use syntax::errors; -use syntax::expand::SpecialDerives; use syntax::print::pprust; use syntax::parse::token::{self, Nonterminal, Token}; use syntax::tokenstream::{TokenStream, TokenTree}; @@ -184,8 +183,6 @@ pub trait Resolver { ns: Namespace, ) -> (ast::Path, Res); - fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool; - fn lint_buffer(&mut self) -> &mut lint::LintBuffer; } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ca4505445582..17b62b3bda29 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -36,7 +36,6 @@ use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use syntax::{struct_span_err, unwrap_or}; -use syntax::expand::SpecialDerives; use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy}; use syntax::ast::{CRATE_NODE_ID, Crate}; use syntax::ast::{ItemKind, Path}; @@ -934,10 +933,10 @@ pub struct Resolver<'a> { multi_segment_macro_resolutions: Vec<(Vec, Span, MacroKind, ParentScope<'a>, Option)>, builtin_attrs: Vec<(Ident, ParentScope<'a>)>, - /// Some built-in derives mark items they are applied to so they are treated specially later. + /// `derive(Copy)` marks items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. - special_derives: FxHashMap, + copy_derives: FxHashSet, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. invocation_parent_scopes: FxHashMap>, @@ -1076,12 +1075,6 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { &mut self.definitions } - fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool { - let def_id = self.definitions.local_def_id(node_id); - let expn_id = self.definitions.expansion_that_defined(def_id.index); - self.has_derives(expn_id, derives) - } - fn lint_buffer(&mut self) -> &mut lint::LintBuffer { &mut self.lint_buffer } @@ -1226,7 +1219,7 @@ impl<'a> Resolver<'a> { single_segment_macro_resolutions: Default::default(), multi_segment_macro_resolutions: Default::default(), builtin_attrs: Default::default(), - special_derives: Default::default(), + copy_derives: Default::default(), active_features: features.declared_lib_features.iter().map(|(feat, ..)| *feat) .chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat)) @@ -1312,10 +1305,6 @@ impl<'a> Resolver<'a> { } } - fn has_derives(&self, expn_id: ExpnId, markers: SpecialDerives) -> bool { - self.special_derives.get(&expn_id).map_or(false, |m| m.contains(markers)) - } - /// Entry point to crate resolution. pub fn resolve_crate(&mut self, krate: &Crate) { let _prof_timer = diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 84d3d3a48b03..9997d0f946a2 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -14,7 +14,6 @@ use rustc::{ty, lint, span_bug}; use syntax::ast::{self, NodeId, Ident}; use syntax::attr::StabilityLevel; use syntax::edition::Edition; -use syntax::expand::SpecialDerives; use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name}; use syntax::feature_gate::GateIssue; use syntax::print::pprust; @@ -255,12 +254,12 @@ impl<'a> base::Resolver for Resolver<'a> { } } - fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool { - self.has_derives(expn_id, derives) + fn has_derive_copy(&self, expn_id: ExpnId) -> bool { + self.copy_derives.contains(&expn_id) } - fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives) { - *self.special_derives.entry(expn_id).or_default() |= derives; + fn add_derive_copy(&mut self, expn_id: ExpnId) { + self.copy_derives.insert(expn_id); } } diff --git a/src/libsyntax/expand/mod.rs b/src/libsyntax/expand/mod.rs index 357295081970..03b30fda745f 100644 --- a/src/libsyntax/expand/mod.rs +++ b/src/libsyntax/expand/mod.rs @@ -5,14 +5,6 @@ use syntax_pos::symbol::sym; pub mod allocator; -bitflags::bitflags! { - /// Built-in derives that need some extra tracking beyond the usual macro functionality. - #[derive(Default)] - pub struct SpecialDerives: u8 { - const COPY = 1 << 2; - } -} - pub fn is_proc_macro_attr(attr: &Attribute) -> bool { [sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive] .iter().any(|kind| attr.check_name(*kind)) diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index d79b69105879..6cc7b7da53b2 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -13,7 +13,6 @@ use syntax::symbol::{kw, sym, Ident, Symbol}; use syntax::{ThinVec, MACRO_ARGUMENTS}; use syntax::tokenstream::{self, TokenStream}; use syntax::visit::Visitor; -crate use syntax::expand::SpecialDerives; use errors::{DiagnosticBuilder, DiagnosticId}; use smallvec::{smallvec, SmallVec}; @@ -860,8 +859,8 @@ pub trait Resolver { fn check_unused_macros(&mut self); - fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool; - fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives); + fn has_derive_copy(&self, expn_id: ExpnId) -> bool; + fn add_derive_copy(&mut self, expn_id: ExpnId); } #[derive(Clone)] diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index bdb50dbfb4f4..da70fdbb0f30 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -432,7 +432,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // can be in scope for all code produced by that container's expansion. item.visit_with(&mut MarkAttrs(&helper_attrs)); if has_copy { - self.cx.resolver.add_derives(invoc.expansion_data.id, SpecialDerives::COPY); + self.cx.resolver.add_derive_copy(invoc.expansion_data.id); } let mut derive_placeholders = Vec::with_capacity(derives.len()); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 061afa379c6e..c056d03614d0 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData}; -use syntax::expand::SpecialDerives; use syntax_expand::base::{Annotatable, ExtCtxt}; use syntax::ptr::P; use syntax::symbol::{kw, sym, Symbol}; @@ -37,7 +36,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, ItemKind::Struct(_, Generics { ref params, .. }) | ItemKind::Enum(_, Generics { ref params, .. }) => { let container_id = cx.current_expansion.id.expn_data().parent; - if cx.resolver.has_derives(container_id, SpecialDerives::COPY) && + if cx.resolver.has_derive_copy(container_id) && !params.iter().any(|param| match param.kind { ast::GenericParamKind::Type { .. } => true, _ => false, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index c04b65245e1f..2e5ae235893c 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -186,7 +186,6 @@ use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::attr; -use syntax::expand::SpecialDerives; use syntax::source_map::respan; use syntax::util::map_in_place::MapInPlace; use syntax::ptr::P; @@ -427,10 +426,8 @@ impl<'a> TraitDef<'a> { } }; let container_id = cx.current_expansion.id.expn_data().parent; - let is_always_copy = - cx.resolver.has_derives(container_id, SpecialDerives::COPY) && - has_no_type_params; - let use_temporaries = is_packed && is_always_copy; + let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id); + let use_temporaries = is_packed && always_copy; let newitem = match item.kind { ast::ItemKind::Struct(ref struct_def, ref generics) => { From 99243616cc0c096e1d35b7c60d0b0ca6fc10fd48 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 4 Nov 2019 10:09:58 +0100 Subject: [PATCH 13/17] Review feedback: alpha-rename field from `copy_derives` to `containers_derving_copy`. --- src/librustc_resolve/lib.rs | 4 ++-- src/librustc_resolve/macros.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 17b62b3bda29..5c996bffb9ad 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -936,7 +936,7 @@ pub struct Resolver<'a> { /// `derive(Copy)` marks items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. - copy_derives: FxHashSet, + containers_deriving_copy: FxHashSet, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. invocation_parent_scopes: FxHashMap>, @@ -1219,7 +1219,7 @@ impl<'a> Resolver<'a> { single_segment_macro_resolutions: Default::default(), multi_segment_macro_resolutions: Default::default(), builtin_attrs: Default::default(), - copy_derives: Default::default(), + containers_deriving_copy: Default::default(), active_features: features.declared_lib_features.iter().map(|(feat, ..)| *feat) .chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat)) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 9997d0f946a2..0fbd6b0e5d30 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -255,11 +255,11 @@ impl<'a> base::Resolver for Resolver<'a> { } fn has_derive_copy(&self, expn_id: ExpnId) -> bool { - self.copy_derives.contains(&expn_id) + self.containers_deriving_copy.contains(&expn_id) } fn add_derive_copy(&mut self, expn_id: ExpnId) { - self.copy_derives.insert(expn_id); + self.containers_deriving_copy.insert(expn_id); } } From a8ccbf5f2fa75007ce0effe58caef4e342859a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 5 Nov 2019 10:29:54 -0800 Subject: [PATCH 14/17] Account for typo in turbofish and suggest `::` --- src/libsyntax/parse/parser/diagnostics.rs | 14 ++++++++++---- .../type-ascription-instead-of-path-2.stderr | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/parse/parser/diagnostics.rs b/src/libsyntax/parse/parser/diagnostics.rs index ad479e6278b7..fc2b10f22609 100644 --- a/src/libsyntax/parse/parser/diagnostics.rs +++ b/src/libsyntax/parse/parser/diagnostics.rs @@ -358,7 +358,7 @@ impl<'a> Parser<'a> { err: &mut DiagnosticBuilder<'_>, maybe_expected_semicolon: bool, ) { - if let Some((sp, likely_path)) = self.last_type_ascription { + if let Some((sp, likely_path)) = self.last_type_ascription.take() { let sm = self.sess.source_map(); let next_pos = sm.lookup_char_pos(self.token.span.lo()); let op_pos = sm.lookup_char_pos(sp.hi()); @@ -395,7 +395,6 @@ impl<'a> Parser<'a> { err.note("for more information, see \ https://github.com/rust-lang/rust/issues/23416"); } - self.last_type_ascription = None; } } @@ -1083,8 +1082,15 @@ impl<'a> Parser<'a> { } pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool { - self.token.is_ident() && - if let ast::ExprKind::Path(..) = node { true } else { false } && + (self.token == token::Lt && // `foo: true, + _ => false, + } && !self.token.is_reserved_ident() && // v `foo:bar(baz)` self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) || self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar,_>>()?; | - ^ expected `::` | | - | tried to parse a type due to this type ascription + | help: maybe write a path separator here: `::` | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` = note: for more information, see https://github.com/rust-lang/rust/issues/23416 From 25953321c00cc07cee0d414716a344357524d32b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 5 Nov 2019 13:49:36 +0200 Subject: [PATCH 15/17] rustc: remove "GlobalMetaData" dead code from hir::map::definitions. --- src/librustc/hir/map/definitions.rs | 90 +------------------ src/librustc_codegen_utils/symbol_names/v0.rs | 3 +- src/test/mir-opt/graphviz.rs | 10 +-- .../mir-opt/inline-closure-borrows-arg.rs | 2 +- src/test/mir-opt/inline-closure.rs | 2 +- src/test/mir-opt/retag.rs | 2 +- .../escape-argument-callee.stderr | 4 +- .../escape-argument.stderr | 4 +- .../escape-upvar-nested.stderr | 6 +- .../escape-upvar-ref.stderr | 4 +- ...pagate-approximated-fail-no-postdom.stderr | 4 +- .../propagate-approximated-ref.stderr | 4 +- ...er-to-static-comparing-against-free.stderr | 8 +- ...oximated-shorter-to-static-no-bound.stderr | 4 +- ...mated-shorter-to-static-wrong-bound.stderr | 4 +- .../propagate-approximated-val.stderr | 4 +- .../propagate-despite-same-free-region.stderr | 4 +- ...ail-to-approximate-longer-no-bounds.stderr | 4 +- ...-to-approximate-longer-wrong-bounds.stderr | 4 +- .../propagate-from-trait-match.stderr | 4 +- .../return-wrong-bound-region.stderr | 4 +- .../projection-no-regions-closure.stderr | 16 ++-- .../projection-one-region-closure.stderr | 18 ++-- ...tion-one-region-trait-bound-closure.stderr | 20 ++--- ...e-region-trait-bound-static-closure.stderr | 20 ++--- ...tion-two-region-trait-bound-closure.stderr | 34 +++---- ...ram-closure-approximate-lower-bound.stderr | 10 +-- ...m-closure-outlives-from-return-type.stderr | 4 +- ...-closure-outlives-from-where-clause.stderr | 20 ++--- 29 files changed, 116 insertions(+), 201 deletions(-) diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index be8d82173e48..1e444e8a5b84 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -19,7 +19,7 @@ use std::hash::Hash; use syntax::ast; use syntax_pos::symbol::{Symbol, sym}; use syntax_pos::hygiene::ExpnId; -use syntax_pos::{Span, DUMMY_SP}; +use syntax_pos::Span; /// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa. /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey` @@ -310,10 +310,6 @@ pub enum DefPathData { AnonConst, /// An `impl Trait` type node. ImplTrait, - /// Identifies a piece of crate metadata that is global to a whole crate - /// (as opposed to just one item). `GlobalMetaData` components are only - /// supposed to show up right below the crate root. - GlobalMetaData(Symbol), } #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, @@ -444,9 +440,6 @@ impl Definitions { self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index); self.set_invocation_parent(ExpnId::root(), root_index); - // Allocate some other `DefIndex`es that always must exist. - GlobalMetaDataKind::allocate_def_indices(self); - root_index } @@ -553,8 +546,7 @@ impl DefPathData { TypeNs(name) | ValueNs(name) | MacroNs(name) | - LifetimeNs(name) | - GlobalMetaData(name) => Some(name), + LifetimeNs(name) => Some(name), Impl | CrateRoot | @@ -572,8 +564,7 @@ impl DefPathData { TypeNs(name) | ValueNs(name) | MacroNs(name) | - LifetimeNs(name) | - GlobalMetaData(name) => { + LifetimeNs(name) => { name } // Note that this does not show up in user print-outs. @@ -591,78 +582,3 @@ impl DefPathData { self.as_symbol().to_string() } } - -// We define the `GlobalMetaDataKind` enum with this macro because we want to -// make sure that we exhaustively iterate over all variants when registering -// the corresponding `DefIndex`es in the `DefTable`. -macro_rules! define_global_metadata_kind { - (pub enum GlobalMetaDataKind { - $($variant:ident),* - }) => ( - pub enum GlobalMetaDataKind { - $($variant),* - } - - impl GlobalMetaDataKind { - fn allocate_def_indices(definitions: &mut Definitions) { - $({ - let instance = GlobalMetaDataKind::$variant; - definitions.create_def_with_parent( - CRATE_DEF_INDEX, - ast::DUMMY_NODE_ID, - DefPathData::GlobalMetaData(instance.name()), - ExpnId::root(), - DUMMY_SP - ); - - // Make sure calling `def_index` does not crash. - instance.def_index(&definitions.table); - })* - } - - pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex { - let def_key = DefKey { - parent: Some(CRATE_DEF_INDEX), - disambiguated_data: DisambiguatedDefPathData { - data: DefPathData::GlobalMetaData(self.name()), - disambiguator: 0, - } - }; - - // These `DefKey`s are all right after the root, - // so a linear search is fine. - let index = def_path_table.index_to_key - .iter() - .position(|k| *k == def_key) - .unwrap(); - - DefIndex::from(index) - } - - fn name(&self) -> Symbol { - - let string = match *self { - $( - GlobalMetaDataKind::$variant => { - concat!("{{GlobalMetaData::", stringify!($variant), "}}") - } - )* - }; - - Symbol::intern(string) - } - } - ) -} - -define_global_metadata_kind!(pub enum GlobalMetaDataKind { - Krate, - CrateDeps, - DylibDependencyFormats, - LangItems, - LangItemsMissing, - NativeLibraries, - SourceMap, - Impls, - ExportedSymbols -}); diff --git a/src/librustc_codegen_utils/symbol_names/v0.rs b/src/librustc_codegen_utils/symbol_names/v0.rs index 55b148fceb21..0fe4c7c67487 100644 --- a/src/librustc_codegen_utils/symbol_names/v0.rs +++ b/src/librustc_codegen_utils/symbol_names/v0.rs @@ -601,8 +601,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { | DefPathData::Misc | DefPathData::Impl | DefPathData::MacroNs(_) - | DefPathData::LifetimeNs(_) - | DefPathData::GlobalMetaData(_) => { + | DefPathData::LifetimeNs(_) => { bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data) } }; diff --git a/src/test/mir-opt/graphviz.rs b/src/test/mir-opt/graphviz.rs index fdd4e226c5a7..fcbb189c1117 100644 --- a/src/test/mir-opt/graphviz.rs +++ b/src/test/mir-opt/graphviz.rs @@ -7,14 +7,14 @@ fn main() {} // END RUST SOURCE // START rustc.main.mir_map.0.dot -// digraph Mir_0_12 { // The name here MUST be an ASCII identifier. +// digraph Mir_0_3 { // The name here MUST be an ASCII identifier. // graph [fontname="monospace"]; // node [fontname="monospace"]; // edge [fontname="monospace"]; // label=>; -// bb0__0_12 [shape="none", label=<
0
_0 = ()
goto
>]; -// bb1__0_12 [shape="none", label=<
1
resume
>]; -// bb2__0_12 [shape="none", label=<
2
return
>]; -// bb0__0_12 -> bb2__0_12 [label=""]; +// bb0__0_3 [shape="none", label=<
0
_0 = ()
goto
>]; +// bb1__0_3 [shape="none", label=<
1
resume
>]; +// bb2__0_3 [shape="none", label=<
2
return
>]; +// bb0__0_3 -> bb2__0_3 [label=""]; // } // END rustc.main.mir_map.0.dot diff --git a/src/test/mir-opt/inline-closure-borrows-arg.rs b/src/test/mir-opt/inline-closure-borrows-arg.rs index 0e1db68f3725..491130b7c5d3 100644 --- a/src/test/mir-opt/inline-closure-borrows-arg.rs +++ b/src/test/mir-opt/inline-closure-borrows-arg.rs @@ -20,7 +20,7 @@ fn foo(_t: T, q: &i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@HirId { owner: DefIndex(13), local_id: 31 }]; +// _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/inline-closure.rs b/src/test/mir-opt/inline-closure.rs index fa8557f3b38a..7c0259b643a6 100644 --- a/src/test/mir-opt/inline-closure.rs +++ b/src/test/mir-opt/inline-closure.rs @@ -16,7 +16,7 @@ fn foo(_t: T, q: i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@HirId { owner: DefIndex(13), local_id: 15 }]; +// _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs index db36a1fab5f2..96b848eb1d41 100644 --- a/src/test/mir-opt/retag.rs +++ b/src/test/mir-opt/retag.rs @@ -100,7 +100,7 @@ fn main() { // } // END rustc.main.EraseRegions.after.mir // START rustc.main-{{closure}}.EraseRegions.after.mir -// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(22), local_id: 72 }], _2: &i32) -> &i32 { +// fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(13), local_id: 72 }], _2: &i32) -> &i32 { // ... // bb0: { // Retag([fn entry] _1); diff --git a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr index cc5ffca10475..1f15ce5c212f 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr @@ -4,7 +4,7 @@ note: No external requirements LL | let mut closure = expect_sig(|p, y| *p = y); | ^^^^^^^^^^^^^ | - = note: defining type: DefId(0:13 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:4 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) i32)), ] @@ -30,7 +30,7 @@ LL | | deref(p); LL | | } | |_^ | - = note: defining type: DefId(0:12 ~ escape_argument_callee[317d]::test[0]) with substs [] + = note: defining type: DefId(0:3 ~ escape_argument_callee[317d]::test[0]) with substs [] error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/escape-argument.stderr b/src/test/ui/nll/closure-requirements/escape-argument.stderr index fdf95b8acebf..610a4aed796c 100644 --- a/src/test/ui/nll/closure-requirements/escape-argument.stderr +++ b/src/test/ui/nll/closure-requirements/escape-argument.stderr @@ -4,7 +4,7 @@ note: No external requirements LL | let mut closure = expect_sig(|p, y| *p = y); | ^^^^^^^^^^^^^ | - = note: defining type: DefId(0:13 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:4 ~ escape_argument[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) mut &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32)), ] @@ -21,7 +21,7 @@ LL | | deref(p); LL | | } | |_^ | - = note: defining type: DefId(0:12 ~ escape_argument[317d]::test[0]) with substs [] + = note: defining type: DefId(0:3 ~ escape_argument[317d]::test[0]) with substs [] error[E0597]: `y` does not live long enough --> $DIR/escape-argument.rs:27:25 diff --git a/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr b/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr index 186f25a3c89d..7c4d48cdf9fc 100644 --- a/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr +++ b/src/test/ui/nll/closure-requirements/escape-upvar-nested.stderr @@ -4,7 +4,7 @@ note: External requirements LL | let mut closure1 = || p = &y; | ^^^^^^^^^ | - = note: defining type: DefId(0:14 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:5 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]::{{closure}}[0]) with closure substs [ i16, extern "rust-call" fn(()), &'_#1r i32, @@ -23,7 +23,7 @@ LL | | closure1(); LL | | }; | |_________^ | - = note: defining type: DefId(0:13 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:4 ~ escape_upvar_nested[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, extern "rust-call" fn(()), &'_#1r i32, @@ -44,7 +44,7 @@ LL | | deref(p); LL | | } | |_^ | - = note: defining type: DefId(0:12 ~ escape_upvar_nested[317d]::test[0]) with substs [] + = note: defining type: DefId(0:3 ~ escape_upvar_nested[317d]::test[0]) with substs [] error[E0597]: `y` does not live long enough --> $DIR/escape-upvar-nested.rs:21:40 diff --git a/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr b/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr index 0df2c0f69a71..4446486808bc 100644 --- a/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr +++ b/src/test/ui/nll/closure-requirements/escape-upvar-ref.stderr @@ -4,7 +4,7 @@ note: External requirements LL | let mut closure = || p = &y; | ^^^^^^^^^ | - = note: defining type: DefId(0:13 ~ escape_upvar_ref[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:4 ~ escape_upvar_ref[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, extern "rust-call" fn(()), &'_#1r i32, @@ -25,7 +25,7 @@ LL | | deref(p); LL | | } | |_^ | - = note: defining type: DefId(0:12 ~ escape_upvar_ref[317d]::test[0]) with substs [] + = note: defining type: DefId(0:3 ~ escape_upvar_ref[317d]::test[0]) with substs [] error[E0597]: `y` does not live long enough --> $DIR/escape-upvar-ref.rs:23:35 diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr index 8916fdcfc88f..43406c05a250 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr @@ -8,7 +8,7 @@ LL | | demand_y(x, y, p) LL | | }, | |_________^ | - = note: defining type: DefId(0:27 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:18 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), ] @@ -39,7 +39,7 @@ LL | | ); LL | | } | |_^ | - = note: defining type: DefId(0:23 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:14 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]) with substs [] error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr index fa8384311ea5..3bd3fc517ceb 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr @@ -9,7 +9,7 @@ LL | | LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), ] @@ -30,7 +30,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_approximated_ref[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_approximated_ref[317d]::supply[0]) with substs [] error: lifetime may not live long enough --> $DIR/propagate-approximated-ref.rs:45:9 diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index cfaa75b8ef86..5ebc22da0365 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -8,7 +8,7 @@ LL | | LL | | }) | |_____^ | - = note: defining type: DefId(0:18 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:9 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]) with closure substs [ i32, for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)), ] @@ -35,7 +35,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:17 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs [] + = note: defining type: DefId(0:8 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs [] note: External requirements --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:35:15 @@ -46,7 +46,7 @@ LL | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static LL | | }) | |_____^ | - = note: defining type: DefId(0:20 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:11 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [ i32, for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>)), ] @@ -65,7 +65,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:19 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs [] + = note: defining type: DefId(0:10 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs [] error[E0597]: `a` does not live long enough --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26 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 601b3577e0ee..e93634aa3da5 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 @@ -10,7 +10,7 @@ LL | | demand_y(x, y, x.get()) LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) u32>)), ] @@ -31,7 +31,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs [] error[E0521]: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:32:5 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 5b5440e7a964..2127eab43448 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 @@ -10,7 +10,7 @@ LL | | demand_y(x, y, x.get()) LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), ] @@ -31,7 +31,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs [] error[E0521]: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:35:5 diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr index a08cde2c9c63..9078877492f7 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr @@ -9,7 +9,7 @@ LL | | LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), ] @@ -30,7 +30,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_approximated_val[317d]::test[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_approximated_val[317d]::test[0]) with substs [] error: lifetime may not live long enough --> $DIR/propagate-approximated-val.rs:38:9 diff --git a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr index 60847bb2e929..c5468e73cfa0 100644 --- a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr @@ -8,7 +8,7 @@ LL | | demand_y(x, y, p) LL | | }, | |_________^ | - = note: defining type: DefId(0:23 ~ propagate_despite_same_free_region[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:14 ~ propagate_despite_same_free_region[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), ] @@ -28,5 +28,5 @@ LL | | ); LL | | } | |_^ | - = note: defining type: DefId(0:21 ~ propagate_despite_same_free_region[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:12 ~ propagate_despite_same_free_region[317d]::supply[0]) with substs [] diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr index a660c763bff7..bf43c8938654 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr @@ -9,7 +9,7 @@ LL | | LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>)), ] @@ -39,7 +39,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]) with substs [] error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr index 9671b8ebff3a..569bae999dd2 100644 --- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr @@ -9,7 +9,7 @@ LL | | LL | | }); | |_____^ | - = note: defining type: DefId(0:25 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:16 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 't1)) u32>)), ] @@ -39,7 +39,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:22 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]) with substs [] + = note: defining type: DefId(0:13 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]) with substs [] error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr index 457b5950b7ff..0d622654c528 100644 --- a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr @@ -11,7 +11,7 @@ LL | | require(value); LL | | }); | |_____^ | - = note: defining type: DefId(0:23 ~ propagate_from_trait_match[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:14 ~ propagate_from_trait_match[317d]::supply[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -32,7 +32,7 @@ LL | | }); LL | | } | |_^ | - = note: defining type: DefId(0:20 ~ propagate_from_trait_match[317d]::supply[0]) with substs [ + = note: defining type: DefId(0:11 ~ propagate_from_trait_match[317d]::supply[0]) with substs [ '_#1r, T, ] diff --git a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr index 8aff6d5b8927..00c56a796d1b 100644 --- a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr +++ b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr @@ -4,7 +4,7 @@ note: No external requirements LL | expect_sig(|a, b| b); // ought to return `a` | ^^^^^^^^ | - = note: defining type: DefId(0:13 ~ return_wrong_bound_region[317d]::test[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:4 ~ return_wrong_bound_region[317d]::test[0]::{{closure}}[0]) with closure substs [ i16, for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) i32, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) i32)) -> &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 'r)) i32, ] @@ -27,7 +27,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:12 ~ return_wrong_bound_region[317d]::test[0]) with substs [] + = note: defining type: DefId(0:3 ~ return_wrong_bound_region[317d]::test[0]) with substs [] error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr index 9fa54e83812f..dd61023a15b0 100644 --- a/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-no-regions-closure.stderr @@ -4,7 +4,7 @@ note: External requirements LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:22 ~ projection_no_regions_closure[317d]::no_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:13 ~ projection_no_regions_closure[317d]::no_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -25,7 +25,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:19 ~ projection_no_regions_closure[317d]::no_region[0]) with substs [ + = note: defining type: DefId(0:10 ~ projection_no_regions_closure[317d]::no_region[0]) with substs [ '_#1r, T, ] @@ -44,7 +44,7 @@ note: External requirements LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:26 ~ projection_no_regions_closure[317d]::correct_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:17 ~ projection_no_regions_closure[317d]::correct_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -64,7 +64,7 @@ LL | | with_signature(x, |mut y| Box::new(y.next())) LL | | } | |_^ | - = note: defining type: DefId(0:23 ~ projection_no_regions_closure[317d]::correct_region[0]) with substs [ + = note: defining type: DefId(0:14 ~ projection_no_regions_closure[317d]::correct_region[0]) with substs [ '_#1r, T, ] @@ -75,7 +75,7 @@ note: External requirements LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:31 ~ projection_no_regions_closure[317d]::wrong_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:22 ~ projection_no_regions_closure[317d]::wrong_region[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -97,7 +97,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:27 ~ projection_no_regions_closure[317d]::wrong_region[0]) with substs [ + = note: defining type: DefId(0:18 ~ projection_no_regions_closure[317d]::wrong_region[0]) with substs [ '_#1r, '_#2r, T, @@ -117,7 +117,7 @@ note: External requirements LL | with_signature(x, |mut y| Box::new(y.next())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:36 ~ projection_no_regions_closure[317d]::outlives_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:27 ~ projection_no_regions_closure[317d]::outlives_region[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -139,7 +139,7 @@ LL | | with_signature(x, |mut y| Box::new(y.next())) LL | | } | |_^ | - = note: defining type: DefId(0:32 ~ projection_no_regions_closure[317d]::outlives_region[0]) with substs [ + = note: defining type: DefId(0:23 ~ projection_no_regions_closure[317d]::outlives_region[0]) with substs [ '_#1r, '_#2r, T, diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr index 10b2bd1af470..c5c0e106c8a9 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr @@ -4,7 +4,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:28 ~ projection_one_region_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:19 ~ projection_one_region_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -27,7 +27,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:24 ~ projection_one_region_closure[317d]::no_relationships_late[0]) with substs [ + = note: defining type: DefId(0:15 ~ projection_one_region_closure[317d]::no_relationships_late[0]) with substs [ '_#1r, T, ] @@ -38,7 +38,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:24 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(25), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:15 ~ projection_one_region_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(16), 'a))`... error: lifetime may not live long enough --> $DIR/projection-one-region-closure.rs:45:39 @@ -57,7 +57,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:33 ~ projection_one_region_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:24 ~ projection_one_region_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -80,7 +80,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:29 ~ projection_one_region_closure[317d]::no_relationships_early[0]) with substs [ + = note: defining type: DefId(0:20 ~ projection_one_region_closure[317d]::no_relationships_early[0]) with substs [ '_#1r, '_#2r, T, @@ -111,7 +111,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:38 ~ projection_one_region_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:29 ~ projection_one_region_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -133,7 +133,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:34 ~ projection_one_region_closure[317d]::projection_outlives[0]) with substs [ + = note: defining type: DefId(0:25 ~ projection_one_region_closure[317d]::projection_outlives[0]) with substs [ '_#1r, '_#2r, T, @@ -145,7 +145,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:43 ~ projection_one_region_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:34 ~ projection_one_region_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -168,7 +168,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:39 ~ projection_one_region_closure[317d]::elements_outlive[0]) with substs [ + = note: defining type: DefId(0:30 ~ projection_one_region_closure[317d]::elements_outlive[0]) with substs [ '_#1r, '_#2r, T, diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr index b4b74bfc1284..3fcf9731fc3a 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr @@ -4,7 +4,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:28 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:19 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -26,7 +26,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:24 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_late[0]) with substs [ + = note: defining type: DefId(0:15 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_late[0]) with substs [ '_#1r, T, ] @@ -48,7 +48,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:33 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:24 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -70,7 +70,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:29 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_early[0]) with substs [ + = note: defining type: DefId(0:20 ~ projection_one_region_trait_bound_closure[317d]::no_relationships_early[0]) with substs [ '_#1r, '_#2r, T, @@ -93,7 +93,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:38 ~ projection_one_region_trait_bound_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:29 ~ projection_one_region_trait_bound_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -115,7 +115,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:34 ~ projection_one_region_trait_bound_closure[317d]::projection_outlives[0]) with substs [ + = note: defining type: DefId(0:25 ~ projection_one_region_trait_bound_closure[317d]::projection_outlives[0]) with substs [ '_#1r, '_#2r, T, @@ -127,7 +127,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:43 ~ projection_one_region_trait_bound_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:34 ~ projection_one_region_trait_bound_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -149,7 +149,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:39 ~ projection_one_region_trait_bound_closure[317d]::elements_outlive[0]) with substs [ + = note: defining type: DefId(0:30 ~ projection_one_region_trait_bound_closure[317d]::elements_outlive[0]) with substs [ '_#1r, '_#2r, T, @@ -161,7 +161,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:47 ~ projection_one_region_trait_bound_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:38 ~ projection_one_region_trait_bound_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -182,7 +182,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:44 ~ projection_one_region_trait_bound_closure[317d]::one_region[0]) with substs [ + = note: defining type: DefId(0:35 ~ projection_one_region_trait_bound_closure[317d]::one_region[0]) with substs [ '_#1r, T, ] diff --git a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-static-closure.stderr b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-static-closure.stderr index a757a43499f4..9cc2e504e100 100644 --- a/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-static-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-static-closure.stderr @@ -4,7 +4,7 @@ note: No external requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:28 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:19 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -23,7 +23,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:24 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]) with substs [ + = note: defining type: DefId(0:15 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]) with substs [ '_#1r, T, ] @@ -34,7 +34,7 @@ note: No external requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:33 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:24 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -54,7 +54,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:29 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_early[0]) with substs [ + = note: defining type: DefId(0:20 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_early[0]) with substs [ '_#1r, '_#2r, T, @@ -66,7 +66,7 @@ note: No external requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:38 ~ projection_one_region_trait_bound_static_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:29 ~ projection_one_region_trait_bound_static_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -86,7 +86,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:34 ~ projection_one_region_trait_bound_static_closure[317d]::projection_outlives[0]) with substs [ + = note: defining type: DefId(0:25 ~ projection_one_region_trait_bound_static_closure[317d]::projection_outlives[0]) with substs [ '_#1r, '_#2r, T, @@ -98,7 +98,7 @@ note: No external requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:43 ~ projection_one_region_trait_bound_static_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:34 ~ projection_one_region_trait_bound_static_closure[317d]::elements_outlive[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -118,7 +118,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:39 ~ projection_one_region_trait_bound_static_closure[317d]::elements_outlive[0]) with substs [ + = note: defining type: DefId(0:30 ~ projection_one_region_trait_bound_static_closure[317d]::elements_outlive[0]) with substs [ '_#1r, '_#2r, T, @@ -130,7 +130,7 @@ note: No external requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:47 ~ projection_one_region_trait_bound_static_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:38 ~ projection_one_region_trait_bound_static_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -149,7 +149,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:44 ~ projection_one_region_trait_bound_static_closure[317d]::one_region[0]) with substs [ + = note: defining type: DefId(0:35 ~ projection_one_region_trait_bound_static_closure[317d]::one_region[0]) with substs [ '_#1r, T, ] diff --git a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr index a48766cd7340..c4f65a29b8e3 100644 --- a/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr +++ b/src/test/ui/nll/ty-outlives/projection-two-region-trait-bound-closure.stderr @@ -4,7 +4,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:31 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:22 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -27,7 +27,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:26 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]) with substs [ + = note: defining type: DefId(0:17 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]) with substs [ '_#1r, '_#2r, T, @@ -39,7 +39,7 @@ error[E0309]: the associated type `>::AssocType` may LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0:26 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(27), 'a))`... + = help: consider adding an explicit lifetime bound `>::AssocType: ReFree(DefId(0:17 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(18), 'a))`... note: External requirements --> $DIR/projection-two-region-trait-bound-closure.rs:48:29 @@ -47,7 +47,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:37 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:28 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_early[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, '_#3r, @@ -70,7 +70,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:32 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_early[0]) with substs [ + = note: defining type: DefId(0:23 ~ projection_two_region_trait_bound_closure[317d]::no_relationships_early[0]) with substs [ '_#1r, '_#2r, '_#3r, @@ -91,7 +91,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:43 ~ projection_two_region_trait_bound_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:34 ~ projection_two_region_trait_bound_closure[317d]::projection_outlives[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, '_#3r, @@ -114,7 +114,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:38 ~ projection_two_region_trait_bound_closure[317d]::projection_outlives[0]) with substs [ + = note: defining type: DefId(0:29 ~ projection_two_region_trait_bound_closure[317d]::projection_outlives[0]) with substs [ '_#1r, '_#2r, '_#3r, @@ -127,7 +127,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:49 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive1[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:40 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive1[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, '_#3r, @@ -150,7 +150,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:44 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive1[0]) with substs [ + = note: defining type: DefId(0:35 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive1[0]) with substs [ '_#1r, '_#2r, '_#3r, @@ -163,7 +163,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:55 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive2[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:46 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive2[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, '_#3r, @@ -186,7 +186,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:50 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive2[0]) with substs [ + = note: defining type: DefId(0:41 ~ projection_two_region_trait_bound_closure[317d]::elements_outlive2[0]) with substs [ '_#1r, '_#2r, '_#3r, @@ -199,7 +199,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:60 ~ projection_two_region_trait_bound_closure[317d]::two_regions[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:51 ~ projection_two_region_trait_bound_closure[317d]::two_regions[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -221,7 +221,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:56 ~ projection_two_region_trait_bound_closure[317d]::two_regions[0]) with substs [ + = note: defining type: DefId(0:47 ~ projection_two_region_trait_bound_closure[317d]::two_regions[0]) with substs [ '_#1r, T, ] @@ -243,7 +243,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:65 ~ projection_two_region_trait_bound_closure[317d]::two_regions_outlive[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:56 ~ projection_two_region_trait_bound_closure[317d]::two_regions_outlive[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -265,7 +265,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:61 ~ projection_two_region_trait_bound_closure[317d]::two_regions_outlive[0]) with substs [ + = note: defining type: DefId(0:52 ~ projection_two_region_trait_bound_closure[317d]::two_regions_outlive[0]) with substs [ '_#1r, '_#2r, T, @@ -277,7 +277,7 @@ note: External requirements LL | with_signature(cell, t, |cell, t| require(cell, t)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:69 ~ projection_two_region_trait_bound_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:60 ~ projection_two_region_trait_bound_closure[317d]::one_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -298,7 +298,7 @@ LL | | with_signature(cell, t, |cell, t| require(cell, t)); LL | | } | |_^ | - = note: defining type: DefId(0:66 ~ projection_two_region_trait_bound_closure[317d]::one_region[0]) with substs [ + = note: defining type: DefId(0:57 ~ projection_two_region_trait_bound_closure[317d]::one_region[0]) with substs [ '_#1r, T, ] diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr index 2ed94df1f347..fd8d8917c187 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr @@ -4,7 +4,7 @@ note: External requirements LL | twice(cell, value, |a, b| invoke(a, b)); | ^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:20 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:11 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]::{{closure}}[0]) with closure substs [ T, i16, for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) T)), @@ -21,7 +21,7 @@ LL | | twice(cell, value, |a, b| invoke(a, b)); LL | | } | |_^ | - = note: defining type: DefId(0:18 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]) with substs [ + = note: defining type: DefId(0:9 ~ ty_param_closure_approximate_lower_bound[317d]::generic[0]) with substs [ T, ] @@ -31,7 +31,7 @@ note: External requirements LL | twice(cell, value, |a, b| invoke(a, b)); | ^^^^^^^^^^^^^^^^^^^ | - = note: defining type: DefId(0:24 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:15 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]::{{closure}}[0]) with closure substs [ T, i16, for<'r, 's> extern "rust-call" fn((std::option::Option>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0), 's)) T)), @@ -49,7 +49,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:21 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]) with substs [ + = note: defining type: DefId(0:12 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]) with substs [ T, ] @@ -59,7 +59,7 @@ error[E0309]: the parameter type `T` may not live long enough LL | twice(cell, value, |a, b| invoke(a, b)); | ^^^^^^^^^^^^^^^^^^^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:21 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(22), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:12 ~ ty_param_closure_approximate_lower_bound[317d]::generic_fail[0]), BrNamed(crate0:DefIndex(13), 'a))`... error: aborting due to previous error diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr index d689949969d7..7c8dc94eda98 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-return-type.stderr @@ -4,7 +4,7 @@ note: External requirements LL | with_signature(x, |y| y) | ^^^^^ | - = note: defining type: DefId(0:20 ~ ty_param_closure_outlives_from_return_type[317d]::no_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:11 ~ ty_param_closure_outlives_from_return_type[317d]::no_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -25,7 +25,7 @@ LL | | LL | | } | |_^ | - = note: defining type: DefId(0:17 ~ ty_param_closure_outlives_from_return_type[317d]::no_region[0]) with substs [ + = note: defining type: DefId(0:8 ~ ty_param_closure_outlives_from_return_type[317d]::no_region[0]) with substs [ '_#1r, T, ] diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr index 11444c9f72be..97b84d1bdf80 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr +++ b/src/test/ui/nll/ty-outlives/ty-param-closure-outlives-from-where-clause.stderr @@ -11,7 +11,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = note: defining type: DefId(0:23 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:14 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]::{{closure}}[0]) with closure substs [ T, i32, extern "rust-call" fn((std::cell::Cell<&'_#1r ()>, T)), @@ -32,7 +32,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:20 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]) with substs [ + = note: defining type: DefId(0:11 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]) with substs [ T, ] @@ -49,7 +49,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:20 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(21), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:11 ~ ty_param_closure_outlives_from_where_clause[317d]::no_region[0]), BrNamed(crate0:DefIndex(12), 'a))`... note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:43:26 @@ -64,7 +64,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = note: defining type: DefId(0:27 ~ ty_param_closure_outlives_from_where_clause[317d]::correct_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:18 ~ ty_param_closure_outlives_from_where_clause[317d]::correct_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -85,7 +85,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:24 ~ ty_param_closure_outlives_from_where_clause[317d]::correct_region[0]) with substs [ + = note: defining type: DefId(0:15 ~ ty_param_closure_outlives_from_where_clause[317d]::correct_region[0]) with substs [ '_#1r, T, ] @@ -101,7 +101,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = note: defining type: DefId(0:32 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:23 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]::{{closure}}[0]) with closure substs [ '_#1r, T, i32, @@ -123,7 +123,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:28 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]) with substs [ + = note: defining type: DefId(0:19 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]) with substs [ '_#1r, T, ] @@ -139,7 +139,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:28 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(29), 'a))`... + = help: consider adding an explicit lifetime bound `T: ReFree(DefId(0:19 ~ ty_param_closure_outlives_from_where_clause[317d]::wrong_region[0]), BrNamed(crate0:DefIndex(20), 'a))`... note: External requirements --> $DIR/ty-param-closure-outlives-from-where-clause.rs:77:26 @@ -151,7 +151,7 @@ LL | | require(&x, &y) LL | | }) | |_____^ | - = note: defining type: DefId(0:37 ~ ty_param_closure_outlives_from_where_clause[317d]::outlives_region[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0:28 ~ ty_param_closure_outlives_from_where_clause[317d]::outlives_region[0]::{{closure}}[0]) with closure substs [ '_#1r, '_#2r, T, @@ -173,7 +173,7 @@ LL | | }) LL | | } | |_^ | - = note: defining type: DefId(0:33 ~ ty_param_closure_outlives_from_where_clause[317d]::outlives_region[0]) with substs [ + = note: defining type: DefId(0:24 ~ ty_param_closure_outlives_from_where_clause[317d]::outlives_region[0]) with substs [ '_#1r, '_#2r, T, From bbd7f5c85b4c9f547490786a1453eaaf20dd0696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 4 Nov 2019 10:57:41 -0800 Subject: [PATCH 16/17] Do not ICE whith a precision flag in formatting str and no format arguments --- src/libsyntax_ext/format.rs | 10 ++++++---- src/test/ui/if/ifmt-bad-arg.rs | 5 +++++ src/test/ui/if/ifmt-bad-arg.stderr | 13 ++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 37310f46f7ee..3c7f80aa399b 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -374,10 +374,12 @@ impl<'a, 'b> Context<'a, 'b> { format!("are {} arguments", count) }, )); - e.span_label( - self.args[pos].span, - "this parameter corresponds to the precision flag", - ); + if let Some(arg) = self.args.get(pos) { + e.span_label( + arg.span, + "this parameter corresponds to the precision flag", + ); + } zero_based_note = true; } _ => {} diff --git a/src/test/ui/if/ifmt-bad-arg.rs b/src/test/ui/if/ifmt-bad-arg.rs index ba897f171af2..a0b0a8fb9859 100644 --- a/src/test/ui/if/ifmt-bad-arg.rs +++ b/src/test/ui/if/ifmt-bad-arg.rs @@ -86,4 +86,9 @@ tenth number: {}", println!("{:foo}", 1); //~ ERROR unknown format trait `foo` println!("{5} {:4$} {6:7$}", 1); //~^ ERROR invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument) + + // We used to ICE here because we tried to unconditionally access the first argument, which + // doesn't exist. + println!("{:.*}"); + //~^ ERROR 2 positional arguments in format string, but no arguments were given } diff --git a/src/test/ui/if/ifmt-bad-arg.stderr b/src/test/ui/if/ifmt-bad-arg.stderr index c58cbc312335..11dcc3a6d232 100644 --- a/src/test/ui/if/ifmt-bad-arg.stderr +++ b/src/test/ui/if/ifmt-bad-arg.stderr @@ -285,6 +285,17 @@ LL | println!("{5} {:4$} {6:7$}", 1); = note: positional arguments are zero-based = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html +error: 2 positional arguments in format string, but no arguments were given + --> $DIR/ifmt-bad-arg.rs:92:15 + | +LL | println!("{:.*}"); + | ^^--^ + | | + | this precision flag adds an extra required argument at position 0, which is why there are 2 arguments expected + | + = note: positional arguments are zero-based + = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html + error[E0308]: mismatched types --> $DIR/ifmt-bad-arg.rs:78:32 | @@ -303,6 +314,6 @@ LL | println!("{} {:07$.*} {}", 1, 3.2, 4); = note: expected type `&usize` found type `&{float}` -error: aborting due to 35 previous errors +error: aborting due to 36 previous errors For more information about this error, try `rustc --explain E0308`. From b0f258b2c4c5bc0764890e4989874783a8d37db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 4 Nov 2019 18:47:02 -0800 Subject: [PATCH 17/17] Tweak type mismatch caused by break on tail expr When `break;` has a type mismatch because the `Destination` points at a tail expression with an obligation flowing from a return type, point at the return type. Fix #39968. --- src/librustc/traits/error_reporting.rs | 2 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/expr.rs | 10 +++++++++- src/librustc_typeck/check/mod.rs | 14 +++++++------- src/test/ui/type/type-error-break-tail.rs | 8 ++++++++ src/test/ui/type/type-error-break-tail.stderr | 18 ++++++++++++++++++ 6 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/type/type-error-break-tail.rs create mode 100644 src/test/ui/type/type-error-break-tail.stderr diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index b55c0f29a70e..d32a4eee5ae8 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1169,7 +1169,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn suggest_fn_call( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, ) { diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index b4e07e4a0dfb..af892bf8179f 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -553,7 +553,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn check_for_cast( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr, checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 8668dd99a8cf..81e4bb6f2ad8 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -583,7 +583,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { assert!(e_ty.is_unit()); let ty = coerce.expected_ty(); - coerce.coerce_forced_unit(self, &cause, &mut |err| { + coerce.coerce_forced_unit(self, &cause, &mut |mut err| { + self.suggest_mismatched_types_on_tail( + &mut err, + expr, + ty, + e_ty, + cause.span, + target_id, + ); let val = match ty.kind { ty::Bool => "true", ty::Char => "'a'", diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f7132cd868aa..8ecf736df410 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4246,7 +4246,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// - Possible missing return type if the return type is the default, and not `fn main()`. pub fn suggest_mismatched_types_on_tail( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &'tcx hir::Expr, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -4273,7 +4273,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` fn suggest_fn_call( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -4386,7 +4386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn suggest_ref_or_into( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -4454,7 +4454,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// in the heap by calling `Box::new()`. fn suggest_boxing_when_appropriate( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -4498,7 +4498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// it suggests adding a semicolon. fn suggest_missing_semicolon( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expression: &'tcx hir::Expr, expected: Ty<'tcx>, cause_span: Span, @@ -4537,7 +4537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// type. fn suggest_missing_return_type( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, fn_decl: &hir::FnDecl, expected: Ty<'tcx>, found: Ty<'tcx>, @@ -4603,7 +4603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// `.await` to the tail of the expression. fn suggest_missing_await( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, expr: &hir::Expr, expected: Ty<'tcx>, found: Ty<'tcx>, diff --git a/src/test/ui/type/type-error-break-tail.rs b/src/test/ui/type/type-error-break-tail.rs new file mode 100644 index 000000000000..d4e3e93d06bc --- /dev/null +++ b/src/test/ui/type/type-error-break-tail.rs @@ -0,0 +1,8 @@ +fn loop_ending() -> i32 { + loop { + if false { break; } //~ ERROR mismatched types + return 42; + } +} + +fn main() {} diff --git a/src/test/ui/type/type-error-break-tail.stderr b/src/test/ui/type/type-error-break-tail.stderr new file mode 100644 index 000000000000..e5297d9a596d --- /dev/null +++ b/src/test/ui/type/type-error-break-tail.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/type-error-break-tail.rs:3:20 + | +LL | fn loop_ending() -> i32 { + | --- expected `i32` because of return type +LL | loop { +LL | if false { break; } + | ^^^^^ + | | + | expected i32, found () + | help: give it a value of the expected type: `break 42` + | + = note: expected type `i32` + found type `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.