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 #127819

Merged
merged 25 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e37b92f
Use an iterator to find `expand_until`
Zalathar Jul 7, 2024
0081162
delete #![allow(unsafe_op_in_unsafe_fn)]
Sword-Destiny Jul 16, 2024
060a40d
clean unsafe op in unsafe fn
Sword-Destiny Jul 16, 2024
00fff8a
clean unsafe op in unsafe fn
Sword-Destiny Jul 16, 2024
af5c90d
clean unsafe op in unsafe fn
Sword-Destiny Jul 16, 2024
9183af2
deny unsafe_op_in_unsafe_fn for teeos
Sword-Destiny Jul 16, 2024
71eb49c
fmt
compiler-errors Jul 14, 2024
28503d6
Fix unsafe_op_in_unsafe_fn in compiler
compiler-errors Jul 14, 2024
664907c
run-make-support: update gimli to 0.31.0
Mrmaxmeier Jul 16, 2024
fb98fbb
Make `ErrorGuaranteed` discoverable outside types, consts, and lifetimes
oli-obk Jul 16, 2024
077d0da
add test for issue 127590
chenyukang Jul 16, 2024
48ddf5e
Fix the issue of invalid suggestion for a reference of iterator
chenyukang Jul 16, 2024
53f7f8c
Remove an unnecessary impl
oli-obk Jul 16, 2024
9a4c105
Just store a span instead of the whole item
oli-obk Jul 8, 2024
b879e29
Remove a needless borrow
oli-obk Jul 9, 2024
d9f9592
Remove a boilerplaty abstraction
oli-obk Jul 9, 2024
117ff0a
Fix a bunch of sites that were walking instead of visiting, making it…
oli-obk Jul 9, 2024
5ee4533
Rollup merge of #127669 - chenyukang:yukang-fix-deref-127590, r=nneth…
matthiaskrgr Jul 16, 2024
7409a52
Rollup merge of #127707 - Zalathar:expand-until, r=Nadrieril
matthiaskrgr Jul 16, 2024
73028fe
Rollup merge of #127730 - compiler-errors:ed-2024-unsafe, r=petrochenkov
matthiaskrgr Jul 16, 2024
08809eb
Rollup merge of #127789 - Sword-Destiny:master, r=petrochenkov
matthiaskrgr Jul 16, 2024
2876b1b
Rollup merge of #127805 - Mrmaxmeier:run-make-bump-gimli, r=jieyouxu
matthiaskrgr Jul 16, 2024
8fd1df8
Rollup merge of #127808 - oli-obk:tainting_visitors2, r=lcnr,nnethercote
matthiaskrgr Jul 16, 2024
862852f
Rollup merge of #127817 - oli-obk:mut_visitor_fix, r=petrochenkov
matthiaskrgr Jul 16, 2024
ab4cc44
Rollup merge of #127818 - oli-obk:ast_validation_simplifications, r=p…
matthiaskrgr Jul 16, 2024
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
13 changes: 12 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,17 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "gimli"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64"
dependencies = [
"fallible-iterator",
"indexmap",
"stable_deref_trait",
]

[[package]]
name = "glob"
version = "0.3.1"
Expand Down Expand Up @@ -3421,7 +3432,7 @@ dependencies = [
"ar",
"bstr",
"build_helper",
"gimli 0.28.1",
"gimli 0.31.0",
"object 0.34.0",
"regex",
"similar",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl Step for Size {

#[inline]
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
Self::from_bytes(u64::forward_unchecked(start.bytes(), count))
Self::from_bytes(unsafe { u64::forward_unchecked(start.bytes(), count) })
}

#[inline]
Expand All @@ -642,7 +642,7 @@ impl Step for Size {

#[inline]
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
Self::from_bytes(u64::backward_unchecked(start.bytes(), count))
Self::from_bytes(unsafe { u64::backward_unchecked(start.bytes(), count) })
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
TyKind::Slice(ty) => vis.visit_ty(ty),
TyKind::Ptr(mt) => vis.visit_mt(mt),
TyKind::Ref(lt, mt) => {
visit_opt(lt, |lt| noop_visit_lifetime(lt, vis));
visit_opt(lt, |lt| vis.visit_lifetime(lt));
vis.visit_mt(mt);
}
TyKind::BareFn(bft) => {
Expand Down Expand Up @@ -925,7 +925,7 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
vis.visit_id(id);
visit_attrs(attrs, vis);
vis.visit_ident(ident);
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
match kind {
GenericParamKind::Lifetime => {}
GenericParamKind::Type { default } => {
Expand Down Expand Up @@ -983,7 +983,7 @@ fn noop_visit_where_predicate<T: MutVisitor>(pred: &mut WherePredicate, vis: &mu
}
WherePredicate::RegionPredicate(rp) => {
let WhereRegionPredicate { span, lifetime, bounds } = rp;
noop_visit_lifetime(lifetime, vis);
vis.visit_lifetime(lifetime);
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
vis.visit_span(span);
}
Expand Down
96 changes: 26 additions & 70 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,20 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use thin_vec::thin_vec;

use crate::errors;
use crate::errors::{self, TildeConstReason};

/// Is `self` allowed semantically as the first parameter in an `FnDecl`?
enum SelfSemantic {
Yes,
No,
}

/// What is the context that prevents using `~const`?
// FIXME(effects): Consider getting rid of this in favor of `errors::TildeConstReason`, they're
// almost identical. This gets rid of an abstraction layer which might be considered bad.
enum DisallowTildeConstContext<'a> {
TraitObject,
Fn(FnKind<'a>),
Trait(Span),
TraitImpl(Span),
Impl(Span),
TraitAssocTy(Span),
TraitImplAssocTy(Span),
InherentAssocTy(Span),
Item,
}

enum TraitOrTraitImpl<'a> {
enum TraitOrTraitImpl {
Trait { span: Span, constness: Option<Span> },
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref: &'a TraitRef },
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref: Span },
}

impl<'a> TraitOrTraitImpl<'a> {
impl TraitOrTraitImpl {
fn constness(&self) -> Option<Span> {
match self {
Self::Trait { constness: Some(span), .. }
Expand All @@ -81,9 +66,9 @@ struct AstValidator<'a> {
features: &'a Features,

/// The span of the `extern` in an `extern { ... }` block, if any.
extern_mod: Option<&'a Item>,
extern_mod: Option<Span>,

outer_trait_or_trait_impl: Option<TraitOrTraitImpl<'a>>,
outer_trait_or_trait_impl: Option<TraitOrTraitImpl>,

has_proc_macro_decls: bool,

Expand All @@ -92,7 +77,7 @@ struct AstValidator<'a> {
/// e.g., `impl Iterator<Item = impl Debug>`.
outer_impl_trait: Option<Span>,

disallow_tilde_const: Option<DisallowTildeConstContext<'a>>,
disallow_tilde_const: Option<TildeConstReason>,

/// Used to ban `impl Trait` in path projections like `<impl Iterator>::Item`
/// or `Foo::Bar<impl Trait>`
Expand All @@ -115,7 +100,7 @@ impl<'a> AstValidator<'a> {
trait_.map(|(constness, polarity, trait_ref)| TraitOrTraitImpl::TraitImpl {
constness,
polarity,
trait_ref,
trait_ref: trait_ref.path.span,
}),
);
f(self);
Expand Down Expand Up @@ -145,7 +130,7 @@ impl<'a> AstValidator<'a> {

fn with_tilde_const(
&mut self,
disallowed: Option<DisallowTildeConstContext<'a>>,
disallowed: Option<TildeConstReason>,
f: impl FnOnce(&mut Self),
) {
let old = mem::replace(&mut self.disallow_tilde_const, disallowed);
Expand Down Expand Up @@ -224,7 +209,7 @@ impl<'a> AstValidator<'a> {
}
}
TyKind::TraitObject(..) => self
.with_tilde_const(Some(DisallowTildeConstContext::TraitObject), |this| {
.with_tilde_const(Some(TildeConstReason::TraitObject), |this| {
visit::walk_ty(this, t)
}),
TyKind::Path(qself, path) => {
Expand Down Expand Up @@ -354,7 +339,7 @@ impl<'a> AstValidator<'a> {
}
}

fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl<'a>) {
fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl) {
let Const::Yes(span) = constness else {
return;
};
Expand All @@ -367,7 +352,7 @@ impl<'a> AstValidator<'a> {
..
} = parent
{
Some(trait_ref.path.span.shrink_to_lo())
Some(trait_ref.shrink_to_lo())
} else {
None
};
Expand Down Expand Up @@ -579,7 +564,7 @@ impl<'a> AstValidator<'a> {
}

fn current_extern_span(&self) -> Span {
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
self.session.source_map().guess_head_span(self.extern_mod.unwrap())
}

/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
Expand Down Expand Up @@ -980,7 +965,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
this.visit_vis(&item.vis);
this.visit_ident(item.ident);
let disallowed = matches!(constness, Const::No)
.then(|| DisallowTildeConstContext::TraitImpl(item.span));
.then(|| TildeConstReason::TraitImpl { span: item.span });
this.with_tilde_const(disallowed, |this| this.visit_generics(generics));
this.visit_trait_ref(t);
this.visit_ty(self_ty);
Expand Down Expand Up @@ -1035,7 +1020,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
this.visit_vis(&item.vis);
this.visit_ident(item.ident);
this.with_tilde_const(
Some(DisallowTildeConstContext::Impl(item.span)),
Some(TildeConstReason::Impl { span: item.span }),
|this| this.visit_generics(generics),
);
this.visit_ty(self_ty);
Expand Down Expand Up @@ -1080,7 +1065,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => {
self.with_in_extern_mod(*safety, |this| {
let old_item = mem::replace(&mut this.extern_mod, Some(item));
let old_item = mem::replace(&mut this.extern_mod, Some(item.span));
this.visibility_not_permitted(
&item.vis,
errors::VisibilityNotPermittedNote::IndividualForeignItems,
Expand Down Expand Up @@ -1154,7 +1139,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
this.visit_ident(item.ident);
let disallowed = is_const_trait
.is_none()
.then(|| DisallowTildeConstContext::Trait(item.span));
.then(|| TildeConstReason::Trait { span: item.span });
this.with_tilde_const(disallowed, |this| {
this.visit_generics(generics);
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
Expand Down Expand Up @@ -1399,40 +1384,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.dcx().emit_err(errors::ConstBoundTraitObject { span: trait_ref.span });
}
(_, BoundConstness::Maybe(span), BoundPolarity::Positive)
if let Some(reason) = &self.disallow_tilde_const =>
if let Some(reason) = self.disallow_tilde_const =>
{
let reason = match reason {
DisallowTildeConstContext::Fn(FnKind::Closure(..)) => {
errors::TildeConstReason::Closure
}
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => {
errors::TildeConstReason::Function { ident: ident.span }
}
&DisallowTildeConstContext::Trait(span) => {
errors::TildeConstReason::Trait { span }
}
&DisallowTildeConstContext::TraitImpl(span) => {
errors::TildeConstReason::TraitImpl { span }
}
&DisallowTildeConstContext::Impl(span) => {
// FIXME(effects): Consider providing a help message or even a structured
// suggestion for moving such bounds to the assoc const fns if available.
errors::TildeConstReason::Impl { span }
}
&DisallowTildeConstContext::TraitAssocTy(span) => {
errors::TildeConstReason::TraitAssocTy { span }
}
&DisallowTildeConstContext::TraitImplAssocTy(span) => {
errors::TildeConstReason::TraitImplAssocTy { span }
}
&DisallowTildeConstContext::InherentAssocTy(span) => {
errors::TildeConstReason::InherentAssocTy { span }
}
DisallowTildeConstContext::TraitObject => {
errors::TildeConstReason::TraitObject
}
DisallowTildeConstContext::Item => errors::TildeConstReason::Item,
};
self.dcx().emit_err(errors::TildeConstDisallowed { span, reason });
}
(
Expand Down Expand Up @@ -1569,7 +1522,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
.and_then(TraitOrTraitImpl::constness)
.is_some();

let disallowed = (!tilde_const_allowed).then(|| DisallowTildeConstContext::Fn(fk));
let disallowed = (!tilde_const_allowed).then(|| match fk {
FnKind::Fn(_, ident, _, _, _, _) => TildeConstReason::Function { ident: ident.span },
FnKind::Closure(_, _, _) => TildeConstReason::Closure,
});
self.with_tilde_const(disallowed, |this| visit::walk_fn(this, fk));
}

Expand Down Expand Up @@ -1664,12 +1620,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
AssocItemKind::Type(_) => {
let disallowed = (!parent_is_const).then(|| match self.outer_trait_or_trait_impl {
Some(TraitOrTraitImpl::Trait { .. }) => {
DisallowTildeConstContext::TraitAssocTy(item.span)
TildeConstReason::TraitAssocTy { span: item.span }
}
Some(TraitOrTraitImpl::TraitImpl { .. }) => {
DisallowTildeConstContext::TraitImplAssocTy(item.span)
TildeConstReason::TraitImplAssocTy { span: item.span }
}
None => DisallowTildeConstContext::InherentAssocTy(item.span),
None => TildeConstReason::InherentAssocTy { span: item.span },
});
self.with_tilde_const(disallowed, |this| {
this.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt))
Expand Down Expand Up @@ -1852,7 +1808,7 @@ pub fn check_crate(
outer_trait_or_trait_impl: None,
has_proc_macro_decls: false,
outer_impl_trait: None,
disallow_tilde_const: Some(DisallowTildeConstContext::Item),
disallow_tilde_const: Some(TildeConstReason::Item),
is_impl_trait_banned: false,
extern_mod_safety: None,
lint_buffer: lints,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ pub struct TildeConstDisallowed {
pub reason: TildeConstReason,
}

#[derive(Subdiagnostic)]
#[derive(Subdiagnostic, Copy, Clone)]
pub enum TildeConstReason {
#[note(ast_passes_closure)]
Closure,
Expand Down
50 changes: 27 additions & 23 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ pub(crate) unsafe fn codegen(
) {
let llcx = &*module_llvm.llcx;
let llmod = module_llvm.llmod();
let usize = match tcx.sess.target.pointer_width {
16 => llvm::LLVMInt16TypeInContext(llcx),
32 => llvm::LLVMInt32TypeInContext(llcx),
64 => llvm::LLVMInt64TypeInContext(llcx),
tws => bug!("Unsupported target word size for int: {}", tws),
let usize = unsafe {
match tcx.sess.target.pointer_width {
16 => llvm::LLVMInt16TypeInContext(llcx),
32 => llvm::LLVMInt32TypeInContext(llcx),
64 => llvm::LLVMInt64TypeInContext(llcx),
tws => bug!("Unsupported target word size for int: {}", tws),
}
};
let i8 = llvm::LLVMInt8TypeInContext(llcx);
let i8p = llvm::LLVMPointerTypeInContext(llcx, 0);
let i8 = unsafe { llvm::LLVMInt8TypeInContext(llcx) };
let i8p = unsafe { llvm::LLVMPointerTypeInContext(llcx, 0) };

if kind == AllocatorKind::Default {
for method in ALLOCATOR_METHODS {
Expand Down Expand Up @@ -73,23 +75,25 @@ pub(crate) unsafe fn codegen(
true,
);

// __rust_alloc_error_handler_should_panic
let name = OomStrategy::SYMBOL;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.default_hidden_visibility() {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
}
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
let llval = llvm::LLVMConstInt(i8, val as u64, False);
llvm::LLVMSetInitializer(ll_g, llval);

let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.default_hidden_visibility() {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
unsafe {
// __rust_alloc_error_handler_should_panic
let name = OomStrategy::SYMBOL;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.default_hidden_visibility() {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
}
let val = tcx.sess.opts.unstable_opts.oom.should_panic();
let llval = llvm::LLVMConstInt(i8, val as u64, False);
llvm::LLVMSetInitializer(ll_g, llval);

let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.default_hidden_visibility() {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
}
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);
}
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);

if tcx.sess.opts.debuginfo != DebugInfo::None {
let dbg_cx = debuginfo::CodegenUnitDebugContext::new(llmod);
Expand Down
Loading
Loading