Skip to content

Commit 7d5b746

Browse files
committed
Auto merge of #111350 - chenyukang:yukang-remove-type-asc, r=Nilstrieb
Remove leftover of type ascription feature gating Fixes #111325 r? `@Nilstrieb`
2 parents dff88b2 + 8baa32f commit 7d5b746

File tree

3 files changed

+3
-54
lines changed

3 files changed

+3
-54
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-49
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId};
44
use rustc_ast::{PatKind, RangeEnd};
5-
use rustc_errors::{Applicability, StashKey};
65
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
76
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
87
use rustc_session::Session;
@@ -374,55 +373,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
374373
}
375374
}
376375

377-
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
378-
if let ast::StmtKind::Semi(expr) = &stmt.kind
379-
&& let ast::ExprKind::Assign(lhs, _, _) = &expr.kind
380-
&& let ast::ExprKind::Type(..) = lhs.kind
381-
&& self.sess.parse_sess.span_diagnostic.err_count() == 0
382-
&& !self.features.type_ascription
383-
&& !lhs.span.allows_unstable(sym::type_ascription)
384-
{
385-
// When we encounter a statement of the form `foo: Ty = val;`, this will emit a type
386-
// ascription error, but the likely intention was to write a `let` statement. (#78907).
387-
feature_err(
388-
&self.sess.parse_sess,
389-
sym::type_ascription,
390-
lhs.span,
391-
"type ascription is experimental",
392-
).span_suggestion_verbose(
393-
lhs.span.shrink_to_lo(),
394-
"you might have meant to introduce a new binding",
395-
"let ",
396-
Applicability::MachineApplicable,
397-
).emit();
398-
}
399-
visit::walk_stmt(self, stmt);
400-
}
401-
402376
fn visit_expr(&mut self, e: &'a ast::Expr) {
403377
match e.kind {
404-
ast::ExprKind::Type(..) => {
405-
if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
406-
// To avoid noise about type ascription in common syntax errors,
407-
// only emit if it is the *only* error.
408-
gate_feature_post!(
409-
&self,
410-
type_ascription,
411-
e.span,
412-
"type ascription is experimental"
413-
);
414-
} else {
415-
// And if it isn't, cancel the early-pass warning.
416-
if let Some(err) = self
417-
.sess
418-
.parse_sess
419-
.span_diagnostic
420-
.steal_diagnostic(e.span, StashKey::EarlySyntaxWarning)
421-
{
422-
err.cancel()
423-
}
424-
}
425-
}
426378
ast::ExprKind::TryBlock(_) => {
427379
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
428380
}
@@ -629,7 +581,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
629581
gate_all!(box_patterns, "box pattern syntax is experimental");
630582
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
631583
gate_all!(try_blocks, "`try` blocks are unstable");
632-
gate_all!(type_ascription, "type ascription is experimental");
633584

634585
visit::walk_crate(&mut visitor, krate);
635586
}

compiler/rustc_hir_typeck/src/cast.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
689689
fn trivial_cast_lint(&self, fcx: &FnCtxt<'a, 'tcx>) {
690690
let t_cast = self.cast_ty;
691691
let t_expr = self.expr_ty;
692-
let type_asc_or =
693-
if fcx.tcx.features().type_ascription { "type ascription or " } else { "" };
694692
let (adjective, lint) = if t_cast.is_numeric() && t_expr.is_numeric() {
695693
("numeric ", lint::builtin::TRIVIAL_NUMERIC_CASTS)
696694
} else {
@@ -711,7 +709,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
711709
|lint| {
712710
lint.help(format!(
713711
"cast can be replaced by coercion; this might \
714-
require {type_asc_or}a temporary variable"
712+
require a temporary variable"
715713
))
716714
},
717715
);

tests/ui/lint/trivial-casts-featuring-type-ascription.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: trivial numeric cast: `i32` as `i32`
44
LL | let lugubrious = 12i32 as i32;
55
| ^^^^^^^^^^^^
66
|
7-
= help: cast can be replaced by coercion; this might require type ascription or a temporary variable
7+
= help: cast can be replaced by coercion; this might require a temporary variable
88
note: the lint level is defined here
99
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:24
1010
|
@@ -17,7 +17,7 @@ error: trivial cast: `&u32` as `*const u32`
1717
LL | let _ = haunted as *const u32;
1818
| ^^^^^^^^^^^^^^^^^^^^^
1919
|
20-
= help: cast can be replaced by coercion; this might require type ascription or a temporary variable
20+
= help: cast can be replaced by coercion; this might require a temporary variable
2121
note: the lint level is defined here
2222
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:9
2323
|

0 commit comments

Comments
 (0)