Logo
Explore Help
Register Sign In
rust-lang/rust
1
0
Fork 0
You've already forked rust
Code Issues Pull Requests Actions 1 Packages Projects Releases Wiki Activity
Files
8b2491160d71aa7a84ed822b85e9b3eff6097225
rust/src/test/compile-fail/private-method.rs

17 lines
318 B
Rust
Raw Normal View History

Allow explicit self-calls within classes Allow writing self.f() within a class that has a method f. In a future commit, this syntax will be required. For now, you can write either self.f() or f(). I added a "privacy" field to all methods (whether class methods or not), which allowed me to refactor the AST somewhat (getting rid of the class_item type; now there's just class_member).
2012-03-28 18:50:33 -07:00
// error-pattern:Call to private method not allowed
Enforce privacy declarations for class fields and methods
2012-03-26 09:59:59 -07:00
class cat {
priv {
Bulk-edit mutable -> mut.
2012-03-26 18:35:18 -07:00
let mut meows : uint;
Enforce privacy declarations for class fields and methods
2012-03-26 09:59:59 -07:00
fn nap() { uint::range(1u, 10000u) {|_i|}}
}
let how_hungry : int;
Require "self" as base expression for intra-class method or field references All field or method references within a class must begin with "self." now. A bare reference to a field or method in the same class will no longer typecheck.
2012-03-29 12:21:13 -07:00
new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
Enforce privacy declarations for class fields and methods
2012-03-26 09:59:59 -07:00
}
fn main() {
let nyan : cat = cat(52u, 99);
nyan.nap();
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.6 Page: 223ms Template: 4ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API