Skip to content

Commit c63b6a4

Browse files
Noratriebchenyukang
authored andcommitted
Rip it out
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
1 parent 2034b6d commit c63b6a4

File tree

97 files changed

+946
-949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+946
-949
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ pub enum ClosureBinder {
15891589
pub struct MacCall {
15901590
pub path: Path,
15911591
pub args: P<DelimArgs>,
1592-
pub prior_type_ascription: Option<(Span, bool)>,
15931592
}
15941593

15951594
impl MacCall {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
631631
}
632632

633633
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
634-
let MacCall { path, args, prior_type_ascription: _ } = mac;
634+
let MacCall { path, args } = mac;
635635
vis.visit_path(path);
636636
visit_delim_args(args, vis);
637637
}

compiler/rustc_ast/src/util/parser.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ pub enum AssocOp {
5353
DotDot,
5454
/// `..=` range
5555
DotDotEq,
56-
/// `:`
57-
Colon,
5856
}
5957

6058
#[derive(PartialEq, Debug)]
@@ -96,7 +94,6 @@ impl AssocOp {
9694
token::DotDotEq => Some(DotDotEq),
9795
// DotDotDot is no longer supported, but we need some way to display the error
9896
token::DotDotDot => Some(DotDotEq),
99-
token::Colon => Some(Colon),
10097
// `<-` should probably be `< -`
10198
token::LArrow => Some(Less),
10299
_ if t.is_keyword(kw::As) => Some(As),
@@ -133,7 +130,7 @@ impl AssocOp {
133130
pub fn precedence(&self) -> usize {
134131
use AssocOp::*;
135132
match *self {
136-
As | Colon => 14,
133+
As => 14,
137134
Multiply | Divide | Modulus => 13,
138135
Add | Subtract => 12,
139136
ShiftLeft | ShiftRight => 11,
@@ -156,7 +153,7 @@ impl AssocOp {
156153
Assign | AssignOp(_) => Fixity::Right,
157154
As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd
158155
| BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual
159-
| LAnd | LOr | Colon => Fixity::Left,
156+
| LAnd | LOr => Fixity::Left,
160157
DotDot | DotDotEq => Fixity::None,
161158
}
162159
}
@@ -166,8 +163,9 @@ impl AssocOp {
166163
match *self {
167164
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
168165
Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract
169-
| ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | DotDotEq
170-
| Colon => false,
166+
| ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | DotDotEq => {
167+
false
168+
}
171169
}
172170
}
173171

@@ -177,7 +175,7 @@ impl AssocOp {
177175
Assign | AssignOp(_) => true,
178176
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply
179177
| Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor
180-
| BitOr | LAnd | LOr | DotDot | DotDotEq | Colon => false,
178+
| BitOr | LAnd | LOr | DotDot | DotDotEq => false,
181179
}
182180
}
183181

@@ -202,7 +200,7 @@ impl AssocOp {
202200
BitOr => Some(BinOpKind::BitOr),
203201
LAnd => Some(BinOpKind::And),
204202
LOr => Some(BinOpKind::Or),
205-
Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None,
203+
Assign | AssignOp(_) | As | DotDot | DotDotEq => None,
206204
}
207205
}
208206

@@ -223,10 +221,9 @@ impl AssocOp {
223221
Greater | // `{ 42 } > 3`
224222
GreaterEqual | // `{ 42 } >= 3`
225223
AssignOp(_) | // `{ 42 } +=`
226-
As | // `{ 42 } as usize`
227224
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
228-
// NotEqual | // `{ 42 } != { 42 }` struct literals parser recovery.
229-
Colon, // `{ 42 }: usize`
225+
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
226+
As // `{ 42 } as usize`
230227
)
231228
}
232229
}
@@ -254,7 +251,6 @@ pub enum ExprPrecedence {
254251
Binary(BinOpKind),
255252

256253
Cast,
257-
Type,
258254

259255
Assign,
260256
AssignOp,
@@ -313,7 +309,6 @@ impl ExprPrecedence {
313309
// Binop-like expr kinds, handled by `AssocOp`.
314310
ExprPrecedence::Binary(op) => AssocOp::from_ast_binop(op).precedence() as i8,
315311
ExprPrecedence::Cast => AssocOp::As.precedence() as i8,
316-
ExprPrecedence::Type => AssocOp::Colon.precedence() as i8,
317312

318313
ExprPrecedence::Assign |
319314
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,16 @@ impl<'a> State<'a> {
341341
self.print_type(ty);
342342
}
343343
ast::ExprKind::Type(expr, ty) => {
344-
let prec = AssocOp::Colon.precedence() as i8;
345-
self.print_expr_maybe_paren(expr, prec);
346-
self.word_space(":");
344+
self.word("type_ascribe!(");
345+
self.ibox(0);
346+
self.print_expr(expr);
347+
348+
self.word(",");
349+
self.space_if_not_bol();
347350
self.print_type(ty);
351+
352+
self.end();
353+
self.word(")");
348354
}
349355
ast::ExprKind::Let(pat, scrutinee, _) => {
350356
self.print_let(pat, scrutinee);

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub fn parse_asm_args<'a>(
6969
if allow_templates {
7070
// After a template string, we always expect *only* a comma...
7171
let mut err = diag.create_err(errors::AsmExpectedComma { span: p.token.span });
72-
p.maybe_annotate_with_ascription(&mut err, false);
7372
return Err(err);
7473
} else {
7574
// ...after that delegate to `expect` to also include the other expected tokens.

compiler/rustc_builtin_macros/src/assert.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub fn expand_assert<'cx>(
6161
delim: MacDelimiter::Parenthesis,
6262
tokens,
6363
}),
64-
prior_type_ascription: None,
6564
})),
6665
);
6766
expr_if_not(cx, call_site_span, cond_expr, then, None)

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ impl<'cx, 'a> Context<'cx, 'a> {
182182
delim: MacDelimiter::Parenthesis,
183183
tokens: initial.into_iter().chain(captures).collect::<TokenStream>(),
184184
}),
185-
prior_type_ascription: None,
186185
})),
187186
)
188187
}

compiler/rustc_builtin_macros/src/edition_panic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ fn expand<'cx>(
6363
delim: MacDelimiter::Parenthesis,
6464
tokens: tts,
6565
}),
66-
prior_type_ascription: None,
6766
})),
6867
),
6968
)

compiler/rustc_expand/src/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ pub struct ExpansionData {
992992
pub depth: usize,
993993
pub module: Rc<ModuleData>,
994994
pub dir_ownership: DirOwnership,
995-
pub prior_type_ascription: Option<(Span, bool)>,
996995
/// Some parent node that is close to this macro call
997996
pub lint_node_id: NodeId,
998997
pub is_trailing_mac: bool,
@@ -1043,7 +1042,6 @@ impl<'a> ExtCtxt<'a> {
10431042
depth: 0,
10441043
module: Default::default(),
10451044
dir_ownership: DirOwnership::Owned { relative: None },
1046-
prior_type_ascription: None,
10471045
lint_node_id: ast::CRATE_NODE_ID,
10481046
is_trailing_mac: false,
10491047
},

compiler/rustc_expand/src/expand.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
657657
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span)
658658
}
659659
SyntaxExtensionKind::LegacyBang(expander) => {
660-
let prev = self.cx.current_expansion.prior_type_ascription;
661-
self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription;
662660
let tok_result = expander.expand(self.cx, span, mac.args.tokens.clone());
663661
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
664662
result
665663
} else {
666664
self.error_wrong_fragment_kind(fragment_kind, &mac, span);
667665
fragment_kind.dummy(span)
668666
};
669-
self.cx.current_expansion.prior_type_ascription = prev;
670667
result
671668
}
672669
_ => unreachable!(),

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ fn expand_macro<'cx>(
250250
trace_macros_note(&mut cx.expansions, sp, msg);
251251
}
252252

253-
let mut p = Parser::new(sess, tts, false, None);
254-
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
253+
let p = Parser::new(sess, tts, false, None);
255254

256255
if is_local {
257256
cx.resolver.record_macro_rule_usage(node_id, i);

compiler/rustc_expand/src/placeholders.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn placeholder(
2121
delim: ast::MacDelimiter::Parenthesis,
2222
tokens: ast::tokenstream::TokenStream::new(Vec::new()),
2323
}),
24-
prior_type_ascription: None,
2524
})
2625
}
2726

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,10 +1407,16 @@ impl<'a> State<'a> {
14071407
self.print_type(ty);
14081408
}
14091409
hir::ExprKind::Type(expr, ty) => {
1410-
let prec = AssocOp::Colon.precedence() as i8;
1411-
self.print_expr_maybe_paren(expr, prec);
1412-
self.word_space(":");
1410+
self.word("type_ascribe!(");
1411+
self.ibox(0);
1412+
self.print_expr(expr);
1413+
1414+
self.word(",");
1415+
self.space_if_not_bol();
14131416
self.print_type(ty);
1417+
1418+
self.end();
1419+
self.word(")");
14141420
}
14151421
hir::ExprKind::DropTemps(init) => {
14161422
// Print `{`:

compiler/rustc_parse/messages.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ parse_maybe_fn_typo_with_impl = you might have meant to write `impl` instead of
420420
parse_expected_fn_path_found_fn_keyword = expected identifier, found keyword `fn`
421421
.suggestion = use `Fn` to refer to the trait
422422
423+
parse_path_single_colon = path separator must be a double colon
424+
.suggestion = use a double colon instead
425+
426+
parse_colon_as_semi = statements are terminated with a semicolon
427+
.suggestion = use a semicolon instead
428+
429+
parse_type_ascription_removed = type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
430+
423431
parse_where_clause_before_tuple_struct_body = where clauses are not allowed before tuple struct bodies
424432
.label = unexpected where clause
425433
.name_label = while parsing this tuple struct

compiler/rustc_parse/src/errors.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,28 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword {
13401340
pub fn_token_span: Span,
13411341
}
13421342

1343+
#[derive(Diagnostic)]
1344+
#[diag(parse_path_single_colon)]
1345+
pub(crate) struct PathSingleColon {
1346+
#[primary_span]
1347+
#[suggestion(applicability = "machine-applicable", code = "::")]
1348+
pub span: Span,
1349+
1350+
#[note(parse_type_ascription_removed)]
1351+
pub type_ascription: Option<()>,
1352+
}
1353+
1354+
#[derive(Diagnostic)]
1355+
#[diag(parse_colon_as_semi)]
1356+
pub(crate) struct ColonAsSemi {
1357+
#[primary_span]
1358+
#[suggestion(applicability = "machine-applicable", code = ";")]
1359+
pub span: Span,
1360+
1361+
#[note(parse_type_ascription_removed)]
1362+
pub type_ascription: Option<()>,
1363+
}
1364+
13431365
#[derive(Diagnostic)]
13441366
#[diag(parse_where_clause_before_tuple_struct_body)]
13451367
pub(crate) struct WhereClauseBeforeTupleStructBody {

0 commit comments

Comments
 (0)