forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#104614 - Nilstrieb:type-ascribe!, r=TaKO8Ki
Add `type_ascribe!` macro as placeholder syntax for type ascription This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription. I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether. Part of rust-lang#101728
- Loading branch information
Showing
32 changed files
with
265 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use rustc_ast::ptr::P; | ||
use rustc_ast::tokenstream::TokenStream; | ||
use rustc_ast::{token, Expr, ExprKind, Ty}; | ||
use rustc_errors::PResult; | ||
use rustc_expand::base::{self, DummyResult, ExtCtxt, MacEager}; | ||
use rustc_span::Span; | ||
|
||
pub fn expand_type_ascribe( | ||
cx: &mut ExtCtxt<'_>, | ||
span: Span, | ||
tts: TokenStream, | ||
) -> Box<dyn base::MacResult + 'static> { | ||
let (expr, ty) = match parse_ascribe(cx, tts) { | ||
Ok(parsed) => parsed, | ||
Err(mut err) => { | ||
err.emit(); | ||
return DummyResult::any(span); | ||
} | ||
}; | ||
|
||
let asc_expr = cx.expr(span, ExprKind::Type(expr, ty)); | ||
|
||
return MacEager::expr(asc_expr); | ||
} | ||
|
||
fn parse_ascribe<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Expr>, P<Ty>)> { | ||
let mut parser = cx.new_parser_from_tts(stream); | ||
|
||
let expr = parser.parse_expr()?; | ||
parser.expect(&token::Comma)?; | ||
|
||
let ty = parser.parse_ty()?; | ||
|
||
Ok((expr, ty)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,40 @@ | ||
error: comparison operators cannot be chained | ||
--> $DIR/issue-93835.rs:2:8 | ||
| | ||
LL | fn e() { | ||
| - while parsing this struct | ||
LL | p:a<p:p<e=6>> | ||
| ^ ^ | ||
| | ||
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments | ||
= help: or use `(...)` if you meant to specify fn arguments | ||
|
||
error[E0425]: cannot find value `p` in this scope | ||
--> $DIR/issue-93835.rs:2:5 | ||
| | ||
LL | p:a<p:p<e=6>> | ||
| ^ not found in this scope | ||
| | ||
help: you might have meant to write a `struct` literal | ||
| | ||
LL ~ fn e() { SomeStruct { | ||
LL | p:a<p:p<e=6>> | ||
... | ||
LL | | ||
LL ~ }} | ||
--> $DIR/issue-93835.rs:4:19 | ||
| | ||
help: maybe you meant to write a path separator here | ||
| | ||
LL | p::a<p:p<e=6>> | ||
| ~~ | ||
help: maybe you meant to write an assignment here | ||
| | ||
LL | let p:a<p:p<e=6>> | ||
| ~~~~~ | ||
LL | type_ascribe!(p, a<p:p<e=6>>); | ||
| ^ not found in this scope | ||
|
||
error[E0658]: associated const equality is incomplete | ||
--> $DIR/issue-93835.rs:2:13 | ||
error[E0412]: cannot find type `a` in this scope | ||
--> $DIR/issue-93835.rs:4:22 | ||
| | ||
LL | p:a<p:p<e=6>> | ||
| ^^^ | ||
LL | type_ascribe!(p, a<p:p<e=6>>); | ||
| ^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `p` in this scope | ||
--> $DIR/issue-93835.rs:4:26 | ||
| | ||
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information | ||
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable | ||
LL | type_ascribe!(p, a<p:p<e=6>>); | ||
| ^ not found in this scope | ||
|
||
error[E0658]: associated const equality is incomplete | ||
--> $DIR/issue-93835.rs:2:13 | ||
--> $DIR/issue-93835.rs:4:28 | ||
| | ||
LL | p:a<p:p<e=6>> | ||
| ^^^ | ||
LL | type_ascribe!(p, a<p:p<e=6>>); | ||
| ^^^ | ||
| | ||
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information | ||
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable | ||
|
||
error[E0658]: associated type bounds are unstable | ||
--> $DIR/issue-93835.rs:2:9 | ||
--> $DIR/issue-93835.rs:4:24 | ||
| | ||
LL | p:a<p:p<e=6>> | ||
| ^^^^^^^^ | ||
LL | type_ascribe!(p, a<p:p<e=6>>); | ||
| ^^^^^^^^ | ||
| | ||
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information | ||
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0658. | ||
For more information about an error, try `rustc --explain E0425`. | ||
Some errors have detailed explanations: E0405, E0412, E0425, E0658. | ||
For more information about an error, try `rustc --explain E0405`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#![feature(type_ascription)] | ||
|
||
fn main() { | ||
2: n([u8; || 1]) | ||
type_ascribe!(2, n([u8; || 1])) | ||
//~^ ERROR cannot find type `n` in this scope | ||
//~| ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.