From 3136bfef9319a40c95efc38409ad3e57d40882dd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 9 Feb 2022 17:39:28 +0000 Subject: [PATCH] Special case the situation where the previous span is the same as the new one --- compiler/rustc_typeck/src/collect/type_of.rs | 6 +++++- src/test/ui/impl-trait/issue-86465.stderr | 9 +++------ .../multiple-def-uses-in-one-fn-infer.stderr | 9 +++------ .../multiple-def-uses-in-one-fn-lifetimes.stderr | 9 +++------ .../multiple-def-uses-in-one-fn2.stderr | 9 +++------ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 4e1edd17194..95d1b6a15f5 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -610,7 +610,11 @@ fn check(&mut self, def_id: LocalDefId) { concrete_type.span, format!("expected `{}`, got `{}`", prev.ty, concrete_type.ty), ); - err.span_note(prev.span, "previous use here"); + if prev.span == concrete_type.span { + err.span_label(prev.span, "this expression supplies two conflicting concrete types for the same opaque type"); + } else { + err.span_note(prev.span, "previous use here"); + } err.emit(); } } else { diff --git a/src/test/ui/impl-trait/issue-86465.stderr b/src/test/ui/impl-trait/issue-86465.stderr index fc7bad60183..90d6904ed61 100644 --- a/src/test/ui/impl-trait/issue-86465.stderr +++ b/src/test/ui/impl-trait/issue-86465.stderr @@ -1,14 +1,11 @@ error: concrete type differs from previous defining opaque type use --> $DIR/issue-86465.rs:6:5 | -LL | (a, a) - | ^^^^^^ expected `&'a u32`, got `&'b u32` - | -note: previous use here - --> $DIR/issue-86465.rs:6:5 - | LL | (a, a) | ^^^^^^ + | | + | expected `&'a u32`, got `&'b u32` + | this expression supplies two conflicting concrete types for the same opaque type error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr index e3709d822ff..27811700912 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr @@ -1,14 +1,11 @@ error: concrete type differs from previous defining opaque type use --> $DIR/multiple-def-uses-in-one-fn-infer.rs:10:5 | -LL | (42_i64, 60) - | ^^^^^^^^^^^^ expected `i64`, got `i32` - | -note: previous use here - --> $DIR/multiple-def-uses-in-one-fn-infer.rs:10:5 - | LL | (42_i64, 60) | ^^^^^^^^^^^^ + | | + | expected `i64`, got `i32` + | this expression supplies two conflicting concrete types for the same opaque type error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr index ed2e48e4aff..81e603e2355 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr @@ -1,14 +1,11 @@ error: concrete type differs from previous defining opaque type use --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | -LL | (i, i) - | ^^^^^^ expected `&'a i32`, got `&'b i32` - | -note: previous use here - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 - | LL | (i, i) | ^^^^^^ + | | + | expected `&'a i32`, got `&'b i32` + | this expression supplies two conflicting concrete types for the same opaque type error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr index de3f8700708..0f752212ac9 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr @@ -1,14 +1,11 @@ error: concrete type differs from previous defining opaque type use --> $DIR/multiple-def-uses-in-one-fn2.rs:10:5 | -LL | (a.clone(), a) - | ^^^^^^^^^^^^^^ expected `A`, got `B` - | -note: previous use here - --> $DIR/multiple-def-uses-in-one-fn2.rs:10:5 - | LL | (a.clone(), a) | ^^^^^^^^^^^^^^ + | | + | expected `A`, got `B` + | this expression supplies two conflicting concrete types for the same opaque type error: aborting due to previous error