Skip to content

Commit 9fefb67

Browse files
committed
Auto merge of rust-lang#55356 - Aaron1011:fix/rustdoc-negative-auto, r=nikomatsakis
Check for negative impls when finding auto traits Fixes rust-lang#55321 When AutoTraitFinder begins examining a type, it checks for an explicit negative impl. However, it wasn't checking for negative impls found when calling 'select' on predicates found from nested obligations. This commit makes AutoTraitFinder check for negative impls whenever it makes a call to 'select'. If a negative impl is found, it immediately bails out. Normal users of SelectioContext don't need to worry about this, since they stop as soon as an Unimplemented error is encountered. However, we add predicates to our ParamEnv when we encounter this error, so we need to handle negative impls specially (so that we don't try adding them to our ParamEnv).
2 parents 5c9f7dc + 56acb2a commit 9fefb67

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/librustc/traits/auto_trait.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
309309
) -> Option<(ty::ParamEnv<'c>, ty::ParamEnv<'c>)> {
310310
let tcx = infcx.tcx;
311311

312-
let mut select = SelectionContext::new(&infcx);
312+
let mut select = SelectionContext::with_negative(&infcx, true);
313313

314314
let mut already_visited = FxHashSet::default();
315315
let mut predicates = VecDeque::new();
@@ -338,6 +338,21 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
338338

339339
match &result {
340340
&Ok(Some(ref vtable)) => {
341+
// If we see an explicit negative impl (e.g. 'impl !Send for MyStruct'),
342+
// we immediately bail out, since it's impossible for us to continue.
343+
match vtable {
344+
Vtable::VtableImpl(VtableImplData { impl_def_id, .. }) => {
345+
// Blame tidy for the weird bracket placement
346+
if infcx.tcx.impl_polarity(*impl_def_id) == hir::ImplPolarity::Negative
347+
{
348+
debug!("evaluate_nested_obligations: Found explicit negative impl\
349+
{:?}, bailing out", impl_def_id);
350+
return None;
351+
}
352+
},
353+
_ => {}
354+
}
355+
341356
let obligations = vtable.clone().nested_obligations().into_iter();
342357

343358
if !self.evaluate_nested_obligations(

src/test/rustdoc/issue-55321.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#![feature(optin_builtin_traits)]
13+
14+
// @has issue_55321/struct.A.html
15+
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//*/code' "impl !Send for A"
16+
// @has - '//*[@id="implementations-list"]/*[@class="impl"]//*/code' "impl !Sync for A"
17+
pub struct A();
18+
19+
impl !Send for A {}
20+
impl !Sync for A {}
21+
22+
// @has issue_55321/struct.B.html
23+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> !Send for \
24+
// B<T>"
25+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<T> !Sync for \
26+
// B<T>"
27+
pub struct B<T: ?Sized>(A, Box<T>);

0 commit comments

Comments
 (0)