Skip to content

Commit 6883244

Browse files
committed
Remove maybe_typeck_results from LateContext.
1 parent 8df0dbc commit 6883244

9 files changed

Lines changed: 11 additions & 16 deletions

File tree

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx> TypeInformationCtxt<'tcx> for (&LateContext<'tcx>, LocalDefId) {
234234
type Error = !;
235235

236236
fn typeck_results(&self) -> Self::TypeckResults<'_> {
237-
self.0.maybe_typeck_results().expect("expected typeck results")
237+
self.0.typeck_results()
238238
}
239239

240240
fn structurally_resolve_type(&self, _span: Span, ty: Ty<'tcx>) -> Ty<'tcx> {

compiler/rustc_lint/src/context.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,10 @@ impl<'tcx> LateContext<'tcx> {
659659
self.tcx.type_is_use_cloned_modulo_regions(self.typing_env(), ty)
660660
}
661661

662-
/// Gets the type-checking results for the current body,
663-
/// or `None` if outside a body.
664-
pub fn maybe_typeck_results(&self) -> Option<&'tcx ty::TypeckResults<'tcx>> {
665-
self.typeck_results
666-
}
667-
668662
/// Gets the type-checking results for the current body.
669663
/// As this will ICE if called outside bodies, only call when working with
670664
/// `Expr` or `Pat` nodes (they are guaranteed to be found only in bodies).
665+
#[inline]
671666
#[track_caller]
672667
pub fn typeck_results(&self) -> &'tcx ty::TypeckResults<'tcx> {
673668
self.typeck_results.expect("`LateContext::typeck_results` called outside of body")
@@ -680,7 +675,7 @@ impl<'tcx> LateContext<'tcx> {
680675
match *qpath {
681676
hir::QPath::Resolved(_, path) => path.res,
682677
hir::QPath::TypeRelative(..) => self
683-
.maybe_typeck_results()
678+
.typeck_results
684679
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
685680
.or_else(|| {
686681
self.tcx

compiler/rustc_lint/src/unit_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitBindings {
5353
// - explicitly wrote `let pat = ();`
5454
// - explicitly wrote `let () = init;`.
5555
if !local.span.from_expansion()
56-
&& let Some(tyck_results) = cx.maybe_typeck_results()
56+
&& let Some(tyck_results) = cx.typeck_results
5757
&& let Some(init) = local.init
5858
&& let init_ty = tyck_results.expr_ty(init)
5959
&& let local_ty = tyck_results.node_type(local.hir_id)

src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn check_raw_ptr<'tcx>(
7878
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
7979
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
8080
&arg.pat.kind,
81-
cx.maybe_typeck_results()
81+
cx.typeck_results
8282
.map(|typeck_results| typeck_results.pat_ty(arg.pat).kind()),
8383
) {
8484
Some(id)

src/tools/clippy/clippy_lints/src/implicit_hasher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
303303
fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self {
304304
Self {
305305
cx,
306-
maybe_typeck_results: cx.maybe_typeck_results(),
306+
maybe_typeck_results: cx.typeck_results,
307307
target,
308308
suggestions: BTreeMap::new(),
309309
}

src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl PassByRefOrValue {
174174
&& size <= self.ref_min_size
175175
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
176176
{
177-
if let Some(typeck) = cx.maybe_typeck_results()
177+
if let Some(typeck) = cx.typeck_results
178178
// Don't lint if a raw pointer is created.
179179
// TODO: Limit the check only to raw pointers to the argument (or part of the argument)
180180
// which escape the current function.

src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
6969
pub fn new(cx: &'a LateContext<'tcx>) -> Self {
7070
Self {
7171
cx,
72-
maybe_typeck_results: cx.maybe_typeck_results().map(|x| (x, x)),
72+
maybe_typeck_results: cx.typeck_results.map(|x| (x, x)),
7373
allow_side_effects: true,
7474
expr_fallback: None,
7575
path_check: PathCheck::default(),
@@ -1140,7 +1140,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11401140
pub fn new(cx: &'a LateContext<'tcx>) -> Self {
11411141
Self {
11421142
cx,
1143-
maybe_typeck_results: cx.maybe_typeck_results(),
1143+
maybe_typeck_results: cx.typeck_results,
11441144
s: FxHasher::default(),
11451145
path_check: PathCheck::default(),
11461146
}

src/tools/clippy/clippy_utils/src/res.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx> MaybeTypeckRes<'tcx> for LateContext<'tcx> {
7272
#[inline]
7373
#[cfg_attr(debug_assertions, track_caller)]
7474
fn typeck_res(&self) -> Option<&TypeckResults<'tcx>> {
75-
if let Some(typeck) = self.maybe_typeck_results() {
75+
if let Some(typeck) = self.typeck_results {
7676
Some(typeck)
7777
} else {
7878
// It's possible to get the `TypeckResults` for any other body, but

src/tools/clippy/clippy_utils/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub use type_certainty::expr_type_is_certain;
4141

4242
/// Lower a [`hir::Ty`] to a [`rustc_middle::ty::Ty`].
4343
pub fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
44-
cx.maybe_typeck_results()
44+
cx.typeck_results
4545
.filter(|results| results.hir_owner == hir_ty.hir_id.owner)
4646
.and_then(|results| results.node_type_opt(hir_ty.hir_id))
4747
.unwrap_or_else(|| lower_ty(cx.tcx, hir_ty))

0 commit comments

Comments
 (0)