Skip to content

Commit

Permalink
Merge #89 #90
Browse files Browse the repository at this point in the history
89: Automated pull from upstream `master` r=Dajamante a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117006
* rust-lang/rust#117511
* rust-lang/rust#117641
  * rust-lang/rust#117637
  * rust-lang/rust#117631
  * rust-lang/rust#117516
  * rust-lang/rust#117190
* rust-lang/rust#117292
* rust-lang/rust#117603
* rust-lang/rust#116988
* rust-lang/rust#117630
  * rust-lang/rust#117615
  * rust-lang/rust#117613
  * rust-lang/rust#117592
* rust-lang/rust#117578
* rust-lang/rust#117435
* rust-lang/rust#117607



90: bump serde and serde_derive r=tshepang a=Dajamante

Trying to get around the failure seen in #86 

Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Co-authored-by: SparrowLii <liyuan179@huawei.com>
Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
Co-authored-by: Gurinder Singh <frederick.the.fool@gmail.com>
Co-authored-by: Michael Goulet <michael@errs.io>
Co-authored-by: Thom Chiovoloni <thom@shift.click>
Co-authored-by: klensy <klensy@users.noreply.github.com>
Co-authored-by: Jack Huey <31162821+jackh726@users.noreply.github.com>
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Sven Marnach <sven@mozilla.com>
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
Co-authored-by: aissata <aimaiga2@gmail.com>
  • Loading branch information
16 people committed Nov 7, 2023
3 parents 7d8c41c + 45efc75 + a5eb8a1 commit e8a60e5
Show file tree
Hide file tree
Showing 52 changed files with 683 additions and 548 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock
Expand Up @@ -3724,9 +3724,9 @@ dependencies = [

[[package]]
name = "portable-atomic"
version = "1.4.2"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e"
checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b"

[[package]]
name = "ppv-lite86"
Expand Down Expand Up @@ -4487,6 +4487,7 @@ dependencies = [
"measureme",
"memmap2",
"parking_lot 0.12.1",
"portable-atomic",
"rustc-hash",
"rustc-rayon",
"rustc-rayon-core",
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_abi/src/layout.rs
Expand Up @@ -906,9 +906,8 @@ fn univariant<
use rand::{seq::SliceRandom, SeedableRng};
// `ReprOptions.layout_seed` is a deterministic seed we can use to randomize field
// ordering.
let mut rng = rand_xoshiro::Xoshiro128StarStar::seed_from_u64(
repr.field_shuffle_seed.as_u64(),
);
let mut rng =
rand_xoshiro::Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);

// Shuffle the ordering of the fields.
optimizing.shuffle(&mut rng);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_abi/src/lib.rs
Expand Up @@ -76,15 +76,14 @@ pub struct ReprOptions {
pub align: Option<Align>,
pub pack: Option<Align>,
pub flags: ReprFlags,
#[cfg(feature = "randomize")]
/// The seed to be used for randomizing a type's layout
///
/// Note: This could technically be a `Hash128` which would
/// Note: This could technically be a `u128` which would
/// be the "most accurate" hash as it'd encompass the item and crate
/// hash without loss, but it does pay the price of being larger.
/// Everything's a tradeoff, a 64-bit seed should be sufficient for our
/// purposes (primarily `-Z randomize-layout`)
pub field_shuffle_seed: rustc_data_structures::stable_hasher::Hash64,
pub field_shuffle_seed: u64,
}

impl ReprOptions {
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Expand Up @@ -2,7 +2,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty};
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
use rustc_span::{BytePos, Span};
use rustc_span::{BytePos, ExpnKind, MacroKind, Span};

use crate::diagnostics::CapturedMessageOpt;
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
Expand Down Expand Up @@ -488,6 +488,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
args_span,
}
});

self.add_note_for_packed_struct_derive(err, original_path.local);
}
}
}
Expand Down Expand Up @@ -594,4 +596,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);
}
}

/// Adds an explanatory note if the move error occurs in a derive macro
/// expansion of a packed struct.
/// Such errors happen because derive macro expansions shy away from taking
/// references to the struct's fields since doing so would be undefined behaviour
fn add_note_for_packed_struct_derive(&self, err: &mut Diagnostic, local: Local) {
let local_place: PlaceRef<'tcx> = local.into();
let local_ty = local_place.ty(self.body.local_decls(), self.infcx.tcx).ty.peel_refs();

if let Some(adt) = local_ty.ty_adt_def()
&& adt.repr().packed()
&& let ExpnKind::Macro(MacroKind::Derive, name) = self.body.span.ctxt().outer_expn_data().kind
{
err.note(format!("`#[derive({name})]` triggers a move because taking references to the fields of a packed struct is undefined behaviour"));
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/env.rs
Expand Up @@ -108,7 +108,7 @@ pub fn expand_env<'cx>(

return DummyResult::any(sp);
}
Some(value) => cx.expr_str(sp, value),
Some(value) => cx.expr_str(span, value),
};
MacEager::expr(e)
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Expand Up @@ -104,11 +104,7 @@ pub trait CodegenBackend {
outputs: &OutputFilenames,
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;

/// This is called on the returned `Box<dyn Any>` from `join_codegen`
///
/// # Panics
///
/// Panics when the passed `Box<dyn Any>` was not returned by `join_codegen`.
/// This is called on the returned `CodegenResults` from `join_codegen`
fn link(
&self,
sess: &Session,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/Cargo.toml
Expand Up @@ -47,6 +47,9 @@ features = [
memmap2 = "0.2.1"
# tidy-alphabetical-end

[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
portable-atomic = "1.5.1"

[features]
# tidy-alphabetical-start
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rustc-rayon", "rustc-rayon-core"]
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_data_structures/src/marker.rs
Expand Up @@ -138,7 +138,6 @@ cfg_match! {
[std::sync::atomic::AtomicUsize]
[std::sync::atomic::AtomicU8]
[std::sync::atomic::AtomicU32]
[std::sync::atomic::AtomicU64]
[std::backtrace::Backtrace]
[std::io::Error]
[std::fs::File]
Expand All @@ -148,6 +147,18 @@ cfg_match! {
[crate::owned_slice::OwnedSlice]
);

// PowerPC and MIPS platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
already_sync!(
[std::sync::atomic::AtomicU64]
);

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
already_sync!(
[portable_atomic::AtomicU64]
);

macro_rules! impl_dyn_sync {
($($($attr: meta)* [$ty: ty where $($generics2: tt)*])*) => {
$(unsafe impl<$($generics2)*> DynSync for $ty {})*
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_data_structures/src/sync.rs
Expand Up @@ -265,7 +265,15 @@ cfg_match! {

pub use std::sync::OnceLock;

pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};

// PowerPC and MIPS platforms with 32-bit pointers do not
// have AtomicU64 type.
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
pub use std::sync::atomic::AtomicU64;

#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
pub use portable_atomic::AtomicU64;

pub use std::sync::Arc as Lrc;
pub use std::sync::Weak as Weak;
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_driver_impl/src/lib.rs
Expand Up @@ -41,6 +41,7 @@ use rustc_session::cstore::MetadataLoader;
use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, EarlyErrorHandler, Session};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::source_map::FileLoader;
use rustc_span::symbol::sym;
use rustc_span::FileName;
Expand Down Expand Up @@ -421,8 +422,12 @@ fn run_compiler(
// effects of writing the dep-info and reporting errors.
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
} else {
let krate = queries.parse()?.steal();
pretty::print(sess, *ppm, pretty::PrintExtra::AfterParsing { krate });
let krate = queries.parse()?;
pretty::print(
sess,
*ppm,
pretty::PrintExtra::AfterParsing { krate: &*krate.borrow() },
);
}
trace!("finished pretty-printing");
return early_exit();
Expand Down Expand Up @@ -477,8 +482,7 @@ fn run_compiler(
}

if sess.opts.unstable_opts.print_vtable_sizes {
let crate_name =
compiler.session().opts.crate_name.as_deref().unwrap_or("<UNKNOWN_CRATE>");
let crate_name = queries.global_ctxt()?.enter(|tcx| tcx.crate_name(LOCAL_CRATE));

sess.code_stats.print_vtable_sizes(crate_name);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/pretty.rs
Expand Up @@ -217,7 +217,7 @@ fn write_or_print(out: &str, sess: &Session) {
// Extra data for pretty-printing, the form of which depends on what kind of
// pretty-printing we are doing.
pub enum PrintExtra<'tcx> {
AfterParsing { krate: ast::Crate },
AfterParsing { krate: &'tcx ast::Crate },
NeedsAstMap { tcx: TyCtxt<'tcx> },
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Expand Up @@ -32,6 +32,7 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _
use rustc_trait_selection::traits::{
self, ObligationCause, ObligationCauseCode, ObligationCtxt, WellFormedLoc,
};
use rustc_type_ir::TypeFlags;

use std::cell::LazyCell;
use std::ops::{ControlFlow, Deref};
Expand Down Expand Up @@ -1877,7 +1878,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
continue;
}
// Match the existing behavior.
if pred.is_global() && !pred.has_late_bound_vars() {
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
let pred = self.normalize(span, None, pred);
let hir_node = tcx.hir().find_by_def_id(self.body_def_id);

Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_hir_typeck/src/expr.rs
Expand Up @@ -959,12 +959,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MachineApplicable,
);
});
self.check_for_missing_semi(lhs, &mut err);

adjust_err(&mut err);

err.emit();
}

/// Check if the expression that could not be assigned to was a typoed expression that
pub fn check_for_missing_semi(
&self,
expr: &'tcx hir::Expr<'tcx>,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
) -> bool {
if let hir::ExprKind::Binary(binop, lhs, rhs) = expr.kind
&& let hir::BinOpKind::Mul = binop.node
&& self.tcx.sess.source_map().is_multiline(lhs.span.between(rhs.span))
&& rhs.is_syntactic_place_expr()
{
// v missing semicolon here
// foo()
// *bar = baz;
// (#80446).
err.span_suggestion_verbose(
lhs.span.shrink_to_hi(),
"you might have meant to write a semicolon here",
";".to_string(),
Applicability::MachineApplicable,
);
return true;
}
false
}

// Check if an expression `original_expr_id` comes from the condition of a while loop,
/// as opposed from the body of a while loop, which we can naively check by iterating
/// parents until we find a loop...
Expand Down
88 changes: 88 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Expand Up @@ -409,6 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.downgrade_to_delayed_bug();
}

self.find_builder_fn(&mut err, rcvr_ty, source);
if tcx.ty_is_opaque_future(rcvr_ty) && item_name.name == sym::poll {
err.help(format!(
"method `poll` found on `Pin<&mut {ty_str}>`, \
Expand Down Expand Up @@ -1407,6 +1408,93 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

/// Look at all the associated functions without receivers in the type's inherent impls
/// to look for builders that return `Self`, `Option<Self>` or `Result<Self, _>`.
fn find_builder_fn(&self, err: &mut Diagnostic, rcvr_ty: Ty<'tcx>, source: SelfSource<'tcx>) {
let ty::Adt(adt_def, _) = rcvr_ty.kind() else {
return;
};
let SelfSource::QPath(ty) = source else {
return;
};
let hir = self.tcx.hir();
if let Some(Node::Pat(_)) = hir.find(hir.parent_id(ty.hir_id)) {
// Do not suggest a fn call when a pattern is expected.
return;
}
let mut items = self
.tcx
.inherent_impls(adt_def.did())
.iter()
.flat_map(|i| self.tcx.associated_items(i).in_definition_order())
// Only assoc fn with no receivers.
.filter(|item| matches!(item.kind, ty::AssocKind::Fn) && !item.fn_has_self_parameter)
.filter_map(|item| {
// Only assoc fns that return `Self`, `Option<Self>` or `Result<Self, _>`.
let ret_ty = self.tcx.fn_sig(item.def_id).skip_binder().output();
let ret_ty = self.tcx.erase_late_bound_regions(ret_ty);
let ty::Adt(def, args) = ret_ty.kind() else {
return None;
};
// Check for `-> Self`
if self.can_eq(self.param_env, ret_ty, rcvr_ty) {
return Some((item.def_id, ret_ty));
}
// Check for `-> Option<Self>` or `-> Result<Self, _>`
if ![self.tcx.lang_items().option_type(), self.tcx.get_diagnostic_item(sym::Result)]
.contains(&Some(def.did()))
{
return None;
}
let arg = args.get(0)?.expect_ty();
if self.can_eq(self.param_env, rcvr_ty, arg) {
Some((item.def_id, ret_ty))
} else {
None
}
})
.collect::<Vec<_>>();
let post = if items.len() > 5 {
let items_len = items.len();
items.truncate(4);
format!("\nand {} others", items_len - 4)
} else {
String::new()
};
match &items[..] {
[] => {}
[(def_id, ret_ty)] => {
err.span_note(
self.tcx.def_span(def_id),
format!(
"if you're trying to build a new `{rcvr_ty}`, consider using `{}` which \
returns `{ret_ty}`",
self.tcx.def_path_str(def_id),
),
);
}
_ => {
let span: MultiSpan = items
.iter()
.map(|(def_id, _)| self.tcx.def_span(def_id))
.collect::<Vec<Span>>()
.into();
err.span_note(
span,
format!(
"if you're trying to build a new `{rcvr_ty}` consider using one of the \
following associated functions:\n{}{post}",
items
.iter()
.map(|(def_id, _ret_ty)| self.tcx.def_path_str(def_id))
.collect::<Vec<String>>()
.join("\n")
),
);
}
}
}

/// Suggest calling `Ty::method` if `.method()` isn't found because the method
/// doesn't take a `self` receiver.
fn suggest_associated_call_syntax(
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_hir_typeck/src/op.rs
Expand Up @@ -379,6 +379,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(err, output_def_id)
}
};
if self.check_for_missing_semi(expr, &mut err)
&& let hir::Node::Expr(expr) = self.tcx.hir().get_parent(expr.hir_id)
&& let hir::ExprKind::Assign(..) = expr.kind
{
// We defer to the later error produced by `check_lhs_assignable`.
err.delay_as_bug();
}

let suggest_deref_binop =
|err: &mut DiagnosticBuilder<'_, _>, lhs_deref_ty: Ty<'tcx>| {
Expand Down

0 comments on commit e8a60e5

Please sign in to comment.