mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
Merge #1717
1717: Don't add `?` bounds as real bounds r=flodiebold a=matklad closes #1709 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
79a46f2588
@ -75,6 +75,7 @@ impl GenericParams {
|
||||
};
|
||||
generics.parent_params = parent.map(|p| db.generic_params(p));
|
||||
let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
|
||||
// FIXME: add `: Sized` bound for everything except for `Self` in traits
|
||||
match def {
|
||||
GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
|
||||
GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start),
|
||||
@ -86,6 +87,9 @@ impl GenericParams {
|
||||
generics.fill(&it.source(db).ast, start + 1);
|
||||
}
|
||||
GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),
|
||||
// Note that we don't add `Self` here: in `impl`s, `Self` is not a
|
||||
// type-parameter, but rather is a type-alias for impl's target
|
||||
// type, so this is handled by the resovler.
|
||||
GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start),
|
||||
GenericDef::EnumVariant(_) => {}
|
||||
}
|
||||
@ -135,6 +139,10 @@ impl GenericParams {
|
||||
}
|
||||
|
||||
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
|
||||
if bound.has_question_mark() {
|
||||
// FIXME: remove this bound
|
||||
return;
|
||||
}
|
||||
let path = bound
|
||||
.type_ref()
|
||||
.and_then(|tr| match tr {
|
||||
|
@ -3028,6 +3028,35 @@ fn test(s: S) {
|
||||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deref_trait_with_question_mark_size() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
#[lang = "deref"]
|
||||
trait Deref {
|
||||
type Target;
|
||||
fn deref(&self) -> &Self::Target;
|
||||
}
|
||||
|
||||
struct Arc<T>;
|
||||
impl<T: ?Sized> Deref for Arc<T> {
|
||||
type Target = T;
|
||||
}
|
||||
|
||||
struct S;
|
||||
impl S {
|
||||
fn foo(&self) -> u128 {}
|
||||
}
|
||||
|
||||
fn test(s: Arc<S>) {
|
||||
(*s, s.foo())<|>
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "(S, u128)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn obligation_from_function_clause() {
|
||||
let t = type_at(
|
||||
|
@ -382,6 +382,18 @@ impl ast::WherePred {
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::TypeBound {
|
||||
pub fn question_mark_token(&self) -> Option<SyntaxToken> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == T![?])
|
||||
}
|
||||
pub fn has_question_mark(&self) -> bool {
|
||||
self.question_mark_token().is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::TraitDef {
|
||||
pub fn is_auto(&self) -> bool {
|
||||
self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
|
||||
|
Loading…
Reference in New Issue
Block a user