Skip to content

Commit 7bd3d6c

Browse files
authoredJan 28, 2021
Rollup merge of rust-lang#79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir` In the continuation of rust-lang#79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2 parents e9b2cf4 + dce2262 commit 7bd3d6c

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed
 

‎clippy_lints/src/bytecount.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use crate::utils::{
22
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
33
};
44
use if_chain::if_chain;
5-
use rustc_ast::ast::UintTy;
65
use rustc_errors::Applicability;
76
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp};
87
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty;
8+
use rustc_middle::ty::{self, UintTy};
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110
use rustc_span::sym;
1211
use rustc_span::Symbol;

‎clippy_lints/src/consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
use crate::utils::{clip, sext, unsext};
44
use if_chain::if_chain;
5-
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
5+
use rustc_ast::ast::{self, LitFloatType, LitKind};
66
use rustc_data_structures::sync::Lrc;
77
use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp};
99
use rustc_lint::LateContext;
1010
use rustc_middle::mir::interpret::Scalar;
1111
use rustc_middle::ty::subst::{Subst, SubstsRef};
12-
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt};
1313
use rustc_middle::{bug, span_bug};
1414
use rustc_span::symbol::Symbol;
1515
use std::cmp::Ordering::{self, Equal};
@@ -167,8 +167,8 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
167167
LitKind::Char(c) => Constant::Char(c),
168168
LitKind::Int(n, _) => Constant::Int(n),
169169
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
170-
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
171-
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
170+
ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
171+
ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
172172
},
173173
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() {
174174
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),

‎clippy_lints/src/enum_clike.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
44
use crate::consts::{miri_to_const, Constant};
55
use crate::utils::span_lint;
6-
use rustc_ast::ast::{IntTy, UintTy};
76
use rustc_hir::{Item, ItemKind};
87
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty;
8+
use rustc_middle::ty::{self, IntTy, UintTy};
109
use rustc_middle::ty::util::IntTypeExt;
1110
use rustc_session::{declare_lint_pass, declare_tool_lint};
1211
use std::convert::TryFrom;

‎clippy_lints/src/float_literal.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::utils::{numeric_literal, span_lint_and_sugg};
22
use if_chain::if_chain;
3-
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
3+
use rustc_ast::ast::{self, LitFloatType, LitKind};
44
use rustc_errors::Applicability;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty;
7+
use rustc_middle::ty::{self, FloatTy};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use std::fmt;
1010

@@ -75,8 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
7575
let digits = count_digits(&sym_str);
7676
let max = max_digits(fty);
7777
let type_suffix = match lit_float_ty {
78-
LitFloatType::Suffixed(FloatTy::F32) => Some("f32"),
79-
LitFloatType::Suffixed(FloatTy::F64) => Some("f64"),
78+
LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"),
79+
LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"),
8080
LitFloatType::Unsuffixed => None
8181
};
8282
let (is_whole, mut float_str) = match fty {

‎clippy_lints/src/mutex_atomic.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This lint is **warn** by default
44
55
use crate::utils::{is_type_diagnostic_item, span_lint};
6-
use rustc_ast::ast;
76
use rustc_hir::Expr;
87
use rustc_lint::{LateContext, LateLintPass};
98
use rustc_middle::ty::{self, Ty};
@@ -77,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex {
7776
atomic_name
7877
);
7978
match *mutex_param.kind() {
80-
ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
81-
ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
79+
ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
80+
ty::Int(t) if t != ty::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
8281
_ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg),
8382
};
8483
}

‎clippy_lints/src/transmute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
443443
);
444444
},
445445
),
446-
(ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => {
446+
(ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => {
447447
span_lint_and_then(
448448
cx,
449449
TRANSMUTE_INT_TO_CHAR,
@@ -468,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
468468
(ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => {
469469
if_chain! {
470470
if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind());
471-
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind();
471+
if let ty::Uint(ty::UintTy::U8) = slice_ty.kind();
472472
if from_mutbl == to_mutbl;
473473
then {
474474
let postfix = if *from_mutbl == Mutability::Mut {
@@ -536,7 +536,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
536536
}
537537
},
538538
),
539-
(ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => {
539+
(ty::Int(ty::IntTy::I8) | ty::Uint(ty::UintTy::U8), ty::Bool) => {
540540
span_lint_and_then(
541541
cx,
542542
TRANSMUTE_INT_TO_BOOL,

‎clippy_lints/src/types.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::cmp::Ordering;
55
use std::collections::BTreeMap;
66

77
use if_chain::if_chain;
8-
use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
8+
use rustc_ast::{LitFloatType, LitIntType, LitKind};
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir as hir;
1111
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
@@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
1818
use rustc_middle::hir::map::Map;
1919
use rustc_middle::lint::in_external_macro;
2020
use rustc_middle::ty::TypeFoldable;
21-
use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults};
21+
use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults, UintTy};
2222
use rustc_semver::RustcVersion;
2323
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
2424
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -1106,9 +1106,7 @@ fn is_empty_block(expr: &Expr<'_>) -> bool {
11061106
expr.kind,
11071107
ExprKind::Block(
11081108
Block {
1109-
stmts: &[],
1110-
expr: None,
1111-
..
1109+
stmts: &[], expr: None, ..
11121110
},
11131111
_,
11141112
)

‎clippy_lints/src/utils/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::mem;
3535

3636
use if_chain::if_chain;
3737
use rustc_ast::ast::{self, Attribute, LitKind};
38-
use rustc_attr as attr;
3938
use rustc_data_structures::fx::FxHashMap;
4039
use rustc_errors::Applicability;
4140
use rustc_hir as hir;
@@ -1224,27 +1223,27 @@ pub fn get_arg_name(pat: &Pat<'_>) -> Option<Symbol> {
12241223
}
12251224
}
12261225

1227-
pub fn int_bits(tcx: TyCtxt<'_>, ity: ast::IntTy) -> u64 {
1228-
Integer::from_attr(&tcx, attr::IntType::SignedInt(ity)).size().bits()
1226+
pub fn int_bits(tcx: TyCtxt<'_>, ity: ty::IntTy) -> u64 {
1227+
Integer::from_int_ty(&tcx, ity).size().bits()
12291228
}
12301229

12311230
#[allow(clippy::cast_possible_wrap)]
12321231
/// Turn a constant int byte representation into an i128
1233-
pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ast::IntTy) -> i128 {
1232+
pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ty::IntTy) -> i128 {
12341233
let amt = 128 - int_bits(tcx, ity);
12351234
((u as i128) << amt) >> amt
12361235
}
12371236

12381237
#[allow(clippy::cast_sign_loss)]
12391238
/// clip unused bytes
1240-
pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ast::IntTy) -> u128 {
1239+
pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ty::IntTy) -> u128 {
12411240
let amt = 128 - int_bits(tcx, ity);
12421241
((u as u128) << amt) >> amt
12431242
}
12441243

12451244
/// clip unused bytes
1246-
pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ast::UintTy) -> u128 {
1247-
let bits = Integer::from_attr(&tcx, attr::IntType::UnsignedInt(ity)).size().bits();
1245+
pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ty::UintTy) -> u128 {
1246+
let bits = Integer::from_uint_ty(&tcx, ity).size().bits();
12481247
let amt = 128 - bits;
12491248
(u << amt) >> amt
12501249
}

0 commit comments

Comments
 (0)
Please sign in to comment.