Skip to content

Rollup of 10 pull requests #94134

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 25 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bfd16ab
mips64-openwrt-linux-musl: correct soft-foat
Grommish Feb 9, 2022
64406c5
kmc-solid: Use the filesystem thread-safety wrapper
kawadakk Feb 10, 2022
784c7a6
only mark projection as ambiguous if GAT substs are constrained
compiler-errors Feb 11, 2022
fbbcb08
Add --scrape-tests flags so rustdoc can scrape examples from tests
willcrichton Feb 12, 2022
7c6ff4b
Add the known-bug compiletest prop
jackh726 Feb 12, 2022
e660d52
Use known-bug prop for GAT bug tests
jackh726 Feb 12, 2022
5aae654
Cleanup header parsing by extracting common logic
jackh726 Feb 12, 2022
36cf48b
Don't allow error annotations in known-bug tests
jackh726 Feb 14, 2022
879e4f8
use an enum in matches_projection_projection
compiler-errors Feb 12, 2022
3a73ca5
Implement --check-cfg option (RFC 3013)
Urgau Sep 29, 2021
568aeda
MemTagSanitizer Support
ivanloz Dec 3, 2021
f04f732
Add more information to `impl Trait` deny error
compiler-errors Jan 12, 2022
207fb5f
fix impl trait message, bless tests
compiler-errors Feb 18, 2022
4bed748
Suggest `impl Trait` return type
Noratrieb Oct 14, 2021
11250b8
asm: Allow the use of r8-r14 as clobbers on Thumb1
Amanieu Feb 10, 2022
f8b83a2
Rollup merge of #89892 - Nilstrieb:suggest-return-impl-trait, r=jackh726
matthiaskrgr Feb 18, 2022
0bb72a2
Rollup merge of #91675 - ivanloz:memtagsan, r=nagisa
matthiaskrgr Feb 18, 2022
5c08c39
Rollup merge of #92806 - compiler-errors:better-impl-trait-deny, r=es…
matthiaskrgr Feb 18, 2022
e3a1e19
Rollup merge of #93497 - willcrichton:rustdoc-scrape-test, r=Guillaum…
matthiaskrgr Feb 18, 2022
32c8acd
Rollup merge of #93814 - Itus-Shield:mips64-openwrt, r=bjorn3
matthiaskrgr Feb 18, 2022
724cca6
Rollup merge of #93847 - solid-rs:fix-kmc-solid-fs-ts, r=yaahc
matthiaskrgr Feb 18, 2022
cb35370
Rollup merge of #93877 - Amanieu:asm_fixes, r=nagisa
matthiaskrgr Feb 18, 2022
1e2f63d
Rollup merge of #93892 - compiler-errors:issue-92917, r=jackh726,niko…
matthiaskrgr Feb 18, 2022
576afec
Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov
matthiaskrgr Feb 18, 2022
620b0c5
Rollup merge of #93953 - jackh726:known_bug, r=Mark-Simulacrum
matthiaskrgr Feb 18, 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
Prev Previous commit
Next Next commit
only mark projection as ambiguous if GAT substs are constrained
  • Loading branch information
compiler-errors committed Feb 11, 2022
commit 784c7a6cadf218b518734c4f21690334401ff83a
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
let index = self.values().push(TypeVariableData { origin });
assert_eq!(eq_key.vid.as_u32(), index as u32);

debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,);
debug!("new_var(index={:?}, universe={:?}, origin={:?})", eq_key.vid, universe, origin);

eq_key.vid
}
Expand Down
57 changes: 27 additions & 30 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,16 +1073,6 @@ fn project<'cx, 'tcx>(
return Ok(Projected::Progress(Progress::error(selcx.tcx())));
}

// If the obligation contains any inference types or consts in associated
// type substs, then we don't assemble any candidates.
// This isn't really correct, but otherwise we can end up in a case where
// we constrain inference variables by selecting a single predicate, when
// we need to stay general. See issue #91762.
let (_, predicate_own_substs) = obligation.predicate.trait_ref_and_own_substs(selcx.tcx());
if predicate_own_substs.iter().any(|g| g.has_infer_types_or_consts()) {
return Err(ProjectionError::TooManyCandidates);
}

let mut candidates = ProjectionCandidateSet::None;

// Make sure that the following procedures are kept in order. ParamEnv
Expand Down Expand Up @@ -1180,7 +1170,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
ProjectionCandidate::TraitDef,
bounds.iter(),
true,
)
);
}

/// In the case of a trait object like
Expand Down Expand Up @@ -1245,27 +1235,34 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let bound_predicate = predicate.kind();
if let ty::PredicateKind::Projection(data) = predicate.kind().skip_binder() {
let data = bound_predicate.rebind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;

let is_match = same_def_id
&& infcx.probe(|_| {
selcx.match_projection_projections(
obligation,
data,
potentially_unnormalized_candidates,
)
});
if data.projection_def_id() != obligation.predicate.item_def_id {
continue;
}

if is_match {
candidate_set.push_candidate(ctor(data));
let is_match = infcx.probe(|_| {
selcx.match_projection_projections(
obligation,
data,
potentially_unnormalized_candidates,
)
});

if potentially_unnormalized_candidates
&& !obligation.predicate.has_infer_types_or_consts()
{
// HACK: Pick the first trait def candidate for a fully
// inferred predicate. This is to allow duplicates that
// differ only in normalization.
return;
match is_match {
Some(true) => {
candidate_set.push_candidate(ctor(data));

if potentially_unnormalized_candidates
&& !obligation.predicate.has_infer_types_or_consts()
{
// HACK: Pick the first trait def candidate for a fully
// inferred predicate. This is to allow duplicates that
// differ only in normalization.
return;
}
}
Some(false) => {}
None => {
candidate_set.mark_ambiguous();
}
}
}
Expand Down
27 changes: 24 additions & 3 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1508,12 +1508,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
})
}

/// Return Some(true) if the obligation's predicate type applies to the env_predicate, and
/// Some(false) if it does not. Returns None in the case that the projection type is a GAT,
/// and applying this env_predicate constrains any of the obligation's GAT substitutions.
pub(super) fn match_projection_projections(
&mut self,
obligation: &ProjectionTyObligation<'tcx>,
env_predicate: PolyProjectionPredicate<'tcx>,
potentially_unnormalized_candidates: bool,
) -> bool {
) -> Option<bool> {
let mut nested_obligations = Vec::new();
let (infer_predicate, _) = self.infcx.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
Expand All @@ -1535,7 +1538,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
infer_predicate.projection_ty
};

self.infcx
let is_match = self
.infcx
.at(&obligation.cause, obligation.param_env)
.define_opaque_types(false)
.sup(obligation.predicate, infer_projection)
Expand All @@ -1545,7 +1549,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
nested_obligations.into_iter().chain(obligations),
)
.map_or(false, |res| res.may_apply())
})
});

if is_match {
let generics = self.tcx().generics_of(obligation.predicate.item_def_id);
if !generics.params.is_empty() {
// If any of the obligation's predicate substs shallow-resolve to
// something new, that means that we must have newly inferred something
// about the GAT. We should give up with ambiguity in that case.
if obligation.predicate.substs[generics.parent_count..]
.iter()
.any(|&p| p.has_infer_types_or_consts() && self.infcx.shallow_resolve(p) != p)
{
return None;
}
}
}

Some(is_match)
}

///////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/generic-associated-types/issue-74824.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ impl<T> UnsafeCopy for T {}
fn main() {
let b = Box::new(42usize);
let copy = <()>::copy(&b);
//~^ type annotations needed

let raw_b = Box::deref(&b) as *const _;
let raw_copy = Box::deref(&copy) as *const _;
Expand Down
11 changes: 2 additions & 9 deletions src/test/ui/generic-associated-types/issue-74824.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ help: consider restricting type parameter `T`
LL | type Copy<T: std::clone::Clone>: Copy = Box<T>;
| +++++++++++++++++++

error[E0282]: type annotations needed
--> $DIR/issue-74824.rs:19:16
|
LL | let copy = <()>::copy(&b);
| ^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `copy`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0282.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0277`.
35 changes: 35 additions & 0 deletions src/test/ui/generic-associated-types/issue-93874.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// check-pass

#![feature(generic_associated_types)]

pub trait Build {
type Output<O>;
fn build<O>(self, input: O) -> Self::Output<O>;
}

pub struct IdentityBuild;
impl Build for IdentityBuild {
type Output<O> = O;
fn build<O>(self, input: O) -> Self::Output<O> {
input
}
}

fn a() {
let _x: u8 = IdentityBuild.build(10);
}

fn b() {
let _x: Vec<u8> = IdentityBuild.build(Vec::new());
}

fn c() {
let mut f = IdentityBuild.build(|| ());
(f)();
}

pub fn main() {
a();
b();
c();
}