Skip to content

Rollup of 8 pull requests #111174

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

Merged
merged 18 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bd146c7
Explicitly reject negative and reservation drop impls
compiler-errors Apr 26, 2023
3c6d9ec
Use the full Fingerprint when stringifying Svh
saethlin Apr 30, 2023
ed468ee
Encode def span for foreign RPITITs
compiler-errors Apr 30, 2023
6197e4d
Don't `use RibKind::*`
WaffleLapkin May 1, 2023
0fa5920
Remove "RibKind" suffix from `RibKind` variants
WaffleLapkin May 1, 2023
8a08514
Add needs-unwind annotations to tests that need stack unwinding
bjorn3 May 2, 2023
1590350
Remove `allow(rustc::potential_query_instability)` for `builtin_macros`
clubby789 Apr 30, 2023
e3e93f2
Use `GrowableBitSet` to store positional indexes in `asm!`
clubby789 May 2, 2023
4d0887e
correctly recurse when expanding anon consts
BoxyUwU May 2, 2023
8345340
Validate resolution for SelfCtor too.
cjgillot Apr 30, 2023
6fca1a9
Rollup merge of #110859 - compiler-errors:no-negative-drop-impls, r=o…
matthiaskrgr May 4, 2023
1187ce7
Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkov
matthiaskrgr May 4, 2023
3ce6dd2
Rollup merge of #111024 - saethlin:stringify-full-svh, r=oli-obk
matthiaskrgr May 4, 2023
6387eda
Rollup merge of #111027 - clubby789:query-instability-builtin-macros,…
matthiaskrgr May 4, 2023
b194b43
Rollup merge of #111039 - compiler-errors:foreign-span-rpitit, r=tmiasko
matthiaskrgr May 4, 2023
5075457
Rollup merge of #111070 - WaffleLapkin:break_ribs, r=lcnr
matthiaskrgr May 4, 2023
f2bc7e0
Rollup merge of #111094 - bjorn3:fix_test_annotations, r=jyn514
matthiaskrgr May 4, 2023
b4d992f
Rollup merge of #111103 - BoxyUwU:normal_fold_with_gce_norm, r=compil…
matthiaskrgr May 4, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,7 @@ dependencies = [
"rustc_expand",
"rustc_feature",
"rustc_fluent_macro",
"rustc_index",
"rustc_lexer",
"rustc_lint_defs",
"rustc_macros",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_builtin_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_expand = { path = "../rustc_expand" }
rustc_feature = { path = "../rustc_feature" }
rustc_index = { path = "../rustc_index" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
Expand Down
21 changes: 11 additions & 10 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter};
use rustc_ast::tokenstream::TokenStream;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_errors::PResult;
use rustc_expand::base::{self, *};
use rustc_index::bit_set::GrowableBitSet;
use rustc_parse::parser::Parser;
use rustc_parse_format as parse;
use rustc_session::lint;
Expand All @@ -20,8 +21,8 @@ use crate::errors;
pub struct AsmArgs {
pub templates: Vec<P<ast::Expr>>,
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
named_args: FxHashMap<Symbol, usize>,
reg_args: FxHashSet<usize>,
named_args: FxIndexMap<Symbol, usize>,
reg_args: GrowableBitSet<usize>,
pub clobber_abis: Vec<(Symbol, Span)>,
options: ast::InlineAsmOptions,
pub options_spans: Vec<Span>,
Expand Down Expand Up @@ -56,8 +57,8 @@ pub fn parse_asm_args<'a>(
let mut args = AsmArgs {
templates: vec![first_template],
operands: vec![],
named_args: FxHashMap::default(),
reg_args: FxHashSet::default(),
named_args: Default::default(),
reg_args: Default::default(),
clobber_abis: Vec::new(),
options: ast::InlineAsmOptions::empty(),
options_spans: vec![],
Expand Down Expand Up @@ -213,7 +214,7 @@ pub fn parse_asm_args<'a>(
} else {
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
let explicit = args.reg_args.iter().map(|p| args.operands[*p].1).collect();
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();

diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
}
Expand Down Expand Up @@ -446,8 +447,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
// Register operands are implicitly used since they are not allowed to be
// referenced in the template string.
let mut used = vec![false; args.operands.len()];
for pos in &args.reg_args {
used[*pos] = true;
for pos in args.reg_args.iter() {
used[pos] = true;
}
let named_pos: FxHashMap<usize, Symbol> =
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
Expand Down Expand Up @@ -581,7 +582,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
if idx >= args.operands.len()
|| named_pos.contains_key(&idx)
|| args.reg_args.contains(&idx)
|| args.reg_args.contains(idx)
{
let msg = format!("invalid reference to argument at index {}", idx);
let mut err = ecx.struct_span_err(span, &msg);
Expand All @@ -608,7 +609,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
args.operands[idx].1,
"named arguments cannot be referenced by position",
);
} else if args.reg_args.contains(&idx) {
} else if args.reg_args.contains(idx) {
err.span_label(
args.operands[idx].1,
"explicit register argument",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This crate contains implementations of built-in macros and other code generating facilities
//! injecting code into the crate before it is lowered to HIR.

#![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)]
#![feature(box_patterns)]
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_data_structures/src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl Fingerprint {
)
}

#[inline]
pub(crate) fn as_u128(self) -> u128 {
u128::from(self.1) << 64 | u128::from(self.0)
}

// Combines two hashes in an order independent way. Make sure this is what
// you want.
#[inline]
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_data_structures/src/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ impl Svh {
Svh { hash }
}

pub fn as_u64(&self) -> u64 {
self.hash.to_smaller_hash().as_u64()
pub fn as_u128(self) -> u128 {
self.hash.as_u128()
}

pub fn to_string(&self) -> String {
format!("{:016x}", self.hash.to_smaller_hash())
pub fn to_hex(self) -> String {
format!("{:032x}", self.hash.as_u128())
}
}

impl fmt::Display for Svh {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(&self.to_string())
f.pad(&self.to_hex())
}
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,7 @@ hir_analysis_const_specialize = cannot specialize on const impl with non-const i
hir_analysis_static_specialize = cannot specialize on `'static` lifetime

hir_analysis_missing_tilde_const = missing `~const` qualifier for specialization

hir_analysis_drop_impl_negative = negative `Drop` impls are not supported

hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported
17 changes: 16 additions & 1 deletion compiler/rustc_hir_analysis/src/check/dropck.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
//
// We don't do any drop checking during hir typeck.
use crate::hir::def_id::{DefId, LocalDefId};
use rustc_errors::{struct_span_err, ErrorGuaranteed};
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::util::IgnoreRegions;
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};

use crate::errors;
use crate::hir::def_id::{DefId, LocalDefId};

/// This function confirms that the `Drop` implementation identified by
/// `drop_impl_did` is not any more specialized than the type it is
/// attached to (Issue #8142).
Expand All @@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
///
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
match tcx.impl_polarity(drop_impl_did) {
ty::ImplPolarity::Positive => {}
ty::ImplPolarity::Negative => {
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Negative {
span: tcx.def_span(drop_impl_did),
}));
}
ty::ImplPolarity::Reservation => {
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Reservation {
span: tcx.def_span(drop_impl_did),
}));
}
}
let dtor_self_type = tcx.type_of(drop_impl_did).subst_identity();
let dtor_predicates = tcx.predicates_of(drop_impl_did);
match dtor_self_type.kind() {
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,17 @@ pub(crate) struct MissingTildeConst {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
pub(crate) enum DropImplPolarity {
#[diag(hir_analysis_drop_impl_negative)]
Negative {
#[primary_span]
span: Span,
},
#[diag(hir_analysis_drop_impl_reservation)]
Reservation {
#[primary_span]
span: Span,
},
}
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]);

// Append the svh
base_n::push_str(svh.as_u64() as u128, INT_ENCODE_BASE, &mut new_sub_dir_name);
base_n::push_str(svh.as_u128(), INT_ENCODE_BASE, &mut new_sub_dir_name);

// Create the full path
let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::AnonConst
| DefKind::InlineConst
| DefKind::OpaqueTy
| DefKind::ImplTraitPlaceholder
| DefKind::Field
| DefKind::Impl { .. }
| DefKind::Closure
| DefKind::Generator => true,
DefKind::ForeignMod | DefKind::ImplTraitPlaceholder | DefKind::GlobalAsm => false,
DefKind::ForeignMod | DefKind::GlobalAsm => false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/abstract_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ impl<'tcx> TyCtxt<'tcx> {
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
Ok(Some(bac)) => {
let substs = self.tcx.erase_regions(uv.substs);
bac.subst(self.tcx, substs)
let bac = bac.subst(self.tcx, substs);
return bac.fold_with(self);
}
Ok(None) => c,
},
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,16 @@ impl<'tcx> TyCtxt<'tcx> {
let ty = self.type_of(adt_did).subst_identity();
let mut dtor_candidate = None;
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
return;
};

if validate(self, impl_did).is_err() {
// Already `ErrorGuaranteed`, no need to delay a span bug here.
return;
}

let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
return;
};

if let Some((old_item_id, _)) = dtor_candidate {
self.sess
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

let sm = self.tcx.sess.source_map();
let def_id = match outer_res {
Res::SelfTyParam { .. } => {
Res::SelfTyParam { .. } | Res::SelfCtor(_) => {
err.span_label(span, "can't use `Self` here");
return err;
}
Expand Down
Loading