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 10 pull requests #105456

Merged
merged 30 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7674ede
Detect long types in E0308 and write them to disk
estebank Nov 26, 2022
360c0a7
Tweak shortening logic to be less trigger happy
estebank Nov 26, 2022
73b371a
Further tweak the type shortening logic
estebank Nov 26, 2022
be02bd9
Remove unneeded test change
estebank Nov 26, 2022
360bcb6
fix test
estebank Nov 26, 2022
34b3c49
fix rebase
estebank Nov 28, 2022
427a079
kmc-solid: Use `expose_addr` and `from_exposed_addr` for pointer-inte…
kawadakk Dec 1, 2022
47f2f6d
kmc-solid: Add a stub implementation of `is_terminal`
kawadakk Dec 1, 2022
f482e55
kmc-solid: Address compiler warnings
kawadakk Dec 1, 2022
ae7633f
kmc-solid: Don't do `Box::from_raw(&*(x: Box<T>) as *const T as *mut T)`
kawadakk Dec 1, 2022
e2d41f4
Make nested RPITIT inherit the parent opaque's generics.
cjgillot Dec 4, 2022
9397ea1
make retagging work even with 'unstable' places
RalfJung Dec 5, 2022
34c58e8
Stacked Borrows: factor the logic determining the new permissions on …
RalfJung Dec 5, 2022
3a07aa9
Stop passing -export-dynamic to wasm-ld.
sunfishcode Dec 7, 2022
e9dd591
Add help for `#![feature(impl_trait_in_fn_trait_return)]`
cuviper Dec 7, 2022
d30848b
Use `Symbol` for the crate name instead of `String`/`str`
oli-obk Dec 6, 2022
8bc30cb
CI: add missing line continuation marker
ComputerDruid Dec 7, 2022
a3c4c2e
Fix warning when libcore is compiled with no_fp_fmt_parse
nbdd0121 Dec 8, 2022
7a46692
Remove `UnsafetyState`.
nnethercote Dec 8, 2022
9af48e5
Fix a typo.
nnethercote Dec 8, 2022
086bdbb
Rollup merge of #104922 - estebank:fur-elize, r=oli-obk
matthiaskrgr Dec 8, 2022
cd936cc
Rollup merge of #105120 - solid-rs:patch/kmc-solid/maintainance, r=th…
matthiaskrgr Dec 8, 2022
e826a9a
Rollup merge of #105255 - cjgillot:issue-105197, r=compiler-errors
matthiaskrgr Dec 8, 2022
f1f7560
Rollup merge of #105317 - RalfJung:retag-rework, r=oli-obk
matthiaskrgr Dec 8, 2022
4d5a2f3
Rollup merge of #105405 - sunfishcode:sunfishcode/export-dynamic, r=T…
matthiaskrgr Dec 8, 2022
2fbde2b
Rollup merge of #105408 - cuviper:help-rpitirpit, r=compiler-errors
matthiaskrgr Dec 8, 2022
fbfc5ad
Rollup merge of #105423 - oli-obk:symbols, r=jackh726
matthiaskrgr Dec 8, 2022
d429e46
Rollup merge of #105433 - ComputerDruid:docker_continuation_fix, r=jy…
matthiaskrgr Dec 8, 2022
433189b
Rollup merge of #105434 - nbdd0121:lib, r=thomcc
matthiaskrgr Dec 8, 2022
660795e
Rollup merge of #105441 - nnethercote:rm-UnsafetyState, r=lcnr
matthiaskrgr Dec 8, 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"smallvec",
"termize",
"tracing",
"winapi",
]
Expand Down
32 changes: 21 additions & 11 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ enum ImplTraitContext {
},
/// Impl trait in type aliases.
TypeAliasesOpaqueTy,
/// `impl Trait` is unstably accepted in this position.
FeatureGated(ImplTraitPosition, Symbol),
/// `impl Trait` is not accepted in this position.
Disallowed(ImplTraitPosition),
}
Expand Down Expand Up @@ -1372,25 +1374,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
path
}
ImplTraitContext::Disallowed(
position @ (ImplTraitPosition::TraitReturn | ImplTraitPosition::ImplReturn),
) => {
ImplTraitContext::FeatureGated(position, feature) => {
self.tcx
.sess
.create_feature_err(
MisplacedImplTrait {
span: t.span,
position: DiagnosticArgFromDisplay(&position),
position: DiagnosticArgFromDisplay(position),
},
sym::return_position_impl_trait_in_trait,
*feature,
)
.emit();
hir::TyKind::Err
}
ImplTraitContext::Disallowed(position) => {
self.tcx.sess.emit_err(MisplacedImplTrait {
span: t.span,
position: DiagnosticArgFromDisplay(&position),
position: DiagnosticArgFromDisplay(position),
});
hir::TyKind::Err
}
Expand Down Expand Up @@ -1739,14 +1739,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
match &decl.output {
FnRetTy::Ty(ty) => {
let mut context = if kind.return_impl_trait_allowed(self.tcx) {
let context = if kind.return_impl_trait_allowed(self.tcx) {
let fn_def_id = self.local_def_id(fn_node_id);
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
in_trait: matches!(kind, FnDeclKind::Trait),
}
} else {
ImplTraitContext::Disallowed(match kind {
let position = match kind {
FnDeclKind::Fn | FnDeclKind::Inherent => {
unreachable!("fn should allow in-band lifetimes")
}
Expand All @@ -1755,9 +1755,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
FnDeclKind::Pointer => ImplTraitPosition::PointerReturn,
FnDeclKind::Trait => ImplTraitPosition::TraitReturn,
FnDeclKind::Impl => ImplTraitPosition::ImplReturn,
})
};
match kind {
FnDeclKind::Trait | FnDeclKind::Impl => ImplTraitContext::FeatureGated(
position,
sym::return_position_impl_trait_in_trait,
),
_ => ImplTraitContext::Disallowed(position),
}
};
hir::FnRetTy::Return(self.lower_ty(ty, &mut context))
hir::FnRetTy::Return(self.lower_ty(ty, &context))
}
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
}
Expand Down Expand Up @@ -1938,7 +1945,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output,
span,
if in_trait && !this.tcx.features().return_position_impl_trait_in_trait {
ImplTraitContext::Disallowed(ImplTraitPosition::TraitReturn)
ImplTraitContext::FeatureGated(
ImplTraitPosition::TraitReturn,
sym::return_position_impl_trait_in_trait,
)
} else {
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_ast::{self as ast, *};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, PartialRes, Res};
use rustc_hir::GenericArg;
use rustc_span::symbol::{kw, Ident};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{BytePos, Span, DUMMY_SP};

use smallvec::{smallvec, SmallVec};
Expand Down Expand Up @@ -352,11 +352,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
// ```
FnRetTy::Ty(ty)
if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. })
&& self.tcx.features().impl_trait_in_fn_trait_return =>
{
self.lower_ty(&ty, itctx)
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. }) => {
if self.tcx.features().impl_trait_in_fn_trait_return {
self.lower_ty(&ty, itctx)
} else {
self.lower_ty(
&ty,
&ImplTraitContext::FeatureGated(
ImplTraitPosition::FnTraitReturn,
sym::impl_trait_in_fn_trait_return,
),
)
}
}
FnRetTy::Ty(ty) => {
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn link_binary<'a>(
sess,
crate_type,
outputs,
codegen_results.crate_info.local_crate_name.as_str(),
codegen_results.crate_info.local_crate_name,
);
match crate_type {
CrateType::Rlib => {
Expand Down
16 changes: 14 additions & 2 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,21 @@ pub trait Machine<'mir, 'tcx>: Sized {
Ok(())
}

/// Executes a retagging operation.
/// Executes a retagging operation for a single pointer.
/// Returns the possibly adjusted pointer.
#[inline]
fn retag(
fn retag_ptr_value(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_kind: mir::RetagKind,
val: &ImmTy<'tcx, Self::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
Ok(val.clone())
}

/// Executes a retagging operation on a compound value.
/// Replaces all pointers stored in the given place.
#[inline]
fn retag_place_contents(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_kind: mir::RetagKind,
_place: &PlaceTy<'tcx, Self::Provenance>,
Expand Down
39 changes: 35 additions & 4 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::mir;
use rustc_middle::mir::interpret::{InterpResult, Scalar};
use rustc_middle::ty::layout::LayoutOf;

use super::{InterpCx, Machine};
use super::{ImmTy, InterpCx, Machine};

/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
/// same type as the result.
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Stacked Borrows.
Retag(kind, place) => {
let dest = self.eval_place(**place)?;
M::retag(self, *kind, &dest)?;
M::retag_place_contents(self, *kind, &dest)?;
}

Intrinsic(box ref intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
Expand Down Expand Up @@ -247,10 +247,41 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?;
}

AddressOf(_, place) | Ref(_, _, place) => {
Ref(_, borrow_kind, place) => {
let src = self.eval_place(place)?;
let place = self.force_allocation(&src)?;
self.write_immediate(place.to_ref(self), &dest)?;
let val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
// A fresh reference was created, make sure it gets retagged.
let val = M::retag_ptr_value(
self,
if borrow_kind.allows_two_phase_borrow() {
mir::RetagKind::TwoPhase
} else {
mir::RetagKind::Default
},
&val,
)?;
self.write_immediate(*val, &dest)?;
}

AddressOf(_, place) => {
// Figure out whether this is an addr_of of an already raw place.
let place_base_raw = if place.has_deref() {
let ty = self.frame().body.local_decls[place.local].ty;
ty.is_unsafe_ptr()
} else {
// Not a deref, and thus not raw.
false
};

let src = self.eval_place(place)?;
let place = self.force_allocation(&src)?;
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
if !place_base_raw {
// If this was not already raw, it needs retagging.
val = M::retag_ptr_value(self, mir::RetagKind::Raw, &val)?;
}
self.write_immediate(*val, &dest)?;
}

NullaryOp(null_op, ty) => {
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rustc_data_structures::sync::SeqCst;
use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{ErrorGuaranteed, PResult};
use rustc_feature::find_gated_cfg;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries};
use rustc_lint::LintStore;
Expand Down Expand Up @@ -374,14 +375,14 @@ fn run_compiler(
queries.global_ctxt()?.peek_mut().enter(|tcx| {
let result = tcx.analysis(());
if sess.opts.unstable_opts.save_analysis {
let crate_name = queries.crate_name()?.peek().clone();
let crate_name = tcx.crate_name(LOCAL_CRATE);
sess.time("save_analysis", || {
save::process_crate(
tcx,
&crate_name,
crate_name,
compiler.input(),
None,
DumpHandler::new(compiler.output_dir().as_deref(), &crate_name),
DumpHandler::new(compiler.output_dir().as_deref(), crate_name),
)
});
}
Expand Down Expand Up @@ -678,7 +679,7 @@ fn print_crate_info(
let crate_types = collect_crate_types(sess, attrs);
for &style in &crate_types {
let fname =
rustc_session::output::filename_for_input(sess, style, &id, &t_outputs);
rustc_session::output::filename_for_input(sess, style, id, &t_outputs);
println!("{}", fname.file_name().unwrap().to_string_lossy());
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ pub trait LintStoreExpand {
node_id: NodeId,
attrs: &[Attribute],
items: &[P<Item>],
name: &str,
name: Symbol,
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ impl InvocationCollectorNode for P<ast::Item> {
ecx.current_expansion.lint_node_id,
&attrs,
&items,
ident.name.as_str(),
ident.name,
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl<'tcx> AttributeMap<'tcx> {
pub struct OwnerNodes<'tcx> {
/// Pre-computed hash of the full HIR.
pub hash_including_bodies: Fingerprint,
/// Pre-computed hash of the item signature, sithout recursing into the body.
/// Pre-computed hash of the item signature, without recursing into the body.
pub hash_without_bodies: Fingerprint,
/// Full HIR for the current owner.
// The zeroth node's parent should never be accessed: the owner's parent is computed by the
Expand Down
38 changes: 21 additions & 17 deletions compiler/rustc_hir/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::definitions::{DefKey, DefPathData, DisambiguatedDefPathData};
use rustc_span::def_id::{DefPathHash, StableCrateId};
use rustc_span::edition::Edition;
use rustc_span::{create_session_if_not_set_then, Symbol};

#[test]
fn def_path_hash_depends_on_crate_id() {
Expand All @@ -11,26 +13,28 @@ fn def_path_hash_depends_on_crate_id() {
// the crate by changing the crate disambiguator (e.g. via bumping the
// crate's version number).

let id0 = StableCrateId::new("foo", false, vec!["1".to_string()]);
let id1 = StableCrateId::new("foo", false, vec!["2".to_string()]);
create_session_if_not_set_then(Edition::Edition2024, |_| {
let id0 = StableCrateId::new(Symbol::intern("foo"), false, vec!["1".to_string()]);
let id1 = StableCrateId::new(Symbol::intern("foo"), false, vec!["2".to_string()]);

let h0 = mk_test_hash(id0);
let h1 = mk_test_hash(id1);
let h0 = mk_test_hash(id0);
let h1 = mk_test_hash(id1);

assert_ne!(h0.stable_crate_id(), h1.stable_crate_id());
assert_ne!(h0.local_hash(), h1.local_hash());
assert_ne!(h0.stable_crate_id(), h1.stable_crate_id());
assert_ne!(h0.local_hash(), h1.local_hash());

fn mk_test_hash(stable_crate_id: StableCrateId) -> DefPathHash {
let parent_hash = DefPathHash::new(stable_crate_id, 0);
fn mk_test_hash(stable_crate_id: StableCrateId) -> DefPathHash {
let parent_hash = DefPathHash::new(stable_crate_id, 0);

let key = DefKey {
parent: None,
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::CrateRoot,
disambiguator: 0,
},
};
let key = DefKey {
parent: None,
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::CrateRoot,
disambiguator: 0,
},
};

key.compute_stable_hash(parent_hash)
}
key.compute_stable_hash(parent_hash)
}
})
}
16 changes: 1 addition & 15 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use hir::{
GenericParamKind, HirId, Node,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::lint;
Expand Down Expand Up @@ -143,20 +142,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
Some(tcx.typeck_root_def_id(def_id))
}
Node::Item(item) => match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy {
origin:
hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
in_trait,
..
}) => {
if in_trait {
assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn))
} else {
assert!(matches!(tcx.def_kind(fn_def_id), DefKind::AssocFn | DefKind::Fn))
}
Some(fn_def_id.to_def_id())
}
ItemKind::OpaqueTy(hir::OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
ItemKind::OpaqueTy(hir::OpaqueTy { .. }) => {
let parent_id = tcx.hir().get_parent_item(hir_id);
assert_ne!(parent_id, hir::CRATE_OWNER_ID);
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::coercion::CoerceMany;
use crate::gather_locals::GatherLocalsVisitor;
use crate::FnCtxt;
use crate::{GeneratorTypes, UnsafetyState};
use crate::GeneratorTypes;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::intravisit::Visitor;
Expand Down Expand Up @@ -30,7 +30,6 @@ pub(super) fn check_fn<'a, 'tcx>(
can_be_generator: Option<hir::Movability>,
) -> Option<GeneratorTypes<'tcx>> {
let fn_id = fcx.tcx.hir().local_def_id_to_hir_id(fn_def_id);
fcx.ps.set(UnsafetyState::function(fn_sig.unsafety, fn_id));

let tcx = fcx.tcx;
let hir = tcx.hir();
Expand Down
Loading