Skip to content

Commit 79a46f2

Browse files
bors[bot]matklad
andauthored
Merge #1717
1717: Don't add `?` bounds as real bounds r=flodiebold a=matklad closes #1709 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 5c7d832 + 9f23893 commit 79a46f2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

crates/ra_hir/src/generics.rs

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl GenericParams {
7575
};
7676
generics.parent_params = parent.map(|p| db.generic_params(p));
7777
let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
78+
// FIXME: add `: Sized` bound for everything except for `Self` in traits
7879
match def {
7980
GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
8081
GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start),
@@ -86,6 +87,9 @@ impl GenericParams {
8687
generics.fill(&it.source(db).ast, start + 1);
8788
}
8889
GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),
90+
// Note that we don't add `Self` here: in `impl`s, `Self` is not a
91+
// type-parameter, but rather is a type-alias for impl's target
92+
// type, so this is handled by the resovler.
8993
GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start),
9094
GenericDef::EnumVariant(_) => {}
9195
}
@@ -135,6 +139,10 @@ impl GenericParams {
135139
}
136140

137141
fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) {
142+
if bound.has_question_mark() {
143+
// FIXME: remove this bound
144+
return;
145+
}
138146
let path = bound
139147
.type_ref()
140148
.and_then(|tr| match tr {

crates/ra_hir/src/ty/tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,35 @@ fn test(s: S) {
30283028
assert_eq!(t, "{unknown}");
30293029
}
30303030

3031+
#[test]
3032+
fn deref_trait_with_question_mark_size() {
3033+
let t = type_at(
3034+
r#"
3035+
//- /main.rs
3036+
#[lang = "deref"]
3037+
trait Deref {
3038+
type Target;
3039+
fn deref(&self) -> &Self::Target;
3040+
}
3041+
3042+
struct Arc<T>;
3043+
impl<T: ?Sized> Deref for Arc<T> {
3044+
type Target = T;
3045+
}
3046+
3047+
struct S;
3048+
impl S {
3049+
fn foo(&self) -> u128 {}
3050+
}
3051+
3052+
fn test(s: Arc<S>) {
3053+
(*s, s.foo())<|>
3054+
}
3055+
"#,
3056+
);
3057+
assert_eq!(t, "(S, u128)");
3058+
}
3059+
30313060
#[test]
30323061
fn obligation_from_function_clause() {
30333062
let t = type_at(

crates/ra_syntax/src/ast/extensions.rs

+12
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ impl ast::WherePred {
382382
}
383383
}
384384

385+
impl ast::TypeBound {
386+
pub fn question_mark_token(&self) -> Option<SyntaxToken> {
387+
self.syntax()
388+
.children_with_tokens()
389+
.filter_map(|it| it.into_token())
390+
.find(|it| it.kind() == T![?])
391+
}
392+
pub fn has_question_mark(&self) -> bool {
393+
self.question_mark_token().is_some()
394+
}
395+
}
396+
385397
impl ast::TraitDef {
386398
pub fn is_auto(&self) -> bool {
387399
self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])

0 commit comments

Comments
 (0)