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 5 pull requests #104791

Closed
wants to merge 104 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
7c56896
Feat: extracted method from trait impl is placed in existing impl
TiddoLangerak Aug 9, 2022
7402366
Avoid cloning IMPL node if we don't have to
TiddoLangerak Aug 10, 2022
d5e6aa3
Pre-cast impl nodes to ast::Impl in find_non_trait_impl
TiddoLangerak Sep 1, 2022
c98fc53
Generalize reborrow hints as adjustment hints
Veykril Nov 4, 2022
95d20fc
Add adjustment hint tests
Veykril Nov 4, 2022
d841ad1
Fix up adjustment hints configurations
Veykril Nov 4, 2022
e468a1a
internal: Optimize `apply_document_changes` a bit
Veykril Nov 4, 2022
28afe57
Add tests for LineEndings::normalize
Veykril Nov 5, 2022
b87a23b
Rename convertor -> converter
lowr Nov 2, 2022
41b0c54
Fix `tt::Punct`'s spacing calculation
lowr Nov 5, 2022
1dcc25a
internal: Use a process group for flycheck
Veykril Nov 5, 2022
7742077
Auto merge of #13552 - Veykril:flycheck-process-group, r=Veykril
bors Nov 7, 2022
f54c313
Auto merge of #13547 - Veykril:line-index, r=Veykril
bors Nov 7, 2022
cff7ab1
Fix typos
lnicola Nov 7, 2022
364820a
Auto merge of #13566 - lnicola:therefor, r=lnicola
bors Nov 7, 2022
f24fbc2
rustfmt
Veykril Nov 7, 2022
8ad4a1d
Update sysroot crates
Veykril Nov 7, 2022
d3d3806
Auto merge of #12991 - TiddoLangerak:extract-method-from-trait-into-i…
bors Nov 7, 2022
180b4ce
Fix the length displayed for byte string literals with escaped newlines
noritada Nov 7, 2022
c0310c1
Auto merge of #13565 - Veykril:sysroot, r=Veykril
bors Nov 7, 2022
ee2dd93
Don't trigger adjustment hints in all inlay hint tests
Veykril Nov 7, 2022
ffd7bf8
Bump Cargo rust-version fields to latest stable
Veykril Nov 7, 2022
bdf8547
Clarify the intent
noritada Nov 7, 2022
3a839ea
Auto merge of #13569 - Veykril:rust-version, r=Veykril
bors Nov 7, 2022
b0e56ef
Auto merge of #13545 - Veykril:adjustment-hints, r=Veykril
bors Nov 7, 2022
2340d70
Add test code for unescaping byte strings
noritada Nov 7, 2022
b169e1e
Remove code duplication
Veykril Nov 7, 2022
8a633fe
Auto merge of #13570 - Veykril:dedup-crates-for, r=Veykril
bors Nov 7, 2022
d1c9775
Auto merge of #13568 - noritada:fix/len-of-byte-string-with-escaped-n…
bors Nov 7, 2022
6a06f6f
Deduplicate reference search results
Veykril Nov 7, 2022
a27e4da
Auto merge of #13571 - Veykril:unique-references, r=Veykril
bors Nov 7, 2022
fa70b0a
internal: Use Cancellable in favor of Result for clarity
Veykril Nov 7, 2022
0aa0da9
Auto merge of #13572 - Veykril:cancellable, r=Veykril
bors Nov 7, 2022
1cb6ab8
internal: error instead of panic on invalid file range
Veykril Nov 7, 2022
b8b1951
Auto merge of #13573 - Veykril:invalid-file-range, r=Veykril
bors Nov 7, 2022
90e2db8
fix: Fix item completions not working properly after unit structs and…
Veykril Nov 8, 2022
236c116
Auto merge of #13581 - Veykril:unit-struct-compl, r=Veykril
bors Nov 8, 2022
4403dde
Nest Cargo.lock under Cargo.toml in Code
lnicola Nov 8, 2022
977a029
Auto merge of #13582 - lnicola:nest-cargo-toml, r=lnicola
bors Nov 8, 2022
9be0615
Don't canonicalize self type when querying FnOnce signature
Nov 8, 2022
392784a
Auto merge of #13584 - jonas-schievink:fix-signature-panic, r=jonas-s…
bors Nov 8, 2022
3c35d44
Add proc-macro dependency to rustc_private crates
Veykril Nov 9, 2022
599142c
Auto merge of #13590 - Veykril:proc-macro-rustc-src, r=Veykril
bors Nov 9, 2022
4f415fc
Ignore outermost non-delimited `Subtree` when reversing fixups
lowr Nov 10, 2022
5b07061
Test `TokenTree`s' equality modulo `Punct`s' spacing
lowr Nov 10, 2022
dea49d0
fix: check visibility of each segment in path resolution
lowr Nov 11, 2022
e75afeb
Resolve invisible defs in `fix_visibility` assist
lowr Nov 11, 2022
19306c0
Fix tests that depended on loose visibility restriction
lowr Nov 11, 2022
e35836e
Send status notification if there are no found workspaces
Veykril Nov 11, 2022
ff78d24
Auto merge of #13603 - Veykril:no-workspaces, r=Veykril
bors Nov 11, 2022
6f313ce
Auto merge of #13548 - lowr:fix/tt-punct-spacing, r=Veykril
bors Nov 11, 2022
57cc2a6
Auto merge of #13602 - lowr:fix/nameres-transitive-visibility, r=Veykril
bors Nov 11, 2022
e50712c
fix: Fix hover in attributed items not preferring similar kinded tokens
Veykril Nov 11, 2022
add8539
Auto merge of #13604 - Veykril:hover-attr, r=Veykril
bors Nov 11, 2022
c6c932d
chore: Align config property
poliorcetics Sep 24, 2022
0d4737a
feat: Support passing multiple targets to cargo (for Rust 1.64.0+)
poliorcetics Sep 24, 2022
a143ff0
fix: Fix r-a eagerly showing no discovered workspace errors
Veykril Nov 11, 2022
d3531e8
Auto merge of #13605 - Veykril:empty-ws-error, r=Veykril
bors Nov 11, 2022
6674bd8
fix: Add trait alias grammar to rust.ungram
Veykril Nov 11, 2022
2656303
Auto merge of #13606 - Veykril:trait-alias, r=Veykril
bors Nov 11, 2022
6b4b7d8
internal: Add version info to unsupported proc macro abi error
Veykril Nov 11, 2022
45ec315
Auto merge of #13607 - Veykril:proc-macro-error, r=Veykril
bors Nov 11, 2022
46417ad
Update several crates to bring support for the new Tier 3 Windows tar…
mati865 Nov 13, 2022
15dfeab
Fix GAT completion not including generic parameters
Nov 15, 2022
a516b90
Auto merge of #13622 - jonas-schievink:fix-gat-completions, r=jonas-s…
bors Nov 15, 2022
7e77d4e
Strip comments and attributes off of all trait item completions
Nov 15, 2022
8292dd8
Auto merge of #13623 - jonas-schievink:strip-trait-item-completions, …
bors Nov 15, 2022
0dd0dfb
Auto merge of #13615 - mati865:miow-update, r=jonas-schievink
bors Nov 15, 2022
1ad11b5
fix: resolve inference variable before applying adjustments
lowr Nov 16, 2022
92e393c
Auto merge of #13624 - lowr:fix/unsize-array-inference-variable, r=ln…
bors Nov 16, 2022
7577c44
Update proc-macro-srv tests
lowr Nov 16, 2022
9cf5c22
Auto merge of #13625 - lowr:fix/proc-macro-src-test, r=lnicola
bors Nov 16, 2022
cd6459e
Make "Remove dbg!()" assist work on selections
Nov 17, 2022
e162d58
Auto merge of #13629 - jonas-schievink:remove-dbg-selection, r=jonas-…
bors Nov 17, 2022
656d886
Make it more obvious which SCIP features we do not yet emit in code
Veykril Nov 18, 2022
bee27eb
Auto merge of #13632 - Veykril:scip, r=Veykril
bors Nov 18, 2022
073a63b
feat: Allow viewing the full compiler diagnostic in a readonly textview
Veykril Nov 18, 2022
8452844
Fix tests checking the data value
Veykril Nov 18, 2022
791cb87
Auto merge of #13633 - Veykril:vscode-full-diagnostics, r=Veykril
bors Nov 18, 2022
52bc15f
fix: Fix proc-macro-srv search paths for Arch Linux
Veykril Nov 18, 2022
a3f8fd7
fix: format expression parsing edge-cases
kartva Nov 19, 2022
dc8254c
fix: Fix nested macro diagnostics pointing at macro expansion files
Veykril Nov 19, 2022
ac60077
Auto merge of #13639 - Veykril:macro-diags, r=Veykril
bors Nov 19, 2022
6d4b2b4
run cargo fmt
kartva Nov 19, 2022
a4f071a
fix(assists): remove `item_const` which had default value when implem…
bvanjoi Nov 19, 2022
8050fdb
Auto merge of #13642 - bvanjoi:fix-13292, r=Veykril
bors Nov 19, 2022
2d9ed4f
Auto merge of #13641 - DesmondWillowbrook:fix-move-format-string, r=V…
bors Nov 19, 2022
38fa47f
Auto merge of #13290 - poliorcetics:multiple-targets, r=Veykril
bors Nov 19, 2022
e39d90a
Improve grammar of architecture.md
ZZzzaaKK Nov 20, 2022
ebbc549
Fix typo on 'configuration' anchor
VannTen Nov 20, 2022
75e1de8
Auto merge of #13649 - ZZzzaaKK:master, r=lnicola
bors Nov 20, 2022
2656297
Auto merge of #13653 - VannTen:fix/doc-typo-vim-lsp, r=Veykril
bors Nov 20, 2022
a2da749
codegen-llvm: never combine DSOLocal and DllImport
dvdhrm Nov 21, 2022
46e0b02
test/codegen: test inter-crate linkage with static relocation
dvdhrm Nov 22, 2022
0a756cc
get rid of to_poly_trait_predicate
oli-obk Nov 18, 2022
b19cf14
Simplify a bunch of trait ref obligation creations
oli-obk Nov 18, 2022
409203a
Use ObligationCtxt::normalize
spastorino Nov 23, 2022
37c3521
:arrow_up: rust-analyzer
lnicola Nov 23, 2022
54a6d4e
Add `#![deny(unsafe_op_in_unsafe_fn)]` in liballoc tests
thomcc Nov 20, 2022
36ceaff
Rollup merge of #104586 - oli-obk:santa-clauses-make-goals, r=jackh726
Manishearth Nov 23, 2022
94af91d
Rollup merge of #104654 - thomcc:alloc-tests-unsafe_op_in_unsafe_fn, …
Manishearth Nov 23, 2022
b69a9f0
Rollup merge of #104679 - dvdhrm:rw/dso, r=petrochenkov
Manishearth Nov 23, 2022
e5a3db4
Rollup merge of #104775 - spastorino:use-obligation-ctxt-normalize, r…
Manishearth Nov 23, 2022
2e860eb
Rollup merge of #104778 - lnicola:rust-analyzer-2022-11-23, r=lnicola
Manishearth Nov 23, 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
16 changes: 10 additions & 6 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,18 @@ impl<'ll> CodegenCx<'ll, '_> {
llvm::set_thread_local_mode(g, self.tls_model);
}

let dso_local = unsafe { self.should_assume_dso_local(g, true) };
if dso_local {
unsafe {
llvm::LLVMRustSetDSOLocal(g, true);
}
}

if !def_id.is_local() {
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
// Local definitions can never be imported, so we must not apply
// the DLLImport annotation.
!dso_local &&
// ThinLTO can't handle this workaround in all cases, so we don't
// emit the attrs. Instead we make them unnecessary by disallowing
// dynamic linking when linker plugin based LTO is enabled.
Expand Down Expand Up @@ -340,12 +350,6 @@ impl<'ll> CodegenCx<'ll, '_> {
}
}

unsafe {
if self.should_assume_dso_local(g, true) {
llvm::LLVMRustSetDSOLocal(g, true);
}
}

self.instances.borrow_mut().insert(instance, g);
g
}
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
use rustc_middle::mir::*;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef, TypeVisitable};
use rustc_middle::ty::{Binder, TraitRef, TypeVisitable};
use rustc_mir_dataflow::{self, Analysis};
use rustc_span::{sym, Span, Symbol};
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
Expand Down Expand Up @@ -726,11 +726,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}

let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
let poly_trait_pred = Binder::dummy(TraitPredicate {
trait_ref,
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
});
let poly_trait_pred =
Binder::dummy(trait_ref).with_constness(ty::BoundConstness::ConstIfConst);
let obligation =
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);

Expand Down Expand Up @@ -819,9 +816,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
tcx,
ObligationCause::dummy_with_span(*fn_span),
param_env,
tcx.mk_predicate(
poly_trait_pred.map_bound(ty::PredicateKind::Trait),
),
poly_trait_pred,
);

// improve diagnostics by showing what failed. Our requirements are stricter this time
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use rustc_middle::mir;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, TraitPredicate,
Ty,
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty,
};
use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef};
use rustc_middle::ty::{Binder, TraitRef};
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, Pos, Span, Symbol};
Expand Down Expand Up @@ -150,11 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
tcx,
ObligationCause::dummy(),
param_env,
Binder::dummy(TraitPredicate {
trait_ref,
constness: BoundConstness::NotConst,
polarity: ImplPolarity::Positive,
}),
Binder::dummy(trait_ref),
);

let infcx = tcx.infer_ctxt().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,8 @@ impl Qualif for NeedsNonConstDrop {
cx.tcx,
ObligationCause::dummy_with_span(cx.body.span),
cx.param_env,
ty::Binder::dummy(ty::TraitPredicate {
trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]),
constness: ty::BoundConstness::ConstIfConst,
polarity: ty::ImplPolarity::Positive,
}),
ty::Binder::dummy(cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]))
.with_constness(ty::BoundConstness::ConstIfConst),
);

let infcx = cx.tcx.infer_ctxt().build();
Expand Down
21 changes: 4 additions & 17 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,11 @@ fn compare_predicate_entailment<'tcx>(

debug!("compare_impl_method: caller_bounds={:?}", param_env.caller_bounds());

let mut selcx = traits::SelectionContext::new(&infcx);
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, normalize_cause, predicate);
let predicate = ocx.normalize(normalize_cause, param_env, predicate);

ocx.register_obligations(obligations);
let cause = ObligationCause::new(
span,
impl_m_hir_id,
Expand Down Expand Up @@ -1555,14 +1552,11 @@ fn compare_type_predicate_entailment<'tcx>(

debug!("compare_type_predicate_entailment: caller_bounds={:?}", param_env.caller_bounds());

let mut selcx = traits::SelectionContext::new(&infcx);

assert_eq!(impl_ty_own_bounds.predicates.len(), impl_ty_own_bounds.spans.len());
for (span, predicate) in std::iter::zip(impl_ty_own_bounds.spans, impl_ty_own_bounds.predicates)
{
let cause = ObligationCause::misc(span, impl_ty_hir_id);
let traits::Normalized { value: predicate, obligations } =
traits::normalize(&mut selcx, param_env, cause, predicate);
let predicate = ocx.normalize(cause, param_env, predicate);

let cause = ObligationCause::new(
span,
Expand All @@ -1573,7 +1567,6 @@ fn compare_type_predicate_entailment<'tcx>(
kind: impl_ty.kind,
},
);
ocx.register_obligations(obligations);
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
}

Expand Down Expand Up @@ -1756,7 +1749,6 @@ pub fn check_type_bounds<'tcx>(
let assumed_wf_types =
ocx.assumed_wf_types(param_env, impl_ty_span, impl_ty.def_id.expect_local());

let mut selcx = traits::SelectionContext::new(&infcx);
let normalize_cause = ObligationCause::new(
impl_ty_span,
impl_ty_hir_id,
Expand Down Expand Up @@ -1785,16 +1777,11 @@ pub fn check_type_bounds<'tcx>(
debug!("check_type_bounds: item_bounds={:?}", obligations);

for mut obligation in util::elaborate_obligations(tcx, obligations) {
let traits::Normalized { value: normalized_predicate, obligations } = traits::normalize(
&mut selcx,
normalize_param_env,
normalize_cause.clone(),
obligation.predicate,
);
let normalized_predicate =
ocx.normalize(normalize_cause.clone(), normalize_param_env, obligation.predicate);
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
obligation.predicate = normalized_predicate;

ocx.register_obligations(obligations);
ocx.register_obligation(obligation);
}
// Check that all obligations are satisfied by the implementation's
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ fn receiver_is_implemented<'tcx>(
let tcx = wfcx.tcx();
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));

let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref);

if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
true
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.param_env,
ty::Binder::dummy(
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
)
.to_poly_trait_predicate(),
),
));
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
traits::ObligationCause::dummy(),
self.param_env,
ty::Binder::dummy(ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
}),
ty::Binder::dummy(trait_ref),
);
match SelectionContext::new(&self).select(&obligation) {
Ok(Some(traits::ImplSource::UserDefined(impl_source))) => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Binder::dummy(self.tcx.mk_trait_ref(
into_def_id,
[expr_ty, expected_ty]
))
.to_poly_trait_predicate(),
)),
))
{
let sugg = if expr.precedence().order() >= PREC_POSTFIX {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
),
self.param_env,
poly_trait_ref.without_const(),
poly_trait_ref,
),
substs,
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
trait_ref: ty::TraitRef<'tcx>,
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate();
let predicate = ty::Binder::dummy(trait_ref);
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
traits::SelectionContext::new(self).select(&obligation)
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,25 @@ impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tc
}
}

impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
#[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
pred.to_predicate(tcx)
}
}

impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
#[inline(always)]
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
})
}
}

impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(PredicateKind::Trait).to_predicate(tcx)
Expand Down
17 changes: 0 additions & 17 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,23 +853,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
pub fn def_id(&self) -> DefId {
self.skip_binder().def_id
}

pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
})
}

/// Same as [`PolyTraitRef::to_poly_trait_predicate`] but sets a negative polarity instead.
pub fn to_poly_trait_predicate_negative_polarity(&self) -> ty::PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Negative,
})
}
}

impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
tcx,
cause.clone(),
self.param_env,
ty::Binder::dummy(trait_ref).without_const(),
ty::Binder::dummy(trait_ref),
);
if !self.infcx.predicate_may_hold(&obligation) {
debug!("overloaded_deref_ty: cannot match obligation");
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_trait_selection/src/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::traits::project::ProjectAndUnifyResult;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{PolyTraitRef, Region, RegionVid};
use rustc_middle::ty::{ImplPolarity, Region, RegionVid};

use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};

Expand Down Expand Up @@ -88,19 +88,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {

let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);

let trait_pred = ty::Binder::dummy(trait_ref);

let infcx = tcx.infer_ctxt().build();
let mut selcx = SelectionContext::new(&infcx);
for f in [
PolyTraitRef::to_poly_trait_predicate,
PolyTraitRef::to_poly_trait_predicate_negative_polarity,
] {
for polarity in [true, false] {
let result = selcx.select(&Obligation::new(
tcx,
ObligationCause::dummy(),
orig_env,
f(&trait_pred),
ty::Binder::dummy(ty::TraitPredicate {
trait_ref,
constness: ty::BoundConstness::NotConst,
polarity: if polarity {
ImplPolarity::Positive
} else {
ImplPolarity::Negative
},
}),
));
if let Ok(Some(ImplSource::UserDefined(_))) = result {
debug!(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/traits/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub fn codegen_select_candidate<'tcx>(
let mut selcx = SelectionContext::new(&infcx);

let obligation_cause = ObligationCause::dummy();
let obligation =
Obligation::new(tcx, obligation_cause, param_env, trait_ref.to_poly_trait_predicate());
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);

let selection = match selcx.select(&obligation) {
Ok(Some(selection)) => selection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
)
};

let obligation = obligation.with(self.tcx, trait_ref.to_poly_trait_predicate());
let obligation = obligation.with(self.tcx, trait_ref);
let mut selcx = SelectionContext::with_query_mode(
&self,
crate::traits::TraitQueryMode::Standard,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ fn subst_and_check_impossible_predicates<'tcx>(
// associated items.
if let Some(trait_def_id) = tcx.trait_of_item(key.0) {
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
predicates.push(ty::Binder::dummy(trait_ref).to_poly_trait_predicate().to_predicate(tcx));
predicates.push(ty::Binder::dummy(trait_ref).to_predicate(tcx));
}

predicates.retain(|predicate| !predicate.needs_subst());
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,7 @@ fn receiver_is_dispatchable<'tcx>(
let obligation = {
let predicate = ty::Binder::dummy(
tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]),
)
.without_const();
);

Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
};
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
// FIXME(named-returns): Binders
let trait_predicate =
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
.to_poly_trait_predicate();
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });

let _ = selcx.infcx().commit_if_ok(|_| {
match selcx.select(&obligation.with(tcx, trait_predicate)) {
Expand Down Expand Up @@ -1542,7 +1541,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
// start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref);
let _ = selcx.infcx().commit_if_ok(|_| {
let impl_source = match selcx.select(&trait_obligation) {
Ok(Some(impl_source)) => impl_source,
Expand Down
Loading