Skip to content

Commit

Permalink
Rollup merge of rust-lang#95654 - notriddle:notriddle/issue-95616, r=…
Browse files Browse the repository at this point in the history
…davidtwco

diagnostics: use correct span for const generics

Fixes rust-lang#95616
  • Loading branch information
Dylan-DPC committed Apr 5, 2022
2 parents e028d93 + 6ece80f commit 33b0fba
Show file tree
Hide file tree
Showing 32 changed files with 91 additions and 56 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Expand Up @@ -2068,7 +2068,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam {
hir_id,
name,
span: self.lower_span(param.ident.span),
span: self.lower_span(param.span()),
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
bounds: self.arena.alloc_from_iter(bounds),
kind,
Expand Down
Expand Up @@ -8,7 +8,7 @@ note: required by a bound in `Add`
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
LL | pub trait Add<Rhs = Self> {
| ^^^ required by this bound in `Add`
| ^^^^^^^^^^ required by this bound in `Add`
help: consider further restricting `Self`
|
LL | trait ArithmeticOps: Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + Div<Output=Self> + Sized {}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-78654.full.stderr
Expand Up @@ -5,10 +5,10 @@ LL | impl<const H: feature> Foo {
| ^^^^^^^ not a type

error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-78654.rs:9:12
--> $DIR/issue-78654.rs:9:6
|
LL | impl<const H: feature> Foo {
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-78654.min.stderr
Expand Up @@ -5,10 +5,10 @@ LL | impl<const H: feature> Foo {
| ^^^^^^^ not a type

error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-78654.rs:9:12
--> $DIR/issue-78654.rs:9:6
|
LL | impl<const H: feature> Foo {
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/defaults/default-on-impl.stderr
@@ -1,8 +1,8 @@
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/default-on-impl.rs:3:12
--> $DIR/default-on-impl.rs:3:6
|
LL | impl<const N: usize = 1> Foo<N> {}
| ^
| ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Up @@ -10,7 +10,7 @@ note: function defined here, with 2 generic parameters: `T`, `P`
--> $DIR/issue-76595.rs:10:4
|
LL | fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
| ^^^^ - -
| ^^^^ - --------------
help: add missing generic argument
|
LL | test::<2, P>();
Expand Down
Expand Up @@ -10,7 +10,7 @@ note: function defined here, with 2 generic parameters: `X`, `Y`
--> $DIR/incorrect-number-of-const-args.rs:1:4
|
LL | fn foo<const X: usize, const Y: usize>() -> usize {
| ^^^ - -
| ^^^ -------------- --------------
help: add missing generic argument
|
LL | foo::<0, Y>();
Expand All @@ -28,7 +28,7 @@ note: function defined here, with 2 generic parameters: `X`, `Y`
--> $DIR/incorrect-number-of-const-args.rs:1:4
|
LL | fn foo<const X: usize, const Y: usize>() -> usize {
| ^^^ - -
| ^^^ -------------- --------------

error: aborting due to 2 previous errors

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/const-generics/issues/issue-68366.full.stderr
@@ -1,17 +1,17 @@
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-68366.rs:11:13
--> $DIR/issue-68366.rs:11:7
|
LL | impl <const N: usize> Collatz<{Some(N)}> {}
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported

error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-68366.rs:17:12
--> $DIR/issue-68366.rs:17:6
|
LL | impl<const N: usize> Foo {}
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/const-generics/issues/issue-68366.min.stderr
Expand Up @@ -8,19 +8,19 @@ LL | impl <const N: usize> Collatz<{Some(N)}> {}
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-68366.rs:11:13
--> $DIR/issue-68366.rs:11:7
|
LL | impl <const N: usize> Collatz<{Some(N)}> {}
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported

error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-68366.rs:17:12
--> $DIR/issue-68366.rs:17:6
|
LL | impl<const N: usize> Foo {}
| ^ unconstrained const parameter
| ^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/const-generics/issues/issue-86820.stderr
@@ -1,14 +1,14 @@
error[E0053]: method `bit` has an incompatible const parameter type for trait
--> $DIR/issue-86820.rs:17:18
--> $DIR/issue-86820.rs:17:12
|
LL | fn bit<const I : usize>(self) -> bool {
| ^
| ^^^^^^^^^^^^^^^
|
note: the const parameter `I` has type `usize`, but the declaration in trait `Bits::bit` has type `u8`
--> $DIR/issue-86820.rs:12:18
--> $DIR/issue-86820.rs:12:12
|
LL | fn bit<const I : u8>(self) -> bool;
| ^
| ^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
@@ -1,8 +1,8 @@
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/default_function_param.rs:3:14
--> $DIR/default_function_param.rs:3:8
|
LL | fn foo<const SIZE: usize = 5usize>() {}
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Up @@ -17,7 +17,7 @@ note: trait defined here, with 1 generic parameter: `N`
--> $DIR/issue-89013-no-kw.rs:1:7
|
LL | trait Foo<const N: usize> {
| ^^^ -
| ^^^ --------------
help: add missing generic argument
|
LL | impl Foo<N, N = 3> for Bar {
Expand Down
Expand Up @@ -29,7 +29,7 @@ note: trait defined here, with 1 generic parameter: `N`
--> $DIR/issue-89013.rs:1:7
|
LL | trait Foo<const N: usize> {
| ^^^ -
| ^^^ --------------
help: add missing generic argument
|
LL | impl Foo<N, N = const 3> for Bar {
Expand Down
Expand Up @@ -2,7 +2,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
--> $DIR/feature-gate-default_type_parameter_fallback.rs:3:8
|
LL | fn avg<T=i32>(_: T) {}
| ^
| ^^^^^
|
= note: `#[deny(invalid_type_param_default)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand All @@ -12,7 +12,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
--> $DIR/feature-gate-default_type_parameter_fallback.rs:8:6
|
LL | impl<T=i32> S<T> {}
| ^
| ^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
Expand Down
Expand Up @@ -10,7 +10,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A`
--> $DIR/generic-impl-more-params-with-defaults.rs:5:8
|
LL | struct Vec<T, A = Heap>(
| ^^^ - -
| ^^^ - --------

error: aborting due to previous error

Expand Down
Expand Up @@ -10,7 +10,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A`
--> $DIR/generic-type-more-params-with-defaults.rs:5:8
|
LL | struct Vec<T, A = Heap>(
| ^^^ - -
| ^^^ - --------

error: aborting due to previous error

Expand Down
Expand Up @@ -9,7 +9,7 @@ note: required by a bound in `Tsized`
--> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14
|
LL | trait Tsized<P: Sized = [Self]> {}
| ^ required by this bound in `Tsized`
| ^^^^^^^^^^^^^^^^^ required by this bound in `Tsized`

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/generics/wrong-number-of-args.stderr
Expand Up @@ -287,7 +287,7 @@ note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C`
--> $DIR/wrong-number-of-args.rs:78:12
|
LL | struct Ty<A, B, C = &'static str>;
| ^^ - - -
| ^^ - - ----------------

error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied
--> $DIR/wrong-number-of-args.rs:96:14
Expand Down Expand Up @@ -922,7 +922,7 @@ note: struct defined here, with at most 3 generic parameters: `K`, `V`, `S`
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
|
LL | pub struct HashMap<K, V, S = RandomState> {
| ^^^^^^^ - - -
| ^^^^^^^ - - ---------------

error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied
--> $DIR/wrong-number-of-args.rs:319:18
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/impl-trait/where-allowed.stderr
Expand Up @@ -293,7 +293,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
--> $DIR/where-allowed.rs:234:7
|
LL | impl <T = impl Debug> T {}
| ^
| ^^^^^^^^^^^^^^
|
= note: `#[deny(invalid_type_param_default)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand All @@ -303,7 +303,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
--> $DIR/where-allowed.rs:241:36
|
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
| ^
| ^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-78957.stderr
Expand Up @@ -2,13 +2,13 @@ error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-78957.rs:5:16
|
LL | pub struct Foo<#[inline] const N: usize>;
| ^^^^^^^^^ - not a function or closure
| ^^^^^^^^^ -------------- not a function or closure

error: attribute should be applied to a function
--> $DIR/issue-78957.rs:7:16
|
LL | pub struct Bar<#[cold] const N: usize>;
| ^^^^^^^ - not a function
| ^^^^^^^ -------------- not a function
|
note: the lint level is defined here
--> $DIR/issue-78957.rs:1:9
Expand All @@ -21,7 +21,7 @@ error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-78957.rs:10:23
|
LL | pub struct Baz<#[repr(C)] const N: usize>;
| ^ - not a struct, enum, or union
| ^ -------------- not a struct, enum, or union

error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-78957.rs:13:17
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/mir/thir-constparam-temp.stderr
Expand Up @@ -13,10 +13,10 @@ note: mutable reference created due to call to this method
LL | fn mut_self(&mut self) {}
| ^^^^^^^^^^^^^^^^^^^^^^
note: `const` item defined here
--> $DIR/thir-constparam-temp.rs:13:14
--> $DIR/thir-constparam-temp.rs:13:8
|
LL | fn foo<const YIKES: Yikes>() {
| ^^^^^
| ^^^^^^^^^^^^^^^^^^

warning: 1 warning emitted

Expand Up @@ -99,10 +99,10 @@ LL | impl X<{ N }> {}
| + +

error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/missing-type-parameter2.rs:6:15
--> $DIR/missing-type-parameter2.rs:6:9
|
LL | impl<T, const A: u8 = 2> X<N> {}
| ^
| ^^^^^^^^^^^^^^^

error[E0747]: unresolved item provided when a constant was expected
--> $DIR/missing-type-parameter2.rs:6:28
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/polymorphization/const_parameters/closures.stderr
Expand Up @@ -11,7 +11,7 @@ error: item has unused generic parameters
--> $DIR/closures.rs:19:19
|
LL | pub fn unused<const T: usize>() -> usize {
| - generic parameter `T` is unused
| -------------- generic parameter `T` is unused
LL |
LL | let add_one = |x: usize| x + 1;
| ^^^^^^^^^^^^^^^^
Expand All @@ -20,13 +20,13 @@ error: item has unused generic parameters
--> $DIR/closures.rs:17:8
|
LL | pub fn unused<const T: usize>() -> usize {
| ^^^^^^ - generic parameter `T` is unused
| ^^^^^^ -------------- generic parameter `T` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:28:19
|
LL | pub fn used_parent<const T: usize>() -> usize {
| - generic parameter `T` is unused
| -------------- generic parameter `T` is unused
LL | let x: usize = T;
LL | let add_one = |x: usize| x + 1;
| ^^^^^^^^^^^^^^^^
Expand All @@ -35,7 +35,7 @@ error: item has unused generic parameters
--> $DIR/closures.rs:48:13
|
LL | pub fn unused_upvar<const T: usize>() -> usize {
| - generic parameter `T` is unused
| -------------- generic parameter `T` is unused
LL | let x: usize = T;
LL | let y = || x;
| ^^^^
Expand Down
Expand Up @@ -11,7 +11,7 @@ error: item has unused generic parameters
--> $DIR/functions.rs:15:8
|
LL | pub fn unused<const T: usize>() {
| ^^^^^^ - generic parameter `T` is unused
| ^^^^^^ -------------- generic parameter `T` is unused

error: aborting due to previous error; 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/polymorphization/generators.stderr
Expand Up @@ -23,7 +23,7 @@ error: item has unused generic parameters
--> $DIR/generators.rs:60:5
|
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
| - generic parameter `T` is unused
| ------------ generic parameter `T` is unused
LL | / || {
LL | |
LL | | yield 1;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/save-analysis/issue-89066.stderr
Expand Up @@ -31,7 +31,7 @@ note: struct defined here, with 2 generic parameters: `T`, `N`
--> $DIR/issue-89066.rs:8:8
|
LL | struct All<'a, T, const N: usize> {
| ^^^ - -
| ^^^ - --------------

error: aborting due to 4 previous errors

Expand Down
@@ -0,0 +1,10 @@
// run-rustfix
// https://github.com/rust-lang/rust/issues/95616

fn buggy_const<'a, const N: usize>(_a: &'a Option<[u8; N]>, _f: &'a str) -> &'a str { //~ERROR [E0106]
return "";
}

fn main() {
buggy_const(&Some([69,69,69,69,0]), "test");
}
@@ -0,0 +1,10 @@
// run-rustfix
// https://github.com/rust-lang/rust/issues/95616

fn buggy_const<const N: usize>(_a: &Option<[u8; N]>, _f: &str) -> &str { //~ERROR [E0106]
return "";
}

fn main() {
buggy_const(&Some([69,69,69,69,0]), "test");
}

0 comments on commit 33b0fba

Please sign in to comment.