about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-06-19 16:37:58 +0000
committerbors <bors@rust-lang.org>2019-06-19 16:37:58 +0000
commit5e0c6a69e075d9c7d19e28264bb8941f72ecaf4e (patch)
tree340f2e3775fb368108e2fe31ba8b24c9aa521111 /src
parente79b2a18a21e6b178d73473bb8fdbf3d18c66051 (diff)
parentbf6c505c23a1026282cc0518743c9cd6e727c2aa (diff)
downloadrust-5e0c6a69e075d9c7d19e28264bb8941f72ecaf4e.tar.gz
rust-5e0c6a69e075d9c7d19e28264bb8941f72ecaf4e.zip
Auto merge of #61962 - Centril:rollup-y6sg1zw, r=Centril
Rollup of 4 pull requests

Successful merges:

 - #60667 ( Add functions for building raw slices to libcore )
 - #61547 (Support `cfg` and `cfg_attr` on generic parameters)
 - #61861 (Update rustfmt and rls)
 - #61940 (Make Place::ty iterate)

Failed merges:

r? @ghost
Diffstat (limited to 'src')
-rw-r--r--src/libcore/ptr/mod.rs47
-rw-r--r--src/libcore/slice/mod.rs19
-rw-r--r--src/librustc/mir/tcx.rs26
-rw-r--r--src/libsyntax/config.rs20
-rw-r--r--src/libsyntax/ext/expand.rs6
-rw-r--r--src/test/ui/conditional-compilation/cfg-generic-params.rs38
-rw-r--r--src/test/ui/conditional-compilation/cfg-generic-params.stderr66
-rw-r--r--src/test/ui/issues/issue-51279.rs27
-rw-r--r--src/test/ui/issues/issue-51279.stderr60
m---------src/tools/rls0
m---------src/tools/rustfmt26
11 files changed, 201 insertions, 134 deletions
diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs
index 8f026a5b7d8..ba88fde6ebc 100644
--- a/src/libcore/ptr/mod.rs
+++ b/src/libcore/ptr/mod.rs
@@ -230,6 +230,53 @@ pub const fn null<T>() -> *const T { 0 as *const T }
 #[rustc_promotable]
 pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
 
+#[repr(C)]
+pub(crate) union Repr<T> {
+    pub(crate) rust: *const [T],
+    rust_mut: *mut [T],
+    pub(crate) raw: FatPtr<T>,
+}
+
+#[repr(C)]
+pub(crate) struct FatPtr<T> {
+    data: *const T,
+    pub(crate) len: usize,
+}
+
+/// Forms a slice from a pointer and a length.
+///
+/// The `len` argument is the number of **elements**, not the number of bytes.
+///
+/// # Examples
+///
+/// ```rust
+/// #![feature(slice_from_raw_parts)]
+/// use std::ptr;
+///
+/// // create a slice pointer when starting out with a pointer to the first element
+/// let mut x = [5, 6, 7];
+/// let ptr = &mut x[0] as *mut _;
+/// let slice = ptr::slice_from_raw_parts_mut(ptr, 3);
+/// assert_eq!(unsafe { &*slice }[2], 7);
+/// ```
+#[inline]
+#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
+pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
+    unsafe { Repr { raw: FatPtr { data, len } }.rust }
+}
+
+/// Performs the same functionality as [`from_raw_parts`], except that a
+/// mutable slice is returned.
+///
+/// See the documentation of [`from_raw_parts`] for more details.
+///
+/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
+#[inline]
+#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
+pub fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
+    unsafe { Repr { raw: FatPtr { data, len } }.rust_mut }
+}
+
 /// Swaps the values at two mutable locations of the same type, without
 /// deinitializing either.
 ///
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index b2376cdf9fa..af1b20a4c10 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -45,19 +45,6 @@ pub mod memchr;
 mod rotate;
 mod sort;
 
-#[repr(C)]
-union Repr<'a, T: 'a> {
-    rust: &'a [T],
-    rust_mut: &'a mut [T],
-    raw: FatPtr<T>,
-}
-
-#[repr(C)]
-struct FatPtr<T> {
-    data: *const T,
-    len: usize,
-}
-
 //
 // Extension traits
 //
@@ -78,7 +65,7 @@ impl<T> [T] {
     #[rustc_const_unstable(feature = "const_slice_len")]
     pub const fn len(&self) -> usize {
         unsafe {
-            Repr { rust: self }.raw.len
+            crate::ptr::Repr { rust: self }.raw.len
         }
     }
 
@@ -5195,7 +5182,7 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
     debug_assert!(data as usize % mem::align_of::<T>() == 0, "attempt to create unaligned slice");
     debug_assert!(mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize,
                   "attempt to create slice covering half the address space");
-    Repr { raw: FatPtr { data, len } }.rust
+    &*ptr::slice_from_raw_parts(data, len)
 }
 
 /// Performs the same functionality as [`from_raw_parts`], except that a
@@ -5216,7 +5203,7 @@ pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T]
     debug_assert!(data as usize % mem::align_of::<T>() == 0, "attempt to create unaligned slice");
     debug_assert!(mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize,
                   "attempt to create slice covering half the address space");
-    Repr { raw: FatPtr { data, len } }.rust_mut
+    &mut *ptr::slice_from_raw_parts_mut(data, len)
 }
 
 /// Converts a reference to T into a slice of length 1 (without copying).
diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs
index afabcdfadd0..2079a2a34e7 100644
--- a/src/librustc/mir/tcx.rs
+++ b/src/librustc/mir/tcx.rs
@@ -122,13 +122,25 @@ impl<'tcx> Place<'tcx> {
     where
         D: HasLocalDecls<'tcx>,
     {
-        match *self {
-            Place::Base(PlaceBase::Local(index)) =>
-                PlaceTy::from_ty(local_decls.local_decls()[index].ty),
-            Place::Base(PlaceBase::Static(ref data)) =>
-                PlaceTy::from_ty(data.ty),
-            Place::Projection(ref proj) =>
-                proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
+        self.iterate(|place_base, place_projections| {
+            let mut place_ty = place_base.ty(local_decls);
+
+            for proj in place_projections {
+                place_ty = place_ty.projection_ty(tcx, &proj.elem);
+            }
+
+            place_ty
+        })
+    }
+}
+
+impl<'tcx> PlaceBase<'tcx> {
+    pub fn ty<D>(&self, local_decls: &D) -> PlaceTy<'tcx>
+        where D: HasLocalDecls<'tcx>
+    {
+        match self {
+            PlaceBase::Local(index) => PlaceTy::from_ty(local_decls.local_decls()[*index].ty),
+            PlaceBase::Static(data) => PlaceTy::from_ty(data.ty),
         }
     }
 }
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index 1cc13ac7878..3b42e1de614 100644
--- a/src/libsyntax/config.rs
+++ b/src/libsyntax/config.rs
@@ -240,6 +240,10 @@ impl<'a> StripUnconfigured<'a> {
         items.flat_map_in_place(|item| self.configure(item));
     }
 
+    pub fn configure_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) {
+        params.flat_map_in_place(|param| self.configure(param));
+    }
+
     fn configure_variant_data(&mut self, vdata: &mut ast::VariantData) {
         match vdata {
             ast::VariantData::Struct(fields, ..) | ast::VariantData::Tuple(fields, _) =>
@@ -301,22 +305,6 @@ impl<'a> StripUnconfigured<'a> {
     pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) {
         fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg));
     }
-
-    /// Denies `#[cfg]` on generic parameters until we decide what to do with it.
-    /// See issue #51279.
-    pub fn disallow_cfg_on_generic_param(&mut self, param: &ast::GenericParam) {
-        for attr in param.attrs() {
-            let offending_attr = if attr.check_name(sym::cfg) {
-                "cfg"
-            } else if attr.check_name(sym::cfg_attr) {
-                "cfg_attr"
-            } else {
-                continue;
-            };
-            let msg = format!("#[{}] cannot be applied on a generic parameter", offending_attr);
-            self.sess.span_diagnostic.span_err(attr.span, &msg);
-        }
-    }
 }
 
 impl<'a> MutVisitor for StripUnconfigured<'a> {
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index be90def0bdd..cfd67575b6f 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1329,9 +1329,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
         }
     }
 
-    fn visit_generic_param(&mut self, param: &mut ast::GenericParam) {
-        self.cfg.disallow_cfg_on_generic_param(&param);
-        noop_visit_generic_param(param, self)
+    fn visit_generic_params(&mut self, params: &mut Vec<ast::GenericParam>) {
+        self.cfg.configure_generic_params(params);
+        noop_visit_generic_params(params, self);
     }
 
     fn visit_attribute(&mut self, at: &mut ast::Attribute) {
diff --git a/src/test/ui/conditional-compilation/cfg-generic-params.rs b/src/test/ui/conditional-compilation/cfg-generic-params.rs
new file mode 100644
index 00000000000..d80d3ea7b7f
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg-generic-params.rs
@@ -0,0 +1,38 @@
+// compile-flags:--cfg yes
+
+fn f_lt<#[cfg(yes)] 'a: 'a, #[cfg(no)] T>() {}
+fn f_ty<#[cfg(no)] 'a: 'a, #[cfg(yes)] T>() {}
+
+type FnGood = for<#[cfg(yes)] 'a, #[cfg(no)] T> fn(); // OK
+type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn();
+//~^ ERROR only lifetime parameters can be used in this context
+
+type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(no)] T> Copy; // OK
+type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy;
+//~^ ERROR only lifetime parameters can be used in this context
+
+struct WhereGood where for<#[cfg(yes)] 'a, #[cfg(no)] T> u8: Copy; // OK
+struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
+//~^ ERROR only lifetime parameters can be used in this context
+
+fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK
+fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {} //~ ERROR attribute `unknown` is currently unknown
+fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK
+fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {} //~ ERROR attribute `unknown` is currently unknown
+
+type FnNo = for<#[cfg_attr(no, unknown)] 'a> fn(); // OK
+type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
+//~^ ERROR attribute `unknown` is currently unknown
+
+type PolyNo = dyn for<#[cfg_attr(no, unknown)] 'a> Copy; // OK
+type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
+//~^ ERROR attribute `unknown` is currently unknown
+
+struct WhereNo where for<#[cfg_attr(no, unknown)] 'a> u8: Copy; // OK
+struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
+//~^ ERROR attribute `unknown` is currently unknown
+
+fn main() {
+    f_lt::<'static>();
+    f_ty::<u8>();
+}
diff --git a/src/test/ui/conditional-compilation/cfg-generic-params.stderr b/src/test/ui/conditional-compilation/cfg-generic-params.stderr
new file mode 100644
index 00000000000..40ca44d9db5
--- /dev/null
+++ b/src/test/ui/conditional-compilation/cfg-generic-params.stderr
@@ -0,0 +1,66 @@
+error: only lifetime parameters can be used in this context
+  --> $DIR/cfg-generic-params.rs:7:45
+   |
+LL | type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn();
+   |                                             ^
+
+error: only lifetime parameters can be used in this context
+  --> $DIR/cfg-generic-params.rs:11:51
+   |
+LL | type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy;
+   |                                                   ^
+
+error: only lifetime parameters can be used in this context
+  --> $DIR/cfg-generic-params.rs:15:54
+   |
+LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
+   |                                                      ^
+
+error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
+  --> $DIR/cfg-generic-params.rs:19:29
+   |
+LL | fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
+   |                             ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
+  --> $DIR/cfg-generic-params.rs:21:29
+   |
+LL | fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
+   |                             ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
+  --> $DIR/cfg-generic-params.rs:24:34
+   |
+LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
+   |                                  ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
+  --> $DIR/cfg-generic-params.rs:28:40
+   |
+LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
+   |                                        ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error[E0658]: The attribute `unknown` is currently unknown to the compiler and may have meaning added to it in the future
+  --> $DIR/cfg-generic-params.rs:32:43
+   |
+LL | struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
+   |                                           ^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
+error: aborting due to 8 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/issues/issue-51279.rs b/src/test/ui/issues/issue-51279.rs
deleted file mode 100644
index f8f3626caab..00000000000
--- a/src/test/ui/issues/issue-51279.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T);
-//~^ ERROR #[cfg] cannot be applied on a generic parameter
-//~^^ ERROR #[cfg] cannot be applied on a generic parameter
-
-impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {}
-//~^ ERROR #[cfg] cannot be applied on a generic parameter
-//~^^ ERROR #[cfg] cannot be applied on a generic parameter
-
-pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {}
-//~^ ERROR #[cfg] cannot be applied on a generic parameter
-//~^^ ERROR #[cfg] cannot be applied on a generic parameter
-
-#[cfg(none)]
-pub struct Y<#[cfg(none)] T>(T); // shouldn't care when the entire item is stripped out
-
-struct M<T>(*const T);
-
-impl<#[cfg_attr(none, may_dangle)] T> Drop for M<T> {
-    //~^ ERROR #[cfg_attr] cannot be applied on a generic parameter
-    fn drop(&mut self) {}
-}
-
-type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>;
-//~^ ERROR #[cfg] cannot be applied on a generic parameter
-//~| ERROR attribute `ignored` is currently unknown to the compiler
-
-fn main() {}
diff --git a/src/test/ui/issues/issue-51279.stderr b/src/test/ui/issues/issue-51279.stderr
deleted file mode 100644
index 9dd4a9f2381..00000000000
--- a/src/test/ui/issues/issue-51279.stderr
+++ /dev/null
@@ -1,60 +0,0 @@
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:1:14
-   |
-LL | pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T);
-   |              ^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:1:31
-   |
-LL | pub struct X<#[cfg(none)] 'a, #[cfg(none)] T>(&'a T);
-   |                               ^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:5:6
-   |
-LL | impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {}
-   |      ^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:5:23
-   |
-LL | impl<#[cfg(none)] 'a, #[cfg(none)] T> X<'a, T> {}
-   |                       ^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:9:10
-   |
-LL | pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {}
-   |          ^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:9:27
-   |
-LL | pub fn f<#[cfg(none)] 'a, #[cfg(none)] T>(_: &'a T) {}
-   |                           ^^^^^^^^^^^^
-
-error: #[cfg_attr] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:18:6
-   |
-LL | impl<#[cfg_attr(none, may_dangle)] T> Drop for M<T> {
-   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: #[cfg] cannot be applied on a generic parameter
-  --> $DIR/issue-51279.rs:23:23
-   |
-LL | type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>;
-   |                       ^^^^^^^^^^^^
-
-error[E0658]: The attribute `ignored` is currently unknown to the compiler and may have meaning added to it in the future
-  --> $DIR/issue-51279.rs:23:8
-   |
-LL | type Z<#[ignored] 'a, #[cfg(none)] T> = X<'a, T>;
-   |        ^^^^^^^^^^
-   |
-   = note: for more information, see https://github.com/rust-lang/rust/issues/29642
-   = help: add #![feature(custom_attribute)] to the crate attributes to enable
-
-error: aborting due to 9 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/tools/rls b/src/tools/rls
-Subproject 483dcbc73f9923e98c71ec9df11ee3d0d5cfb46
+Subproject 3e519650cea91a4b785cd773a3e5965553f7424
diff --git a/src/tools/rustfmt b/src/tools/rustfmt
-Subproject 5274b49caa1a7db6ac10c76bf1a3d5710ccef56
+Subproject d33450247b17d92a951d9663822c5a3635a37dd