Skip to content

Commit e947fad

Browse files
committed
Point to the empty trait alias.
1 parent 1d43b4d commit e947fad

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

compiler/rustc_error_messages/locales/en-US/typeck.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typeck-copy-impl-on-non-adt =
4545
4646
typeck-trait-object-declared-with-no-traits =
4747
at least one trait is required for an object type
48+
.alias-span = this alias does not contain a trait
4849
4950
typeck-ambiguous-lifetime-bound =
5051
ambiguous lifetime bound, explicit lifetime bound required

compiler/rustc_typeck/src/astconv/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13701370
}
13711371

13721372
if regular_traits.is_empty() && auto_traits.is_empty() {
1373-
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span });
1373+
let trait_alias_span = bounds
1374+
.trait_bounds
1375+
.iter()
1376+
.map(|&(trait_ref, _, _)| trait_ref.def_id())
1377+
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
1378+
.map(|trait_ref| tcx.def_span(trait_ref));
1379+
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
13741380
return tcx.ty_error();
13751381
}
13761382

compiler/rustc_typeck/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ pub struct CopyImplOnNonAdt {
103103
pub struct TraitObjectDeclaredWithNoTraits {
104104
#[primary_span]
105105
pub span: Span,
106+
#[label = "alias-span"]
107+
pub trait_alias_span: Option<Span>,
106108
}
107109

108110
#[derive(SessionDiagnostic)]

src/test/ui/traits/alias/only-maybe-bound.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
error[E0224]: at least one trait is required for an object type
22
--> $DIR/only-maybe-bound.rs:13:12
33
|
4+
LL | trait _1 = _0;
5+
| -------------- this alias does not contain a trait
6+
...
47
LL | type _T0 = dyn _1;
58
| ^^^^^^
69

710
error[E0224]: at least one trait is required for an object type
811
--> $DIR/only-maybe-bound.rs:19:12
912
|
13+
LL | trait _2 = _1 + _1;
14+
| ------------------- this alias does not contain a trait
15+
LL |
1016
LL | type _T1 = dyn _2;
1117
| ^^^^^^
1218

src/test/ui/traits/issue-65673.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error[E0224]: at least one trait is required for an object type
22
--> $DIR/issue-65673.rs:9:16
33
|
4+
LL | trait Alias<T> = where T: Trait;
5+
| -------------------------------- this alias does not contain a trait
6+
...
47
LL | type Ctx = dyn Alias<T>;
58
| ^^^^^^^^^^^^
69

0 commit comments

Comments
 (0)