Skip to content

Commit 0706ac0

Browse files
author
Ariel Ben-Yehuda
committed
use the *adjusted* callee type in effect checking
Fixes #28776
1 parent 78edd4f commit 0706ac0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub mod front {
105105
}
106106

107107
pub mod middle {
108+
pub mod expr_use_visitor; // STAGE0: increase glitch immunity
108109
pub mod astconv_util;
109110
pub mod astencode;
110111
pub mod cfg;
@@ -122,7 +123,6 @@ pub mod middle {
122123
pub mod dependency_format;
123124
pub mod effect;
124125
pub mod entry;
125-
pub mod expr_use_visitor;
126126
pub mod free_region;
127127
pub mod intrinsicck;
128128
pub mod infer;

src/librustc/middle/effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
151151
}
152152
}
153153
hir::ExprCall(ref base, _) => {
154-
let base_type = self.tcx.node_id_to_type(base.id);
154+
let base_type = self.tcx.expr_ty_adjusted(base);
155155
debug!("effect: call case, base type is {:?}",
156156
base_type);
157157
if type_is_unsafe_function(base_type) {
158158
self.require_unsafe(expr.span, "call to unsafe function")
159159
}
160160
}
161161
hir::ExprUnary(hir::UnDeref, ref base) => {
162-
let base_type = self.tcx.node_id_to_type(base.id);
162+
let base_type = self.tcx.expr_ty_adjusted(base);
163163
debug!("effect: unary case, base type is {:?}",
164164
base_type);
165165
if let ty::TyRawPtr(_) = base_type.sty {

src/test/compile-fail/issue-28776.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::ptr;
12+
13+
fn main() {
14+
(&ptr::write)(1 as *mut _, 42); //~ ERROR E0133
15+
}

0 commit comments

Comments
 (0)