Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #93525

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bae0da8
Implement data and vtable getters for `RawWaker`
oxalica Dec 12, 2021
d9b98f9
Eliminate duplicate codes of is_single_fp_element
woodenarrow Dec 17, 2021
f8ee57b
`impl Display for io::ErrorKind`
jyn514 Jan 19, 2022
2bae730
update `FutureIncompatibilityReason`
lcnr Jan 27, 2022
2e9ee90
implement lint for suspicious auto trait impls
lcnr Jan 27, 2022
7f24778
Suggest making base prefix lowercase if parsing fails
5225225 Jan 17, 2022
1a77d62
kmc-solid: Increase the default stack size
kawadakk Jan 31, 2022
0b8f372
Remove two unnecessary transmutes from opaque Encoder and Decoder
bjorn3 Jan 29, 2022
ec3b711
Write UI tests, tweak message
5225225 Jan 27, 2022
c15ef58
Fix suggestion to slice if scrutinee is a `Result` or `Option`
FabianWolff Nov 29, 2021
0363f11
Add match on `Vec<_>` to `ui/typeck/issue-91328.rs` test
FabianWolff Jan 15, 2022
95344c0
Add FIXME comment
FabianWolff Jan 31, 2022
a937dd5
Rollup merge of #91343 - FabianWolff:issue-91328-as-deref, r=jackh726
matthiaskrgr Jan 31, 2022
2d658e9
Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnay
matthiaskrgr Jan 31, 2022
0c44c66
Rollup merge of #92021 - woodenarrow:br_single_fp_element, r=Mark-Sim…
matthiaskrgr Jan 31, 2022
561f997
Rollup merge of #93019 - 5225225:uppercase-suffix, r=wesleywiser
matthiaskrgr Jan 31, 2022
802c57d
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
matthiaskrgr Jan 31, 2022
478698b
Rollup merge of #93267 - lcnr:auto-trait-lint, r=nikomatsakis
matthiaskrgr Jan 31, 2022
4aee623
Rollup merge of #93456 - bjorn3:remove_unnecessary_unsafe, r=michaelw…
matthiaskrgr Jan 31, 2022
8968b20
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
matthiaskrgr Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,12 @@ pub struct GrowableBitSet<T: Idx> {
bit_set: BitSet<T>,
}

impl<T: Idx> Default for GrowableBitSet<T> {
fn default() -> Self {
GrowableBitSet::new_empty()
}
}

impl<T: Idx> GrowableBitSet<T> {
/// Ensure that the set can hold at least `min_domain_size` elements.
pub fn ensure(&mut self, min_domain_size: usize) {
Expand Down
43 changes: 43 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,10 @@ declare_lint! {
Warn,
"detects name collision with an existing but unstable method",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::Custom(
"once this associated item is added to the standard library, \
the ambiguity may cause an error or change in behavior!"
),
reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
// Note: this item represents future incompatibility of all unstable functions in the
// standard library, and thus should never be removed or changed to an error.
Expand Down Expand Up @@ -2335,6 +2339,10 @@ declare_lint! {
Warn,
"reservation of a two-phased borrow conflicts with other shared borrows",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::Custom(
"this borrowing pattern was not meant to be accepted, \
and may become a hard error in the future"
),
reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
};
}
Expand Down Expand Up @@ -3046,6 +3054,7 @@ declare_lint_pass! {
DEREF_INTO_DYN_SUPERTRAIT,
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
DUPLICATE_MACRO_ATTRIBUTES,
SUSPICIOUS_AUTO_TRAIT_IMPLS,
]
}

Expand Down Expand Up @@ -3622,3 +3631,37 @@ declare_lint! {
Warn,
"duplicated attribute"
}

declare_lint! {
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
/// implementations of auto traits.
///
/// ### Example
///
/// ```rust
/// struct Foo<T>(T);
///
/// unsafe impl<T> Send for Foo<*const T> {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
/// in two different ways: either by writing an explicit impl or if
/// all fields of the type implement that auto trait.
///
/// The compiler disables the automatic implementation if an explicit one
/// exists for given type constructor. The exact rules governing this
/// are currently unsound and quite subtle and and will be modified in the future.
/// This change will cause the automatic implementation to be disabled in more
/// cases, potentially breaking some code.
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
Warn,
"the rules governing auto traits will change in the future",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
};
}
5 changes: 5 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@ pub enum FutureIncompatibilityReason {
/// This will be an error in a future release, and
/// Cargo should create a report even for dependencies
FutureReleaseErrorReportNow,
/// Code that changes meaning in some way in a
/// future release.
FutureReleaseSemanticsChange,
/// Previously accepted code that will become an
/// error in the provided edition
EditionError(Edition),
/// Code that changes meaning in some way in
/// the provided edition
EditionSemanticsChange(Edition),
/// A custom reason.
Custom(&'static str),
}

impl FutureIncompatibilityReason {
Expand Down
47 changes: 22 additions & 25 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ pub fn struct_lint_level<'s, 'd>(
decorate: Box<dyn for<'b> FnOnce(LintDiagnosticBuilder<'b>) + 'd>,
) {
// Check for future incompatibility lints and issue a stronger warning.
let lint_id = LintId::of(lint);
let future_incompatible = lint.future_incompatible;

let has_future_breakage = future_incompatible.map_or(
Expand Down Expand Up @@ -345,31 +344,29 @@ pub fn struct_lint_level<'s, 'd>(
err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn });

if let Some(future_incompatible) = future_incompatible {
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
"once this associated item is added to the standard library, the ambiguity may \
cause an error or change in behavior!"
.to_owned()
} else if lint_id == LintId::of(builtin::MUTABLE_BORROW_RESERVATION_CONFLICT) {
"this borrowing pattern was not meant to be accepted, and may become a hard error \
in the future"
.to_owned()
} else if let FutureIncompatibilityReason::EditionError(edition) =
future_incompatible.reason
{
let current_edition = sess.edition();
format!(
"this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
current_edition, edition
)
} else if let FutureIncompatibilityReason::EditionSemanticsChange(edition) =
future_incompatible.reason
{
format!("this changes meaning in Rust {}", edition)
} else {
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in a future release!"
.to_owned()
let explanation = match future_incompatible.reason {
FutureIncompatibilityReason::FutureReleaseError
| FutureIncompatibilityReason::FutureReleaseErrorReportNow => {
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in a future release!"
.to_owned()
}
FutureIncompatibilityReason::FutureReleaseSemanticsChange => {
"this will change its meaning in a future release!".to_owned()
}
FutureIncompatibilityReason::EditionError(edition) => {
let current_edition = sess.edition();
format!(
"this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
current_edition, edition
)
}
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
format!("this changes meaning in Rust {}", edition)
}
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
};

if future_incompatible.explain_reason {
err.warn(&explanation);
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ impl<'tcx> TyCtxt<'tcx> {
});
}

pub fn non_blanket_impls_for_ty(
self,
def_id: DefId,
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
let impls = self.trait_impls_of(def_id);
if let Some(simp) =
fast_reject::simplify_type(self, self_ty, SimplifyParams::No, StripReferences::No)
{
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
return impls.iter().copied();
}
}

[].iter().copied()
}

/// Applies function to every impl that could possibly match the self type `self_ty` and returns
/// the first non-none value.
pub fn find_map_relevant_impl<T, F: FnMut(DefId) -> Option<T>>(
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,19 @@ impl<'a> Parser<'a> {
s.len() > 1 && s.starts_with(first_chars) && s[1..].chars().all(|c| c.is_ascii_digit())
}

// Try to lowercase the prefix if it's a valid base prefix.
fn fix_base_capitalisation(s: &str) -> Option<String> {
if let Some(stripped) = s.strip_prefix("B") {
Some(format!("0b{stripped}"))
} else if let Some(stripped) = s.strip_prefix("O") {
Some(format!("0o{stripped}"))
} else if let Some(stripped) = s.strip_prefix("X") {
Some(format!("0x{stripped}"))
} else {
None
}
}

let token::Lit { kind, suffix, .. } = lit;
match err {
// `NotLiteral` is not an error by itself, so we don't report
Expand All @@ -1724,6 +1737,18 @@ impl<'a> Parser<'a> {
self.struct_span_err(span, &msg)
.help("valid widths are 8, 16, 32, 64 and 128")
.emit();
} else if let Some(fixed) = fix_base_capitalisation(suf) {
let msg = "invalid base prefix for number literal";

self.struct_span_err(span, &msg)
.note("base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase")
.span_suggestion(
span,
"try making the prefix lowercase",
fixed,
Applicability::MaybeIncorrect,
)
.emit();
} else {
let msg = format!("invalid suffix `{}` for number literal", suf);
self.struct_span_err(span, &msg)
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ impl serialize::Encoder for Encoder {

#[inline]
fn emit_i8(&mut self, v: i8) -> EncodeResult {
let as_u8: u8 = unsafe { std::mem::transmute(v) };
self.emit_u8(as_u8)
self.emit_u8(v as u8)
}

#[inline]
Expand Down Expand Up @@ -629,9 +628,9 @@ impl<'a> serialize::Decoder for Decoder<'a> {

#[inline]
fn read_i8(&mut self) -> i8 {
let as_u8 = self.data[self.position];
let value = self.data[self.position];
self.position += 1;
unsafe { ::std::mem::transmute(as_u8) }
value as i8
}

#[inline]
Expand Down
22 changes: 2 additions & 20 deletions compiler/rustc_target/src/abi/call/s390x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for a pre-z13 machine or using -mno-vx.

use crate::abi::call::{ArgAbi, FnAbi, Reg};
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::abi::{HasDataLayout, TyAbiInterface};

fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
Expand All @@ -12,24 +12,6 @@ fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
}
}

fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
{
match layout.abi {
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
abi::Abi::Aggregate { .. } => {
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
is_single_fp_element(cx, layout.field(cx, 0))
} else {
false
}
}
_ => false,
}
}

fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
Expand All @@ -40,7 +22,7 @@ where
return;
}

if is_single_fp_element(cx, arg.layout) {
if arg.layout.is_single_fp_element(cx) {
match arg.layout.size.bytes() {
4 => arg.cast_to(Reg::f32()),
8 => arg.cast_to(Reg::f64()),
Expand Down
22 changes: 2 additions & 20 deletions compiler/rustc_target/src/abi/call/x86.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind};
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::abi::{HasDataLayout, TyAbiInterface};
use crate::spec::HasTargetSpec;

#[derive(PartialEq)]
Expand All @@ -8,24 +8,6 @@ pub enum Flavor {
Fastcall,
}

fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout,
{
match layout.abi {
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
abi::Abi::Aggregate { .. } => {
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
is_single_fp_element(cx, layout.field(cx, 0))
} else {
false
}
}
_ => false,
}
}

pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor)
where
Ty: TyAbiInterface<'a, C> + Copy,
Expand All @@ -44,7 +26,7 @@ where
if t.abi_return_struct_as_int {
// According to Clang, everyone but MSVC returns single-element
// float aggregates directly in a floating-point register.
if !t.is_like_msvc && is_single_fp_element(cx, fn_abi.ret.layout) {
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
match fn_abi.ret.layout.size.bytes() {
4 => fn_abi.ret.cast_to(Reg::f32()),
8 => fn_abi.ret.cast_to(Reg::f64()),
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
{
Ty::ty_and_layout_pointee_info_at(self, cx, offset)
}

pub fn is_single_fp_element<C>(self, cx: &C) -> bool
where
Ty: TyAbiInterface<'a, C>,
C: HasDataLayout,
{
match self.abi {
Abi::Scalar(scalar) => scalar.value.is_float(),
Abi::Aggregate { .. } => {
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
self.field(cx, 0).is_single_fp_element(cx)
} else {
false
}
}
_ => false,
}
}
}

impl<'a, Ty> TyAndLayout<'a, Ty> {
Expand Down
Loading