Skip to content

Commit 4d35383

Browse files
committed
Place UnresolvedDelegationCallee in correct place
1 parent b19da8b commit 4d35383

9 files changed

Lines changed: 68 additions & 37 deletions

File tree

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use rustc_span::symbol::kw;
5454
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
5555

5656
use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults};
57-
use crate::errors::CycleInDelegationSignatureResolution;
57+
use crate::errors::{CycleInDelegationSignatureResolution, UnresolvedDelegationCallee};
5858
use crate::{
5959
AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
6060
ResolverAstLoweringExt, index_crate,
@@ -147,7 +147,10 @@ fn check_for_cycles(tcx: TyCtxt<'_>, mut def_id: DefId, span: Span) -> Result<()
147147
{
148148
def_id = id;
149149
if visited.contains(&def_id) {
150-
return Err(tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span }));
150+
return Err(match visited.len() {
151+
1 => tcx.dcx().emit_err(UnresolvedDelegationCallee { span }),
152+
_ => tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span }),
153+
});
151154
}
152155
} else {
153156
return Ok(());

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,10 @@ pub(crate) struct CycleInDelegationSignatureResolution {
528528
#[primary_span]
529529
pub span: Span,
530530
}
531+
532+
#[derive(Diagnostic)]
533+
#[diag("failed to resolve delegation callee")]
534+
pub(crate) struct UnresolvedDelegationCallee {
535+
#[primary_span]
536+
pub span: Span,
537+
}

compiler/rustc_resolve/src/late.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,20 +3906,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39063906
.get(&resolution_node_id)
39073907
.and_then(|r| r.expect_full_res().opt_def_id());
39083908

3909-
let resolution_id = if let Some(resolution_id) = def_id
3910-
// If there is a single unresolved `reuse foo` in a mod it resolves to itself,
3911-
// in this case emit `UnresolvedDelegationCallee` error instead of cycle error.
3912-
&& resolution_id != self.r.current_owner.def_id.to_def_id()
3913-
{
3914-
Ok(resolution_id)
3915-
} else {
3916-
Err(self.r.tcx.dcx().span_delayed_bug(
3909+
let resolution_id = def_id.ok_or_else(|| {
3910+
self.r.tcx.dcx().span_delayed_bug(
39173911
delegation.path.span,
39183912
format!(
39193913
"LateResolutionVisitor: couldn't resolve node {resolution_node_id:?} in delegation item",
39203914
),
3921-
))
3922-
};
3915+
)
3916+
});
39233917

39243918
let info = DelegationInfo { resolution_id };
39253919
self.r.delegation_infos.insert(self.r.current_owner.def_id, info);

tests/ui/delegation/ice-issue-124347.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
trait Trait {
44
reuse Trait::foo { &self.0 }
55
//~^ ERROR: this function takes 0 arguments but 1 argument was supplied
6+
//~| ERROR: failed to resolve delegation callee
67
}
78

89
reuse foo;
910
//~^ WARN: function cannot return without recursing
11+
//~| ERROR: failed to resolve delegation callee
1012

1113
fn main() {}

tests/ui/delegation/ice-issue-124347.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: failed to resolve delegation callee
2+
--> $DIR/ice-issue-124347.rs:4:18
3+
|
4+
LL | reuse Trait::foo { &self.0 }
5+
| ^^^
6+
7+
error: failed to resolve delegation callee
8+
--> $DIR/ice-issue-124347.rs:9:7
9+
|
10+
LL | reuse foo;
11+
| ^^^
12+
113
error[E0061]: this function takes 0 arguments but 1 argument was supplied
214
--> $DIR/ice-issue-124347.rs:4:18
315
|
@@ -16,7 +28,7 @@ LL + reuse Trait::fo&self.0 }
1628
|
1729

1830
warning: function cannot return without recursing
19-
--> $DIR/ice-issue-124347.rs:8:7
31+
--> $DIR/ice-issue-124347.rs:9:7
2032
|
2133
LL | reuse foo;
2234
| ^^^
@@ -27,6 +39,6 @@ LL | reuse foo;
2739
= help: a `loop` may express intention better if this is on purpose
2840
= note: `#[warn(unconditional_recursion)]` on by default
2941

30-
error: aborting due to 1 previous error; 1 warning emitted
42+
error: aborting due to 3 previous errors; 1 warning emitted
3143

3244
For more information about this error, try `rustc --explain E0061`.

tests/ui/delegation/recursive-delegation-errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod first_mod {
44
reuse foo;
55
//~^ WARN: function cannot return without recursing
6+
//~| ERROR: failed to resolve delegation callee
67
}
78

89
mod second_mod {
Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,133 @@
1+
error: failed to resolve delegation callee
2+
--> $DIR/recursive-delegation-errors.rs:4:11
3+
|
4+
LL | reuse foo;
5+
| ^^^
6+
17
error: encountered a cycle during delegation signature resolution
2-
--> $DIR/recursive-delegation-errors.rs:9:11
8+
--> $DIR/recursive-delegation-errors.rs:10:11
39
|
410
LL | reuse foo as bar;
511
| ^^^
612

713
error: encountered a cycle during delegation signature resolution
8-
--> $DIR/recursive-delegation-errors.rs:11:11
14+
--> $DIR/recursive-delegation-errors.rs:12:11
915
|
1016
LL | reuse bar as foo;
1117
| ^^^
1218

1319
error: encountered a cycle during delegation signature resolution
14-
--> $DIR/recursive-delegation-errors.rs:16:11
20+
--> $DIR/recursive-delegation-errors.rs:17:11
1521
|
1622
LL | reuse foo as foo1;
1723
| ^^^
1824

1925
error: encountered a cycle during delegation signature resolution
20-
--> $DIR/recursive-delegation-errors.rs:18:11
26+
--> $DIR/recursive-delegation-errors.rs:19:11
2127
|
2228
LL | reuse foo1 as foo2;
2329
| ^^^^
2430

2531
error: encountered a cycle during delegation signature resolution
26-
--> $DIR/recursive-delegation-errors.rs:20:11
32+
--> $DIR/recursive-delegation-errors.rs:21:11
2733
|
2834
LL | reuse foo2 as foo3;
2935
| ^^^^
3036

3137
error: encountered a cycle during delegation signature resolution
32-
--> $DIR/recursive-delegation-errors.rs:22:11
38+
--> $DIR/recursive-delegation-errors.rs:23:11
3339
|
3440
LL | reuse foo3 as foo4;
3541
| ^^^^
3642

3743
error: encountered a cycle during delegation signature resolution
38-
--> $DIR/recursive-delegation-errors.rs:24:11
44+
--> $DIR/recursive-delegation-errors.rs:25:11
3945
|
4046
LL | reuse foo4 as foo5;
4147
| ^^^^
4248

4349
error: encountered a cycle during delegation signature resolution
44-
--> $DIR/recursive-delegation-errors.rs:26:11
50+
--> $DIR/recursive-delegation-errors.rs:27:11
4551
|
4652
LL | reuse foo5 as foo;
4753
| ^^^^
4854

4955
error: encountered a cycle during delegation signature resolution
50-
--> $DIR/recursive-delegation-errors.rs:32:22
56+
--> $DIR/recursive-delegation-errors.rs:33:22
5157
|
5258
LL | reuse Trait::foo as bar;
5359
| ^^^
5460

5561
error: encountered a cycle during delegation signature resolution
56-
--> $DIR/recursive-delegation-errors.rs:35:22
62+
--> $DIR/recursive-delegation-errors.rs:36:22
5763
|
5864
LL | reuse Trait::bar as foo;
5965
| ^^^
6066

6167
error: encountered a cycle during delegation signature resolution
62-
--> $DIR/recursive-delegation-errors.rs:42:30
68+
--> $DIR/recursive-delegation-errors.rs:43:30
6369
|
6470
LL | reuse super::fifth_mod::{bar as foo, foo as bar};
6571
| ^^^
6672

6773
error: encountered a cycle during delegation signature resolution
68-
--> $DIR/recursive-delegation-errors.rs:42:42
74+
--> $DIR/recursive-delegation-errors.rs:43:42
6975
|
7076
LL | reuse super::fifth_mod::{bar as foo, foo as bar};
7177
| ^^^
7278

7379
error: encountered a cycle during delegation signature resolution
74-
--> $DIR/recursive-delegation-errors.rs:47:27
80+
--> $DIR/recursive-delegation-errors.rs:48:27
7581
|
7682
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
7783
| ^^^
7884

7985
error: encountered a cycle during delegation signature resolution
80-
--> $DIR/recursive-delegation-errors.rs:47:39
86+
--> $DIR/recursive-delegation-errors.rs:48:39
8187
|
8288
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
8389
| ^^^
8490

8591
error: encountered a cycle during delegation signature resolution
86-
--> $DIR/recursive-delegation-errors.rs:47:51
92+
--> $DIR/recursive-delegation-errors.rs:48:51
8793
|
8894
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
8995
| ^^^
9096

9197
error[E0283]: type annotations needed
92-
--> $DIR/recursive-delegation-errors.rs:32:22
98+
--> $DIR/recursive-delegation-errors.rs:33:22
9399
|
94100
LL | reuse Trait::foo as bar;
95101
| ^^^ cannot infer type
96102
|
97103
= note: the type must implement `fourth_mod::Trait`
98104

99105
error[E0283]: type annotations needed
100-
--> $DIR/recursive-delegation-errors.rs:35:22
106+
--> $DIR/recursive-delegation-errors.rs:36:22
101107
|
102108
LL | reuse Trait::bar as foo;
103109
| ^^^ cannot infer type
104110
|
105111
= note: the type must implement `fourth_mod::Trait`
106112

107113
error[E0283]: type annotations needed
108-
--> $DIR/recursive-delegation-errors.rs:47:27
114+
--> $DIR/recursive-delegation-errors.rs:48:27
109115
|
110116
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
111117
| ^^^ cannot infer type
112118
|
113119
= note: the type must implement `GlobReuse`
114120

115121
error[E0283]: type annotations needed
116-
--> $DIR/recursive-delegation-errors.rs:47:39
122+
--> $DIR/recursive-delegation-errors.rs:48:39
117123
|
118124
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
119125
| ^^^ cannot infer type
120126
|
121127
= note: the type must implement `GlobReuse`
122128

123129
error[E0283]: type annotations needed
124-
--> $DIR/recursive-delegation-errors.rs:47:51
130+
--> $DIR/recursive-delegation-errors.rs:48:51
125131
|
126132
LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
127133
| ^^^ cannot infer type
@@ -140,6 +146,6 @@ LL | reuse foo;
140146
= help: a `loop` may express intention better if this is on purpose
141147
= note: `#[warn(unconditional_recursion)]` on by default
142148

143-
error: aborting due to 20 previous errors; 1 warning emitted
149+
error: aborting due to 21 previous errors; 1 warning emitted
144150

145151
For more information about this error, try `rustc --explain E0283`.

tests/ui/delegation/unlowered-path-ice-154820.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(fn_delegation)]
22

3-
reuse foo:: < {
3+
reuse foo:: < { //~ ERROR: failed to resolve delegation callee
44
//~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied
55
fn foo() {}
66
reuse foo;

tests/ui/delegation/unlowered-path-ice-154820.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ LL | reuse foo;
88
|
99
= note: `foo` must be defined only once in the value namespace of this block
1010

11+
error: failed to resolve delegation callee
12+
--> $DIR/unlowered-path-ice-154820.rs:3:7
13+
|
14+
LL | reuse foo:: < {
15+
| ^^^
16+
1117
error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied
1218
--> $DIR/unlowered-path-ice-154820.rs:3:7
1319
|
@@ -28,7 +34,7 @@ note: function defined here, with 0 generic parameters
2834
LL | reuse foo:: < {
2935
| ^^^
3036

31-
error: aborting due to 2 previous errors
37+
error: aborting due to 3 previous errors
3238

3339
Some errors have detailed explanations: E0107, E0428.
3440
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)