diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-12-12 21:15:19 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-12-24 22:10:15 -0800 |
| commit | 66ea471f9d4a14e5af72e86ee7b12ed9d9fa3ca5 (patch) | |
| tree | 79a5b8c8da979a43daffd60cd0bcd68e625e8280 /src/librustc_error_codes | |
| parent | 8e74f630546676e0a40e8f5debac531a8e44912a (diff) | |
| download | rust-66ea471f9d4a14e5af72e86ee7b12ed9d9fa3ca5.tar.gz rust-66ea471f9d4a14e5af72e86ee7b12ed9d9fa3ca5.zip | |
Handle more specific case E0222
Diffstat (limited to 'src/librustc_error_codes')
| -rw-r--r-- | src/librustc_error_codes/error_codes.rs | 3 | ||||
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0222.md | 51 |
2 files changed, 52 insertions, 2 deletions
diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index fbcc976bd49..18d58d9d19e 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -116,6 +116,7 @@ E0211: include_str!("./error_codes/E0211.md"), E0214: include_str!("./error_codes/E0214.md"), E0220: include_str!("./error_codes/E0220.md"), E0221: include_str!("./error_codes/E0221.md"), +E0222: include_str!("./error_codes/E0222.md"), E0223: include_str!("./error_codes/E0223.md"), E0225: include_str!("./error_codes/E0225.md"), E0229: include_str!("./error_codes/E0229.md"), @@ -457,8 +458,6 @@ E0745: include_str!("./error_codes/E0745.md"), // E0217, // ambiguous associated type, defined in multiple supertraits // E0218, // no associated type defined // E0219, // associated type defined in higher-ranked supertrait -// E0222, // Error code E0045 (variadic function must have C or cdecl calling - // convention) duplicate E0224, // at least one non-builtin train is required for an object type E0226, // only a single explicit lifetime bound is permitted E0227, // ambiguous lifetime bound, explicit lifetime bound required diff --git a/src/librustc_error_codes/error_codes/E0222.md b/src/librustc_error_codes/error_codes/E0222.md new file mode 100644 index 00000000000..66b6c4d712b --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0222.md @@ -0,0 +1,51 @@ +An attempt was made to constrain an associated type. +For example: + +```compile_fail,E0222 +pub trait Vehicle { + type Color; +} + +pub trait Box { + type Color; +} + +pub trait BoxCar : Box + Vehicle {} + +fn dent_object<COLOR>(c: dyn BoxCar<Color=COLOR>) {} // Invalid constraint +``` + +In this example, `BoxCar` has two super-traits: `Vehicle` and `Box`. Both of +these traits define an associated type `Color`. `BoxCar` inherits two types +with that name from both super-traits. Because of this, we need to use the +fully qualified path syntax to refer to the appropriate `Color` associated +type, either `<BoxCar as Vehicle>::Color` or `<BoxCar as Box>::Color`, but this +syntax is not allowed to be used in a function signature. + +In order to encode this kind of constraint, a `where` clause and a new type +parameter are needed: + +``` +pub trait Vehicle { + type Color; +} + +pub trait Box { + type Color; +} + +pub trait BoxCar : Box + Vehicle {} + +// Introduce a new `CAR` type parameter +fn foo<CAR, COLOR>( + c: CAR, +) where + // Bind the type parameter `CAR` to the trait `BoxCar` + CAR: BoxCar, + // Further restrict `<BoxCar as Vehicle>::Color` to be the same as the + // type parameter `COLOR` + CAR: Vehicle<Color = COLOR>, + // We can also simultaneously restrict the other trait's associated type + CAR: Box<Color = COLOR> +{} +``` |
