Skip to content

Commit 82b4af7

Browse files
Make sure we deny unimplemented RTN on qpath segments
1 parent b1a0c0b commit 82b4af7

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

compiler/rustc_ast_lowering/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ ast_lowering_bad_return_type_notation_output =
4343
return type not allowed with return type notation
4444
.suggestion = remove the return type
4545
46+
ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet
47+
4648
ast_lowering_base_expression_double_dot =
4749
base expression required after `..`
4850
.suggestion = add a base expression here

compiler/rustc_ast_lowering/src/errors.rs

+5
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ pub enum BadReturnTypeNotation {
399399
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
400400
span: Span,
401401
},
402+
#[diag(ast_lowering_bad_return_type_notation_position)]
403+
Position {
404+
#[primary_span]
405+
span: Span,
406+
},
402407
}
403408

404409
#[derive(Diagnostic)]

compiler/rustc_ast_lowering/src/path.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::ImplTraitPosition;
22

33
use super::errors::{
4-
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,
4+
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, BadReturnTypeNotation,
5+
GenericTypeWithParentheses, UseAngleBrackets,
56
};
67
use super::ResolverAstLoweringExt;
78
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
@@ -276,8 +277,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
276277
)
277278
}
278279
},
279-
GenericArgs::ParenthesizedElided(_span) => {
280-
todo!()
280+
GenericArgs::ParenthesizedElided(span) => {
281+
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
282+
(
283+
GenericArgsCtor {
284+
args: Default::default(),
285+
constraints: &[],
286+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
287+
span: *span,
288+
},
289+
false,
290+
)
281291
}
282292
}
283293
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(return_type_notation)]
2+
//~^ WARN the feature `return_type_notation` is incomplete
3+
4+
trait Tr {
5+
const CONST: usize;
6+
7+
fn method() -> impl Sized;
8+
}
9+
10+
fn foo<T: Tr>()
11+
where
12+
T::method(..): Send,
13+
//~^ ERROR return type notation not allowed in this position yet
14+
//~| ERROR expected type, found function
15+
<T as Tr>::method(..): Send,
16+
//~^ ERROR return type notation not allowed in this position yet
17+
//~| ERROR expected associated type, found associated function `Tr::method`
18+
{
19+
let _ = T::CONST::(..);
20+
//~^ ERROR return type notation not allowed in this position yet
21+
let _: T::method(..);
22+
//~^ ERROR return type notation not allowed in this position yet
23+
//~| ERROR expected type, found function
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
error[E0575]: expected associated type, found associated function `Tr::method`
2+
--> $DIR/bare-path.rs:15:5
3+
|
4+
LL | <T as Tr>::method(..): Send,
5+
| ^^^^^^^^^^^^^^^^^^^^^ not a associated type
6+
7+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
8+
--> $DIR/bare-path.rs:1:12
9+
|
10+
LL | #![feature(return_type_notation)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
|
13+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
14+
= note: `#[warn(incomplete_features)]` on by default
15+
16+
error: return type notation not allowed in this position yet
17+
--> $DIR/bare-path.rs:19:23
18+
|
19+
LL | let _ = T::CONST::(..);
20+
| ^^^^
21+
22+
error: return type notation not allowed in this position yet
23+
--> $DIR/bare-path.rs:21:21
24+
|
25+
LL | let _: T::method(..);
26+
| ^^^^
27+
28+
error: return type notation not allowed in this position yet
29+
--> $DIR/bare-path.rs:12:14
30+
|
31+
LL | T::method(..): Send,
32+
| ^^^^
33+
34+
error: return type notation not allowed in this position yet
35+
--> $DIR/bare-path.rs:15:22
36+
|
37+
LL | <T as Tr>::method(..): Send,
38+
| ^^^^
39+
40+
error: expected type, found function
41+
--> $DIR/bare-path.rs:12:8
42+
|
43+
LL | T::method(..): Send,
44+
| ^^^^^^ unexpected function
45+
|
46+
note: the associated function is defined here
47+
--> $DIR/bare-path.rs:7:5
48+
|
49+
LL | fn method() -> impl Sized;
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
52+
error: expected type, found function
53+
--> $DIR/bare-path.rs:21:15
54+
|
55+
LL | let _: T::method(..);
56+
| ^^^^^^ unexpected function
57+
|
58+
note: the associated function is defined here
59+
--> $DIR/bare-path.rs:7:5
60+
|
61+
LL | fn method() -> impl Sized;
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
64+
error: aborting due to 7 previous errors; 1 warning emitted
65+
66+
For more information about this error, try `rustc --explain E0575`.

0 commit comments

Comments
 (0)