]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #56245 - mark-i-m:stabilize_ques_kleene, r=alexcrichton
authorbors <bors@rust-lang.org>
Thu, 29 Nov 2018 06:44:12 +0000 (06:44 +0000)
committerbors <bors@rust-lang.org>
Thu, 29 Nov 2018 06:44:12 +0000 (06:44 +0000)
Stabilize feature `macro_at_most_once_rep`

a.k.a. `?` Kleene operator :tada:

cc #48075

r? @Centril

src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_ssa/mir/operand.rs
src/librustc_resolve/resolve_imports.rs
src/test/codegen/issue-56267-2.rs [new file with mode: 0644]
src/test/codegen/issue-56267.rs [new file with mode: 0644]
src/test/ui/imports/issue-56263.rs [new file with mode: 0644]
src/tools/clippy

index d2a99eae3406f969bfe705636f96daeb4b892131..f6bc348b8dc59dd4adbf7177283f7e25f9b0d503 100644 (file)
@@ -589,9 +589,11 @@ fn scalar_load_metadata<'a, 'll, 'tcx>(
             });
             OperandValue::Immediate(to_immediate(self, llval, place.layout))
         } else if let layout::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
-            let mut load = |i, scalar: &layout::Scalar| {
+            let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
+
+            let mut load = |i, scalar: &layout::Scalar, align| {
                 let llptr = self.struct_gep(place.llval, i as u64);
-                let load = self.load(llptr, place.align);
+                let load = self.load(llptr, align);
                 scalar_load_metadata(self, load, scalar);
                 if scalar.is_bool() {
                     self.trunc(load, self.cx().type_i1())
@@ -599,7 +601,11 @@ fn scalar_load_metadata<'a, 'll, 'tcx>(
                     load
                 }
             };
-            OperandValue::Pair(load(0, a), load(1, b))
+
+            OperandValue::Pair(
+                load(0, a, place.align),
+                load(1, b, place.align.restrict_for_offset(b_offset)),
+            )
         } else {
             OperandValue::Ref(place.llval, None, place.align)
         };
index 92d0219caf06bf2e9fd036782380c4d5e7ee695b..fefbc14e4973c481b9ee29c7a955e173b7b3d7a0 100644 (file)
@@ -331,11 +331,21 @@ fn store_with_flags<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 bx.store_with_flags(val, dest.llval, dest.align, flags);
             }
             OperandValue::Pair(a, b) => {
-                for (i, &x) in [a, b].iter().enumerate() {
-                    let llptr = bx.struct_gep(dest.llval, i as u64);
-                    let val = base::from_immediate(bx, x);
-                    bx.store_with_flags(val, llptr, dest.align, flags);
-                }
+                let (a_scalar, b_scalar) = match dest.layout.abi {
+                    layout::Abi::ScalarPair(ref a, ref b) => (a, b),
+                    _ => bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout)
+                };
+                let b_offset = a_scalar.value.size(bx).align_to(b_scalar.value.align(bx).abi);
+
+                let llptr = bx.struct_gep(dest.llval, 0);
+                let val = base::from_immediate(bx, a);
+                let align = dest.align;
+                bx.store_with_flags(val, llptr, align, flags);
+
+                let llptr = bx.struct_gep(dest.llval, 1);
+                let val = base::from_immediate(bx, b);
+                let align = dest.align.restrict_for_offset(b_offset);
+                bx.store_with_flags(val, llptr, align, flags);
             }
         }
     }
index 3bfa862f0dc7dc8a355c8914a2e2037ffa278270..e7cd32f4e810f44d0aedb7964dd9ce999c321290 100644 (file)
@@ -173,7 +173,9 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
             }
             ModuleOrUniformRoot::ExternPrelude => {
                 assert!(!restricted_shadowing);
-                return if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
+                return if ns != TypeNS {
+                    Err((Determined, Weak::No))
+                } else if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
                     Ok(binding)
                 } else if !self.graph_root.unresolved_invocations.borrow().is_empty() {
                     // Macro-expanded `extern crate` items can add names to extern prelude.
diff --git a/src/test/codegen/issue-56267-2.rs b/src/test/codegen/issue-56267-2.rs
new file mode 100644 (file)
index 0000000..53b83f4
--- /dev/null
@@ -0,0 +1,18 @@
+// compile-flags: -C no-prepopulate-passes
+
+#![crate_type="rlib"]
+
+#[allow(dead_code)]
+pub struct Foo<T> {
+    foo: u64,
+    bar: T,
+}
+
+// The load from bar.1 should have alignment 4. Not checking
+// other loads here, as the alignment will be platform-dependent.
+
+// CHECK: %{{.+}} = load i32, i32* %{{.+}}, align 4
+#[no_mangle]
+pub fn test(x: Foo<(i32, i32)>) -> (i32, i32) {
+    x.bar
+}
diff --git a/src/test/codegen/issue-56267.rs b/src/test/codegen/issue-56267.rs
new file mode 100644 (file)
index 0000000..2c33f55
--- /dev/null
@@ -0,0 +1,18 @@
+// compile-flags: -C no-prepopulate-passes
+
+#![crate_type="rlib"]
+
+#[allow(dead_code)]
+pub struct Foo<T> {
+    foo: u64,
+    bar: T,
+}
+
+// The store writing to bar.1 should have alignment 4. Not checking
+// other stores here, as the alignment will be platform-dependent.
+
+// CHECK: store i32 [[TMP1:%.+]], i32* [[TMP2:%.+]], align 4
+#[no_mangle]
+pub fn test(x: (i32, i32)) -> Foo<(i32, i32)> {
+    Foo { foo: 0, bar: x }
+}
diff --git a/src/test/ui/imports/issue-56263.rs b/src/test/ui/imports/issue-56263.rs
new file mode 100644 (file)
index 0000000..4113d43
--- /dev/null
@@ -0,0 +1,8 @@
+// compile-pass
+// edition:2018
+
+use ::std;
+
+fn main() {
+    let std = 10;
+}
index 754b4c07233ee18820265bd18467aa82263f9a3a..b2601beb35b56fd33bd387a1faeccd3ae02352ed 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 754b4c07233ee18820265bd18467aa82263f9a3a
+Subproject commit b2601beb35b56fd33bd387a1faeccd3ae02352ed