diff options
| author | Michael Goulet <michael@errs.io> | 2024-06-28 14:10:32 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-06-28 14:20:44 -0400 |
| commit | 82b4af7511a430e53d2ed554771754552e5ecca8 (patch) | |
| tree | 4f96c357ea42862265110fbd7b7974a69fc820c9 | |
| parent | b1a0c0b1231a554d4ae699221a80a6e2f81bac4d (diff) | |
| download | rust-82b4af7511a430e53d2ed554771754552e5ecca8.tar.gz rust-82b4af7511a430e53d2ed554771754552e5ecca8.zip | |
Make sure we deny unimplemented RTN on qpath segments
5 files changed, 112 insertions, 3 deletions
diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index d6eb344fd1d..9ed93d481e7 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -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 diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 6699c6e75f5..4c77892a6b7 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -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)] diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 1efa5bd3c4c..c6c08649374 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -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}; @@ -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 { diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs new file mode 100644 index 00000000000..f507d82afec --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.rs @@ -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() {} diff --git a/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr new file mode 100644 index 00000000000..cb45de59c7e --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/bare-path.stderr @@ -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`. |
