Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 2, 2020
1 parent 562389d commit 67be07d
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 119 deletions.
23 changes: 10 additions & 13 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use crate::hir::def_id::DefId;
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
use crate::hir::DUMMY_HIR_ID;
use crate::hir::{self, Attribute, HirId, Item, ItemKind, TraitItem, TraitItemKind};
use crate::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use crate::lint::builtin::UNUSED_ATTRIBUTES;
use crate::ty::query::Providers;
use crate::ty::TyCtxt;

use errors::{error_code, struct_span_err};
use errors::struct_span_err;
use rustc_span::Span;

use std::fmt::{self, Display};
Expand Down Expand Up @@ -194,7 +194,7 @@ impl CheckAttrVisitor<'tcx> {
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
}

self.check_repr(attrs, span, target, item, hir_id);
self.check_repr(attrs, span, target, item);
self.check_used(attrs, target);
}

Expand Down Expand Up @@ -355,7 +355,6 @@ impl CheckAttrVisitor<'tcx> {
span: &Span,
target: Target,
item: Option<&Item<'_>>,
hir_id: HirId,
) {
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
// ```
Expand Down Expand Up @@ -445,15 +444,13 @@ impl CheckAttrVisitor<'tcx> {
|| (is_simd && is_c)
|| (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
{
self.tcx
.struct_span_lint_hir(
CONFLICTING_REPR_HINTS,
hir_id,
hint_spans.collect::<Vec<Span>>(),
"conflicting representation hints",
)
.code(error_code!(E0566))
.emit();
struct_span_err!(
self.tcx.sess,
hint_spans.collect::<Vec<Span>>(),
E0566,
"conflicting representation hints",
)
.emit();
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,11 @@ declare_lint! {
}

declare_lint! {
pub BINDING_VARIANT_NAME,
pub BINDINGS_WITH_VARIANT_NAME,
Warn,
"detects pattern bindings with the same name as one of the matched variants"
}

declare_lint! {
pub CONFLICTING_REPR_HINTS,
Warn,
"detects when more than one `#[repr(..)]` attribute, with different meaning, is applied"
}

declare_lint! {
pub UNUSED_MACROS,
Warn,
Expand Down Expand Up @@ -471,7 +465,7 @@ declare_lint_pass! {
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_PATTERNS,
BINDING_VARIANT_NAME,
BINDINGS_WITH_VARIANT_NAME,
UNUSED_MACROS,
WARNINGS,
UNUSED_FEATURES,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_error_codes/error_codes/E0566.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Conflicting representation hints have been used on a same item.

Erroneous code example:

```
#[repr(u32, u64)] // warning!
```compile_fail,E0566
#[repr(u32, u64)]
enum Repr { A }
```

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
let ty_path = cx.tcx.def_path_str(edef.did);
cx.tcx
.struct_span_lint_hir(
lint::builtin::BINDING_VARIANT_NAME,
lint::builtin::BINDINGS_WITH_VARIANT_NAME,
p.hir_id,
p.span,
&format!(
Expand Down
35 changes: 16 additions & 19 deletions src/test/run-make-fulldeps/simd-ffi/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@
// cross-compiled standard libraries.
#![feature(no_core, optin_builtin_traits)]
#![no_core]

#![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)]


#[repr(C)]
#[derive(Copy)]
#[repr(simd)]
pub struct f32x4(f32, f32, f32, f32);


extern {
extern "C" {
#[link_name = "llvm.sqrt.v4f32"]
fn vsqrt(x: f32x4) -> f32x4;
}

pub fn foo(x: f32x4) -> f32x4 {
unsafe {vsqrt(x)}
unsafe { vsqrt(x) }
}

#[repr(C)]
#[derive(Copy)]
#[repr(simd)]
pub struct i32x4(i32, i32, i32, i32);


extern {
extern "C" {
// _mm_sll_epi32
#[cfg(any(target_arch = "x86",
target_arch = "x86-64"))]
#[cfg(any(target_arch = "x86", target_arch = "x86-64"))]
#[link_name = "llvm.x86.sse2.psll.d"]
fn integer(a: i32x4, b: i32x4) -> i32x4;

Expand All @@ -48,22 +41,24 @@ extern {
// just some substitute foreign symbol, not an LLVM intrinsic; so
// we still get type checking, but not as detailed as (ab)using
// LLVM.
#[cfg(not(any(target_arch = "x86",
target_arch = "x86-64",
target_arch = "arm",
target_arch = "aarch64")))]
#[cfg(not(any(
target_arch = "x86",
target_arch = "x86-64",
target_arch = "arm",
target_arch = "aarch64"
)))]
fn integer(a: i32x4, b: i32x4) -> i32x4;
}

pub fn bar(a: i32x4, b: i32x4) -> i32x4 {
unsafe {integer(a, b)}
unsafe { integer(a, b) }
}

#[lang = "sized"]
pub trait Sized { }
pub trait Sized {}

#[lang = "copy"]
pub trait Copy { }
pub trait Copy {}

impl Copy for f32 {}
impl Copy for i32 {}
Expand All @@ -77,4 +72,6 @@ auto trait Freeze {}

#[macro_export]
#[rustc_builtin_macro]
macro_rules! Copy { () => () }
macro_rules! Copy {
() => {};
}
35 changes: 23 additions & 12 deletions src/test/ui/conflicting-repr-hints.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#![allow(dead_code)]

#[repr(C)]
enum A { A }
enum A {
A,
}

#[repr(u64)]
enum B { B }
enum B {
B,
}

#[repr(C, u64)] //~ WARNING conflicting representation hints
enum C { C }
#[repr(C, u64)] //~ ERROR conflicting representation hints
enum C {
C,
}

#[repr(u32, u64)] //~ WARNING conflicting representation hints
enum D { D }
#[repr(u32, u64)] //~ ERROR conflicting representation hints
enum D {
D,
}

#[repr(C, packed)]
struct E(i32);
Expand All @@ -37,20 +45,23 @@ struct J(i32); //~ ERROR type has conflicting packed representation hints
struct K(i32);

#[repr(packed, align(8))]
union X { //~ ERROR type has conflicting packed and align representation hints
i: i32
union X {
//~^ ERROR type has conflicting packed and align representation hints
i: i32,
}

#[repr(packed)]
#[repr(align(8))]
union Y { //~ ERROR type has conflicting packed and align representation hints
i: i32
union Y {
//~^ ERROR type has conflicting packed and align representation hints
i: i32,
}

#[repr(align(8))]
#[repr(packed)]
union Z { //~ ERROR type has conflicting packed and align representation hints
i: i32
union Z {
//~^ ERROR type has conflicting packed and align representation hints
i: i32,
}

fn main() {}
37 changes: 19 additions & 18 deletions src/test/ui/conflicting-repr-hints.stderr
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
warning[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:9:8
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:13:8
|
LL | #[repr(C, u64)]
| ^ ^^^
|
= note: `#[warn(conflicting_repr_hints)]` on by default

warning[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:12:8
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:18:8
|
LL | #[repr(u32, u64)]
| ^^^ ^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:19:1
--> $DIR/conflicting-repr-hints.rs:27:1
|
LL | struct F(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:23:1
--> $DIR/conflicting-repr-hints.rs:31:1
|
LL | struct G(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:27:1
--> $DIR/conflicting-repr-hints.rs:35:1
|
LL | struct H(i32);
| ^^^^^^^^^^^^^^

error[E0634]: type has conflicting packed representation hints
--> $DIR/conflicting-repr-hints.rs:30:1
--> $DIR/conflicting-repr-hints.rs:38:1
|
LL | struct I(i32);
| ^^^^^^^^^^^^^^

error[E0634]: type has conflicting packed representation hints
--> $DIR/conflicting-repr-hints.rs:34:1
--> $DIR/conflicting-repr-hints.rs:42:1
|
LL | struct J(i32);
| ^^^^^^^^^^^^^^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:40:1
--> $DIR/conflicting-repr-hints.rs:48:1
|
LL | / union X {
LL | | i: i32
LL | |
LL | | i: i32,
LL | | }
| |_^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:46:1
--> $DIR/conflicting-repr-hints.rs:55:1
|
LL | / union Y {
LL | | i: i32
LL | |
LL | | i: i32,
LL | | }
| |_^

error[E0587]: type has conflicting packed and align representation hints
--> $DIR/conflicting-repr-hints.rs:52:1
--> $DIR/conflicting-repr-hints.rs:62:1
|
LL | / union Z {
LL | | i: i32
LL | |
LL | | i: i32,
LL | | }
| |_^

error: aborting due to 8 previous errors
error: aborting due to 10 previous errors

Some errors have detailed explanations: E0566, E0587.
For more information about an error, try `rustc --explain E0566`.
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-repr-simd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[repr(simd)] //~ error: SIMD types are experimental
struct Foo(u64, u64);

#[repr(C)] //~ warn: conflicting representation hints
#[repr(C)] //~ ERROR conflicting representation hints
#[repr(simd)] //~ error: SIMD types are experimental
struct Bar(u64, u64);

Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ LL | #[repr(simd)]
= note: for more information, see https://github.com/rust-lang/rust/issues/27731
= help: add `#![feature(repr_simd)]` to the crate attributes to enable

warning[E0566]: conflicting representation hints
error[E0566]: conflicting representation hints
--> $DIR/feature-gate-repr-simd.rs:4:8
|
LL | #[repr(C)]
| ^
LL | #[repr(simd)]
| ^^^^
|
= note: `#[warn(conflicting_repr_hints)]` on by default

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0566, E0658.
For more information about an error, try `rustc --explain E0566`.
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-14221.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `A` is named the same as one of the variants of
LL | A => "A",
| ^ help: to match on the variant, qualify the path: `E::A`
|
= note: `#[warn(binding_variant_name)]` on by default
= note: `#[warn(bindings_with_variant_name)]` on by default

warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E`
--> $DIR/issue-14221.rs:15:13
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-19100.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `Bar` is named the same as one of the variants o
LL | Bar if true
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
|
= note: `#[warn(binding_variant_name)]` on by default
= note: `#[warn(bindings_with_variant_name)]` on by default

warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-19100.rs:22:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-30302.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning[E0170]: pattern binding `Nil` is named the same as one of the variants o
LL | Nil => true,
| ^^^ help: to match on the variant, qualify the path: `Stack::Nil`
|
= note: `#[warn(binding_variant_name)]` on by default
= note: `#[warn(bindings_with_variant_name)]` on by default

error: unreachable pattern
--> $DIR/issue-30302.rs:15:9
Expand Down
Loading

0 comments on commit 67be07d

Please sign in to comment.