Skip to content

Commit 9d9ac91

Browse files
authored
Unrolled build for #158258
Rollup merge of #158258 - oli-obk:opt-out-bound-span, r=camelid Use an unexpanded span for actually written down opt out params I'm trying to land the components of #158122 individually now (and fixing the bugs in the process). TLDR: we didn't use the span of `?Sized` for generating other default bounds of the sized hierarchy, causing in funky diagnostics, this PR fixes that
2 parents cddcbec + cf5f9f1 commit 9d9ac91

5 files changed

Lines changed: 17 additions & 20 deletions

File tree

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ use crate::hir_ty_lowering::{
2525
#[derive(Debug, Default)]
2626
struct CollectedBound {
2727
/// `Trait`
28-
positive: bool,
28+
positive: Option<Span>,
2929
/// `?Trait`
30-
maybe: bool,
30+
maybe: Option<Span>,
3131
/// `!Trait`
32-
negative: bool,
32+
negative: Option<Span>,
3333
}
3434

3535
impl CollectedBound {
3636
/// Returns `true` if any of `Trait`, `?Trait` or `!Trait` were encountered.
3737
fn any(&self) -> bool {
38-
self.positive || self.maybe || self.negative
38+
self.positive.is_some() || self.maybe.is_some() || self.negative.is_some()
3939
}
4040
}
4141

@@ -96,9 +96,9 @@ fn collect_bounds<'a, 'tcx>(
9696
}
9797

9898
match ptr.modifiers.polarity {
99-
hir::BoundPolarity::Maybe(_) => collect_into.maybe = true,
100-
hir::BoundPolarity::Negative(_) => collect_into.negative = true,
101-
hir::BoundPolarity::Positive => collect_into.positive = true,
99+
hir::BoundPolarity::Maybe(_) => collect_into.maybe = Some(ptr.span),
100+
hir::BoundPolarity::Negative(_) => collect_into.negative = Some(ptr.span),
101+
hir::BoundPolarity::Positive => collect_into.positive = Some(ptr.span),
102102
}
103103
});
104104
collect_into
@@ -180,10 +180,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
180180
ImpliedBoundsContext::TyParam(..) | ImpliedBoundsContext::AssociatedTypeOrImplTrait => {
181181
}
182182
}
183-
184183
let collected = collect_sizedness_bounds(tcx, hir_bounds, context, span);
185-
if (collected.sized.maybe || collected.sized.negative)
186-
&& !collected.sized.positive
184+
if let Some(span) = collected.sized.maybe.or(collected.sized.negative)
185+
&& collected.sized.positive.is_none()
187186
&& !collected.meta_sized.any()
188187
&& !collected.pointee_sized.any()
189188
{

tests/ui/const-generics/unused-type-param-suggestion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![crate_type="lib"]
1+
#![crate_type = "lib"]
22

33
struct S<N>;
44
//~^ ERROR type parameter `N` is never used
@@ -25,4 +25,3 @@ type C<N: Sized> = ();
2525
type D<N: ?Sized> = ();
2626
//~^ ERROR type parameter `N` is never used
2727
//~| HELP consider removing `N`
28-
//~| HELP if you intended `N` to be a const parameter

tests/ui/const-generics/unused-type-param-suggestion.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ LL | type D<N: ?Sized> = ();
4747
| ^ unused type parameter
4848
|
4949
= help: consider removing `N` or referring to it in the body of the type alias
50-
= help: if you intended `N` to be a const parameter, use `const N: /* Type */` instead
5150

5251
error: aborting due to 6 previous errors
5352

tests/ui/extern/extern-types-unsized.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ LL | assert_sized::<Bar<A>>();
6767
|
6868
= help: the nightly-only, unstable trait `MetaSized` is not implemented for `A`
6969
note: required by a bound in `Bar`
70-
--> $DIR/extern-types-unsized.rs:14:12
70+
--> $DIR/extern-types-unsized.rs:14:15
7171
|
7272
LL | struct Bar<T: ?Sized> {
73-
| ^ required by this bound in `Bar`
73+
| ^^^^^^ required by this bound in `Bar`
7474

7575
error[E0277]: the size for values of type `A` cannot be known at compilation time
7676
--> $DIR/extern-types-unsized.rs:32:20
@@ -102,10 +102,10 @@ LL | assert_sized::<Bar<Bar<A>>>();
102102
|
103103
= help: the nightly-only, unstable trait `MetaSized` is not implemented for `A`
104104
note: required by a bound in `Bar`
105-
--> $DIR/extern-types-unsized.rs:14:12
105+
--> $DIR/extern-types-unsized.rs:14:15
106106
|
107107
LL | struct Bar<T: ?Sized> {
108-
| ^ required by this bound in `Bar`
108+
| ^^^^^^ required by this bound in `Bar`
109109

110110
error: aborting due to 6 previous errors
111111

tests/ui/sized-hierarchy/overflow.current.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ note: required for `Box<Element>` to implement `ParseTokens`
88
--> $DIR/overflow.rs:13:31
99
|
1010
LL | impl<T: ParseTokens + ?Sized> ParseTokens for Box<T> {
11-
| - ^^^^^^^^^^^ ^^^^^^
12-
| |
13-
| unsatisfied trait bound introduced here
11+
| ------ ^^^^^^^^^^^ ^^^^^^
12+
| |
13+
| unsatisfied trait bound introduced here
1414
= note: 1 redundant requirement hidden
1515
= note: required for `Box<Box<Element>>` to implement `ParseTokens`
1616

0 commit comments

Comments
 (0)