Skip to content

Commit 998986c

Browse files
committed
Noncopyable: fix implicit conversion error
Implicit initializers internally have "Default" parameter ownership specifiers, which can only happen for a noncopyable type if the decl is synthesized, since ownership is required to be specified if it were written in the source. There's no reason to warn for such decls, since the user can't see it anyway. So specifically target an explicitly written "borrowing" as being confusing, since that's the only valid case that could happen anyway. resolves rdar://131546153
1 parent 97d145c commit 998986c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,12 @@ static bool willHaveConfusingConsumption(Type type,
384384
case ConstraintLocator::ApplyArgToParam: {
385385
auto argLoc = loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>();
386386
auto paramFlags = argLoc.getParameterFlags();
387-
if (paramFlags.getOwnershipSpecifier() == ParamSpecifier::Consuming)
388-
return false; // Parameter already declares 'consuming'.
387+
// If the param declares borrowing, then this implicit consumption
388+
// due to the conversion to pass the argument is indeed confusing.
389+
if (paramFlags.getOwnershipSpecifier() == ParamSpecifier::Borrowing)
390+
return true;
389391

390-
return true;
392+
return false;
391393
}
392394

393395
default:

test/Sema/moveonly_casts.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,11 @@ extension Carrot {
123123
let _: any Veggie & ~Copyable = self
124124
}
125125
}
126+
127+
// rdar://131546153 (implicit consuming conversion error triggers incorrectly for implicit initializers)
128+
struct ImplicitInit: ~Copyable {
129+
let x: NC?
130+
}
131+
func test(_ nc: consuming NC) -> ImplicitInit {
132+
return .init(x: nc)
133+
}

0 commit comments

Comments
 (0)