Skip to content

Commit b8eaa16

Browse files
committed
Auto merge of #29778 - Manishearth:rollup, r=Manishearth
- Successful merges: #29677, #29772, #29775, #29777 - Failed merges:
2 parents f1f5c04 + 2670565 commit b8eaa16

File tree

6 files changed

+113
-56
lines changed

6 files changed

+113
-56
lines changed

src/libcore/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -308,27 +308,27 @@ macro_rules! unreachable {
308308
///
309309
/// ```
310310
/// # trait Foo {
311-
/// # fn foo(&self);
312311
/// # fn bar(&self);
312+
/// # fn baz(&self);
313313
/// # }
314314
/// struct MyStruct;
315315
///
316316
/// impl Foo for MyStruct {
317-
/// fn foo(&self) {
317+
/// fn bar(&self) {
318318
/// // implementation goes here
319319
/// }
320320
///
321-
/// fn bar(&self) {
322-
/// // let's not worry about implementing bar() for now
321+
/// fn baz(&self) {
322+
/// // let's not worry about implementing baz() for now
323323
/// unimplemented!();
324324
/// }
325325
/// }
326326
///
327327
/// fn main() {
328328
/// let s = MyStruct;
329-
/// s.foo();
329+
/// s.bar();
330330
///
331-
/// // we aren't even using bar() yet, so this is fine.
331+
/// // we aren't even using baz() yet, so this is fine.
332332
/// }
333333
/// ```
334334
#[macro_export]

src/librustc_resolve/lib.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub enum ResolutionError<'a> {
153153
/// error E0413: declaration shadows an enum variant or unit-like struct in scope
154154
DeclarationShadowsEnumVariantOrUnitLikeStruct(Name),
155155
/// error E0414: only irrefutable patterns allowed here
156-
OnlyIrrefutablePatternsAllowedHere,
156+
OnlyIrrefutablePatternsAllowedHere(DefId, Name),
157157
/// error E0415: identifier is bound more than once in this parameter list
158158
IdentifierBoundMoreThanOnceInParameterList(&'a str),
159159
/// error E0416: identifier is bound more than once in the same pattern
@@ -283,8 +283,19 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn
283283
scope",
284284
name);
285285
},
286-
ResolutionError::OnlyIrrefutablePatternsAllowedHere => {
286+
ResolutionError::OnlyIrrefutablePatternsAllowedHere(did, name) => {
287287
span_err!(resolver.session, span, E0414, "only irrefutable patterns allowed here");
288+
resolver.session.span_note(span, "there already is a constant in scope \
289+
sharing the same name as this pattern");
290+
if let Some(sp) = resolver.ast_map.span_if_local(did) {
291+
resolver.session.span_note(sp, "constant defined here");
292+
}
293+
if let Some(directive) = resolver.current_module
294+
.import_resolutions
295+
.borrow().get(&name) {
296+
let item = resolver.ast_map.expect_item(directive.value_id);
297+
resolver.session.span_note(item.span, "constant imported here");
298+
}
288299
},
289300
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => {
290301
span_err!(resolver.session, span, E0415,
@@ -632,7 +643,7 @@ enum NameSearchType {
632643
#[derive(Copy, Clone)]
633644
enum BareIdentifierPatternResolution {
634645
FoundStructOrEnumVariant(Def, LastPrivate),
635-
FoundConst(Def, LastPrivate),
646+
FoundConst(Def, LastPrivate, Name),
636647
BareIdentifierPatternUnresolved
637648
}
638649

@@ -2685,7 +2696,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26852696
renamed)
26862697
);
26872698
}
2688-
FoundConst(def, lp) if const_ok => {
2699+
FoundConst(def, lp, _) if const_ok => {
26892700
debug!("(resolving pattern) resolving `{}` to \
26902701
constant",
26912702
renamed);
@@ -2700,11 +2711,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27002711
depth: 0
27012712
});
27022713
}
2703-
FoundConst(..) => {
2714+
FoundConst(def, _, name) => {
27042715
resolve_error(
27052716
self,
27062717
pattern.span,
2707-
ResolutionError::OnlyIrrefutablePatternsAllowedHere
2718+
ResolutionError::OnlyIrrefutablePatternsAllowedHere(def.def_id(),
2719+
name)
27082720
);
27092721
}
27102722
BareIdentifierPatternUnresolved => {
@@ -2929,7 +2941,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29292941
return FoundStructOrEnumVariant(def, LastMod(AllPublic));
29302942
}
29312943
def @ DefConst(..) | def @ DefAssociatedConst(..) => {
2932-
return FoundConst(def, LastMod(AllPublic));
2944+
return FoundConst(def, LastMod(AllPublic), name);
29332945
}
29342946
DefStatic(..) => {
29352947
resolve_error(self,

src/librustc_typeck/diagnostics.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,28 @@ defined. For more information see the [opt-in builtin traits RFC](https://github
26772677
.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
26782678
"##,
26792679

2680+
E0321: r##"
2681+
A cross-crate opt-out trait was implemented on something which wasn't a struct
2682+
or enum type. Erroneous code example:
2683+
2684+
```
2685+
#![feature(optin_builtin_traits)]
2686+
2687+
struct Foo;
2688+
2689+
impl !Sync for Foo {}
2690+
2691+
unsafe impl Send for &'static Foo {
2692+
// error: cross-crate traits with a default impl, like `core::marker::Send`,
2693+
// can only be implemented for a struct/enum type, not
2694+
// `&'static Foo`
2695+
```
2696+
2697+
Only structs and enums are permitted to impl Send, Sync, and other opt-out
2698+
trait, and the struct or enum must be local to the current crate. So, for
2699+
example, `unsafe impl Send for Rc<Foo>` is not allowed.
2700+
"##,
2701+
26802702
E0322: r##"
26812703
The `Sized` trait is a special trait built-in to the compiler for types with a
26822704
constant size known at compile-time. This trait is automatically implemented
@@ -3463,7 +3485,6 @@ register_diagnostics! {
34633485
// E0246, // invalid recursive type
34643486
// E0319, // trait impls for defaulted traits allowed just for structs/enums
34653487
E0320, // recursive overflow during dropck
3466-
E0321, // extended coherence rules for defaulted traits violated
34673488
E0328, // cannot implement Unsize explicitly
34683489
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
34693490
// between structures with one field being coerced, none found

src/libstd/ffi/c_str.rs

+32-40
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use libc;
2121
use mem;
2222
use ops::Deref;
2323
use option::Option::{self, Some, None};
24+
use os::raw::c_char;
2425
use result::Result::{self, Ok, Err};
2526
use slice;
2627
use str::{self, Utf8Error};
@@ -36,23 +37,20 @@ use vec::Vec;
3637
///
3738
/// A `CString` is created from either a byte slice or a byte vector. After
3839
/// being created, a `CString` predominately inherits all of its methods from
39-
/// the `Deref` implementation to `[libc::c_char]`. Note that the underlying
40-
/// array is represented as an array of `libc::c_char` as opposed to `u8`. A
41-
/// `u8` slice can be obtained with the `as_bytes` method. Slices produced from
42-
/// a `CString` do *not* contain the trailing nul terminator unless otherwise
43-
/// specified.
40+
/// the `Deref` implementation to `[c_char]`. Note that the underlying array
41+
/// is represented as an array of `c_char` as opposed to `u8`. A `u8` slice
42+
/// can be obtained with the `as_bytes` method. Slices produced from a `CString`
43+
/// do *not* contain the trailing nul terminator unless otherwise specified.
4444
///
4545
/// # Examples
4646
///
4747
/// ```no_run
48-
/// # #![feature(libc)]
49-
/// # extern crate libc;
5048
/// # fn main() {
5149
/// use std::ffi::CString;
52-
/// use libc;
50+
/// use std::os::raw::c_char;
5351
///
5452
/// extern {
55-
/// fn my_printer(s: *const libc::c_char);
53+
/// fn my_printer(s: *const c_char);
5654
/// }
5755
///
5856
/// let c_to_print = CString::new("Hello, world!").unwrap();
@@ -83,11 +81,10 @@ pub struct CString {
8381
/// Inspecting a foreign C string
8482
///
8583
/// ```no_run
86-
/// # #![feature(libc)]
87-
/// extern crate libc;
8884
/// use std::ffi::CStr;
85+
/// use std::os::raw::c_char;
8986
///
90-
/// extern { fn my_string() -> *const libc::c_char; }
87+
/// extern { fn my_string() -> *const c_char; }
9188
///
9289
/// fn main() {
9390
/// unsafe {
@@ -100,12 +97,11 @@ pub struct CString {
10097
/// Passing a Rust-originating C string
10198
///
10299
/// ```no_run
103-
/// # #![feature(libc)]
104-
/// extern crate libc;
105100
/// use std::ffi::{CString, CStr};
101+
/// use std::os::raw::c_char;
106102
///
107103
/// fn work(data: &CStr) {
108-
/// extern { fn work_with(data: *const libc::c_char); }
104+
/// extern { fn work_with(data: *const c_char); }
109105
///
110106
/// unsafe { work_with(data.as_ptr()) }
111107
/// }
@@ -119,11 +115,10 @@ pub struct CString {
119115
/// Converting a foreign C string into a Rust `String`
120116
///
121117
/// ```no_run
122-
/// # #![feature(libc)]
123-
/// extern crate libc;
124118
/// use std::ffi::CStr;
119+
/// use std::os::raw::c_char;
125120
///
126-
/// extern { fn my_string() -> *const libc::c_char; }
121+
/// extern { fn my_string() -> *const c_char; }
127122
///
128123
/// fn my_string_safe() -> String {
129124
/// unsafe {
@@ -139,10 +134,10 @@ pub struct CString {
139134
#[stable(feature = "rust1", since = "1.0.0")]
140135
pub struct CStr {
141136
// FIXME: this should not be represented with a DST slice but rather with
142-
// just a raw `libc::c_char` along with some form of marker to make
137+
// just a raw `c_char` along with some form of marker to make
143138
// this an unsized type. Essentially `sizeof(&CStr)` should be the
144139
// same as `sizeof(&c_char)` but `CStr` should be an unsized type.
145-
inner: [libc::c_char]
140+
inner: [c_char]
146141
}
147142

148143
/// An error returned from `CString::new` to indicate that a nul byte was found
@@ -169,11 +164,10 @@ impl CString {
169164
/// # Examples
170165
///
171166
/// ```no_run
172-
/// # #![feature(libc)]
173-
/// extern crate libc;
174167
/// use std::ffi::CString;
168+
/// use std::os::raw::c_char;
175169
///
176-
/// extern { fn puts(s: *const libc::c_char); }
170+
/// extern { fn puts(s: *const c_char); }
177171
///
178172
/// fn main() {
179173
/// let to_print = CString::new("Hello!").unwrap();
@@ -220,7 +214,7 @@ impl CString {
220214
#[unstable(feature = "cstr_memory2", reason = "recently added",
221215
issue = "27769")]
222216
#[deprecated(since = "1.4.0", reason = "renamed to from_raw")]
223-
pub unsafe fn from_ptr(ptr: *const libc::c_char) -> CString {
217+
pub unsafe fn from_ptr(ptr: *const c_char) -> CString {
224218
CString::from_raw(ptr as *mut _)
225219
}
226220

@@ -230,7 +224,7 @@ impl CString {
230224
/// `into_raw`. The length of the string will be recalculated
231225
/// using the pointer.
232226
#[stable(feature = "cstr_memory", since = "1.4.0")]
233-
pub unsafe fn from_raw(ptr: *mut libc::c_char) -> CString {
227+
pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
234228
let len = libc::strlen(ptr) + 1; // Including the NUL byte
235229
let slice = slice::from_raw_parts(ptr, len as usize);
236230
CString { inner: mem::transmute(slice) }
@@ -247,7 +241,7 @@ impl CString {
247241
#[unstable(feature = "cstr_memory2", reason = "recently added",
248242
issue = "27769")]
249243
#[deprecated(since = "1.4.0", reason = "renamed to into_raw")]
250-
pub fn into_ptr(self) -> *const libc::c_char {
244+
pub fn into_ptr(self) -> *const c_char {
251245
self.into_raw() as *const _
252246
}
253247

@@ -260,8 +254,8 @@ impl CString {
260254
///
261255
/// Failure to call `from_raw` will lead to a memory leak.
262256
#[stable(feature = "cstr_memory", since = "1.4.0")]
263-
pub fn into_raw(self) -> *mut libc::c_char {
264-
Box::into_raw(self.inner) as *mut libc::c_char
257+
pub fn into_raw(self) -> *mut c_char {
258+
Box::into_raw(self.inner) as *mut c_char
265259
}
266260

267261
/// Converts the `CString` into a `String` if it contains valid Unicode data.
@@ -426,15 +420,13 @@ impl CStr {
426420
/// # Examples
427421
///
428422
/// ```no_run
429-
/// # #![feature(libc)]
430-
/// # extern crate libc;
431423
/// # fn main() {
432424
/// use std::ffi::CStr;
425+
/// use std::os::raw::c_char;
433426
/// use std::str;
434-
/// use libc;
435427
///
436428
/// extern {
437-
/// fn my_string() -> *const libc::c_char;
429+
/// fn my_string() -> *const c_char;
438430
/// }
439431
///
440432
/// unsafe {
@@ -445,7 +437,7 @@ impl CStr {
445437
/// # }
446438
/// ```
447439
#[stable(feature = "rust1", since = "1.0.0")]
448-
pub unsafe fn from_ptr<'a>(ptr: *const libc::c_char) -> &'a CStr {
440+
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
449441
let len = libc::strlen(ptr);
450442
mem::transmute(slice::from_raw_parts(ptr, len as usize + 1))
451443
}
@@ -456,7 +448,7 @@ impl CStr {
456448
/// to a contiguous region of memory terminated with a 0 byte to represent
457449
/// the end of the string.
458450
#[stable(feature = "rust1", since = "1.0.0")]
459-
pub fn as_ptr(&self) -> *const libc::c_char {
451+
pub fn as_ptr(&self) -> *const c_char {
460452
self.inner.as_ptr()
461453
}
462454

@@ -560,14 +552,14 @@ impl ToOwned for CStr {
560552
mod tests {
561553
use prelude::v1::*;
562554
use super::*;
563-
use libc;
555+
use os::raw::c_char;
564556
use borrow::Cow::{Borrowed, Owned};
565557
use hash::{SipHasher, Hash, Hasher};
566558

567559
#[test]
568560
fn c_to_rust() {
569561
let data = b"123\0";
570-
let ptr = data.as_ptr() as *const libc::c_char;
562+
let ptr = data.as_ptr() as *const c_char;
571563
unsafe {
572564
assert_eq!(CStr::from_ptr(ptr).to_bytes(), b"123");
573565
assert_eq!(CStr::from_ptr(ptr).to_bytes_with_nul(), b"123\0");
@@ -616,13 +608,13 @@ mod tests {
616608
#[test]
617609
fn to_str() {
618610
let data = b"123\xE2\x80\xA6\0";
619-
let ptr = data.as_ptr() as *const libc::c_char;
611+
let ptr = data.as_ptr() as *const c_char;
620612
unsafe {
621613
assert_eq!(CStr::from_ptr(ptr).to_str(), Ok("123…"));
622614
assert_eq!(CStr::from_ptr(ptr).to_string_lossy(), Borrowed("123…"));
623615
}
624616
let data = b"123\xE2\0";
625-
let ptr = data.as_ptr() as *const libc::c_char;
617+
let ptr = data.as_ptr() as *const c_char;
626618
unsafe {
627619
assert!(CStr::from_ptr(ptr).to_str().is_err());
628620
assert_eq!(CStr::from_ptr(ptr).to_string_lossy(), Owned::<str>(format!("123\u{FFFD}")));
@@ -632,7 +624,7 @@ mod tests {
632624
#[test]
633625
fn to_owned() {
634626
let data = b"123\0";
635-
let ptr = data.as_ptr() as *const libc::c_char;
627+
let ptr = data.as_ptr() as *const c_char;
636628

637629
let owned = unsafe { CStr::from_ptr(ptr).to_owned() };
638630
assert_eq!(owned.as_bytes_with_nul(), data);
@@ -641,7 +633,7 @@ mod tests {
641633
#[test]
642634
fn equal_hash() {
643635
let data = b"123\xE2\xFA\xA6\0";
644-
let ptr = data.as_ptr() as *const libc::c_char;
636+
let ptr = data.as_ptr() as *const c_char;
645637
let cstr: &'static CStr = unsafe { CStr::from_ptr(ptr) };
646638

647639
let mut s = SipHasher::new_with_keys(0, 0);

src/libstd/os/raw.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
1313
#![stable(feature = "raw_os", since = "1.1.0")]
1414

15-
#[cfg(any(target_arch = "aarch64", target_os = "android"))]
15+
#[cfg(any(target_os = "android",
16+
all(target_os = "linux", any(target_arch = "aarch64",
17+
target_arch = "arm"))))]
1618
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
17-
#[cfg(not(any(target_arch = "aarch64", target_os = "android")))]
19+
#[cfg(not(any(target_os = "android",
20+
all(target_os = "linux", any(target_arch = "aarch64",
21+
target_arch = "arm")))))]
1822
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
1923
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
2024
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;

0 commit comments

Comments
 (0)