fix: Fix attributes on generic parameters colliding in item tree

This commit is contained in:
Lukas Wirth 2024-04-27 12:33:04 +02:00
parent 2668912688
commit bfe59bbdc8
11 changed files with 248 additions and 210 deletions

View file

@ -1056,23 +1056,7 @@ impl<'a> TyLoweringContext<'a> {
let clause = match bound.as_ref() {
TypeBound::Path(path, TraitBoundModifier::None) => {
trait_ref = self.lower_trait_ref_from_path(path, Some(self_ty));
trait_ref
.clone()
.filter(|tr| {
// ignore `T: Drop` or `T: Destruct` bounds.
// - `T: ~const Drop` has a special meaning in Rust 1.61 that we don't implement.
// (So ideally, we'd only ignore `~const Drop` here)
// - `Destruct` impls are built-in in 1.62 (current nightly as of 08-04-2022), so until
// the builtin impls are supported by Chalk, we ignore them here.
if let Some(lang) = self.db.lang_attr(tr.hir_trait_id().into()) {
if matches!(lang, LangItem::Drop | LangItem::Destruct) {
return false;
}
}
true
})
.map(WhereClause::Implemented)
.map(crate::wrap_empty_binders)
trait_ref.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
}
TypeBound::Path(path, TraitBoundModifier::Maybe) => {
let sized_trait = self

View file

@ -1599,85 +1599,6 @@ fn f(s: S) {
);
}
#[test]
fn rust_161_option_clone() {
check_types(
r#"
//- minicore: option, drop
fn test(o: &Option<i32>) {
o.my_clone();
//^^^^^^^^^^^^ Option<i32>
}
pub trait MyClone: Sized {
fn my_clone(&self) -> Self;
}
impl<T> const MyClone for Option<T>
where
T: ~const MyClone + ~const Drop + ~const Destruct,
{
fn my_clone(&self) -> Self {
match self {
Some(x) => Some(x.my_clone()),
None => None,
}
}
}
impl const MyClone for i32 {
fn my_clone(&self) -> Self {
*self
}
}
pub trait Destruct {}
impl<T: ?Sized> const Destruct for T {}
"#,
);
}
#[test]
fn rust_162_option_clone() {
check_types(
r#"
//- minicore: option, drop
fn test(o: &Option<i32>) {
o.my_clone();
//^^^^^^^^^^^^ Option<i32>
}
pub trait MyClone: Sized {
fn my_clone(&self) -> Self;
}
impl<T> const MyClone for Option<T>
where
T: ~const MyClone + ~const Destruct,
{
fn my_clone(&self) -> Self {
match self {
Some(x) => Some(x.my_clone()),
None => None,
}
}
}
impl const MyClone for i32 {
fn my_clone(&self) -> Self {
*self
}
}
#[lang = "destruct"]
pub trait Destruct {}
"#,
);
}
#[test]
fn tuple_struct_pattern_with_unmatched_args_crash() {
check_infer(
@ -2040,3 +1961,17 @@ fn main() {
"#,
)
}
#[test]
fn cfg_first_trait_param_16141() {
check_no_mismatches(
r#"
//- minicore: sized, coerce_unsized
trait Bar {
fn bar(&self) {}
}
impl<#[cfg(feature = "a-feature")] A> Bar for (){}
"#,
)
}

View file

@ -238,6 +238,7 @@ fn infer_for_loop() {
//- minicore: iterator
//- /main.rs crate:main deps:alloc
#![no_std]
extern crate alloc;
use alloc::collections::Vec;
fn test() {