From 3be18f0edca612b10d2ef40c7ed0e377f89f94e0 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Thu, 11 Jun 2015 23:45:27 +0300 Subject: [PATCH] Prevent raw pointers from being used as an explicit self This can't be made to work with the current setup. Fixes #26194. --- src/librustc_typeck/collect.rs | 4 ++-- src/test/compile-fail/issue-26194.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-26194.rs diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 610c429b1fb..8d057914748 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2174,7 +2174,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>( if let ast::SelfExplicit(ref ast_type, _) = explicit_self.node { let typ = ccx.icx(&method_type.predicates).to_ty(rs, &**ast_type); let base_type = match typ.sty { - ty::ty_ptr(tm) | ty::ty_rptr(_, tm) => tm.ty, + ty::ty_rptr(_, tm) => tm.ty, ty::ty_uniq(typ) => typ, _ => typ, }; @@ -2220,7 +2220,7 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>( ppaux::ty_to_string(tcx, required_type)) })); - // We could conceviably add more free-reion relations here, + // We could conceviably add more free-region relations here, // but since this code is just concerned with checking that // the `&Self` types etc match up, it's not really necessary. // It would just allow people to be more approximate in some diff --git a/src/test/compile-fail/issue-26194.rs b/src/test/compile-fail/issue-26194.rs new file mode 100644 index 00000000000..b5c875cc4cb --- /dev/null +++ b/src/test/compile-fail/issue-26194.rs @@ -0,0 +1,18 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct S(String); + +impl S { + fn f(self: *mut S) -> String { self.0 } + //~^ ERROR mismatched self type +} + +fn main() { S("".to_owned()).f(); }