Skip to content

Commit 13037a3

Browse files
committed
auto merge of #17163 : pcwalton/rust/impls-next-to-struct, r=alexcrichton
type they provide an implementation for. This breaks code like: mod foo { struct Foo { ... } } impl foo::Foo { ... } Change this code to: mod foo { struct Foo { ... } impl Foo { ... } } Closes #17059. RFC #155. [breaking-change] r? @brson
2 parents 0f99aba + 467bea0 commit 13037a3

File tree

20 files changed

+89
-36
lines changed

20 files changed

+89
-36
lines changed

src/compiletest/runtest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use util::logv;
2020
use util;
2121

2222
use std::io::File;
23+
use std::io::fs::PathExtensions;
2324
use std::io::fs;
2425
use std::io::net::tcp;
2526
use std::io::process::ProcessExit;

src/libglob/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
use std::cell::Cell;
3939
use std::{cmp, os, path};
40+
use std::io::fs::PathExtensions;
4041
use std::io::fs;
4142
use std::path::is_sep;
4243
use std::string::String;

src/libnative/io/process.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::rt::rtio;
2121
use super::file;
2222
use super::util;
2323

24+
#[cfg(windows)] use std::io::fs::PathExtensions;
2425
#[cfg(windows)] use std::string::String;
2526
#[cfg(unix)] use super::c;
2627
#[cfg(unix)] use super::retry;

src/librustc/back/link.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use util::ppaux;
2828
use util::sha2::{Digest, Sha256};
2929

3030
use std::char;
31+
use std::io::fs::PathExtensions;
3132
use std::io::{fs, TempDir, Command};
3233
use std::io;
3334
use std::mem;

src/librustc/metadata/filesearch.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#![allow(non_camel_case_types)]
1212

1313
use std::cell::RefCell;
14-
use std::os;
15-
use std::io::fs;
1614
use std::collections::HashSet;
15+
use std::io::fs::PathExtensions;
16+
use std::io::fs;
17+
use std::os;
1718

1819
use util::fs as myfs;
1920

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ use util::fs;
229229

230230
use std::c_str::ToCStr;
231231
use std::cmp;
232+
use std::io::fs::PathExtensions;
232233
use std::io;
233234
use std::mem;
234235
use std::ptr;

src/librustc/middle/resolve.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,10 +1313,6 @@ impl<'a> Resolver<'a> {
13131313
// If this implements an anonymous trait, then add all the
13141314
// methods within to a new module, if the type was defined
13151315
// within this module.
1316-
//
1317-
// FIXME (#3785): This is quite unsatisfactory. Perhaps we
1318-
// should modify anonymous traits to only be implementable in
1319-
// the same module that declared the type.
13201316

13211317
// Create the module and add all methods.
13221318
match ty.node {
@@ -1400,7 +1396,13 @@ impl<'a> Resolver<'a> {
14001396
}
14011397
}
14021398
}
1403-
_ => {}
1399+
_ => {
1400+
self.resolve_error(ty.span,
1401+
"inherent implementations may \
1402+
only be implemented in the same \
1403+
module as the type they are \
1404+
implemented for")
1405+
}
14041406
}
14051407

14061408
parent

src/librustc_back/archive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! A helper class for dealing with static archives
1212
13+
use std::io::fs::PathExtensions;
1314
use std::io::process::{Command, ProcessOutput};
1415
use std::io::{fs, TempDir};
1516
use std::io;

src/librustdoc/html/render.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
3636
use std::collections::{HashMap, HashSet};
3737
use std::fmt;
38+
use std::io::fs::PathExtensions;
3839
use std::io::{fs, File, BufferedWriter, MemWriter, BufferedReader};
3940
use std::io;
4041
use std::str;

src/libstd/io/fs.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ particular bits of it, etc.
3131
3232
```rust
3333
# #![allow(unused_must_use)]
34+
use std::io::fs::PathExtensions;
3435
use std::io::{File, fs};
3536
3637
let path = Path::new("foo.txt");
@@ -622,8 +623,9 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
622623
/// # Example
623624
///
624625
/// ```rust
625-
/// use std::io;
626+
/// use std::io::fs::PathExtensions;
626627
/// use std::io::fs;
628+
/// use std::io;
627629
///
628630
/// // one possible implementation of fs::walk_dir only visiting files
629631
/// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> {
@@ -868,45 +870,54 @@ impl Seek for File {
868870
}
869871
}
870872

871-
impl path::Path {
873+
/// Utility methods for paths.
874+
pub trait PathExtensions {
872875
/// Get information on the file, directory, etc at this path.
873876
///
874877
/// Consult the `fs::stat` documentation for more info.
875878
///
876879
/// This call preserves identical runtime/error semantics with `file::stat`.
877-
pub fn stat(&self) -> IoResult<FileStat> { stat(self) }
880+
fn stat(&self) -> IoResult<FileStat>;
878881

879882
/// Get information on the file, directory, etc at this path, not following
880883
/// symlinks.
881884
///
882885
/// Consult the `fs::lstat` documentation for more info.
883886
///
884887
/// This call preserves identical runtime/error semantics with `file::lstat`.
885-
pub fn lstat(&self) -> IoResult<FileStat> { lstat(self) }
888+
fn lstat(&self) -> IoResult<FileStat>;
886889

887890
/// Boolean value indicator whether the underlying file exists on the local
888891
/// filesystem. Returns false in exactly the cases where `fs::stat` fails.
889-
pub fn exists(&self) -> bool {
890-
self.stat().is_ok()
891-
}
892+
fn exists(&self) -> bool;
892893

893894
/// Whether the underlying implementation (be it a file path, or something
894895
/// else) points at a "regular file" on the FS. Will return false for paths
895896
/// to non-existent locations or directories or other non-regular files
896897
/// (named pipes, etc). Follows links when making this determination.
897-
pub fn is_file(&self) -> bool {
898-
match self.stat() {
899-
Ok(s) => s.kind == io::TypeFile,
900-
Err(..) => false
901-
}
902-
}
898+
fn is_file(&self) -> bool;
903899

904900
/// Whether the underlying implementation (be it a file path, or something
905901
/// else) is pointing at a directory in the underlying FS. Will return
906902
/// false for paths to non-existent locations or if the item is not a
907903
/// directory (eg files, named pipes, etc). Follows links when making this
908904
/// determination.
909-
pub fn is_dir(&self) -> bool {
905+
fn is_dir(&self) -> bool;
906+
}
907+
908+
impl PathExtensions for path::Path {
909+
fn stat(&self) -> IoResult<FileStat> { stat(self) }
910+
fn lstat(&self) -> IoResult<FileStat> { lstat(self) }
911+
fn exists(&self) -> bool {
912+
self.stat().is_ok()
913+
}
914+
fn is_file(&self) -> bool {
915+
match self.stat() {
916+
Ok(s) => s.kind == io::TypeFile,
917+
Err(..) => false
918+
}
919+
}
920+
fn is_dir(&self) -> bool {
910921
match self.stat() {
911922
Ok(s) => s.kind == io::TypeDirectory,
912923
Err(..) => false

0 commit comments

Comments
 (0)