Skip to content

Commit fb1eed7

Browse files
authored
Unrolled build for #142671
Rollup merge of #142671 - davidtwco:no-default-bounds-attr, r=lcnr add #![rustc_no_implicit_bounds] Follow-up from #137944. Adds a new `rustc_attrs` attribute that stops rustc from adding any default bounds. Useful for tests where default bounds just add noise and make debugging harder. After reviewing all tests with `?Sized`, these tests seem like they could probably benefit from `#![rustc_no_implicit_bounds]`. - Skipping most of `tests/ui/unsized` as these seem to want to test `?Sized` - Skipping tests that used `Box<T>` because it's still bound by `T: MetaSized` - Skipping parsing or other tests that cared about `?Sized` syntactically - Skipping tests for `derive(CoercePointee)` because this appears to check that the pointee type is relaxed with `?Sized` explicitly r? `@lcnr`
2 parents 13c46fd + 1fd13fd commit fb1eed7

21 files changed

+125
-98
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
11391139
TEST, rustc_insignificant_dtor, Normal, template!(Word),
11401140
WarnFollowing, EncodeCrossCrate::Yes
11411141
),
1142+
rustc_attr!(
1143+
TEST, rustc_no_implicit_bounds, CrateLevel, template!(Word),
1144+
WarnFollowing, EncodeCrossCrate::No
1145+
),
11421146
rustc_attr!(
11431147
TEST, rustc_strict_coherence, Normal, template!(Word),
11441148
WarnFollowing, EncodeCrossCrate::Yes

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use rustc_errors::codes::*;
55
use rustc_errors::struct_span_code_err;
66
use rustc_hir as hir;
77
use rustc_hir::def::{DefKind, Res};
8-
use rustc_hir::def_id::{DefId, LocalDefId};
8+
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
99
use rustc_hir::{AmbigArg, LangItem, PolyTraitRef};
1010
use rustc_middle::bug;
1111
use rustc_middle::ty::{
1212
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1313
TypeVisitor, Upcast,
1414
};
15-
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw};
15+
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
1616
use rustc_trait_selection::traits;
1717
use smallvec::SmallVec;
1818
use tracing::{debug, instrument};
@@ -188,6 +188,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
188188
) {
189189
let tcx = self.tcx();
190190

191+
// Skip adding any default bounds if `#![rustc_no_implicit_bounds]`
192+
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) {
193+
return;
194+
}
195+
191196
let meta_sized_did = tcx.require_lang_item(LangItem::MetaSized, span);
192197
let pointee_sized_did = tcx.require_lang_item(LangItem::PointeeSized, span);
193198

@@ -408,24 +413,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
408413
let tcx = self.tcx();
409414
let trait_id = tcx.lang_items().get(trait_);
410415
if let Some(trait_id) = trait_id
411-
&& self.do_not_provide_default_trait_bound(
412-
trait_id,
413-
hir_bounds,
414-
self_ty_where_predicates,
415-
)
416+
&& self.should_add_default_traits(trait_id, hir_bounds, self_ty_where_predicates)
416417
{
417418
add_trait_bound(tcx, bounds, self_ty, trait_id, span);
418419
}
419420
}
420421

421-
fn do_not_provide_default_trait_bound<'a>(
422+
/// Returns `true` if default trait bound should be added.
423+
fn should_add_default_traits<'a>(
422424
&self,
423425
trait_def_id: DefId,
424426
hir_bounds: &'a [hir::GenericBound<'tcx>],
425427
self_ty_where_predicates: Option<(LocalDefId, &'tcx [hir::WherePredicate<'tcx>])>,
426428
) -> bool {
427429
let collected = collect_bounds(hir_bounds, self_ty_where_predicates, trait_def_id);
428-
!collected.any()
430+
!self.tcx().has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) && !collected.any()
429431
}
430432

431433
/// Lower HIR bounds into `bounds` given the self type `param_ty` and the overarching late-bound vars if any.

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ symbols! {
18761876
rustc_never_returns_null_ptr,
18771877
rustc_never_type_options,
18781878
rustc_no_implicit_autorefs,
1879+
rustc_no_implicit_bounds,
18791880
rustc_no_mir_inline,
18801881
rustc_nonnull_optimization_guaranteed,
18811882
rustc_nounwind,
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
//@ compile-flags: -Znext-solver=coherence
22

3+
#![feature(rustc_attrs)]
4+
#![rustc_no_implicit_bounds]
35
#![recursion_limit = "10"]
46

57
trait Trait {}
68

7-
struct W<T: ?Sized>(*const T);
9+
struct W<T>(*const T);
810
trait TwoW {}
9-
impl<T: ?Sized + TwoW> TwoW for W<W<T>> {}
11+
impl<T: TwoW> TwoW for W<W<T>> {}
1012

11-
impl<T: ?Sized + TwoW> Trait for W<T> {}
12-
impl<T: ?Sized + TwoW> Trait for T {}
13+
impl<T: TwoW> Trait for W<T> {}
14+
impl<T: TwoW> Trait for T {}
1315
//~^ ERROR conflicting implementations of trait `Trait` for type `W
1416

1517
fn main() {}

tests/ui/traits/next-solver/coherence/coherence-fulfill-overflow.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0119]: conflicting implementations of trait `Trait` for type `W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<_>>>>>>>>>>>>>>>>>>>>>>>`
2-
--> $DIR/coherence-fulfill-overflow.rs:12:1
2+
--> $DIR/coherence-fulfill-overflow.rs:14:1
33
|
4-
LL | impl<T: ?Sized + TwoW> Trait for W<T> {}
5-
| ------------------------------------- first implementation here
6-
LL | impl<T: ?Sized + TwoW> Trait for T {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<_>>>>>>>>>>>>>>>>>>>>>>>`
4+
LL | impl<T: TwoW> Trait for W<T> {}
5+
| ---------------------------- first implementation here
6+
LL | impl<T: TwoW> Trait for T {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<_>>>>>>>>>>>>>>>>>>>>>>>`
88

99
error: aborting due to 1 previous error
1010

tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ revisions: with without
22
//@ compile-flags: -Znext-solver
33
#![feature(rustc_attrs)]
4+
#![rustc_no_implicit_bounds]
45

56
// This test is incredibly subtle. At its core the goal is to get a coinductive cycle,
67
// which, depending on its root goal, either holds or errors. We achieve this by getting
@@ -17,20 +18,20 @@
1718
// test for that.
1819

1920
#[rustc_coinductive]
20-
trait Trait<T: ?Sized, V: ?Sized, D: ?Sized> {}
21-
struct A<T: ?Sized>(*const T);
22-
struct B<T: ?Sized>(*const T);
21+
trait Trait<T, V, D> {}
22+
struct A<T>(*const T);
23+
struct B<T>(*const T);
2324

24-
trait IncompleteGuidance<T: ?Sized, V: ?Sized> {}
25-
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, u8> for T {}
26-
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i8> for T {}
27-
impl<T: ?Sized, U: ?Sized + 'static> IncompleteGuidance<U, i16> for T {}
25+
trait IncompleteGuidance<T, V> {}
26+
impl<T, U: 'static> IncompleteGuidance<U, u8> for T {}
27+
impl<T, U: 'static> IncompleteGuidance<U, i8> for T {}
28+
impl<T, U: 'static> IncompleteGuidance<U, i16> for T {}
2829

29-
trait ImplGuidance<T: ?Sized, V: ?Sized> {}
30-
impl<T: ?Sized> ImplGuidance<u32, u8> for T {}
31-
impl<T: ?Sized> ImplGuidance<i32, i8> for T {}
30+
trait ImplGuidance<T, V> {}
31+
impl<T> ImplGuidance<u32, u8> for T {}
32+
impl<T> ImplGuidance<i32, i8> for T {}
3233

33-
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T>
34+
impl<T, U, V, D> Trait<U, V, D> for A<T>
3435
where
3536
T: IncompleteGuidance<U, V>,
3637
A<T>: Trait<U, D, V>,
@@ -39,17 +40,17 @@ where
3940
{
4041
}
4142

42-
trait ToU8<T: ?Sized> {}
43+
trait ToU8<T> {}
4344
impl ToU8<u8> for () {}
4445

45-
impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for B<T>
46+
impl<T, U, V, D> Trait<U, V, D> for B<T>
4647
where
4748
T: ImplGuidance<U, V>,
4849
A<T>: Trait<U, V, D>,
4950
{
5051
}
5152

52-
fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {}
53+
fn impls_trait<T: Trait<U, V, D>, U, V, D>() {}
5354

5455
fn with_bound<X>()
5556
where

tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.with.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error[E0277]: the trait bound `A<X>: Trait<_, _, _>` is not satisfied
2-
--> $DIR/incompleteness-unstable-result.rs:65:19
2+
--> $DIR/incompleteness-unstable-result.rs:66:19
33
|
44
LL | impls_trait::<A<X>, _, _, _>();
55
| ^^^^ the trait `Trait<_, _, _>` is not implemented for `A<X>`
66
|
77
= help: the trait `Trait<U, V, D>` is implemented for `A<T>`
88
note: required for `A<X>` to implement `Trait<_, _, _>`
9-
--> $DIR/incompleteness-unstable-result.rs:33:50
9+
--> $DIR/incompleteness-unstable-result.rs:34:18
1010
|
11-
LL | impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T>
12-
| ^^^^^^^^^^^^^^ ^^^^
11+
LL | impl<T, U, V, D> Trait<U, V, D> for A<T>
12+
| ^^^^^^^^^^^^^^ ^^^^
1313
...
1414
LL | A<T>: Trait<U, D, V>,
1515
| -------------- unsatisfied trait bound introduced here
1616
= note: 8 redundant requirements hidden
1717
= note: required for `A<X>` to implement `Trait<_, _, _>`
1818
note: required by a bound in `impls_trait`
19-
--> $DIR/incompleteness-unstable-result.rs:52:28
19+
--> $DIR/incompleteness-unstable-result.rs:53:19
2020
|
21-
LL | fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {}
22-
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait`
21+
LL | fn impls_trait<T: Trait<U, V, D>, U, V, D>() {}
22+
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait`
2323

2424
error: aborting due to 1 previous error
2525

tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.without.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error[E0277]: the trait bound `A<X>: Trait<_, _, _>` is not satisfied
2-
--> $DIR/incompleteness-unstable-result.rs:65:19
2+
--> $DIR/incompleteness-unstable-result.rs:66:19
33
|
44
LL | impls_trait::<A<X>, _, _, _>();
55
| ^^^^ the trait `Trait<_, _, _>` is not implemented for `A<X>`
66
|
77
= help: the trait `Trait<U, V, D>` is implemented for `A<T>`
88
note: required for `A<X>` to implement `Trait<_, _, _>`
9-
--> $DIR/incompleteness-unstable-result.rs:33:50
9+
--> $DIR/incompleteness-unstable-result.rs:34:18
1010
|
11-
LL | impl<T: ?Sized, U: ?Sized, V: ?Sized, D: ?Sized> Trait<U, V, D> for A<T>
12-
| ^^^^^^^^^^^^^^ ^^^^
11+
LL | impl<T, U, V, D> Trait<U, V, D> for A<T>
12+
| ^^^^^^^^^^^^^^ ^^^^
1313
...
1414
LL | A<T>: Trait<U, D, V>,
1515
| -------------- unsatisfied trait bound introduced here
1616
= note: 8 redundant requirements hidden
1717
= note: required for `A<X>` to implement `Trait<_, _, _>`
1818
note: required by a bound in `impls_trait`
19-
--> $DIR/incompleteness-unstable-result.rs:52:28
19+
--> $DIR/incompleteness-unstable-result.rs:53:19
2020
|
21-
LL | fn impls_trait<T: ?Sized + Trait<U, V, D>, U: ?Sized, V: ?Sized, D: ?Sized>() {}
22-
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait`
21+
LL | fn impls_trait<T: Trait<U, V, D>, U, V, D>() {}
22+
| ^^^^^^^^^^^^^^ required by this bound in `impls_trait`
2323

2424
error: aborting due to 1 previous error
2525

tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
//@ compile-flags: -Znext-solver
22
#![feature(rustc_attrs)]
3+
#![rustc_no_implicit_bounds]
34

45
// Check that we correctly rerun the trait solver for heads of cycles,
56
// even if they are not the root.
67

7-
struct A<T: ?Sized>(*const T);
8-
struct B<T: ?Sized>(*const T);
9-
struct C<T: ?Sized>(*const T);
8+
struct A<T>(*const T);
9+
struct B<T>(*const T);
10+
struct C<T>(*const T);
1011

1112
#[rustc_coinductive]
1213
trait Trait<'a, 'b> {}
1314
trait NotImplemented {}
1415

15-
impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for A<T> where B<T>: Trait<'a, 'b> {}
16+
impl<'a, 'b, T> Trait<'a, 'b> for A<T> where B<T>: Trait<'a, 'b> {}
1617

1718
// With this the root of `B<T>` is `A<T>`, even if the other impl does
1819
// not have a cycle with `A<T>`. This candidate never applies because of
1920
// the `A<T>: NotImplemented` bound.
20-
impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for B<T>
21+
impl<'a, 'b, T> Trait<'a, 'b> for B<T>
2122
where
2223
A<T>: Trait<'a, 'b>,
2324
A<T>: NotImplemented,
@@ -31,7 +32,7 @@ where
3132
// use the impl itself to prove that adds region constraints as we uniquified the
3233
// regions in the `A<T>: Trait<'a, 'b>` where-bound. As both the impl above
3334
// and the impl below now apply with some constraints, we failed with ambiguity.
34-
impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for B<T>
35+
impl<'a, 'b, T> Trait<'a, 'b> for B<T>
3536
where
3637
A<T>: NotImplemented,
3738
{}
@@ -40,22 +41,22 @@ where
4041
//
4142
// Because of the coinductive cycle through `C<T>` it also requires
4243
// 'a to be 'static.
43-
impl<'a, T: ?Sized> Trait<'a, 'static> for B<T>
44+
impl<'a, T> Trait<'a, 'static> for B<T>
4445
where
4546
C<T>: Trait<'a, 'a>,
4647
{}
4748

4849
// In the first iteration of `B<T>: Trait<'a, 'b>` we don't add any
4950
// constraints here, only after setting the provisional result to require
5051
// `'b == 'static` do we also add that constraint for `'a`.
51-
impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for C<T>
52+
impl<'a, 'b, T> Trait<'a, 'b> for C<T>
5253
where
5354
B<T>: Trait<'a, 'b>,
5455
{}
5556

56-
fn impls_trait<'a, 'b, T: Trait<'a, 'b> + ?Sized>() {}
57+
fn impls_trait<'a, 'b, T: Trait<'a, 'b>>() {}
5758

58-
fn check<'a, T: ?Sized>() {
59+
fn check<'a, T>() {
5960
impls_trait::<'a, 'static, A<T>>();
6061
//~^ ERROR lifetime may not live long enough
6162
}

tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: lifetime may not live long enough
2-
--> $DIR/fixpoint-rerun-all-cycle-heads.rs:59:5
2+
--> $DIR/fixpoint-rerun-all-cycle-heads.rs:60:5
33
|
4-
LL | fn check<'a, T: ?Sized>() {
4+
LL | fn check<'a, T>() {
55
| -- lifetime `'a` defined here
66
LL | impls_trait::<'a, 'static, A<T>>();
77
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`

tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ compile-flags: -Znext-solver
2+
#![feature(rustc_attrs)]
3+
#![rustc_no_implicit_bounds]
24

35
// This currently hangs if we do not erase constraints from
46
// overflow.
@@ -17,9 +19,9 @@
1719
// the solver to hang without hitting the recursion limit.
1820
trait Trait {}
1921

20-
struct W<T: ?Sized>(*const T);
22+
struct W<T>(*const T);
2123

22-
impl<T: ?Sized> Trait for W<W<T>>
24+
impl<T> Trait for W<W<T>>
2325
where
2426
W<T>: Trait,
2527
W<T>: Trait,

tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
2-
--> $DIR/inductive-fixpoint-hang.rs:31:19
2+
--> $DIR/inductive-fixpoint-hang.rs:33:19
33
|
44
LL | impls_trait::<W<_>>();
55
| ^^^^
66
|
77
note: required by a bound in `impls_trait`
8-
--> $DIR/inductive-fixpoint-hang.rs:28:19
8+
--> $DIR/inductive-fixpoint-hang.rs:30:19
99
|
1010
LL | fn impls_trait<T: Trait>() {}
1111
| ^^^^^ required by this bound in `impls_trait`

tests/ui/traits/next-solver/cycles/provisional-cache-impacts-behavior.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ compile-flags: -Znext-solver
22
//@ check-pass
33
#![feature(rustc_attrs)]
4+
#![rustc_no_implicit_bounds]
45

56
// A test showcasing that using a provisional cache can differ
67
// from only tracking stack entries.
@@ -59,9 +60,9 @@ trait B {}
5960
#[rustc_coinductive]
6061
trait C {}
6162

62-
impl<T: ?Sized + B + C> A for T {}
63-
impl<T: ?Sized + A + C> B for T {}
64-
impl<T: ?Sized + B> C for T {}
63+
impl<T: B + C> A for T {}
64+
impl<T: A + C> B for T {}
65+
impl<T: B> C for T {}
6566

6667
fn impls_a<T: A>() {}
6768

tests/ui/traits/next-solver/dont-canonicalize-re-error.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ compile-flags: -Znext-solver
2+
#![feature(rustc_attrs)]
3+
#![rustc_no_implicit_bounds]
24

35
trait Tr<'a> {}
46

@@ -16,9 +18,9 @@ trait Tr<'a> {}
1618
// Then, when we recompute the goal `W<?0>: Constrain<'error>`, when
1719
// collecting ambiguities and overflows, we end up assembling a default
1820
// error candidate w/o ambiguity, which causes the goal to pass, and ICE.
19-
impl<'a, A: ?Sized> Tr<'a> for W<A> {}
20-
struct W<A: ?Sized>(A);
21-
impl<'a, A: ?Sized> Tr<'a> for A where A: Constrain<'a> {}
21+
impl<'a, A> Tr<'a> for W<A> {}
22+
struct W<A>(A);
23+
impl<'a, A> Tr<'a> for A where A: Constrain<'a> {}
2224
//~^ ERROR conflicting implementations of trait `Tr<'_>` for type `W<_>`
2325

2426
trait Constrain<'a> {}

0 commit comments

Comments
 (0)