Skip to content

Commit

Permalink
Make sure we deny unimplemented RTN on qpath segments
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 28, 2024
1 parent b1a0c0b commit 82b4af7
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ast_lowering_bad_return_type_notation_output =
return type not allowed with return type notation
.suggestion = remove the return type
ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet
ast_lowering_base_expression_double_dot =
base expression required after `..`
.suggestion = add a base expression here
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ pub enum BadReturnTypeNotation {
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
span: Span,
},
#[diag(ast_lowering_bad_return_type_notation_position)]
Position {
#[primary_span]
span: Span,
},
}

#[derive(Diagnostic)]
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::ImplTraitPosition;

use super::errors::{
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, BadReturnTypeNotation,
GenericTypeWithParentheses, UseAngleBrackets,
};
use super::ResolverAstLoweringExt;
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
Expand Down Expand Up @@ -276,8 +277,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
}
},
GenericArgs::ParenthesizedElided(_span) => {
todo!()
GenericArgs::ParenthesizedElided(span) => {
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
(
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: *span,
},
false,
)
}
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/associated-type-bounds/return-type-notation/bare-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![feature(return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete

trait Tr {
const CONST: usize;

fn method() -> impl Sized;
}

fn foo<T: Tr>()
where
T::method(..): Send,
//~^ ERROR return type notation not allowed in this position yet
//~| ERROR expected type, found function
<T as Tr>::method(..): Send,
//~^ ERROR return type notation not allowed in this position yet
//~| ERROR expected associated type, found associated function `Tr::method`
{
let _ = T::CONST::(..);
//~^ ERROR return type notation not allowed in this position yet
let _: T::method(..);
//~^ ERROR return type notation not allowed in this position yet
//~| ERROR expected type, found function
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
error[E0575]: expected associated type, found associated function `Tr::method`
--> $DIR/bare-path.rs:15:5
|
LL | <T as Tr>::method(..): Send,
| ^^^^^^^^^^^^^^^^^^^^^ not a associated type

warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bare-path.rs:1:12
|
LL | #![feature(return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= note: `#[warn(incomplete_features)]` on by default

error: return type notation not allowed in this position yet
--> $DIR/bare-path.rs:19:23
|
LL | let _ = T::CONST::(..);
| ^^^^

error: return type notation not allowed in this position yet
--> $DIR/bare-path.rs:21:21
|
LL | let _: T::method(..);
| ^^^^

error: return type notation not allowed in this position yet
--> $DIR/bare-path.rs:12:14
|
LL | T::method(..): Send,
| ^^^^

error: return type notation not allowed in this position yet
--> $DIR/bare-path.rs:15:22
|
LL | <T as Tr>::method(..): Send,
| ^^^^

error: expected type, found function
--> $DIR/bare-path.rs:12:8
|
LL | T::method(..): Send,
| ^^^^^^ unexpected function
|
note: the associated function is defined here
--> $DIR/bare-path.rs:7:5
|
LL | fn method() -> impl Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: expected type, found function
--> $DIR/bare-path.rs:21:15
|
LL | let _: T::method(..);
| ^^^^^^ unexpected function
|
note: the associated function is defined here
--> $DIR/bare-path.rs:7:5
|
LL | fn method() -> impl Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 7 previous errors; 1 warning emitted

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

0 comments on commit 82b4af7

Please sign in to comment.